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


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.wares.BdWares;
import com.hzs.common.domain.sale.wares.BdWaresSpecs;
import com.hzs.sale.wares.mapper.BdWaresSpecsMapper;
import com.hzs.sale.wares.service.IBdWaresSpecsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 规格明细表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2022-09-09
 */
@Service
public class BdWaresSpecsServiceImpl extends ServiceImpl<BdWaresSpecsMapper, BdWaresSpecs> implements IBdWaresSpecsService {
    @Autowired
    private RedisService redisService;
    /**
     * 查询 根据id
     * @param pkWaresSpecs
     * @return
     */
    @Override
    public BdWaresSpecs selectByPkId(Integer pkWaresSpecs) {
        String redisKey = CacheConstants.BD_WARES_SPECS + pkWaresSpecs;
        BdWaresSpecs waresSpecs = redisService.getCacheObject(redisKey);
        if (null == waresSpecs) {
            waresSpecs = baseMapper.selectByPkId(pkWaresSpecs);
            if (null != waresSpecs) {
                redisService.setCacheObject(redisKey, waresSpecs,CacheConstants.WARES_REFRESH_TIME, TimeUnit.DAYS);
            }
        }
        return waresSpecs;
    }
}
