package com.sckw.product.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sckw.core.model.constant.Global;
import com.sckw.product.dao.KwpGoodsAttributeMapper;
import com.sckw.product.model.KwpGoodsAttribute;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc: 商品-参数类目service
 * @author: yzc
 * @date: 2023-06-25 14:47
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class KwpGoodsAttributeService {

    private final KwpGoodsAttributeMapper kwpGoodsAttributeMapper;

    /**
     * @desc: 批量插入
     * @author: yzc
     * @date: 2023-07-05 11:21
     * @Param list:
     * @return: void
     */
    public void insertBatch(List<KwpGoodsAttribute> list) {
        kwpGoodsAttributeMapper.insertBatch(list);
    }

    /**
     * @desc: 通过商品id获取
     * @author: yzc
     * @date: 2023-07-05 14:44
     * @Param id:
     * @return: java.util.List<com.sckw.product.model.KwpGoodsAttribute>
     */
    public List<KwpGoodsAttribute> getByGoodsId(Long goodsId) {
        LambdaQueryWrapper<KwpGoodsAttribute> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KwpGoodsAttribute::getGoodsId, goodsId).eq(KwpGoodsAttribute::getDelFlag, Global.NO);
        return kwpGoodsAttributeMapper.selectList(wrapper);
    }

    /**
     * @desc: 删除商品相关属性
     * @author: yzc
     * @date: 2023-07-06 15:00
     * @Param goodsIds:
     * @return: void
     */
    public void delByGoodsIds(List<Long> goodsIds) {
        LambdaUpdateWrapper<KwpGoodsAttribute> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(KwpGoodsAttribute::getGoodsId, goodsIds).eq(KwpGoodsAttribute::getDelFlag, Global.NO)
                .set(KwpGoodsAttribute::getDelFlag, Global.YES);
        kwpGoodsAttributeMapper.update(null, wrapper);
    }
}
