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.ext.BdWaresSpecsRelationExt;
import com.hzs.common.domain.sale.wares.BdWaresSpecsRelation;
import com.hzs.sale.wares.mapper.BdWaresSpecsRelationMapper;
import com.hzs.sale.wares.service.IBdWaresSpecsRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 规格明细值 服务实现类
 *
 * @author hzs
 * @since 2022-09-09
 */
@Service
public class BdWaresSpecsRelationServiceImpl extends ServiceImpl<BdWaresSpecsRelationMapper, BdWaresSpecsRelation> implements IBdWaresSpecsRelationService {
    @Autowired
    private RedisService redisService;

    /**
     * 查询产品规格
     *
     * @param pkWaresSpecsSku
     * @return
     */
    @Override
    public List<BdWaresSpecsRelationExt> selectByWaresSpecsSku(Integer pkWaresSpecsSku) {
        String redisKey = CacheConstants.BD_WARES_SPECS_RELATION + pkWaresSpecsSku;
        List<BdWaresSpecsRelationExt> waresSpecsRelationExt = redisService.getCacheObject(redisKey);
        if (null == waresSpecsRelationExt) {
            waresSpecsRelationExt = baseMapper.selectByWaresSpecsSku(pkWaresSpecsSku);
            if (null != waresSpecsRelationExt) {
                redisService.setCacheObject(redisKey, waresSpecsRelationExt, CacheConstants.WARES_REFRESH_TIME, TimeUnit.DAYS);
            }
        }
        return waresSpecsRelationExt;
    }

    /**
     * 查询规格明细值
     * @param pkWares
     * @param pkProduct
     * @return
     */
    @Override
    public List<BdWaresSpecsRelationExt> getWaresProduct(Integer pkWares, Integer pkProduct,Integer pkWaresSpecsSku,List<Integer> waresSpecsIds) {
        return baseMapper.getWaresProduct(pkWares,pkProduct,pkWaresSpecsSku,waresSpecsIds);
    }

}

