Authored by hugufei

add ProductStorageLogicService

... ... @@ -36,6 +36,8 @@ public class ProductGoodsLogicService {
private StorageService storageService;
@Autowired
private BasicDataCacheService basicDataCacheService;
@Autowired
private ProductStorageLogicService productStorageLogicService;
/**
* 全量增量都有调用
... ... @@ -44,7 +46,7 @@ public class ProductGoodsLogicService {
// 构建productColorsMap
try {
if (productIds == null || productIds.isEmpty()) {
return new ArrayList<ProductGoodsBO>();
return new ArrayList<>();
}
List<Goods> goodsList = goodsMapper.selectListByProductIds(productIds);
List<Integer> goodsIds = goodsList.stream().map(Goods::getId).collect(Collectors.toList());
... ... @@ -53,16 +55,7 @@ public class ProductGoodsLogicService {
storageList = storageService.getStoragesByGoodsIds(goodsIds);
}
// 构建goodStorageMap
Map<Integer, Integer> goodStorageMap = new HashMap<>();
if (!CollectionUtils.isEmpty(storageList)) {
for (Storage storage : storageList) {
if (goodStorageMap.containsKey(storage.getGoodsId())) {
goodStorageMap.put(storage.getGoodsId(), storage.getStorageNum() + goodStorageMap.get(storage.getGoodsId()));
} else {
goodStorageMap.put(storage.getGoodsId(), storage.getStorageNum());
}
}
}
Map<Integer, Integer> goodStorageMap =productStorageLogicService.queryGoodStorageMap(storageList);
// 构建goodsCoverImagesMap
Map<Integer, GoodsCoverImage> goodsCoverImagesMap = goodsCoverImageLogicService.selectGoodsCoverImagesByProductIds(productIds);
... ...
package com.yoho.search.consumer.service.logicService;
import com.yoho.search.dal.model.Storage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class ProductStorageLogicService {
private static final Integer VALID_STATUS = Integer.valueOf(1);
private List<Storage> filterValidStorage(List<Storage> storageList) {
return storageList.stream().filter(storage -> VALID_STATUS.equals(storage.getStatus()) && storage.getStorageNum() != null && storage.getStorageNum() > 0)
.collect(Collectors.toList());
}
/**
* 构建goods库存
*
* @param storageList
* @return
*/
public Map<Integer, Integer> queryGoodStorageMap(List<Storage> storageList) {
List<Storage> validStorageList = this.filterValidStorage(storageList);
if (CollectionUtils.isEmpty(validStorageList)) {
return new HashMap<>();
}
// 构建goodsValidStorageMap
Map<Integer, Integer> goodsValidStorageMap = new HashMap<>();
for (Storage storage : storageList) {
Integer goodsId = storage.getGoodsId();
int oldvalue = MapUtils.getIntValue(goodsValidStorageMap, goodsId, 0);
goodsValidStorageMap.put(goodsId, oldvalue + storage.getStorageNum());
}
return goodsValidStorageMap;
}
/**
* 构建skn库存
*
* @param storageList
* @return
*/
public Map<Integer, Integer> queryProductValidStorageMap(List<Storage> storageList) {
List<Storage> validStorageList = this.filterValidStorage(storageList);
if (CollectionUtils.isEmpty(validStorageList)) {
return new HashMap<>();
}
// 构建productValidStorageMap
Map<Integer, Integer> productValidStorageMap = new HashMap<>();
for (Storage storage : storageList) {
Integer productId = storage.getProductId();
int oldvalue = MapUtils.getIntValue(productValidStorageMap, productId, 0);
productValidStorageMap.put(productId, oldvalue + storage.getStorageNum());
}
return productValidStorageMap;
}
}
... ...