package com.sckw.product.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.product.dao.KwpGoodsMapper;
import com.sckw.product.model.KwpGoods;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 商品接口
 * @create :2025-11-04 15:50:00
 */
@Repository
public class KwpGoodsRepository extends ServiceImpl<KwpGoodsMapper, KwpGoods> {
    public List<KwpGoods> queryByEntIdAndGoodsName(Long entId, String goodsName) {
        return list(Wrappers.<KwpGoods>lambdaQuery()
                .eq(KwpGoods::getDelFlag,0)
                .eq(Objects.nonNull(entId),KwpGoods::getEntId,entId)
                .like(StringUtils.isNotBlank(goodsName),KwpGoods::getName,goodsName));

    }

    public List<KwpGoods> queryByGoodsNameAndTypeAndDesc(String goodsName, String goodsType, String goodsSpec) {
        return list(Wrappers.<KwpGoods>lambdaQuery()
                .eq(KwpGoods::getDelFlag,0)
                .like(StringUtils.isNotBlank(goodsName),KwpGoods::getName,goodsName)
                .like(StringUtils.isNotBlank(goodsType),KwpGoods::getGoodsType,goodsType)
                .like(StringUtils.isNotBlank(goodsSpec),KwpGoods::getSpec,goodsSpec));
    }

    public List<KwpGoods> queryByGoodsName(String goodsName) {
        return list(Wrappers.<KwpGoods>lambdaQuery()
                .eq(KwpGoods::getDelFlag,0)
                .like(StringUtils.isNotBlank(goodsName),KwpGoods::getName,goodsName));
    }

    public List<KwpGoods> queryGoodsByEntId(Long entId) {
        return list(Wrappers.<KwpGoods>lambdaQuery()
                .eq(KwpGoods::getEntId,entId)
                .eq(KwpGoods::getDelFlag,0));
    }
}
