...
|
...
|
@@ -30,37 +30,41 @@ public class PromotionPriceService { |
|
|
private PromotionMatchService promotionMatchService;
|
|
|
|
|
|
public List<Map<String, Object>> fillPromotionPrice(List<Map<String, Object>> productList) {
|
|
|
try {
|
|
|
List<Map<String, Object>> results = new ArrayList<>();
|
|
|
if (CollectionUtils.isEmpty(productList)) {
|
|
|
return new ArrayList<>();
|
|
|
//1、参数判断
|
|
|
if (productList == null || productList.isEmpty()) {
|
|
|
return productList;
|
|
|
}
|
|
|
//获取所有促销信息,制作一个以promotionId为key的Map
|
|
|
//2、获取所有促销信息,制作一个以promotionId为key的Map
|
|
|
List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
|
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
|
|
return productList;
|
|
|
}
|
|
|
Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
|
|
//3、循环匹配promotionPrice
|
|
|
for (Map<String, Object> product : productList) {
|
|
|
Integer promotionPrice = this.getPromotionPrice(product, promotionIndexBOMap);
|
|
|
product.put("promotion_price", promotionPrice);
|
|
|
}
|
|
|
//4、返回结果
|
|
|
return productList;
|
|
|
}
|
|
|
|
|
|
//遍历每个skn,计算promotion_price字段
|
|
|
for (Map<String, Object> productMap : productList) {
|
|
|
|
|
|
private Integer getPromotionPrice(Map<String, Object> product, Map<Integer, PromotionIndexBO> promotionIndexBOMap) {
|
|
|
try {
|
|
|
//全球购skn,promotion_price为空
|
|
|
if ("Y".equals(MapUtils.getString(productMap, "is_global"))) {
|
|
|
productMap.put("promotion_price", null);
|
|
|
results.add(productMap);
|
|
|
continue;
|
|
|
if ("Y".equals(MapUtils.getString(product, "is_global"))) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//获取当前变价计划里的salesPrice,默认salesPrice为skn的sales_price
|
|
|
Double salesPrice = this.getProductPricePlanSalesPrice(productMap);
|
|
|
|
|
|
Double salesPrice = this.getProductPricePlanSalesPrice(product);
|
|
|
if (salesPrice == null) {
|
|
|
return null;
|
|
|
}
|
|
|
//获取单个skn的促销列表
|
|
|
productMap.put("promotion_price", null);
|
|
|
List<Map<String, String>> promotionTagList = (List<Map<String, String>>) productMap.get("promotion_tag");
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(promotionTagList)) {
|
|
|
boolean isPromotionPriceActive = false;
|
|
|
List<Map<String, String>> promotionTagList = (List<Map<String, String>>) product.get("promotion_tag");
|
|
|
if (promotionTagList == null || promotionTagList.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
List<PromotionIndexBO> promotionIndexBOS = new ArrayList<>();
|
|
|
Map<Integer, Map<String, String>> promotionTagMap = new HashMap<>();
|
|
|
for (Map<String, String> promotionTag : promotionTagList) {
|
...
|
...
|
@@ -71,20 +75,20 @@ public class PromotionPriceService { |
|
|
}
|
|
|
//生成安装权重排序后的促销列表
|
|
|
List<PromotionIndexBO> tempPromotionIndexBos = promotionIndexBOS.stream().sorted(Comparator.comparing(PromotionIndexBO::getPriority).reversed()).collect(Collectors.toList());
|
|
|
List<PromotionIndexBO> SortedPromotionIndexBOs = new ArrayList<>();
|
|
|
List<PromotionIndexBO> sortedPromotionIndexBOs = new ArrayList<>();
|
|
|
//去掉不满足的促销
|
|
|
for (PromotionIndexBO promotionIndexBO : tempPromotionIndexBos) {
|
|
|
//判断是否满足金额和件数条件
|
|
|
String conditionParam = promotionIndexBOMap.get(promotionIndexBO.getId()).getConditionParam();
|
|
|
PromotionCond promotionCond = promotionCondService.buildPromotionCondWithJsonString(conditionParam);
|
|
|
boolean result = promotionMatchService.matchProductForPromotionPrice(promotionCond, productMap);
|
|
|
boolean result = promotionMatchService.matchProductForPromotionPrice(promotionCond, product);
|
|
|
if (result) {
|
|
|
SortedPromotionIndexBOs.add(promotionIndexBO);
|
|
|
sortedPromotionIndexBOs.add(promotionIndexBO);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//生成按照权重排序后的促销标签列表
|
|
|
List<Integer> promotionIdList = SortedPromotionIndexBOs.stream().map(PromotionIndexBO::getId).collect(Collectors.toList());
|
|
|
List<Integer> promotionIdList = sortedPromotionIndexBOs.stream().map(PromotionIndexBO::getId).collect(Collectors.toList());
|
|
|
List<Map<String, String>> promotionTagListSorted = new ArrayList<>();
|
|
|
for (Integer id : promotionIdList) {
|
|
|
promotionTagListSorted.add(promotionTagMap.get(id));
|
...
|
...
|
@@ -92,13 +96,15 @@ public class PromotionPriceService { |
|
|
|
|
|
//记录因为互斥需要跳过的促销的位置列表
|
|
|
Set<Integer> markForDeletePositionSet = new HashSet<>();
|
|
|
this.buildMarkForDeletePositionSet(markForDeletePositionSet, SortedPromotionIndexBOs, promotionIdList);
|
|
|
this.buildMarkForDeletePositionSet(markForDeletePositionSet, sortedPromotionIndexBOs, promotionIdList);
|
|
|
|
|
|
//把需要跳过的促销id从列表中删除
|
|
|
for (Integer position : markForDeletePositionSet) {
|
|
|
promotionIdList.remove(SortedPromotionIndexBOs.get(position).getId());
|
|
|
promotionIdList.remove(sortedPromotionIndexBOs.get(position).getId());
|
|
|
}
|
|
|
|
|
|
boolean isPromotionPriceActive = false;
|
|
|
|
|
|
//遍历每个促销,计算促销价
|
|
|
Double currentSalesPrice = salesPrice;
|
|
|
for (Map<String, String> promotionTag : promotionTagListSorted) {
|
...
|
...
|
@@ -152,17 +158,13 @@ public class PromotionPriceService { |
|
|
}
|
|
|
}
|
|
|
if (isPromotionPriceActive) {
|
|
|
Integer finalPrice = getIntCeilPrice(currentSalesPrice);
|
|
|
productMap.put("promotion_price", finalPrice.toString());
|
|
|
}
|
|
|
return getIntCeilPrice(currentSalesPrice);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
//插入字段
|
|
|
results.add(productMap);
|
|
|
}
|
|
|
return results;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -190,11 +192,14 @@ public class PromotionPriceService { |
|
|
}
|
|
|
|
|
|
private Double getProductPricePlanSalesPrice(Map<String, Object> productMap) {
|
|
|
Double salesPrice = Double.valueOf(productMap.get("sales_price").toString());
|
|
|
//1、取当前销售价
|
|
|
Double salesPrice = MapUtils.getDoubleValue(productMap, "sales_price", 0);
|
|
|
List<Map<String, String>> pricePlanList = (List<Map<String, String>>) productMap.get("product_price_plan_list");
|
|
|
List<Map<String, String>> pricePlanListSorted;
|
|
|
pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isNotEmpty(pricePlanListSorted)) {
|
|
|
if (pricePlanList == null || pricePlanList.isEmpty()) {
|
|
|
return salesPrice;
|
|
|
}
|
|
|
//2、截取当前销售价格-取满足时间的第一个变价计算,获取current_saleprice
|
|
|
List<Map<String, String>> pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
|
|
long currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
for (Map<String, String> pricePlanMap : pricePlanListSorted) {
|
|
|
Integer effectTime = MapUtils.getInteger(pricePlanMap, "effect_time");
|
...
|
...
|
@@ -207,11 +212,9 @@ public class PromotionPriceService { |
|
|
return salesPrice;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return salesPrice;
|
|
|
}
|
|
|
|
|
|
|
|
|
private static Integer getIntCeilPrice(Double price) {
|
|
|
return Double.valueOf(Math.ceil(price)).intValue();
|
|
|
}
|
...
|
...
|
|