Authored by mali

是否可添加尺码

@@ -25,6 +25,8 @@ public enum UfoProductCacheKeyEnum { @@ -25,6 +25,8 @@ public enum UfoProductCacheKeyEnum {
25 STORAGE_PRICE_IN_STOCK_INFO_KEY("ufo:product:storagePrice:inStock", "商品现货价格信息", 5, TimeUnit.MINUTES), 25 STORAGE_PRICE_IN_STOCK_INFO_KEY("ufo:product:storagePrice:inStock", "商品现货价格信息", 5, TimeUnit.MINUTES),
26 26
27 BIE_STORAGE_PRICE_IN_STOCK_INFO_KEY("ufo:product:BiestoragePrice:inStock", "求购商品现货价格信息", 5, TimeUnit.MINUTES), 27 BIE_STORAGE_PRICE_IN_STOCK_INFO_KEY("ufo:product:BiestoragePrice:inStock", "求购商品现货价格信息", 5, TimeUnit.MINUTES),
  28 +
  29 + ALL_SIZE_BY_SORTID_KEY("ufo:product:sort:Size", "品类下的尺码信息", 15, TimeUnit.MINUTES),
28 ; 30 ;
29 31
30 private String cacheKey; 32 private String cacheKey;
1 package com.yohoufo.product.service.impl; 1 package com.yohoufo.product.service.impl;
2 2
  3 +import com.google.common.collect.Lists;
3 import com.yohobuy.ufo.model.GoodsSize; 4 import com.yohobuy.ufo.model.GoodsSize;
4 import com.yohobuy.ufo.model.ProductInfo; 5 import com.yohobuy.ufo.model.ProductInfo;
5 import com.yohoufo.common.utils.DateUtil; 6 import com.yohoufo.common.utils.DateUtil;
6 import com.yohoufo.dal.product.BrandSeriesMapper; 7 import com.yohoufo.dal.product.BrandSeriesMapper;
7 import com.yohoufo.dal.product.ProductMapper; 8 import com.yohoufo.dal.product.ProductMapper;
8 -import com.yohoufo.dal.product.model.Brand;  
9 -import com.yohoufo.dal.product.model.BrandSeries;  
10 -import com.yohoufo.dal.product.model.Product; 9 +import com.yohoufo.dal.product.ProductSortMapper;
  10 +import com.yohoufo.dal.product.SizeMapper;
  11 +import com.yohoufo.dal.product.model.*;
11 import com.yohoufo.product.cache.UfoProductCacheKeyEnum; 12 import com.yohoufo.product.cache.UfoProductCacheKeyEnum;
12 import com.yohoufo.product.cache.UfoProductCacheService; 13 import com.yohoufo.product.cache.UfoProductCacheService;
13 import com.yohoufo.product.service.cache.BrandCacheService; 14 import com.yohoufo.product.service.cache.BrandCacheService;
@@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
20 import org.springframework.util.CollectionUtils; 21 import org.springframework.util.CollectionUtils;
21 import java.math.BigDecimal; 22 import java.math.BigDecimal;
  23 +import java.util.ArrayList;
22 import java.util.List; 24 import java.util.List;
23 import java.util.Objects; 25 import java.util.Objects;
24 import java.util.Optional; 26 import java.util.Optional;
@@ -46,6 +48,12 @@ public class ProductHelpService { @@ -46,6 +48,12 @@ public class ProductHelpService {
46 @Autowired 48 @Autowired
47 private BidProductService bidProductService; 49 private BidProductService bidProductService;
48 50
  51 + @Autowired
  52 + private ProductSortMapper productSortMapper;
  53 +
  54 + @Autowired
  55 + private SizeMapper sizeMapper;
  56 +
49 public ProductInfo convertProductInfo(Product product) { 57 public ProductInfo convertProductInfo(Product product) {
50 ProductInfo productInfo = new ProductInfo(); 58 ProductInfo productInfo = new ProductInfo();
51 productInfo.setProductId(product.getId()); 59 productInfo.setProductId(product.getId());
@@ -143,4 +151,23 @@ public class ProductHelpService { @@ -143,4 +151,23 @@ public class ProductHelpService {
143 productInfo.setMosterPrice(mosterPrice); 151 productInfo.setMosterPrice(mosterPrice);
144 } 152 }
145 } 153 }
  154 +
  155 + public List<Size> getAllSizeBySortId(Integer sortId) {
  156 + List<Size> cache = productCacheService.getListCacheByString(UfoProductCacheKeyEnum.ALL_SIZE_BY_SORTID_KEY, Size.class, sortId);
  157 + if (CollectionUtils.isEmpty(cache)) {
  158 + ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);
  159 + List<Size> sizes = Lists.newArrayList();
  160 + if (sort != null) {
  161 + List<Integer> idList = new ArrayList<>();
  162 + idList.add(sortId);
  163 + if (sort.getParentId() != null && sort.getParentId() > 0) {
  164 + idList.add(sort.getParentId());
  165 + }
  166 + sizes = sizeMapper.selectAllSizeBySortIdList(idList);
  167 + }
  168 + productCacheService.setCacheByString(UfoProductCacheKeyEnum.ALL_SIZE_BY_SORTID_KEY, sizes, sortId);
  169 + return sizes;
  170 + }
  171 + return cache;
  172 + }
146 } 173 }
@@ -353,17 +353,7 @@ public class ProductServiceImpl implements ProductService { @@ -353,17 +353,7 @@ public class ProductServiceImpl implements ProductService {
353 } 353 }
354 354
355 private List<Size> getAllSizeBySortId(Integer sortId) { 355 private List<Size> getAllSizeBySortId(Integer sortId) {
356 - ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);  
357 - List<Size> sizes = Lists.newArrayList();  
358 - if (sort != null) {  
359 - List<Integer> idList = new ArrayList<>();  
360 - idList.add(sortId);  
361 - if (sort.getParentId() != null && sort.getParentId() > 0) {  
362 - idList.add(sort.getParentId());  
363 - }  
364 - sizes = sizeMapper.selectAllSizeBySortIdList(idList);  
365 - }  
366 - return sizes; 356 + return productHelpService.getAllSizeBySortId(sortId);
367 } 357 }
368 358
369 @Override 359 @Override