package com.sckw.order.serivce;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sckw.core.model.constant.Global;
import com.sckw.core.utils.CollectionUtils;
import com.sckw.order.dao.KwoTradeOrderAddressMapper;
import com.sckw.order.model.KwoTradeOrderAddress;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * @desc: 交易订单装卸货地址信息service
 * @author: yzc
 * @date: 2023-06-25 14:28
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class KwoTradeOrderAddressService {

    private final KwoTradeOrderAddressMapper kwoTradeOrderAddressMapper;

    /**
     * @desc: 批量插入
     * @author: yzc
     * @date: 2023-07-13 9:52
     * @Param list:
     * @return: void
     */
    public void insertBatch(List<KwoTradeOrderAddress> list) {
        kwoTradeOrderAddressMapper.insertBatch(list);
    }

    /**
     * @desc: 根据orderId删除
     * @author: yzc
     * @date: 2023-07-14 14:49
     * @Param orderId:
     * @return: void
     */
    public void delByOrderId(Long orderId) {
        LambdaUpdateWrapper<KwoTradeOrderAddress> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(KwoTradeOrderAddress::getTOrderId, orderId).eq(KwoTradeOrderAddress::getDelFlag, Global.NO)
                .set(KwoTradeOrderAddress::getDelFlag, Global.YES);
        kwoTradeOrderAddressMapper.update(null, wrapper);
    }

    /**
     * @desc: 根据orderId获取
     * @author: yzc
     * @date: 2023-07-18 11:24
     * @Param torderId:
     * @return: java.util.List<com.sckw.order.model.KwoTradeOrderAddress>
     */
    public List<KwoTradeOrderAddress> getByOrderId(Long torderId) {
        LambdaQueryWrapper<KwoTradeOrderAddress> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KwoTradeOrderAddress::getTOrderId, torderId).eq(KwoTradeOrderAddress::getDelFlag, Global.NO);
        List<KwoTradeOrderAddress> list = kwoTradeOrderAddressMapper.selectList(wrapper);
        return CollectionUtils.emptyIfNull(list);
    }

    /**
     * @desc: 根据orderIds删除
     * @author: yzc
     * @date: 2023-07-18 16:50
     * @Param orderIds:
     * @return: void
     */
    public void delByOrderIds(List<Long> orderIds) {
        LambdaUpdateWrapper<KwoTradeOrderAddress> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(KwoTradeOrderAddress::getTOrderId, orderIds).eq(KwoTradeOrderAddress::getDelFlag, Global.NO)
                .set(KwoTradeOrderAddress::getDelFlag, Global.YES);
        kwoTradeOrderAddressMapper.update(null, wrapper);
    }

    /**
     * @desc: 根据orderIds查询
     * @author: yzc
     * @date: 2023-08-02 18:11
     * @Param tOrderIds:
     * @return: java.util.List<com.sckw.order.model.KwoTradeOrderAddress>
     */
    public List<KwoTradeOrderAddress> getByOrderIds(Collection<Long> tOrderIds) {
        LambdaQueryWrapper<KwoTradeOrderAddress> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(KwoTradeOrderAddress::getTOrderId, tOrderIds).eq(KwoTradeOrderAddress::getDelFlag, Global.NO);
        List<KwoTradeOrderAddress> list = kwoTradeOrderAddressMapper.selectList(wrapper);
        return CollectionUtils.emptyIfNull(list);
    }
}
