|
@@ -30,37 +30,41 @@ public class PromotionPriceService { |
|
@@ -30,37 +30,41 @@ public class PromotionPriceService { |
30
|
private PromotionMatchService promotionMatchService;
|
30
|
private PromotionMatchService promotionMatchService;
|
31
|
|
31
|
|
32
|
public List<Map<String, Object>> fillPromotionPrice(List<Map<String, Object>> productList) {
|
32
|
public List<Map<String, Object>> fillPromotionPrice(List<Map<String, Object>> productList) {
|
33
|
- try {
|
|
|
34
|
- List<Map<String, Object>> results = new ArrayList<>();
|
|
|
35
|
- if (CollectionUtils.isEmpty(productList)) {
|
|
|
36
|
- return new ArrayList<>();
|
33
|
+ //1、参数判断
|
|
|
34
|
+ if (productList == null || productList.isEmpty()) {
|
|
|
35
|
+ return productList;
|
37
|
}
|
36
|
}
|
38
|
- //获取所有促销信息,制作一个以promotionId为key的Map
|
37
|
+ //2、获取所有促销信息,制作一个以promotionId为key的Map
|
39
|
List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
38
|
List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
40
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
39
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
41
|
return productList;
|
40
|
return productList;
|
42
|
}
|
41
|
}
|
43
|
Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
42
|
Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
|
|
43
|
+ //3、循环匹配promotionPrice
|
|
|
44
|
+ for (Map<String, Object> product : productList) {
|
|
|
45
|
+ Integer promotionPrice = this.getPromotionPrice(product, promotionIndexBOMap);
|
|
|
46
|
+ product.put("promotion_price", promotionPrice);
|
|
|
47
|
+ }
|
|
|
48
|
+ //4、返回结果
|
|
|
49
|
+ return productList;
|
|
|
50
|
+ }
|
44
|
|
51
|
|
45
|
- //遍历每个skn,计算promotion_price字段
|
|
|
46
|
- for (Map<String, Object> productMap : productList) {
|
|
|
47
|
-
|
52
|
+ private Integer getPromotionPrice(Map<String, Object> product, Map<Integer, PromotionIndexBO> promotionIndexBOMap) {
|
|
|
53
|
+ try {
|
48
|
//全球购skn,promotion_price为空
|
54
|
//全球购skn,promotion_price为空
|
49
|
- if ("Y".equals(MapUtils.getString(productMap, "is_global"))) {
|
|
|
50
|
- productMap.put("promotion_price", null);
|
|
|
51
|
- results.add(productMap);
|
|
|
52
|
- continue;
|
55
|
+ if ("Y".equals(MapUtils.getString(product, "is_global"))) {
|
|
|
56
|
+ return null;
|
53
|
}
|
57
|
}
|
54
|
-
|
|
|
55
|
//获取当前变价计划里的salesPrice,默认salesPrice为skn的sales_price
|
58
|
//获取当前变价计划里的salesPrice,默认salesPrice为skn的sales_price
|
56
|
- Double salesPrice = this.getProductPricePlanSalesPrice(productMap);
|
|
|
57
|
-
|
59
|
+ Double salesPrice = this.getProductPricePlanSalesPrice(product);
|
|
|
60
|
+ if (salesPrice == null) {
|
|
|
61
|
+ return null;
|
|
|
62
|
+ }
|
58
|
//获取单个skn的促销列表
|
63
|
//获取单个skn的促销列表
|
59
|
- productMap.put("promotion_price", null);
|
|
|
60
|
- List<Map<String, String>> promotionTagList = (List<Map<String, String>>) productMap.get("promotion_tag");
|
|
|
61
|
-
|
|
|
62
|
- if (CollectionUtils.isNotEmpty(promotionTagList)) {
|
|
|
63
|
- boolean isPromotionPriceActive = false;
|
64
|
+ List<Map<String, String>> promotionTagList = (List<Map<String, String>>) product.get("promotion_tag");
|
|
|
65
|
+ if (promotionTagList == null || promotionTagList.isEmpty()) {
|
|
|
66
|
+ return null;
|
|
|
67
|
+ }
|
64
|
List<PromotionIndexBO> promotionIndexBOS = new ArrayList<>();
|
68
|
List<PromotionIndexBO> promotionIndexBOS = new ArrayList<>();
|
65
|
Map<Integer, Map<String, String>> promotionTagMap = new HashMap<>();
|
69
|
Map<Integer, Map<String, String>> promotionTagMap = new HashMap<>();
|
66
|
for (Map<String, String> promotionTag : promotionTagList) {
|
70
|
for (Map<String, String> promotionTag : promotionTagList) {
|
|
@@ -71,20 +75,20 @@ public class PromotionPriceService { |
|
@@ -71,20 +75,20 @@ public class PromotionPriceService { |
71
|
}
|
75
|
}
|
72
|
//生成安装权重排序后的促销列表
|
76
|
//生成安装权重排序后的促销列表
|
73
|
List<PromotionIndexBO> tempPromotionIndexBos = promotionIndexBOS.stream().sorted(Comparator.comparing(PromotionIndexBO::getPriority).reversed()).collect(Collectors.toList());
|
77
|
List<PromotionIndexBO> tempPromotionIndexBos = promotionIndexBOS.stream().sorted(Comparator.comparing(PromotionIndexBO::getPriority).reversed()).collect(Collectors.toList());
|
74
|
- List<PromotionIndexBO> SortedPromotionIndexBOs = new ArrayList<>();
|
78
|
+ List<PromotionIndexBO> sortedPromotionIndexBOs = new ArrayList<>();
|
75
|
//去掉不满足的促销
|
79
|
//去掉不满足的促销
|
76
|
for (PromotionIndexBO promotionIndexBO : tempPromotionIndexBos) {
|
80
|
for (PromotionIndexBO promotionIndexBO : tempPromotionIndexBos) {
|
77
|
//判断是否满足金额和件数条件
|
81
|
//判断是否满足金额和件数条件
|
78
|
String conditionParam = promotionIndexBOMap.get(promotionIndexBO.getId()).getConditionParam();
|
82
|
String conditionParam = promotionIndexBOMap.get(promotionIndexBO.getId()).getConditionParam();
|
79
|
PromotionCond promotionCond = promotionCondService.buildPromotionCondWithJsonString(conditionParam);
|
83
|
PromotionCond promotionCond = promotionCondService.buildPromotionCondWithJsonString(conditionParam);
|
80
|
- boolean result = promotionMatchService.matchProductForPromotionPrice(promotionCond, productMap);
|
84
|
+ boolean result = promotionMatchService.matchProductForPromotionPrice(promotionCond, product);
|
81
|
if (result) {
|
85
|
if (result) {
|
82
|
- SortedPromotionIndexBOs.add(promotionIndexBO);
|
86
|
+ sortedPromotionIndexBOs.add(promotionIndexBO);
|
83
|
}
|
87
|
}
|
84
|
}
|
88
|
}
|
85
|
|
89
|
|
86
|
//生成按照权重排序后的促销标签列表
|
90
|
//生成按照权重排序后的促销标签列表
|
87
|
- List<Integer> promotionIdList = SortedPromotionIndexBOs.stream().map(PromotionIndexBO::getId).collect(Collectors.toList());
|
91
|
+ List<Integer> promotionIdList = sortedPromotionIndexBOs.stream().map(PromotionIndexBO::getId).collect(Collectors.toList());
|
88
|
List<Map<String, String>> promotionTagListSorted = new ArrayList<>();
|
92
|
List<Map<String, String>> promotionTagListSorted = new ArrayList<>();
|
89
|
for (Integer id : promotionIdList) {
|
93
|
for (Integer id : promotionIdList) {
|
90
|
promotionTagListSorted.add(promotionTagMap.get(id));
|
94
|
promotionTagListSorted.add(promotionTagMap.get(id));
|
|
@@ -92,13 +96,15 @@ public class PromotionPriceService { |
|
@@ -92,13 +96,15 @@ public class PromotionPriceService { |
92
|
|
96
|
|
93
|
//记录因为互斥需要跳过的促销的位置列表
|
97
|
//记录因为互斥需要跳过的促销的位置列表
|
94
|
Set<Integer> markForDeletePositionSet = new HashSet<>();
|
98
|
Set<Integer> markForDeletePositionSet = new HashSet<>();
|
95
|
- this.buildMarkForDeletePositionSet(markForDeletePositionSet, SortedPromotionIndexBOs, promotionIdList);
|
99
|
+ this.buildMarkForDeletePositionSet(markForDeletePositionSet, sortedPromotionIndexBOs, promotionIdList);
|
96
|
|
100
|
|
97
|
//把需要跳过的促销id从列表中删除
|
101
|
//把需要跳过的促销id从列表中删除
|
98
|
for (Integer position : markForDeletePositionSet) {
|
102
|
for (Integer position : markForDeletePositionSet) {
|
99
|
- promotionIdList.remove(SortedPromotionIndexBOs.get(position).getId());
|
103
|
+ promotionIdList.remove(sortedPromotionIndexBOs.get(position).getId());
|
100
|
}
|
104
|
}
|
101
|
|
105
|
|
|
|
106
|
+ boolean isPromotionPriceActive = false;
|
|
|
107
|
+
|
102
|
//遍历每个促销,计算促销价
|
108
|
//遍历每个促销,计算促销价
|
103
|
Double currentSalesPrice = salesPrice;
|
109
|
Double currentSalesPrice = salesPrice;
|
104
|
for (Map<String, String> promotionTag : promotionTagListSorted) {
|
110
|
for (Map<String, String> promotionTag : promotionTagListSorted) {
|
|
@@ -152,17 +158,13 @@ public class PromotionPriceService { |
|
@@ -152,17 +158,13 @@ public class PromotionPriceService { |
152
|
}
|
158
|
}
|
153
|
}
|
159
|
}
|
154
|
if (isPromotionPriceActive) {
|
160
|
if (isPromotionPriceActive) {
|
155
|
- Integer finalPrice = getIntCeilPrice(currentSalesPrice);
|
|
|
156
|
- productMap.put("promotion_price", finalPrice.toString());
|
|
|
157
|
- }
|
161
|
+ return getIntCeilPrice(currentSalesPrice);
|
|
|
162
|
+ } else {
|
|
|
163
|
+ return null;
|
158
|
}
|
164
|
}
|
159
|
- //插入字段
|
|
|
160
|
- results.add(productMap);
|
|
|
161
|
- }
|
|
|
162
|
- return results;
|
|
|
163
|
} catch (Exception e) {
|
165
|
} catch (Exception e) {
|
164
|
logger.error(e.getMessage(), e);
|
166
|
logger.error(e.getMessage(), e);
|
165
|
- return new ArrayList<>();
|
167
|
+ return null;
|
166
|
}
|
168
|
}
|
167
|
}
|
169
|
}
|
168
|
|
170
|
|
|
@@ -190,11 +192,14 @@ public class PromotionPriceService { |
|
@@ -190,11 +192,14 @@ public class PromotionPriceService { |
190
|
}
|
192
|
}
|
191
|
|
193
|
|
192
|
private Double getProductPricePlanSalesPrice(Map<String, Object> productMap) {
|
194
|
private Double getProductPricePlanSalesPrice(Map<String, Object> productMap) {
|
193
|
- Double salesPrice = Double.valueOf(productMap.get("sales_price").toString());
|
195
|
+ //1、取当前销售价
|
|
|
196
|
+ Double salesPrice = MapUtils.getDoubleValue(productMap, "sales_price", 0);
|
194
|
List<Map<String, String>> pricePlanList = (List<Map<String, String>>) productMap.get("product_price_plan_list");
|
197
|
List<Map<String, String>> pricePlanList = (List<Map<String, String>>) productMap.get("product_price_plan_list");
|
195
|
- List<Map<String, String>> pricePlanListSorted;
|
|
|
196
|
- pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
|
|
197
|
- if (CollectionUtils.isNotEmpty(pricePlanListSorted)) {
|
198
|
+ if (pricePlanList == null || pricePlanList.isEmpty()) {
|
|
|
199
|
+ return salesPrice;
|
|
|
200
|
+ }
|
|
|
201
|
+ //2、截取当前销售价格-取满足时间的第一个变价计算,获取current_saleprice
|
|
|
202
|
+ List<Map<String, String>> pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
198
|
long currentTime = DateUtil.getCurrentTimeSecond();
|
203
|
long currentTime = DateUtil.getCurrentTimeSecond();
|
199
|
for (Map<String, String> pricePlanMap : pricePlanListSorted) {
|
204
|
for (Map<String, String> pricePlanMap : pricePlanListSorted) {
|
200
|
Integer effectTime = MapUtils.getInteger(pricePlanMap, "effect_time");
|
205
|
Integer effectTime = MapUtils.getInteger(pricePlanMap, "effect_time");
|
|
@@ -207,11 +212,9 @@ public class PromotionPriceService { |
|
@@ -207,11 +212,9 @@ public class PromotionPriceService { |
207
|
return salesPrice;
|
212
|
return salesPrice;
|
208
|
}
|
213
|
}
|
209
|
}
|
214
|
}
|
210
|
- }
|
|
|
211
|
return salesPrice;
|
215
|
return salesPrice;
|
212
|
}
|
216
|
}
|
213
|
|
217
|
|
214
|
-
|
|
|
215
|
private static Integer getIntCeilPrice(Double price) {
|
218
|
private static Integer getIntCeilPrice(Double price) {
|
216
|
return Double.valueOf(Math.ceil(price)).intValue();
|
219
|
return Double.valueOf(Math.ceil(price)).intValue();
|
217
|
}
|
220
|
}
|