Authored by hugufei

fix bug

... ... @@ -75,78 +75,45 @@ public class PromotionIndexBaseService {
return recommendPromotionAggVO;
}
/**
* 传入一个productList,加入促销标签
*/
public List<Map<String, Object>> fillPromotionTag(List<Map<String, Object>> productList) {
try {
//1、判断
if (productList == null || productList.isEmpty()) {
return new ArrayList<>();
return productList;
}
//1.全量查promotion索引内容,用于和每个skn匹配,1分钟缓存
//2、全量查promotion索引内容,用于和每个skn匹配,1分钟缓存
List<PromotionCond> promotionCondList = promotionCondService.getPromotionCondList();
//2.构建每个skn匹配的促销
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
if (promotionCondList == null || promotionCondList.isEmpty()) {
return productList;
}
//3、执行匹配
for (Map<String, Object> productMap : productList) {
//全球购跳过
if ("Y".equals(MapUtils.getString(productMap, "is_global"))) {
productMap.put("promotion_tag", new JSONArray());
results.add(productMap);
continue;
}
//2.1 获取该skn匹配上的促销
List<PromotionCond> matchedPromotionCondList = promotionCondList.stream()
.filter(promotionCond -> promotionMatchService.matchProduct(promotionCond, productMap))
.collect(Collectors.toList());
//2.2 查询促销类型->促销名映射的索引获取map,用于填充促销标签名称,1分钟缓存
Map<String, String> promotionTypeMap = promotionTypeService.getPromotionTypeMap();
//2.3 生成促销标签对象列表
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(matchedPromotionCondList)) {
List<JSONObject> matchedPromotions = matchedPromotionCondList.stream()
.map(promotionCond -> {
JSONObject matchedPromotion = new JSONObject();
matchedPromotion.put("id", promotionCond.getPromotionId());
matchedPromotion.put("type", promotionCond.getPromotionType());
matchedPromotion.put("startTime", promotionCond.getStartTime());
matchedPromotion.put("endTime", promotionCond.getEndTime());
if (!promotionTypeMap.isEmpty() && promotionCond.getShowStatus() == 1) {
matchedPromotion.put("name", promotionTypeMap.get(promotionCond.getPromotionType()));
List<JSONObject> promotion_tag = this.getProductPromotionTag(productMap, promotionCondList);
productMap.put("promotion_tag", promotion_tag);
}
return matchedPromotion;
}).collect(Collectors.toList());
//2.4 列表中插入促销标签信息
productMap.put("promotion_tag", matchedPromotions);
//4、返回
return productList;
}
results.add(productMap);
private List<JSONObject> getProductPromotionTag(Map<String, Object> productMap, List<PromotionCond> promotionCondList) {
try {
//1、promotionCondList判断
if (promotionCondList == null || promotionCondList.isEmpty()) {
return new ArrayList<>();
}
return results;
} catch (Exception e) {
logger.error(e.getMessage(), e);
//2、全球购跳过
if ("Y".equals(MapUtils.getString(productMap, "is_global"))) {
return new ArrayList<>();
}
//3、获取该skn匹配上的促销
List<PromotionCond> matchedPromotionCondList = promotionCondList.stream().filter(promotionCond -> promotionMatchService.matchProduct(promotionCond, productMap)).collect(Collectors.toList());
if(matchedPromotionCondList==null || matchedPromotionCondList.isEmpty()){
return new ArrayList<>();
}
/**
* 获取单个product的促销标签-会弃用
*/
public List<JSONObject> getPromotionTag(Map<String, Object> map) {
try {
//全量查promotion索引内容,用于和每个skn匹配,1分钟缓存
List<PromotionCond> promotionCondList = promotionCondService.getPromotionCondList();
//获取该skn匹配上的促销
List<PromotionCond> matchedPromotionCondList = promotionCondList.stream()
.filter(promotionCond -> promotionMatchService.matchProduct(promotionCond, map))
.collect(Collectors.toList());
//查询促销类型->促销名映射的索引获取map,用于填充促销标签名称,1分钟缓存
//4、查询促销类型->促销名映射的索引获取map,用于填充促销标签名称,1分钟缓存
Map<String, String> promotionTypeMap = promotionTypeService.getPromotionTypeMap();
//生成促销标签对象列表
List<JSONObject> matchedPromotions = new ArrayList<>();
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(matchedPromotionCondList)) {
matchedPromotions = matchedPromotionCondList.stream()
.map(promotionCond -> {
//5、生成促销标签对象列表
List<JSONObject> results = new ArrayList<>();
for (PromotionCond promotionCond:matchedPromotionCondList){
JSONObject matchedPromotion = new JSONObject();
matchedPromotion.put("id", promotionCond.getPromotionId());
matchedPromotion.put("type", promotionCond.getPromotionType());
... ... @@ -155,12 +122,11 @@ public class PromotionIndexBaseService {
if (!promotionTypeMap.isEmpty() && promotionCond.getShowStatus() == 1) {
matchedPromotion.put("name", promotionTypeMap.get(promotionCond.getPromotionType()));
}
return matchedPromotion;
}).collect(Collectors.toList());
results.add(matchedPromotion);
}
return matchedPromotions;
return results;
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.error(e.getMessage(),e);
return new ArrayList<>();
}
}
... ...
... ... @@ -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();
}
... ...