package com.sckw.transport.repository;

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

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

/**
 * @Author: 门卫车辆订单
 * @CreateTime: 2025-10-12
 * @Description:
 * @Version: 1.0
 */

@Repository
public class KwtGatekeeperWaybillOrderRepository extends ServiceImpl<KwtGatekeeperWaybillOrderMapper, KwtGatekeeperWaybillOrder> {


    public List<KwtGatekeeperWaybillOrder> queryGatekeeperWaybillOrderByWOrderIds(List<Long> wOrderIds) {
        return list(
                Wrappers.<KwtGatekeeperWaybillOrder>lambdaQuery()
                        .in(KwtGatekeeperWaybillOrder::getWOrderId, wOrderIds)
                        .orderByDesc(KwtGatekeeperWaybillOrder::getId));
    }

    public List<KwtGatekeeperWaybillOrder> queryGatekeeperWaybillOrderByLogOrderIds(List<Long> logOrderIds) {
        return list(
                Wrappers.<KwtGatekeeperWaybillOrder>lambdaQuery()
                        .in(KwtGatekeeperWaybillOrder::getLOrderId, logOrderIds)
                        .orderByDesc(KwtGatekeeperWaybillOrder::getId));
    }

    public KwtGatekeeperWaybillOrder queryGatekeeperWaybillOrderByWOrderId(Long wOrderId, Integer type) {
        return getOne(
                Wrappers.<KwtGatekeeperWaybillOrder>lambdaQuery()
                        .eq(KwtGatekeeperWaybillOrder::getWOrderId, wOrderId)
                        .eq(KwtGatekeeperWaybillOrder::getType, type)
                        .orderByDesc(KwtGatekeeperWaybillOrder::getId)
                        .last("limit 1"));
    }

    public List<KwtGatekeeperWaybillOrder> queryGatekeeperWaybillOrderByEntId(Set<Long> waybillOrderIds, List<Integer> status) {
        return list(
                Wrappers.<KwtGatekeeperWaybillOrder>lambdaQuery()
                        .in(CollectionUtils.isNotEmpty(waybillOrderIds), KwtGatekeeperWaybillOrder::getWOrderId, waybillOrderIds)
                        .in(KwtGatekeeperWaybillOrder::getStatus, status)
                        .orderByDesc(KwtGatekeeperWaybillOrder::getId));
    }

}