package com.sckw.order.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.core.model.base.BaseModel;
import com.sckw.order.dao.KwoTradeOrderGoodsMapper;
import com.sckw.order.model.KwoTradeOrderGoods;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

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

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 贸易订单商品接口
 * @create :2025-11-07 09:51:00
 */
@Repository
public class KwoTradeOrderGoodsRepository extends ServiceImpl<KwoTradeOrderGoodsMapper, KwoTradeOrderGoods> {
    public List<KwoTradeOrderGoods> queryByCondition(KwoTradeOrderGoods kwoTradeOrderGoods) {
        return list(Wrappers.<KwoTradeOrderGoods>lambdaQuery()
                .eq(BaseModel::getDelFlag, 0)
                .like(StringUtils.isNotBlank(kwoTradeOrderGoods.getGoodsName()),KwoTradeOrderGoods::getGoodsName,
                kwoTradeOrderGoods.getGoodsName()));
    }

    public List<KwoTradeOrderGoods> queryByOrderIds(Set<Long> tradeOrderIds) {
        return list(Wrappers.<KwoTradeOrderGoods>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .in(KwoTradeOrderGoods::getTOrderId,tradeOrderIds));
    }

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

    public KwoTradeOrderGoods queryByOrderId(Long tradeOrderId) {
        return getOne(Wrappers.<KwoTradeOrderGoods>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .eq(KwoTradeOrderGoods::getTOrderId,tradeOrderId)
                .orderByDesc(BaseModel::getId)
                .last("limit 1"));
    }
}
