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

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

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 物流商品相关接口
 * @create :2025-11-11 09:42:00
 */
@Repository
public class KwtLogisticsOrderGoodsRepository extends ServiceImpl<KwtLogisticsOrderGoodsMapper, KwtLogisticsOrderGoods> {
    public List<KwtLogisticsOrderGoods> queryByGoodsName(String goodsName) {
        return list(Wrappers.<KwtLogisticsOrderGoods>lambdaQuery()
                .eq(KwtLogisticsOrderGoods::getDelFlag,0)
                .like(KwtLogisticsOrderGoods::getGoodsName,goodsName));
    }

    public List<KwtLogisticsOrderGoods> queryByLogOrderIds(List<Long> logOrderIdList) {
        return list(Wrappers.<KwtLogisticsOrderGoods>lambdaQuery()
                .eq(KwtLogisticsOrderGoods::getDelFlag,0)
                .in(KwtLogisticsOrderGoods::getLOrderId,logOrderIdList)
        );
    }

    public KwtLogisticsOrderGoods queryByLogOrderId(Long logOrderId) {
        return getOne(Wrappers.<KwtLogisticsOrderGoods>lambdaQuery()
                .eq(KwtLogisticsOrderGoods::getLOrderId,logOrderId)
                .eq(KwtLogisticsOrderGoods::getDelFlag,0)
                .orderByDesc(KwtLogisticsOrderGoods::getId)
                .last("limit 1")
        );
    }

    public List<KwtLogisticsOrderGoods> queryByGoodsIds(Set<Long> goodsIds) {
        return list(Wrappers.<KwtLogisticsOrderGoods>lambdaQuery()
                .eq(KwtLogisticsOrderGoods::getDelFlag,0)
                .in(KwtLogisticsOrderGoods::getGoodsId,goodsIds)
        );
    }

    public List<KwtLogisticsOrderGoods> queryByLogIds(List<Long> logIds) {
        return list(Wrappers.<KwtLogisticsOrderGoods>lambdaQuery()
                .eq(KwtLogisticsOrderGoods::getDelFlag,0)
                .in(KwtLogisticsOrderGoods::getLOrderId,logIds)
        );
    }

    /**
     * 根据物流订单ID列表查询
     */
    public List<KwtLogisticsOrderGoods> queryByLOrderIds(List<Long> lOrderIds) {
        return list(Wrappers.<KwtLogisticsOrderGoods>lambdaQuery()
                .eq(KwtLogisticsOrderGoods::getDelFlag, 0)
                .in(KwtLogisticsOrderGoods::getLOrderId, lOrderIds));
    }
}
