Authored by wangnan

实时促销标签fix

... ... @@ -46,6 +46,7 @@ public class SknReturnInfoCacheBean extends AbstractCacheBean<SknReturnInfoResqu
break;
}
}
finalResults = productIndexBaseService.getProductListWithPromotion(finalResults);
return finalResults;
}
... ...
... ... @@ -221,7 +221,7 @@ public class ProductIndexBaseService {
// 标签
productMap.put("customize_tag", MapUtils.getObject(map, ProductIndexEsField.customizeTags, new JSONArray()));
//productMap.put("promotion_tag", this.getPomotionTags(map));// 促销标签
productMap.put("promotion_tag", this.getPromotionTag(map));// 促销标签
productMap.put("is_promotion_active", "N");// 当前是否有促销正在进行
boolean promotionActive = getPromotionActive(map);
if (promotionActive) {
... ... @@ -358,30 +358,58 @@ public class ProductIndexBaseService {
* 获取商品列表[并返回促销标签信息]
* add by wangnan in 2018/1/29
*/
public List<JSONObject> getPromotionTag(Map<String, Object> map) {
//全量查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分钟缓存
Map<String, String> promotionTypeMap = promotionTypeService.getPromotionTypeMap();
//生成促销标签对象列表
List<JSONObject> matchedPromotions = new ArrayList<>();
if (CollectionUtils.isNotEmpty(matchedPromotionCondList)) {
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()));
}else{
matchedPromotion.put("name", "undefined");
}
return matchedPromotion;
}).collect(Collectors.toList());
}
return matchedPromotions;
}
/**
* 获取skn促销标签-用于在待返回的列表返回之前加上促销标签这个节点
* add by wangnan in 2018/1/29
*/
public List<Map<String, Object>> getProductListWithPromotion(List<Map<String, Object>> productEsSourceList) {
if (productEsSourceList == null || productEsSourceList.isEmpty()) {
return new ArrayList<>();
}
//1.获取结果列表中的skn列表
String[] sknStr = new String[productEsSourceList.size()];
for (int i = 0; i < productEsSourceList.size(); i++) {
sknStr[i] = MapUtils.getString(productEsSourceList.get(i), "product_skn", "");
}
//2.全量查promotion索引内容,用于和每个skn匹配,1分钟缓存
//1.全量查promotion索引内容,用于和每个skn匹配,1分钟缓存
List<PromotionCond> promotionCondList = promotionCondService.getPromotionCondList();
//3.构建每个skn匹配的促销
//2.构建每个skn匹配的促销
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
for (Map<String, Object> productEsSource : productEsSourceList) {
//3.1 获取该skn匹配上的促销
//2.1 获取该skn匹配上的促销
List<PromotionCond> matchedPromotionCondList = promotionCondList.stream()
.filter(promotionCond -> promotionMatchService.matchProduct(promotionCond, productEsSource))
.collect(Collectors.toList());
//3.2 查询促销类型->促销名映射的索引获取map,用于填充促销标签名称,1分钟缓存
//2.2 查询促销类型->促销名映射的索引获取map,用于填充促销标签名称,1分钟缓存
Map<String, String> promotionTypeMap = promotionTypeService.getPromotionTypeMap();
//3.3 生成促销标签对象列表
//2.3 生成促销标签对象列表
if (CollectionUtils.isNotEmpty(matchedPromotionCondList)) {
List<JSONObject> matchedPromotions = matchedPromotionCondList.stream()
.map(promotionCond -> {
... ... @@ -397,7 +425,7 @@ public class ProductIndexBaseService {
}
return matchedPromotion;
}).collect(Collectors.toList());
//3.4 列表中插入促销标签信息
//2.4 列表中插入促销标签信息
productEsSource.put("promotion_tag", matchedPromotions);
}
results.add(productEsSource);
... ...
... ... @@ -74,7 +74,7 @@ public class ProductListHelper {
productListResult.put("page_total", searchResult.getTotalPage());
List<Map<String, Object>> productList = searchResult.getResultList();
productList = productIndexBaseService.getProductListWithPricePlan(productList);
productList = productIndexBaseService.getProductListWithPromotion(productList);
//productList = productIndexBaseService.getProductListWithPromotion(productList);
if(needReSort){
productList = productListSortService.sortProductList(productList);
}
... ...