...
|
...
|
@@ -14,64 +14,59 @@ import java.util.stream.Collectors; |
|
|
/**
|
|
|
* Created by wangnan on 2017/5/11.
|
|
|
*/
|
|
|
public class PromotionAggregation extends AbstractSingleFieldAggregation {
|
|
|
public class ZqNameAggregation extends AbstractSingleFieldAggregation {
|
|
|
|
|
|
private ZqNameIndexBaseService zqNameIndexBaseService;
|
|
|
private ZqNameIndexBaseService zqNameIndexBaseService;
|
|
|
|
|
|
public PromotionAggregation(ZqNameIndexBaseService zqNameIndexBaseService, int count) {
|
|
|
super(count);
|
|
|
this.zqNameIndexBaseService = zqNameIndexBaseService;
|
|
|
}
|
|
|
public ZqNameAggregation(ZqNameIndexBaseService zqNameIndexBaseService, int count) {
|
|
|
super(count);
|
|
|
this.zqNameIndexBaseService = zqNameIndexBaseService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected String getField() {
|
|
|
return ProductIndexEsField.ispromotion;
|
|
|
}
|
|
|
@Override
|
|
|
protected String getField() {
|
|
|
return ProductIndexEsField.ispromotion;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String aggName() {
|
|
|
return "promotionAgg";
|
|
|
}
|
|
|
@Override
|
|
|
public String aggName() {
|
|
|
return "zqNameAgg";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String filterName() {
|
|
|
return "promotion";
|
|
|
}
|
|
|
@Override
|
|
|
public String filterName() {
|
|
|
return "zqName";
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
|
|
|
List<String> promotionIdList = (List<String>) super.getAggregationResponseMap(aggMaps);
|
|
|
if (CollectionUtils.isNotEmpty(promotionIdList)) {
|
|
|
promotionIdList = promotionIdList.stream().collect(Collectors.toList());
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(promotionIdList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
// 调用zqname索引查询title
|
|
|
Map<String, String> promotionParam = new HashMap<>();
|
|
|
promotionParam.put("ids", promotionIdList.stream().collect(Collectors.joining(",")));
|
|
|
List<Map<String, Object>> promotionList = zqNameIndexBaseService.queryZQNameListByParam(promotionParam);
|
|
|
// promotion_title去重,is_promotion用逗号连接
|
|
|
Map<String, Map<String, Object>> titleMap = new HashMap<>();
|
|
|
for (Map<String, Object> map : promotionList) {
|
|
|
String title = map.get("promotion_title").toString();
|
|
|
if (titleMap.containsKey(title)) {
|
|
|
String newKey = map.get("is_promotion").toString();
|
|
|
String oldKey = titleMap.get(title).get("is_promotion").toString();
|
|
|
Map<String, Object> newMap = new HashMap<String, Object>();
|
|
|
newMap.put("promotion_title", title);
|
|
|
newMap.put("is_promotion", newKey + "," + oldKey);
|
|
|
titleMap.put(title, newMap);
|
|
|
} else {
|
|
|
titleMap.put(title, map);
|
|
|
}
|
|
|
}
|
|
|
promotionList = new ArrayList<>();
|
|
|
for (Map.Entry<String, Map<String, Object>> entry : titleMap.entrySet()) {
|
|
|
promotionList.add(entry.getValue());
|
|
|
}
|
|
|
return promotionList == null || promotionList.isEmpty() ? new ArrayList<>() : promotionList;
|
|
|
}
|
|
|
@Override
|
|
|
public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
|
|
|
List<String> zqIdList = (List<String>) super.getAggregationResponseMap(aggMaps);
|
|
|
if (CollectionUtils.isEmpty(zqIdList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
// 调用zqname索引查询zqtitle
|
|
|
String ids = zqIdList.stream().collect(Collectors.joining(","));
|
|
|
List<Map<String, Object>> zqNameList = zqNameIndexBaseService.queryZQNameListByIds(ids);
|
|
|
// promotion_title去重,is_promotion用逗号连接
|
|
|
Map<String, Map<String, Object>> titleMap = new HashMap<>();
|
|
|
for (Map<String, Object> map : zqNameList) {
|
|
|
String title = map.get("promotion_title").toString();
|
|
|
if (titleMap.containsKey(title)) {
|
|
|
String newKey = map.get("is_promotion").toString();
|
|
|
String oldKey = titleMap.get(title).get("is_promotion").toString();
|
|
|
Map<String, Object> newMap = new HashMap<>();
|
|
|
newMap.put("promotion_title", title);
|
|
|
newMap.put("is_promotion", newKey + "," + oldKey);
|
|
|
titleMap.put(title, newMap);
|
|
|
} else {
|
|
|
titleMap.put(title, map);
|
|
|
}
|
|
|
}
|
|
|
zqNameList = new ArrayList<>();
|
|
|
for (Map.Entry<String, Map<String, Object>> entry : titleMap.entrySet()) {
|
|
|
zqNameList.add(entry.getValue());
|
|
|
}
|
|
|
return zqNameList == null || zqNameList.isEmpty() ? new ArrayList<>() : zqNameList;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|