|  | @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  |  import com.fs.store.cache.IFsStoreProductCacheService;
 | 
	
		
			
				|  |  |  import com.fs.store.cache.IFsWarehouseCacheService;
 | 
	
		
			
				|  |  |  import com.fs.store.domain.FsStoreProduct;
 | 
	
		
			
				|  |  | +import com.fs.store.domain.FsStoreProductPackage;
 | 
	
		
			
				|  |  |  import com.fs.store.domain.FsWarehouses;
 | 
	
		
			
				|  |  |  import com.fs.store.service.IFsStoreProductService;
 | 
	
		
			
				|  |  |  import com.fs.system.cache.impl.SysDictDataCacheServiceImpl;
 | 
	
	
		
			
				|  | @@ -11,6 +12,7 @@ import com.github.benmanes.caffeine.cache.Cache;
 | 
	
		
			
				|  |  |  import com.github.benmanes.caffeine.cache.Caffeine;
 | 
	
		
			
				|  |  |  import lombok.RequiredArgsConstructor;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.core.RedisTemplate;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.util.concurrent.TimeUnit;
 | 
	
	
		
			
				|  | @@ -21,26 +23,36 @@ import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  public class IFsStoreProductCacheServiceImpl implements IFsStoreProductCacheService {
 | 
	
		
			
				|  |  |      private final IFsStoreProductService fsStoreProductService;
 | 
	
		
			
				|  |  |      private final IFsWarehouseCacheService fsWarehouseCacheService;
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 使用Caffeine本地缓存
 | 
	
		
			
				|  |  | -     * maximumSize: 最大缓存条数
 | 
	
		
			
				|  |  | -     * expireAfterWrite: 写入后多久过期(分钟)
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private static final Cache<Long, FsStoreProduct> CACHE = Caffeine.newBuilder()
 | 
	
		
			
				|  |  | -            .maximumSize(1000)
 | 
	
		
			
				|  |  | -            .expireAfterWrite(10, TimeUnit.SECONDS)
 | 
	
		
			
				|  |  | -            .build();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static final Cache<Long, String> WAREHOUSE_CACHE = Caffeine.newBuilder()
 | 
	
		
			
				|  |  |              .maximumSize(1000)
 | 
	
		
			
				|  |  |              .expireAfterWrite(10, TimeUnit.SECONDS)
 | 
	
		
			
				|  |  |              .build();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private final RedisTemplate<String,Object> redisTemplate;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public FsStoreProduct selectFsStoreProductById(Long productId) {
 | 
	
		
			
				|  |  |          log.info("开始查询商品信息,商品ID:{}", productId);
 | 
	
		
			
				|  |  | +        if(productId == null) {
 | 
	
		
			
				|  |  | +            throw new IllegalArgumentException("产品id不能为空!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 尝试从缓存获取
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            String redisKey = String.format("fs:store:product:%d", productId);
 | 
	
		
			
				|  |  | +            FsStoreProduct product = (FsStoreProduct) redisTemplate.opsForValue().get(redisKey);
 | 
	
		
			
				|  |  | +            if(product != null) {
 | 
	
		
			
				|  |  | +                log.debug("缓存命中产品信息, productId: {}", productId);
 | 
	
		
			
				|  |  | +                return product;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("获取产品缓存异常, productId: {}, 异常信息: {}", productId, e.getMessage(), e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        log.debug("缓存未命中产品信息, productId: {}, 从数据库查询", productId);
 | 
	
		
			
				|  |  | +        FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(productId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        return CACHE.get(productId, e -> fsStoreProductService.selectFsStoreProductById(productId));
 | 
	
		
			
				|  |  | +        return fsStoreProduct;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 |