|
|
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;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|