...
|
...
|
@@ -8,6 +8,7 @@ import com.yoho.search.dal.model.Goods; |
|
|
import com.yoho.search.dal.model.ProductSizes;
|
|
|
import com.yoho.search.dal.model.Size;
|
|
|
import com.yoho.search.dal.model.Storage;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
...
|
...
|
@@ -37,26 +38,38 @@ public class ProductSizesLogicService { |
|
|
|
|
|
/**
|
|
|
* 获取ProductSizes列表
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ProductSizes> getData(List<Integer> ids) {
|
|
|
//获取ProductId对应的上架的goodsId列表
|
|
|
// 获取ProductId对应的上架的goodsId列表
|
|
|
List<Goods> goodsList = goodsMapper.getByIdsAndStatus(ids);
|
|
|
if(CollectionUtils.isEmpty(goodsList)){
|
|
|
if (CollectionUtils.isEmpty(goodsList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
//获取goodsId对应得Storage列表
|
|
|
// 获取goodsId对应得Storage列表
|
|
|
List<Integer> goodsIdList = goodsList.parallelStream().map(Goods::getId).collect(Collectors.toList());
|
|
|
List<Storage> storageList = storageMapper.getByGoodsIds(goodsIdList);
|
|
|
if (CollectionUtils.isEmpty(storageList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
//过滤状态是上架的且有库存的Goods和Storage
|
|
|
storageList = storageList.parallelStream().filter(storageItem -> VALID_STATUS.equals(storageItem.getStatus()))
|
|
|
.filter(storageItem -> storageItem.getStorageNum() != null && storageItem.getStorageNum().intValue() > 0).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(storageList)){
|
|
|
// 过滤掉下架的sku
|
|
|
storageList = storageList.parallelStream().filter(storageItem -> VALID_STATUS.equals(storageItem.getStatus())).collect(Collectors.toList());
|
|
|
|
|
|
// 计算每个skn则总尺码数
|
|
|
Map<Integer, Integer> sknSizeCountMap = new HashMap<Integer, Integer>();
|
|
|
for (Storage storage : storageList) {
|
|
|
Integer productId = storage.getProductId();
|
|
|
int count = sknSizeCountMap.getOrDefault(productId, 0);
|
|
|
sknSizeCountMap.put(productId, count + 1);
|
|
|
}
|
|
|
|
|
|
// 过滤状态是上架的且有库存的Goods和Storage
|
|
|
storageList = storageList.parallelStream().filter(storageItem -> storageItem.getStorageNum() != null && storageItem.getStorageNum().intValue() > 0)
|
|
|
.collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(storageList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -68,8 +81,7 @@ public class ProductSizesLogicService { |
|
|
validErpSkuIdList.add(s.getErpSkuId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//判断sku列表是否为空
|
|
|
// 判断sku列表是否为空
|
|
|
if (validErpSkuIdList == null || validErpSkuIdList.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
...
|
...
|
@@ -90,24 +102,38 @@ public class ProductSizesLogicService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取尺码信息
|
|
|
List<Size> sizeList = sizeMapper.getByIds(sizeIdSet.stream().collect(Collectors.toList()));
|
|
|
|
|
|
// 填充尺码信息和断码率
|
|
|
if (CollectionUtils.isNotEmpty(sizeList)) {
|
|
|
Map<Integer, String> sizeMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
|
|
|
//productSizesList.forEach(ps -> ps.setSizeNames(Arrays.stream(ps.getSizeIds().split(",")).map(Integer::valueOf).map(sizeId -> sizeMap.get(sizeId)).collect(Collectors.joining(","))));
|
|
|
for (ProductSizes ps : productSizesList) {
|
|
|
String sizeArray[] = ps.getSizeIds().split(",");
|
|
|
// 计算断码率
|
|
|
double breakSizePercent = this.getBreakSizePercent(sknSizeCountMap.getOrDefault(ps.getProductId(), 0), sizeArray == null ? 0 : sizeArray.length);
|
|
|
ps.setBreakSizePercent(breakSizePercent);
|
|
|
// 填充尺码名称
|
|
|
if (sizeArray != null) {
|
|
|
for (int i = 0; i < sizeArray.length; i++) {
|
|
|
if (i == 0) {
|
|
|
ps.setSizeNames(sizeMap.get(Integer.valueOf(sizeArray[i]))+ ",");
|
|
|
ps.setSizeNames(sizeMap.get(Integer.valueOf(sizeArray[i])) + ",");
|
|
|
} else {
|
|
|
ps.setSizeNames(ps.getSizeNames() + sizeMap.get(Integer.valueOf(sizeArray[i]))+ ",");
|
|
|
ps.setSizeNames(ps.getSizeNames() + sizeMap.get(Integer.valueOf(sizeArray[i])) + ",");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return productSizesList;
|
|
|
}
|
|
|
|
|
|
private double getBreakSizePercent(int totalSizeCount, int effectiveSizeCount) {
|
|
|
if (totalSizeCount == 0 || effectiveSizeCount == 0) {
|
|
|
return 100d;
|
|
|
}
|
|
|
return 100d * (effectiveSizeCount - totalSizeCount) / totalSizeCount;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|