package com.hzs.sale.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.domain.sale.classify.BdSpecs;
import com.hzs.sale.product.mapper.BdSpecsMapper;
import com.hzs.sale.product.service.IBdSpecsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品规格表 服务实现类
 */
@Service
public class BdSpecsServiceImpl extends ServiceImpl<BdSpecsMapper, BdSpecs> implements IBdSpecsService {

    @Autowired
    private RedisService redisService;

    @Override
    public BdSpecs getSpecs(Integer specsId) {
        String redisKey = CacheConstants.BD_SPECS + specsId;
        BdSpecs specs = redisService.getCacheObject(redisKey);
        if (null == specs) {
            specs = baseMapper.selectById(specsId);
            if (null != specs) {
                redisService.setCacheObject(redisKey, specs);
            }
        }
        return specs;
    }

    @Override
    public List<BdSpecs> queryBdSpecsByIdList(List<Integer> idList) {
        LambdaQueryWrapper<BdSpecs> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BdSpecs::getPkId, idList);
        return baseMapper.selectList(queryWrapper);
    }

}
