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.KwtLogisticsOrderContractMapper;
import com.sckw.transport.model.KwtLogisticsOrderContract;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 物流订单和物流合同关联接口
 * @create :2025-11-08 10:41:00
 */
@Repository
public class KwtLogisticsOrderContractRepository extends ServiceImpl<KwtLogisticsOrderContractMapper,
        KwtLogisticsOrderContract> {
    public List<KwtLogisticsOrderContract> queryByLogOrderIds(Set<Long> logOrderIds) {
        return list(Wrappers.<KwtLogisticsOrderContract>lambdaQuery()
                .eq(KwtLogisticsOrderContract::getDelFlag,0)
                .in(KwtLogisticsOrderContract::getLOrderId,logOrderIds));
    }
    public KwtLogisticsOrderContract queryByLogOrderId(Long logOrderId) {
        return getOne(Wrappers.<KwtLogisticsOrderContract>lambdaQuery()
                .eq(KwtLogisticsOrderContract::getDelFlag,0)
                .eq(KwtLogisticsOrderContract::getLOrderId,logOrderId)
                .orderByDesc(KwtLogisticsOrderContract::getId)
                .last("limit 1"));
    }

    public List<KwtLogisticsOrderContract> queryByContractId(Long contractId ) {
        return list(Wrappers.<KwtLogisticsOrderContract>lambdaQuery()
                .eq(KwtLogisticsOrderContract::getDelFlag,0)
                .eq(KwtLogisticsOrderContract::getContractId,contractId)
                .select(KwtLogisticsOrderContract::getId,KwtLogisticsOrderContract::getContractId,KwtLogisticsOrderContract::getLOrderId));
    }

    public List<KwtLogisticsOrderContract> queryByLogContractIds(Set<Long> logContractIds) {
        return list(Wrappers.<KwtLogisticsOrderContract>lambdaQuery()
                .eq(KwtLogisticsOrderContract::getDelFlag,0)
                .in(KwtLogisticsOrderContract::getContractId,logContractIds));
    }
}
