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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.domain.sale.classify.BdSpecs;
import com.hzs.common.domain.sale.postage.BdPostage;
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;

/**
 * <p>
 * 产品规格表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2022-08-27
 */
@Service
public class BdSpecsServiceImpl extends ServiceImpl<BdSpecsMapper, BdSpecs> implements IBdSpecsService {
    @Autowired
    private RedisService redisService;

    /**
     * 根据id查询产品规格表
     * @param specsId
     * @return
     */
    @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) {
        QueryWrapper<BdSpecs> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(SystemFieldConstants.PK_ID, idList);
        return baseMapper.selectList(queryWrapper);
    }
}
