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

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

/**
 * @author PC
 */
@Repository
public class KwtLogisticsOrderUnitRepository extends ServiceImpl<KwtLogisticsOrderUnitMapper, KwtLogisticsOrderUnit> {
    public KwtLogisticsOrderUnit queryByLOrderIdAndUnitType(Long lOrderId, int unitType) {
        return getOne(Wrappers.<KwtLogisticsOrderUnit>lambdaQuery()
                .eq(KwtLogisticsOrderUnit::getDelFlag,0)
                .eq(KwtLogisticsOrderUnit::getLOrderId,lOrderId)
                .eq(KwtLogisticsOrderUnit::getUnitType,unitType)
                .orderByDesc(KwtLogisticsOrderUnit::getId)
                .last("limit 1"));
    }

    public List<KwtLogisticsOrderUnit> queryByLOrderIdsAndUnitType(Set<Long> lOrderIds, int unitType) {
        return list(Wrappers.<KwtLogisticsOrderUnit>lambdaQuery()
                .eq(KwtLogisticsOrderUnit::getDelFlag,0)
                .in(KwtLogisticsOrderUnit::getLOrderId,lOrderIds)
                .eq(KwtLogisticsOrderUnit::getUnitType,unitType));
    }
}
