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

import java.util.List;

/**
 * @Author: 马超伟
 * @CreateTime: 2025-10-12
 * @Description:
 * @Version: 1.0
 */

@Repository
public class KwtForkliftWaybillOrderRepository extends ServiceImpl<KwtForkliftWaybillOrderMapper, KwtForkliftWaybillOrder> {

    public KwtForkliftWaybillOrder queryForkliftWaybillOrderByWOrderId(Long wOrderId, Long driverId) {
        return getOne(Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
                .eq(KwtForkliftWaybillOrder::getWOrderId, wOrderId)
                .eq(KwtForkliftWaybillOrder::getDriverId, driverId)
                .eq(KwtForkliftWaybillOrder::getStatus,5)
                .orderByDesc(KwtForkliftWaybillOrder::getId)
                .last("limit 1"));
    }

    public List<KwtForkliftWaybillOrder> queryForkliftWaybillOrderByWOrderIds(List<Long> wOrderIds, Long driverId) {
        return list(
                Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
                        .in(KwtForkliftWaybillOrder::getWOrderId, wOrderIds)
                        .eq(driverId != null, KwtForkliftWaybillOrder::getDriverId, driverId)
                        .orderByDesc(KwtForkliftWaybillOrder::getId));
    }

    public List<KwtForkliftWaybillOrder> queryForkliftWaybillOrderByLogOrderIds(List<Long> logOrderIds, Long driverId) {
        return list(
                Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
                        .in(KwtForkliftWaybillOrder::getLOrderId, logOrderIds)
                        .eq(driverId != null, KwtForkliftWaybillOrder::getDriverId, driverId)
                        .orderByDesc(KwtForkliftWaybillOrder::getId));
    }

    public KwtForkliftWaybillOrder queryForkliftWaybillOrderByFOrderId(Long forkliftId) {
        return getOne(Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
                .eq(KwtForkliftWaybillOrder::getId, forkliftId)
                .orderByDesc(KwtForkliftWaybillOrder::getId)
                .last("limit 1"));
    }

    public KwtForkliftWaybillOrder queryForkliftWaybillOrderByWOrderId(Long wOrderId) {
        return getOne(Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
                .eq(KwtForkliftWaybillOrder::getWOrderId, wOrderId)
                .orderByDesc(KwtForkliftWaybillOrder::getId)
                .last("limit 1"));
    }

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

    public List<KwtForkliftWaybillOrder> queryForkliftWaybillOrdersByWOrderId(Long wOrderId) {
        return list(Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
                .eq(KwtForkliftWaybillOrder::getWOrderId, wOrderId)
                .orderByDesc(KwtForkliftWaybillOrder::getId)
                .orderByDesc(KwtForkliftWaybillOrder::getCreateTime));
    }





}