/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.delivery.comment.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.Transport2;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.delivery.comment.dao.Transport2Mapper;
import com.yami.shop.delivery.comment.param.ShopTransport;
import com.yami.shop.delivery.comment.service.Transport2Service;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lgh on 2018/11/16.
 */
@Service
@AllArgsConstructor
public class Transport2ServiceImpl extends ServiceImpl<Transport2Mapper, Transport2> implements Transport2Service {

    private final Transport2Mapper transportMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertTransportAndTransfee(Transport2 transport) {

        // 插入运费模板
        transportMapper.insert(transport);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @CacheEvict(cacheNames = "TransportAndAllItems", key = "#transport.transportId")
    public void updateTransportAndTransfee(Transport2 transport) {


        // 更新运费模板
        transportMapper.updateById(transport);

    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteTransportAndTransfeeAndTranscity(Long[] ids) {

        // 删除运费模板
        transportMapper.deleteTransports(ids);
    }


    @Override
    @Cacheable(cacheNames = "TransportAndAllItems", key = "#transportId")
    public Transport2 getTransportAndAllItems(Long transportId) {
        Transport2 transport = transportMapper.findByTransportId(transportId);
        if (transport == null) {
            return null;
        }
        return transport;
    }

    @Override
    public Transport2 findByDistance(Long shopId, Double distance) {
        return transportMapper.getTransport(shopId, distance);
    }
    @Override
    public Transport2 findByDistance(Long shopId, Integer platform) {
        return transportMapper.getTransportShopPlatform(shopId, platform);
    }

    @Override
    public Transport2 findByPlatform(Long channelId) {
        return transportMapper.findByPlatform(channelId);
    }

    @Override
    public Transport2 findByDistance(Long shopId, Double distance, Double weight) {
        return transportMapper.getTransportWeight(shopId, distance,weight);
    }

    @Override
    public ShopTransport findShopTransports(Long shopId) {
        ShopTransport shopTransports = transportMapper.findShopTransports(shopId);
        return shopTransports;
    }

    @Override
    public Transport2 queryTransport2ByChannelId(Long channelId) {
        return transportMapper.findByPlatform(channelId);
    }

    @Override
    public IPage<Transport2> transport2List(PageParam<Transport2> page) {
        return  transportMapper.transport2List(page);
    }
}
