...
|
...
|
@@ -59,33 +59,33 @@ public class ProductSizesLogicService { |
|
|
}
|
|
|
|
|
|
// 过滤状态是上架的且有库存的Goods和Storage
|
|
|
Map<Integer,Set<Integer>> productValidStatusSizeIds = new HashMap<Integer, Set<Integer>>();
|
|
|
Map<Integer,Set<Integer>> productHasStorageSizeIds = new HashMap<Integer, Set<Integer>>();
|
|
|
List<Storage> realEffectiveStorageList = new ArrayList<Storage>();
|
|
|
Map<Integer, Integer> productValidStatusSizeCount = new HashMap<Integer, Integer>();
|
|
|
Map<Integer, Integer> productHasStorageSizeCount = new HashMap<Integer, Integer>();
|
|
|
List<Storage> effectiveStorageList = new ArrayList<Storage>();
|
|
|
for (Storage storage : oldStorageList) {
|
|
|
Integer productId = storage.getProductId();
|
|
|
Integer sizeId = storage.getGoodsDimensionId();
|
|
|
//处理未下架的sku
|
|
|
if(!VALID_STATUS.equals(storage.getStatus())){
|
|
|
// 处理未下架的sku
|
|
|
if (!VALID_STATUS.equals(storage.getStatus())) {
|
|
|
continue;
|
|
|
}
|
|
|
this.addToMap(productId, sizeId, productValidStatusSizeIds);
|
|
|
//处理有库存的sku
|
|
|
if(storage.getStorageNum() == null || storage.getStorageNum().intValue() <= 0){
|
|
|
this.increaseMapCount(productId, productValidStatusSizeCount);
|
|
|
// 处理有库存的sku
|
|
|
if (storage.getStorageNum() == null || storage.getStorageNum().intValue() <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
this.addToMap(productId, sizeId, productHasStorageSizeIds);
|
|
|
realEffectiveStorageList.add(storage);
|
|
|
this.increaseMapCount(productId, productHasStorageSizeCount);
|
|
|
effectiveStorageList.add(storage);
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(realEffectiveStorageList)) {
|
|
|
if (CollectionUtils.isEmpty(effectiveStorageList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
// 根据上架的GoodsId筛选Storage数据
|
|
|
Set<Integer> validGoodsIdSet = goodsIdList.stream().collect(Collectors.toSet());
|
|
|
List<Integer> validErpSkuIdList = new ArrayList<>();
|
|
|
for (Storage s : realEffectiveStorageList) {
|
|
|
for (Storage s : effectiveStorageList) {
|
|
|
if (validGoodsIdSet.contains(s.getGoodsId())) {
|
|
|
validErpSkuIdList.add(s.getErpSkuId());
|
|
|
}
|
...
|
...
|
@@ -115,31 +115,32 @@ public class ProductSizesLogicService { |
|
|
List<Size> sizeList = sizeMapper.getByIds(sizeIdSet.stream().collect(Collectors.toList()));
|
|
|
Map<Integer, String> sizeNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
|
|
|
|
|
|
//填充其他信息
|
|
|
// 填充其他信息
|
|
|
for (ProductSizesBO productSizesBO : results) {
|
|
|
// 填充尺码名称
|
|
|
productSizesBO.setSizeNames(this.getSizeNames(productSizesBO.getSizeIdSet(), sizeNameMap));
|
|
|
// 填充断码率
|
|
|
Set<Integer> validStatusSizeIds = productValidStatusSizeIds.getOrDefault(productSizesBO.getProductId(), new HashSet<Integer>());
|
|
|
Set<Integer> hasStorageSizeIds = productHasStorageSizeIds.getOrDefault(productSizesBO.getProductId(), new HashSet<Integer>());
|
|
|
productSizesBO.setBreakSizePercent(this.getBreakSizePercent(validStatusSizeIds, hasStorageSizeIds));
|
|
|
Integer validStatusSizeCount = productValidStatusSizeCount.getOrDefault(productSizesBO.getProductId(), 0);
|
|
|
Integer hasStorageSizeCount = productHasStorageSizeCount.getOrDefault(productSizesBO.getProductId(), 0);
|
|
|
productSizesBO.setBreakSizePercent(this.getBreakSizePercent(validStatusSizeCount, hasStorageSizeCount));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private<K,V> void addToMap(K key,V value,Map<K,Set<V>> map){
|
|
|
Set<V> values = map.get(key);
|
|
|
if(values==null){
|
|
|
values = new HashSet<V>();
|
|
|
map.put(key, values);
|
|
|
private <K, V> void increaseMapCount(K key, Map<K, Integer> map) {
|
|
|
Integer value = map.get(key);
|
|
|
if (value == null) {
|
|
|
value = 0;
|
|
|
}
|
|
|
values.add(value);
|
|
|
value = value + 1;
|
|
|
map.put(key, value);
|
|
|
}
|
|
|
private String getSizeNames(Set<Integer> sizeIds,Map<Integer, String> sizeNameMap){
|
|
|
|
|
|
private String getSizeNames(Set<Integer> sizeIds, Map<Integer, String> sizeNameMap) {
|
|
|
StringBuilder results = new StringBuilder();
|
|
|
for (Integer sizeId : sizeIds) {
|
|
|
String sizeName = sizeNameMap.get(sizeId);
|
|
|
if(sizeName==null){
|
|
|
if (sizeName == null) {
|
|
|
continue;
|
|
|
}
|
|
|
results.append(",").append(sizeName);
|
...
|
...
|
@@ -147,16 +148,13 @@ public class ProductSizesLogicService { |
|
|
return results.toString().replaceFirst(",", "");
|
|
|
}
|
|
|
|
|
|
private double getBreakSizePercent(Set<Integer> validStatusSizeIds,Set<Integer> hasStorageSizeIds) {
|
|
|
if (validStatusSizeIds == null || validStatusSizeIds.isEmpty()) {
|
|
|
private double getBreakSizePercent(Integer validStatusSizeCount, Integer hasStorageSizeCount) {
|
|
|
if (validStatusSizeCount == null || validStatusSizeCount<=0) {
|
|
|
return 100d;
|
|
|
}
|
|
|
if (hasStorageSizeIds == null || hasStorageSizeIds.isEmpty()) {
|
|
|
if (hasStorageSizeCount == null || hasStorageSizeCount<=0) {
|
|
|
return 100d;
|
|
|
}
|
|
|
int totalSizeCount = validStatusSizeIds.size();
|
|
|
int hasStorageSizeCount = hasStorageSizeIds.size();
|
|
|
return 100d * (totalSizeCount - hasStorageSizeCount) / totalSizeCount;
|
|
|
return 100d * (validStatusSizeCount - hasStorageSizeCount) / validStatusSizeCount;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|