package com.sckw.order.serivce;

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

import java.util.List;

/**
 * @desc: 交易订单状态记录信息service
 * @author: yzc
 * @date: 2023-06-25 14:28
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class KwoTradeOrderTrackService {

    private final KwoTradeOrderTrackMapper kwoTradeOrderTrackMapper;

    /**
     * @desc: 插入
     * @author: yzc
     * @date: 2023-07-13 9:51
     * @Param goods:
     * @return: void
     */
    public void insert(KwoTradeOrderTrack track) {
        kwoTradeOrderTrackMapper.insert(track);
    }

    /**
     * @desc: 根据订单id获取
     * @author: yzc
     * @date: 2023-08-18 11:02
     * @Param orderId:
     * @return: java.util.List<com.sckw.order.model.KwoTradeOrderTrack>
     */
    public List<KwoTradeOrderTrack> getByOrderId(Long orderId) {
        LambdaQueryWrapper<KwoTradeOrderTrack> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KwoTradeOrderTrack::getTOrderId, orderId)
                .eq(KwoTradeOrderTrack::getDelFlag, Global.NO)
                .orderByDesc(KwoTradeOrderTrack::getCreateTime);
        List<KwoTradeOrderTrack> list = kwoTradeOrderTrackMapper.selectList(wrapper);
        return CollectionUtils.emptyIfNull(list);
    }

    /**
     * @desc: 根据订单id获取
     * @author: yzc
     * @date: 2023-07-14 18:01
     * @Param orderId:
     * @Param status:
     * @return: com.sckw.order.model.KwoTradeOrderTrack
     */
    public KwoTradeOrderTrack getByOrderId(Long orderId, Integer status) {
        LambdaQueryWrapper<KwoTradeOrderTrack> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KwoTradeOrderTrack::getTOrderId, orderId).eq(KwoTradeOrderTrack::getStatus, status)
                .eq(KwoTradeOrderTrack::getDelFlag, Global.NO).last("LIMIT 1");
        return kwoTradeOrderTrackMapper.selectOne(wrapper);
    }

    /**
     * @desc: 批量插入
     * @author: yzc
     * @date: 2023-07-20 14:21
     * @Param tracks:
     * @return: void
     */
    public void insertBatch(List<KwoTradeOrderTrack> tracks) {
        kwoTradeOrderTrackMapper.insertBatch(tracks);
    }
}
