Authored by mali

是否可添加尺码

... ... @@ -25,6 +25,8 @@ public enum UfoProductCacheKeyEnum {
STORAGE_PRICE_IN_STOCK_INFO_KEY("ufo:product:storagePrice:inStock", "商品现货价格信息", 5, TimeUnit.MINUTES),
BIE_STORAGE_PRICE_IN_STOCK_INFO_KEY("ufo:product:BiestoragePrice:inStock", "求购商品现货价格信息", 5, TimeUnit.MINUTES),
ALL_SIZE_BY_SORTID_KEY("ufo:product:sort:Size", "品类下的尺码信息", 15, TimeUnit.MINUTES),
;
private String cacheKey;
... ...
package com.yohoufo.product.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.ProductInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.product.BrandSeriesMapper;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.model.Brand;
import com.yohoufo.dal.product.model.BrandSeries;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.ProductSortMapper;
import com.yohoufo.dal.product.SizeMapper;
import com.yohoufo.dal.product.model.*;
import com.yohoufo.product.cache.UfoProductCacheKeyEnum;
import com.yohoufo.product.cache.UfoProductCacheService;
import com.yohoufo.product.service.cache.BrandCacheService;
... ... @@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
... ... @@ -46,6 +48,12 @@ public class ProductHelpService {
@Autowired
private BidProductService bidProductService;
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private SizeMapper sizeMapper;
public ProductInfo convertProductInfo(Product product) {
ProductInfo productInfo = new ProductInfo();
productInfo.setProductId(product.getId());
... ... @@ -143,4 +151,23 @@ public class ProductHelpService {
productInfo.setMosterPrice(mosterPrice);
}
}
public List<Size> getAllSizeBySortId(Integer sortId) {
List<Size> cache = productCacheService.getListCacheByString(UfoProductCacheKeyEnum.ALL_SIZE_BY_SORTID_KEY, Size.class, sortId);
if (CollectionUtils.isEmpty(cache)) {
ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);
List<Size> sizes = Lists.newArrayList();
if (sort != null) {
List<Integer> idList = new ArrayList<>();
idList.add(sortId);
if (sort.getParentId() != null && sort.getParentId() > 0) {
idList.add(sort.getParentId());
}
sizes = sizeMapper.selectAllSizeBySortIdList(idList);
}
productCacheService.setCacheByString(UfoProductCacheKeyEnum.ALL_SIZE_BY_SORTID_KEY, sizes, sortId);
return sizes;
}
return cache;
}
}
... ...
... ... @@ -353,17 +353,7 @@ public class ProductServiceImpl implements ProductService {
}
private List<Size> getAllSizeBySortId(Integer sortId) {
ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);
List<Size> sizes = Lists.newArrayList();
if (sort != null) {
List<Integer> idList = new ArrayList<>();
idList.add(sortId);
if (sort.getParentId() != null && sort.getParentId() > 0) {
idList.add(sort.getParentId());
}
sizes = sizeMapper.selectAllSizeBySortIdList(idList);
}
return sizes;
return productHelpService.getAllSizeBySortId(sortId);
}
@Override
... ...