package com.sckw.transport.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.transport.dao.KwtWaybillOrderTicketMapper;
import com.sckw.transport.model.KwtWaybillOrderTicket;
import org.springframework.stereotype.Repository;

import java.util.List;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author PC
 * @author :chenXiaoFei
 * @version :1.0
 * @description :
 * @create :2025-11-17 09:25:00
 */
@Repository
public class KwtWaybillOrderTicketRepository extends ServiceImpl<KwtWaybillOrderTicketMapper, KwtWaybillOrderTicket> {

    public List<KwtWaybillOrderTicket> queryByWOrderId(Long wOrderId) {
        return list(Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .eq(KwtWaybillOrderTicket::getWOrderId,wOrderId)
                .eq(KwtWaybillOrderTicket::getDelFlag,0));
    }

    public KwtWaybillOrderTicket queryByWOrderIdByIdAndType(Long wOrderId, Integer type) {
        return getOne(Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .eq(KwtWaybillOrderTicket::getWOrderId, wOrderId)
                .eq(KwtWaybillOrderTicket::getType, type)
                .eq(KwtWaybillOrderTicket::getDelFlag,0)
                .last("limit 1"));
    }

    public List<KwtWaybillOrderTicket> queryByAddressIds(Set<Long> addressIds) {
        return list(Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .eq(KwtWaybillOrderTicket::getDelFlag,0)
                .in(KwtWaybillOrderTicket::getWAddressId, addressIds)) ;
    }

    public Boolean updateByBillOrderIdAndType(KwtWaybillOrderTicket kwtWaybillOrderTicket,Integer  type) {
        return update(kwtWaybillOrderTicket, Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .eq(KwtWaybillOrderTicket::getWOrderId, kwtWaybillOrderTicket.getWOrderId())
                .eq(KwtWaybillOrderTicket::getType, type));
    }


    public List<KwtWaybillOrderTicket> queryByOperateTime(Date loadStartTime, Date loadEndTime,Integer  type) {
        return list(Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .eq(KwtWaybillOrderTicket::getDelFlag,0)
                .eq(KwtWaybillOrderTicket::getType, type)
                .between(KwtWaybillOrderTicket::getOperateTime, loadStartTime, loadEndTime));
    }

    public List<KwtWaybillOrderTicket> queryByWOrderIds(List<Long> wOrderIds) {
        return list(Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .in(KwtWaybillOrderTicket::getWOrderId, wOrderIds)
                .eq(KwtWaybillOrderTicket::getDelFlag, 0));
    }

    public List<KwtWaybillOrderTicket> queryByWOrderIdsAndType(List<Long> wOrderIds, Integer type) {
        return list(Wrappers.<KwtWaybillOrderTicket>lambdaQuery()
                .in(KwtWaybillOrderTicket::getWOrderId, wOrderIds)
                .eq(KwtWaybillOrderTicket::getType, type)
                .eq(KwtWaybillOrderTicket::getDelFlag, 0));
    }


}
