Showing
7 changed files
with
285 additions
and
225 deletions
1 | package com.yoho.search.dal.model; | 1 | package com.yoho.search.dal.model; |
2 | 2 | ||
3 | - | ||
4 | /** | 3 | /** |
5 | * Created by wangnan on 2016/6/30. | 4 | * Created by wangnan on 2016/6/30. |
6 | */ | 5 | */ |
7 | public class ProductSizes { | 6 | public class ProductSizes { |
8 | - private Integer productId; | ||
9 | - private String sizeIds; | ||
10 | - private String sizeNames; | ||
11 | - private Integer storageNum; | ||
12 | - | ||
13 | - public Integer getProductId() { | ||
14 | - return productId; | ||
15 | - } | ||
16 | - | ||
17 | - public void setProductId(Integer productId) { | ||
18 | - this.productId = productId; | ||
19 | - } | ||
20 | - | ||
21 | - public String getSizeIds() { | ||
22 | - return sizeIds; | ||
23 | - } | ||
24 | - | ||
25 | - public void setSizeIds(String sizeIds) { | ||
26 | - this.sizeIds = sizeIds; | ||
27 | - } | ||
28 | - | ||
29 | - public Integer getStorageNum() { | ||
30 | - return storageNum; | ||
31 | - } | ||
32 | - | ||
33 | - public void setStorageNum(Integer storageNum) { | ||
34 | - this.storageNum = storageNum; | ||
35 | - } | ||
36 | - | ||
37 | - public String getSizeNames() { | ||
38 | - return sizeNames; | ||
39 | - } | ||
40 | - | ||
41 | - public void setSizeNames(String sizeNames) { | ||
42 | - this.sizeNames = sizeNames; | ||
43 | - } | 7 | + private Integer productId; |
8 | + private String sizeIds; | ||
9 | + private String sizeNames; | ||
10 | + private Integer storageNum; | ||
11 | + private double breakSizePercent = 100; | ||
12 | + | ||
13 | + public Integer getProductId() { | ||
14 | + return productId; | ||
15 | + } | ||
16 | + | ||
17 | + public void setProductId(Integer productId) { | ||
18 | + this.productId = productId; | ||
19 | + } | ||
20 | + | ||
21 | + public String getSizeIds() { | ||
22 | + return sizeIds; | ||
23 | + } | ||
24 | + | ||
25 | + public void setSizeIds(String sizeIds) { | ||
26 | + this.sizeIds = sizeIds; | ||
27 | + } | ||
28 | + | ||
29 | + public Integer getStorageNum() { | ||
30 | + return storageNum; | ||
31 | + } | ||
32 | + | ||
33 | + public void setStorageNum(Integer storageNum) { | ||
34 | + this.storageNum = storageNum; | ||
35 | + } | ||
36 | + | ||
37 | + public String getSizeNames() { | ||
38 | + return sizeNames; | ||
39 | + } | ||
40 | + | ||
41 | + public void setSizeNames(String sizeNames) { | ||
42 | + this.sizeNames = sizeNames; | ||
43 | + } | ||
44 | + | ||
45 | + public double getBreakSizePercent() { | ||
46 | + return breakSizePercent; | ||
47 | + } | ||
48 | + | ||
49 | + public void setBreakSizePercent(double breakSizePercent) { | ||
50 | + this.breakSizePercent = breakSizePercent; | ||
51 | + } | ||
52 | + | ||
44 | } | 53 | } |
@@ -25,76 +25,84 @@ import java.util.stream.Collectors; | @@ -25,76 +25,84 @@ import java.util.stream.Collectors; | ||
25 | @Component | 25 | @Component |
26 | public abstract class AbstractStorageRelatedMqListener extends AbstractMqListener { | 26 | public abstract class AbstractStorageRelatedMqListener extends AbstractMqListener { |
27 | 27 | ||
28 | - @Autowired | ||
29 | - private StorageService storageService; | 28 | + @Autowired |
29 | + private StorageService storageService; | ||
30 | 30 | ||
31 | - @Autowired | ||
32 | - private SizeService sizeService; | 31 | + @Autowired |
32 | + private SizeService sizeService; | ||
33 | 33 | ||
34 | - @Autowired | ||
35 | - private GoodsService goodsService; | 34 | + @Autowired |
35 | + private GoodsService goodsService; | ||
36 | 36 | ||
37 | - @Autowired | ||
38 | - private ProductGoodsLogicService productGoodsLogicService; | 37 | + @Autowired |
38 | + private ProductGoodsLogicService productGoodsLogicService; | ||
39 | 39 | ||
40 | - protected void fillStorageNumAndSizeInfo(Integer productId, Map<String, Object> indexData) { | ||
41 | - List<Storage> storageList = storageService.getStoragesByProductId(productId); | ||
42 | - if (CollectionUtils.isNotEmpty(storageList)) { | ||
43 | - // 过滤掉下架的无库存的storage | ||
44 | - storageList = storageList.stream() | ||
45 | - .filter(storage -> Integer.valueOf(1).equals(storage.getStatus())) | ||
46 | - .filter(storage -> storage.getStorageNum() != null && storage.getStorageNum().intValue() > 0) | ||
47 | - .collect(Collectors.toList()); | ||
48 | - } | 40 | + protected void fillStorageNumAndSizeInfo(Integer productId, Map<String, Object> indexData) { |
41 | + List<Storage> storageList = storageService.getStoragesByProductId(productId); | ||
42 | + // 过滤掉下架的storage | ||
43 | + if (CollectionUtils.isNotEmpty(storageList)) { | ||
44 | + storageList = storageList.stream().filter(storage -> Integer.valueOf(1).equals(storage.getStatus())).collect(Collectors.toList()); | ||
45 | + } | ||
46 | + int totalSizeCount = storageList.size(); | ||
49 | 47 | ||
50 | - if (CollectionUtils.isEmpty(storageList)) { | ||
51 | - indexData.put("storageNum", 0); | ||
52 | - indexData.put("isSoonSoldOut", "Y"); | ||
53 | - indexData.put("isSoldOut", "Y"); | ||
54 | - indexData.put("soldOut", 0); | ||
55 | - indexData.put("sizeIds", null); | ||
56 | - } else { | ||
57 | - int storageNum = 0; | ||
58 | - Set<String> sizeSet = new HashSet<String>(); | ||
59 | - for (Storage stor : storageList) { | ||
60 | - storageNum += stor.getStorageNum(); | ||
61 | - if (stor.getGoodsDimensionId() != null) { | ||
62 | - sizeSet.add(stor.getGoodsDimensionId() + ""); | ||
63 | - } | ||
64 | - } | ||
65 | - indexData.put("storageNum", storageNum); | ||
66 | - indexData.put("isSoonSoldOut", storageNum <= 2 ? "Y" : "N"); | ||
67 | - indexData.put("isSoldOut", storageNum == 0 ? "Y" : "N"); | ||
68 | - indexData.put("soldOut", storageNum == 0 ? 0 : 1); | ||
69 | - if (!sizeSet.isEmpty()) { | ||
70 | - // 设置尺码信息 | ||
71 | - indexData.put("sizeIds", StringUtils.join(sizeSet, ",")); | ||
72 | - indexData.put("sizeNames", sizeService.getSizeNamesBySizeIds(sizeSet.stream().map(Integer::valueOf).collect(Collectors.toList()))); | ||
73 | - } else { | ||
74 | - indexData.put("sizeIds", null); | ||
75 | - indexData.put("sizeNames", null); | ||
76 | - } | ||
77 | - } | ||
78 | - } | 48 | + // 过滤掉无库存的storage |
49 | + if (CollectionUtils.isNotEmpty(storageList)) { | ||
50 | + storageList = storageList.stream().filter(storage -> storage.getStorageNum() != null && storage.getStorageNum().intValue() > 0).collect(Collectors.toList()); | ||
51 | + } | ||
52 | + int effectiveSizeCount = storageList.size(); | ||
53 | + | ||
54 | + float breakSizePercent = 100 * (totalSizeCount - effectiveSizeCount)/totalSizeCount; | ||
55 | + | ||
56 | + if (CollectionUtils.isEmpty(storageList)) { | ||
57 | + indexData.put("storageNum", 0); | ||
58 | + indexData.put("isSoonSoldOut", "Y"); | ||
59 | + indexData.put("isSoldOut", "Y"); | ||
60 | + indexData.put("soldOut", 0); | ||
61 | + indexData.put("sizeIds", null); | ||
62 | + indexData.put("breakSizePercent", 100); | ||
63 | + } else { | ||
64 | + int storageNum = 0; | ||
65 | + Set<String> sizeSet = new HashSet<String>(); | ||
66 | + for (Storage stor : storageList) { | ||
67 | + storageNum += stor.getStorageNum(); | ||
68 | + if (stor.getGoodsDimensionId() != null) { | ||
69 | + sizeSet.add(stor.getGoodsDimensionId() + ""); | ||
70 | + } | ||
71 | + } | ||
72 | + indexData.put("storageNum", storageNum); | ||
73 | + indexData.put("isSoonSoldOut", storageNum <= 2 ? "Y" : "N"); | ||
74 | + indexData.put("isSoldOut", storageNum == 0 ? "Y" : "N"); | ||
75 | + indexData.put("soldOut", storageNum == 0 ? 0 : 1); | ||
76 | + if (!sizeSet.isEmpty()) { | ||
77 | + // 设置尺码信息 | ||
78 | + indexData.put("sizeIds", StringUtils.join(sizeSet, ",")); | ||
79 | + indexData.put("sizeNames", sizeService.getSizeNamesBySizeIds(sizeSet.stream().map(Integer::valueOf).collect(Collectors.toList()))); | ||
80 | + } else { | ||
81 | + indexData.put("sizeIds", null); | ||
82 | + indexData.put("sizeNames", null); | ||
83 | + } | ||
84 | + indexData.put("breakSizePercent", breakSizePercent); | ||
85 | + } | ||
86 | + } | ||
79 | 87 | ||
80 | - protected void fillColor(Map<String, Object> indexData, Integer productId) { | ||
81 | - Set<String> colorIdSet = new HashSet<String>(); | ||
82 | - Set<String> colorNameSet = new HashSet<String>(); | ||
83 | - // 第一步:获取goodsList | ||
84 | - List<ProductGoodsBO> productGoodsBOList = goodsService.getProductGoodsByProductId(productId); | ||
85 | - // 第二步、组装goods数据 | ||
86 | - if (productGoodsBOList != null && productGoodsBOList.size() == 1) { | ||
87 | - ProductGoodsBO productGoodsBO = productGoodsBOList.get(0); | ||
88 | - String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); | ||
89 | - JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); | ||
90 | - productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color | ||
91 | - indexData.put("goodsList", goodsListJsonArray); | ||
92 | - indexData.put("colorIds", StringUtils.join(colorIdSet, ",")); | ||
93 | - indexData.put("colorNames", StringUtils.join(colorNameSet, ",")); | ||
94 | - } else { | ||
95 | - indexData.put("goodsList", ""); | ||
96 | - indexData.put("colorIds", ""); | ||
97 | - indexData.put("colorNames", ""); | ||
98 | - } | ||
99 | - } | 88 | + protected void fillColor(Map<String, Object> indexData, Integer productId) { |
89 | + Set<String> colorIdSet = new HashSet<String>(); | ||
90 | + Set<String> colorNameSet = new HashSet<String>(); | ||
91 | + // 第一步:获取goodsList | ||
92 | + List<ProductGoodsBO> productGoodsBOList = goodsService.getProductGoodsByProductId(productId); | ||
93 | + // 第二步、组装goods数据 | ||
94 | + if (productGoodsBOList != null && productGoodsBOList.size() == 1) { | ||
95 | + ProductGoodsBO productGoodsBO = productGoodsBOList.get(0); | ||
96 | + String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); | ||
97 | + JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); | ||
98 | + productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);// 获取有库存且状态正常的color | ||
99 | + indexData.put("goodsList", goodsListJsonArray); | ||
100 | + indexData.put("colorIds", StringUtils.join(colorIdSet, ",")); | ||
101 | + indexData.put("colorNames", StringUtils.join(colorNameSet, ",")); | ||
102 | + } else { | ||
103 | + indexData.put("goodsList", ""); | ||
104 | + indexData.put("colorIds", ""); | ||
105 | + indexData.put("colorNames", ""); | ||
106 | + } | ||
107 | + } | ||
100 | } | 108 | } |
@@ -781,6 +781,9 @@ | @@ -781,6 +781,9 @@ | ||
781 | "type": "string", | 781 | "type": "string", |
782 | "analyzer": "comma_spliter" | 782 | "analyzer": "comma_spliter" |
783 | }, | 783 | }, |
784 | + "breakSizePercent": { | ||
785 | + "type": "double" | ||
786 | + }, | ||
784 | "standardIds": { | 787 | "standardIds": { |
785 | "type": "string", | 788 | "type": "string", |
786 | "analyzer": "comma_spliter" | 789 | "analyzer": "comma_spliter" |
@@ -126,6 +126,8 @@ public class ProductIndexService { | @@ -126,6 +126,8 @@ public class ProductIndexService { | ||
126 | map.put(ProductIndexEsField.colorNames, productIndexBO.getColorNames()); | 126 | map.put(ProductIndexEsField.colorNames, productIndexBO.getColorNames()); |
127 | map.put(ProductIndexEsField.sizeIds, productIndexBO.getSizeIds()); | 127 | map.put(ProductIndexEsField.sizeIds, productIndexBO.getSizeIds()); |
128 | map.put(ProductIndexEsField.sizeNames, productIndexBO.getSizeNames()); | 128 | map.put(ProductIndexEsField.sizeNames, productIndexBO.getSizeNames()); |
129 | + map.put(ProductIndexEsField.breakSizePercent, productIndexBO.getBreakSizePercent()); | ||
130 | + | ||
129 | map.put(ProductIndexEsField.standardIds, productIndexBO.getStandardIds()); | 131 | map.put(ProductIndexEsField.standardIds, productIndexBO.getStandardIds()); |
130 | map.put(ProductIndexEsField.standardNames, productIndexBO.getStandardNames()); | 132 | map.put(ProductIndexEsField.standardNames, productIndexBO.getStandardNames()); |
131 | map.put(ProductIndexEsField.styleIds, productIndexBO.getStyleIds()); | 133 | map.put(ProductIndexEsField.styleIds, productIndexBO.getStyleIds()); |
@@ -53,6 +53,7 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -53,6 +53,7 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
53 | private Integer soldOut; | 53 | private Integer soldOut; |
54 | private String sizeIds; | 54 | private String sizeIds; |
55 | private String sizeNames; | 55 | private String sizeNames; |
56 | + private double breakSizePercent; | ||
56 | 57 | ||
57 | // from product_15day_salesnum | 58 | // from product_15day_salesnum |
58 | private Integer salesNum; | 59 | private Integer salesNum; |
@@ -416,6 +417,14 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -416,6 +417,14 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
416 | return sizeNames; | 417 | return sizeNames; |
417 | } | 418 | } |
418 | 419 | ||
420 | + public double getBreakSizePercent() { | ||
421 | + return breakSizePercent; | ||
422 | + } | ||
423 | + | ||
424 | + public void setBreakSizePercent(double breakSizePercent) { | ||
425 | + this.breakSizePercent = breakSizePercent; | ||
426 | + } | ||
427 | + | ||
419 | public String getIsStudentPrice() { | 428 | public String getIsStudentPrice() { |
420 | return isStudentPrice; | 429 | return isStudentPrice; |
421 | } | 430 | } |
@@ -8,6 +8,7 @@ import com.yoho.search.dal.model.Goods; | @@ -8,6 +8,7 @@ import com.yoho.search.dal.model.Goods; | ||
8 | import com.yoho.search.dal.model.ProductSizes; | 8 | import com.yoho.search.dal.model.ProductSizes; |
9 | import com.yoho.search.dal.model.Size; | 9 | import com.yoho.search.dal.model.Size; |
10 | import com.yoho.search.dal.model.Storage; | 10 | import com.yoho.search.dal.model.Storage; |
11 | + | ||
11 | import org.apache.commons.collections.CollectionUtils; | 12 | import org.apache.commons.collections.CollectionUtils; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
13 | import org.springframework.stereotype.Component; | 14 | import org.springframework.stereotype.Component; |
@@ -21,93 +22,118 @@ import java.util.stream.Collectors; | @@ -21,93 +22,118 @@ import java.util.stream.Collectors; | ||
21 | @Component | 22 | @Component |
22 | public class ProductSizesLogicService { | 23 | public class ProductSizesLogicService { |
23 | 24 | ||
24 | - private static final Integer VALID_STATUS = Integer.valueOf(1); | ||
25 | - | ||
26 | - @Autowired | ||
27 | - private GoodsMapper goodsMapper; | ||
28 | - | ||
29 | - @Autowired | ||
30 | - private StorageMapper storageMapper; | ||
31 | - | ||
32 | - @Autowired | ||
33 | - private SizeMapper sizeMapper; | ||
34 | - | ||
35 | - @Autowired | ||
36 | - private ProductSizesMapper productSizesMapper; | ||
37 | - | ||
38 | - /** | ||
39 | - * 获取ProductSizes列表 | ||
40 | - * @return | ||
41 | - */ | ||
42 | - public List<ProductSizes> getData(List<Integer> ids) { | ||
43 | - //获取ProductId对应的上架的goodsId列表 | ||
44 | - List<Goods> goodsList = goodsMapper.getByIdsAndStatus(ids); | ||
45 | - if(CollectionUtils.isEmpty(goodsList)){ | ||
46 | - return new ArrayList<>(); | ||
47 | - } | ||
48 | - | ||
49 | - //获取goodsId对应得Storage列表 | ||
50 | - List<Integer> goodsIdList = goodsList.parallelStream().map(Goods::getId).collect(Collectors.toList()); | ||
51 | - List<Storage> storageList = storageMapper.getByGoodsIds(goodsIdList); | ||
52 | - if (CollectionUtils.isEmpty(storageList)) { | ||
53 | - return new ArrayList<>(); | ||
54 | - } | ||
55 | - | ||
56 | - //过滤状态是上架的且有库存的Goods和Storage | ||
57 | - storageList = storageList.parallelStream().filter(storageItem -> VALID_STATUS.equals(storageItem.getStatus())) | ||
58 | - .filter(storageItem -> storageItem.getStorageNum() != null && storageItem.getStorageNum().intValue() > 0).collect(Collectors.toList()); | ||
59 | - if(CollectionUtils.isEmpty(storageList)){ | ||
60 | - return new ArrayList<>(); | ||
61 | - } | ||
62 | - | ||
63 | - // 根据上架的GoodsId筛选Storage数据 | ||
64 | - Set<Integer> validGoodsIdSet = goodsIdList.stream().collect(Collectors.toSet()); | ||
65 | - List<Integer> validErpSkuIdList = new ArrayList<>(); | ||
66 | - for (Storage s : storageList) { | ||
67 | - if (validGoodsIdSet.contains(s.getGoodsId())) { | ||
68 | - validErpSkuIdList.add(s.getErpSkuId()); | ||
69 | - } | ||
70 | - } | ||
71 | - | ||
72 | - //判断sku列表是否为空 | ||
73 | - if (validErpSkuIdList == null || validErpSkuIdList.isEmpty()) { | ||
74 | - return new ArrayList<>(); | ||
75 | - } | ||
76 | - | ||
77 | - List<ProductSizes> productSizesList = productSizesMapper.getProductSizes(validErpSkuIdList); | ||
78 | - if (CollectionUtils.isEmpty(productSizesList)) { | ||
79 | - return new ArrayList<>(); | ||
80 | - } | ||
81 | - | ||
82 | - // 设置尺码名称,多个名称之间使用逗号分隔 | ||
83 | - Set<Integer> sizeIdSet = new HashSet<>(); | ||
84 | - for (ProductSizes ps : productSizesList) { | ||
85 | - String sizeArray[] = ps.getSizeIds().split(","); | ||
86 | - if (sizeArray != null) { | ||
87 | - for (int i = 0; i < sizeArray.length; i++) { | ||
88 | - sizeIdSet.add(Integer.valueOf(sizeArray[i])); | ||
89 | - } | ||
90 | - } | ||
91 | - } | ||
92 | - | ||
93 | - List<Size> sizeList = sizeMapper.getByIds(sizeIdSet.stream().collect(Collectors.toList())); | ||
94 | - if (CollectionUtils.isNotEmpty(sizeList)) { | ||
95 | - Map<Integer, String> sizeMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName)); | ||
96 | - //productSizesList.forEach(ps -> ps.setSizeNames(Arrays.stream(ps.getSizeIds().split(",")).map(Integer::valueOf).map(sizeId -> sizeMap.get(sizeId)).collect(Collectors.joining(",")))); | ||
97 | - for (ProductSizes ps : productSizesList) { | ||
98 | - String sizeArray[] = ps.getSizeIds().split(","); | ||
99 | - if (sizeArray != null) { | ||
100 | - for (int i = 0; i < sizeArray.length; i++) { | ||
101 | - if (i == 0) { | ||
102 | - ps.setSizeNames(sizeMap.get(Integer.valueOf(sizeArray[i]))+ ","); | ||
103 | - } else { | ||
104 | - ps.setSizeNames(ps.getSizeNames() + sizeMap.get(Integer.valueOf(sizeArray[i]))+ ","); | ||
105 | - } | ||
106 | - } | ||
107 | - } | ||
108 | - } | ||
109 | - } | ||
110 | - | ||
111 | - return productSizesList; | ||
112 | - } | 25 | + private static final Integer VALID_STATUS = Integer.valueOf(1); |
26 | + | ||
27 | + @Autowired | ||
28 | + private GoodsMapper goodsMapper; | ||
29 | + | ||
30 | + @Autowired | ||
31 | + private StorageMapper storageMapper; | ||
32 | + | ||
33 | + @Autowired | ||
34 | + private SizeMapper sizeMapper; | ||
35 | + | ||
36 | + @Autowired | ||
37 | + private ProductSizesMapper productSizesMapper; | ||
38 | + | ||
39 | + /** | ||
40 | + * 获取ProductSizes列表 | ||
41 | + * | ||
42 | + * @return | ||
43 | + */ | ||
44 | + public List<ProductSizes> getData(List<Integer> ids) { | ||
45 | + // 获取ProductId对应的上架的goodsId列表 | ||
46 | + List<Goods> goodsList = goodsMapper.getByIdsAndStatus(ids); | ||
47 | + if (CollectionUtils.isEmpty(goodsList)) { | ||
48 | + return new ArrayList<>(); | ||
49 | + } | ||
50 | + | ||
51 | + // 获取goodsId对应得Storage列表 | ||
52 | + List<Integer> goodsIdList = goodsList.parallelStream().map(Goods::getId).collect(Collectors.toList()); | ||
53 | + List<Storage> storageList = storageMapper.getByGoodsIds(goodsIdList); | ||
54 | + if (CollectionUtils.isEmpty(storageList)) { | ||
55 | + return new ArrayList<>(); | ||
56 | + } | ||
57 | + | ||
58 | + // 过滤掉下架的sku | ||
59 | + storageList = storageList.parallelStream().filter(storageItem -> VALID_STATUS.equals(storageItem.getStatus())).collect(Collectors.toList()); | ||
60 | + | ||
61 | + // 计算每个skn则总尺码数 | ||
62 | + Map<Integer, Integer> sknSizeCountMap = new HashMap<Integer, Integer>(); | ||
63 | + for (Storage storage : storageList) { | ||
64 | + Integer productId = storage.getProductId(); | ||
65 | + int count = sknSizeCountMap.getOrDefault(productId, 0); | ||
66 | + sknSizeCountMap.put(productId, count + 1); | ||
67 | + } | ||
68 | + | ||
69 | + // 过滤状态是上架的且有库存的Goods和Storage | ||
70 | + storageList = storageList.parallelStream().filter(storageItem -> storageItem.getStorageNum() != null && storageItem.getStorageNum().intValue() > 0) | ||
71 | + .collect(Collectors.toList()); | ||
72 | + if (CollectionUtils.isEmpty(storageList)) { | ||
73 | + return new ArrayList<>(); | ||
74 | + } | ||
75 | + | ||
76 | + // 根据上架的GoodsId筛选Storage数据 | ||
77 | + Set<Integer> validGoodsIdSet = goodsIdList.stream().collect(Collectors.toSet()); | ||
78 | + List<Integer> validErpSkuIdList = new ArrayList<>(); | ||
79 | + for (Storage s : storageList) { | ||
80 | + if (validGoodsIdSet.contains(s.getGoodsId())) { | ||
81 | + validErpSkuIdList.add(s.getErpSkuId()); | ||
82 | + } | ||
83 | + } | ||
84 | + // 判断sku列表是否为空 | ||
85 | + if (validErpSkuIdList == null || validErpSkuIdList.isEmpty()) { | ||
86 | + return new ArrayList<>(); | ||
87 | + } | ||
88 | + | ||
89 | + List<ProductSizes> productSizesList = productSizesMapper.getProductSizes(validErpSkuIdList); | ||
90 | + if (CollectionUtils.isEmpty(productSizesList)) { | ||
91 | + return new ArrayList<>(); | ||
92 | + } | ||
93 | + | ||
94 | + // 设置尺码名称,多个名称之间使用逗号分隔 | ||
95 | + Set<Integer> sizeIdSet = new HashSet<>(); | ||
96 | + for (ProductSizes ps : productSizesList) { | ||
97 | + String sizeArray[] = ps.getSizeIds().split(","); | ||
98 | + if (sizeArray != null) { | ||
99 | + for (int i = 0; i < sizeArray.length; i++) { | ||
100 | + sizeIdSet.add(Integer.valueOf(sizeArray[i])); | ||
101 | + } | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + // 获取尺码信息 | ||
106 | + List<Size> sizeList = sizeMapper.getByIds(sizeIdSet.stream().collect(Collectors.toList())); | ||
107 | + | ||
108 | + // 填充尺码信息和断码率 | ||
109 | + if (CollectionUtils.isNotEmpty(sizeList)) { | ||
110 | + Map<Integer, String> sizeMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName)); | ||
111 | + for (ProductSizes ps : productSizesList) { | ||
112 | + String sizeArray[] = ps.getSizeIds().split(","); | ||
113 | + // 计算断码率 | ||
114 | + double breakSizePercent = this.getBreakSizePercent(sknSizeCountMap.getOrDefault(ps.getProductId(), 0), sizeArray == null ? 0 : sizeArray.length); | ||
115 | + ps.setBreakSizePercent(breakSizePercent); | ||
116 | + // 填充尺码名称 | ||
117 | + if (sizeArray != null) { | ||
118 | + for (int i = 0; i < sizeArray.length; i++) { | ||
119 | + if (i == 0) { | ||
120 | + ps.setSizeNames(sizeMap.get(Integer.valueOf(sizeArray[i])) + ","); | ||
121 | + } else { | ||
122 | + ps.setSizeNames(ps.getSizeNames() + sizeMap.get(Integer.valueOf(sizeArray[i])) + ","); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + } | ||
127 | + } | ||
128 | + } | ||
129 | + return productSizesList; | ||
130 | + } | ||
131 | + | ||
132 | + private double getBreakSizePercent(int totalSizeCount, int effectiveSizeCount) { | ||
133 | + if (totalSizeCount == 0 || effectiveSizeCount == 0) { | ||
134 | + return 100d; | ||
135 | + } | ||
136 | + return 100d * (effectiveSizeCount - totalSizeCount) / totalSizeCount; | ||
137 | + } | ||
138 | + | ||
113 | } | 139 | } |
@@ -17,37 +17,40 @@ import java.util.stream.Collectors; | @@ -17,37 +17,40 @@ import java.util.stream.Collectors; | ||
17 | @Component | 17 | @Component |
18 | public class ProductSizesBuilder implements ViewBuilder { | 18 | public class ProductSizesBuilder implements ViewBuilder { |
19 | 19 | ||
20 | - @Autowired | ||
21 | - private ProductSizesLogicService productSizesLogicService; | ||
22 | - /** | ||
23 | - * 构建ProductSizes数据 | ||
24 | - */ | ||
25 | - @Override | ||
26 | - public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) { | ||
27 | - List<ProductSizes> productSizess = productSizesLogicService.getData(ids); | ||
28 | - Map<Integer, ProductSizes> productSizesMap = productSizess.stream().parallel().collect(Collectors.toMap(ProductSizes::getProductId, (p) -> p)); | ||
29 | - for (ProductIndexBO productIndexBO : productIndexBOs) { | ||
30 | - ProductSizes productSizes = productSizesMap.get(productIndexBO.getProductId()); | ||
31 | - productIndexBO.setIsSoonSoldOut("N"); | ||
32 | - productIndexBO.setIsSoldOut("N"); | ||
33 | - productIndexBO.setSoldOut(1); | ||
34 | - if (productSizes != null) { | ||
35 | - productIndexBO.setStorageNum(BigDecimal.valueOf(productSizes.getStorageNum())); | ||
36 | - if (productSizes.getStorageNum() <= 2) { | ||
37 | - productIndexBO.setIsSoonSoldOut("Y"); | ||
38 | - } | ||
39 | - if (productSizes.getStorageNum() == 0) { | ||
40 | - productIndexBO.setIsSoldOut("Y"); | ||
41 | - productIndexBO.setSoldOut(0); | ||
42 | - } | ||
43 | - productIndexBO.setSizeIds(productSizes.getSizeIds()); | ||
44 | - productIndexBO.setSizeNames(productSizes.getSizeNames()); | ||
45 | - } | ||
46 | - else { | ||
47 | - productIndexBO.setStorageNum(BigDecimal.valueOf(0)); | ||
48 | - productIndexBO.setIsSoldOut("Y"); | ||
49 | - productIndexBO.setSoldOut(0); | ||
50 | - } | ||
51 | - } | ||
52 | - } | 20 | + @Autowired |
21 | + private ProductSizesLogicService productSizesLogicService; | ||
22 | + | ||
23 | + /** | ||
24 | + * 构建ProductSizes数据 | ||
25 | + */ | ||
26 | + @Override | ||
27 | + public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) { | ||
28 | + List<ProductSizes> productSizess = productSizesLogicService.getData(ids); | ||
29 | + Map<Integer, ProductSizes> productSizesMap = productSizess.stream().parallel().collect(Collectors.toMap(ProductSizes::getProductId, (p) -> p)); | ||
30 | + for (ProductIndexBO productIndexBO : productIndexBOs) { | ||
31 | + ProductSizes productSizes = productSizesMap.get(productIndexBO.getProductId()); | ||
32 | + productIndexBO.setIsSoonSoldOut("N"); | ||
33 | + productIndexBO.setIsSoldOut("N"); | ||
34 | + productIndexBO.setSoldOut(1); | ||
35 | + productIndexBO.setBreakSizePercent(100); | ||
36 | + if (productSizes != null) { | ||
37 | + productIndexBO.setStorageNum(BigDecimal.valueOf(productSizes.getStorageNum())); | ||
38 | + if (productSizes.getStorageNum() <= 2) { | ||
39 | + productIndexBO.setIsSoonSoldOut("Y"); | ||
40 | + } | ||
41 | + if (productSizes.getStorageNum() == 0) { | ||
42 | + productIndexBO.setIsSoldOut("Y"); | ||
43 | + productIndexBO.setSoldOut(0); | ||
44 | + } | ||
45 | + productIndexBO.setSizeIds(productSizes.getSizeIds()); | ||
46 | + productIndexBO.setSizeNames(productSizes.getSizeNames()); | ||
47 | + productIndexBO.setBreakSizePercent(productSizes.getBreakSizePercent()); | ||
48 | + } else { | ||
49 | + productIndexBO.setStorageNum(BigDecimal.valueOf(0)); | ||
50 | + productIndexBO.setIsSoldOut("Y"); | ||
51 | + productIndexBO.setSoldOut(0); | ||
52 | + productIndexBO.setBreakSizePercent(100); | ||
53 | + } | ||
54 | + } | ||
55 | + } | ||
53 | } | 56 | } |
-
Please register or login to post a comment