|
@@ -3,12 +3,14 @@ package cn.cslg.pas.service.business.es;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
|
|
|
import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
|
+import cn.cslg.pas.common.dto.es.EsDateRangeDTO;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
|
import cn.cslg.pas.common.vo.business.EsAllCountVO;
|
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
|
+import cn.cslg.pas.common.vo.es.EsDateRangeVO;
|
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.EsCountAnalysisBuilderFactory;
|
|
|
import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.IEsCountAnalysisBuilder;
|
|
@@ -36,7 +38,7 @@ import java.util.stream.Collectors;
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class EsCountService {
|
|
|
private final List<String> childList = Arrays.asList("field");
|
|
|
- private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH","MIN");
|
|
|
+ private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH", "MIN");
|
|
|
private final List<String> dateList = Arrays.asList("PD", "AD", "GD");
|
|
|
private final List<String> numberList = Arrays.asList("QPN", "QDPN", "SFN", "IFN", "PFN");
|
|
|
|
|
@@ -51,18 +53,60 @@ public class EsCountService {
|
|
|
|
|
|
/**
|
|
|
* 聚合统计
|
|
|
+ *
|
|
|
* @param vo
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public EsCountDTO esCountAnalysis(EsAllCountVO vo) throws Exception {
|
|
|
+ List<EsCountVO> countVOS = vo.getCountVOS();
|
|
|
String searchCondition = vo.getCondition();
|
|
|
List<EsCustomFieldValueDTO> customFields = vo.getCustomFields();
|
|
|
+ Integer taskId = vo.getTaskId();
|
|
|
+ Integer projectId = vo.getProjectId();
|
|
|
+ EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
+ HashMap<String, List<EsCountDetailDTO>> map = new HashMap<>();
|
|
|
+ List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
+ if (countVOS.size() > 1) {
|
|
|
+ EsCountVO countVO = countVOS.get(0);
|
|
|
+ List<String> values = countVO.getValues();
|
|
|
+ List<EsCountVO> esCountVOS = new ArrayList<>();
|
|
|
+ esCountVOS.add(countVOS.get(1));
|
|
|
+ if (StringUtils.isNotEmpty(countVO.getFieldId())) {
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCustomFieldValueDTO valueDTO = new EsCustomFieldValueDTO();
|
|
|
+ valueDTO.setFieldId(countVO.getFieldId());
|
|
|
+ valueDTO.setFieldValue(Arrays.asList(value));
|
|
|
+ customFields.add(valueDTO);
|
|
|
+ this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO, value, map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (String value : values) {
|
|
|
+ String condition = countVO.getField() + " = " + value;
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = condition + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = condition;
|
|
|
+ }
|
|
|
+ this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO, value, map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.getReturnData(searchCondition, customFields, taskId, projectId, countVOS, detailDTOS, esCountDTO, "", map);
|
|
|
+ }
|
|
|
+ esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
+ return esCountDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getReturnData(String searchCondition, List<EsCustomFieldValueDTO> customFields, Integer taskId,
|
|
|
+ Integer projectId, List<EsCountVO> countVOS, List<EsCountDetailDTO> detailDTOS,
|
|
|
+ EsCountDTO esCountDTO, String firstName, Map<String, List<EsCountDetailDTO>> map) throws Exception {
|
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
searchCondition = esService.parseCustomField(customFields);
|
|
|
}
|
|
|
- Integer taskId = vo.getTaskId();
|
|
|
- Integer projectId = vo.getProjectId();
|
|
|
+
|
|
|
searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
@@ -78,9 +122,6 @@ public class EsCountService {
|
|
|
query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
}
|
|
|
|
|
|
- EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
- List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
- List<EsCountVO> countVOS = vo.getCountVOS();
|
|
|
for (EsCountVO countVO : countVOS) {
|
|
|
String field = countVO.getField();
|
|
|
Integer topN = countVO.getTopN();
|
|
@@ -113,7 +154,6 @@ public class EsCountService {
|
|
|
if (dateList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
try {
|
|
|
this.getDateCountDTOS(filtersAgg, field, topN, format, detailDTOS, esCountDTO);
|
|
@@ -123,16 +163,14 @@ public class EsCountService {
|
|
|
});
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO);
|
|
|
+ this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
|
|
|
});
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNestedCountDTOS(filtersAgg, field,topN, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
esCountDTO.setAllNumber(filtersAgg.nested().docCount());
|
|
|
}
|
|
@@ -141,16 +179,15 @@ public class EsCountService {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
Integer finalFieldType = fieldType;
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN,detailDTOS,esCountDTO);
|
|
|
+ this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN, detailDTOS, esCountDTO);
|
|
|
});
|
|
|
} else {
|
|
|
Integer finalFieldType1 = fieldType;
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,
|
|
|
+ detailDTOS, esCountDTO, firstName, map,values);
|
|
|
});
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
@@ -158,16 +195,14 @@ public class EsCountService {
|
|
|
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNumberAnalysisDTOS(filtersAgg, field,topN, detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getTermCountDTOS(filtersAgg, field, topN,detailDTOS);
|
|
|
+ this.getTermCountDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
@@ -176,35 +211,118 @@ public class EsCountService {
|
|
|
} else {
|
|
|
if (dateList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getDateCountDTOS(agg, field, topN,format, detailDTOS,esCountDTO);
|
|
|
+ this.getDateCountDTOS(agg, field, topN, format, detailDTOS, esCountDTO);
|
|
|
} else {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field,topN, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
}
|
|
|
} else if (childList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getChildCountDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO);
|
|
|
} else {
|
|
|
- this.getChildAnalysisDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
|
+ detailDTOS, esCountDTO, firstName, map,values);
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
|
- this.getNumberAnalysisDTOS(agg, field,topN, detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
|
|
|
} else {
|
|
|
- this.getTermCountDTOS(agg, field,topN, detailDTOS);
|
|
|
+ this.getTermCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
|
|
|
}
|
|
|
}
|
|
|
+ esCountDTO.setCondition(searchCondition);
|
|
|
+ esCountDTO.setAnalyseMap(map);
|
|
|
}
|
|
|
- esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
- esCountDTO.setCondition(searchCondition);
|
|
|
- return esCountDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public EsDateRangeDTO getFieldRange(EsDateRangeVO rangeVO) throws Exception {
|
|
|
+ String searchCondition = rangeVO.getCondition();
|
|
|
+ String field = rangeVO.getField();
|
|
|
+ List<EsCustomFieldValueDTO> customFields = rangeVO.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = esService.parseCustomField(customFields);
|
|
|
+ }
|
|
|
+ Integer taskId = rangeVO.getTaskId();
|
|
|
+ Integer projectId = rangeVO.getProjectId();
|
|
|
+ searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
+
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ //设置查询索引
|
|
|
+ Query query = null;
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ }
|
|
|
+ String esField = "";
|
|
|
+ if (StringUtils.isNotEmpty(field)) {
|
|
|
+ switch (field) {
|
|
|
+ case "AD":
|
|
|
+ esField = "app_date";
|
|
|
+ break;
|
|
|
+ case "PD":
|
|
|
+ esField = "public_date";
|
|
|
+ break;
|
|
|
+ case "GD":
|
|
|
+ esField = "grant_date";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ EsDateRangeDTO rangeDTO = new EsDateRangeDTO();
|
|
|
+ if (StringUtils.isNotEmpty(esField)) {
|
|
|
+ String finalEsField = esField;
|
|
|
+ Query finalQuery = query;
|
|
|
+ Aggregation min = AggregationBuilders.min(i -> i.field(finalEsField).format("yyyy"));
|
|
|
+ Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filters_agg", min);
|
|
|
+ }}).build();
|
|
|
+
|
|
|
+ Aggregation max = AggregationBuilders.max(i -> i.field(finalEsField).format("yyyy"));
|
|
|
+ Aggregation maxFilters = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("max_agg", max);
|
|
|
+ }}).build();
|
|
|
+
|
|
|
+
|
|
|
+ builder.aggregations("minAgg", filtersAgg);
|
|
|
+ builder.aggregations("maxAgg", maxFilters);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate minAgg = response.aggregations().get("minAgg");
|
|
|
+ if (minAgg != null) {
|
|
|
+ List<FiltersBucket> list = minAgg.filters().buckets().array();
|
|
|
+ for (FiltersBucket bucket : list) {
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("filters_agg");
|
|
|
+ String minValue = aggregate.min().valueAsString();
|
|
|
+ rangeDTO.setMinDate(minValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Aggregate maxAgg = response.aggregations().get("maxAgg");
|
|
|
+ if (maxAgg != null) {
|
|
|
+ List<FiltersBucket> list = maxAgg.filters().buckets().array();
|
|
|
+ for (FiltersBucket bucket : list) {
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("max_agg");
|
|
|
+ String maxValue = aggregate.max().valueAsString();
|
|
|
+ rangeDTO.setMaxDate(maxValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rangeDTO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询共用Aggregation
|
|
|
+ *
|
|
|
* @param countVO
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -302,7 +420,10 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
|
|
|
+ EsCountDTO esCountDTO, String firstName,
|
|
|
+ Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
|
+ List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
countDTO.setField(field);
|
|
|
countDTO.setName("其他");
|
|
@@ -317,13 +438,49 @@ public class EsCountService {
|
|
|
dto.setName(bucket.key().stringValue());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
+ dto.setFirstName(firstName);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
|
if (dto.getNumber() > 0) {
|
|
|
- detailDTOS.add(dto);
|
|
|
+ countDetailDTOS.add(dto);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ List<String> strs = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ strs.addAll(values);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(firstName)) {
|
|
|
+ countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
|
|
|
+ if (countDetailDTOS.size() != values.size()) {
|
|
|
+ for (EsCountDetailDTO detailDTO : countDetailDTOS) {
|
|
|
+ strs.removeIf(i -> i.equals(detailDTO.getName()));
|
|
|
+ }
|
|
|
+ for (String value : strs) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ } else if (countDetailDTOS.isEmpty()) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(firstName, countDetailDTOS);
|
|
|
+ } else {
|
|
|
+ detailDTOS.addAll(countDetailDTOS);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -333,7 +490,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildCountDTOS(Aggregate agg, String field,Integer fieldType, Integer topN,
|
|
|
+ public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
|
List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
@@ -377,8 +534,10 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildAnalysisDTOS(Aggregate agg, String field,Integer fieldType,Integer topN,
|
|
|
- List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ public void getChildAnalysisDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,
|
|
|
+ String firstName, Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
|
+ List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
@@ -390,23 +549,72 @@ public class EsCountService {
|
|
|
dto.setField(field);
|
|
|
dto.setName(termsBucket.key().stringValue());
|
|
|
dto.setNumber(termsBucket.docCount());
|
|
|
+ dto.setFirstName(firstName);
|
|
|
dto.setTopN(topN);
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- detailDTOS.add(dto);
|
|
|
- if (fieldType == null || fieldType != 6) {
|
|
|
- Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
- EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
- detail.setField(field);
|
|
|
- detail.setName("未选择");
|
|
|
- detail.setNumber(docCount);
|
|
|
- detail.setTopN(topN);
|
|
|
- if (!detailDTOS.contains(detail)) {
|
|
|
- detailDTOS.add(detail);
|
|
|
- }
|
|
|
+ countDetailDTOS.add(dto);
|
|
|
+ if (fieldType == null || fieldType != 6) {
|
|
|
+ Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+ detail.setField(field);
|
|
|
+ detail.setName("未选择");
|
|
|
+ detail.setNumber(docCount);
|
|
|
+ detail.setTopN(topN);
|
|
|
+ if (!countDetailDTOS.contains(detail)) {
|
|
|
+ countDetailDTOS.add(detail);
|
|
|
}
|
|
|
}
|
|
|
+// if (dto.getNumber() > 0) {
|
|
|
+// detailDTOS.add(dto);
|
|
|
+// if (fieldType == null || fieldType != 6) {
|
|
|
+// Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
+// EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+// detail.setField(field);
|
|
|
+// detail.setName("未选择");
|
|
|
+// detail.setNumber(docCount);
|
|
|
+// detail.setTopN(topN);
|
|
|
+// if (!detailDTOS.contains(detail)) {
|
|
|
+// detailDTOS.add(detail);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ List<String> strs = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ strs.addAll(values);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(firstName)) {
|
|
|
+ countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
|
|
|
+ if (countDetailDTOS.size() != values.size()) {
|
|
|
+ for (EsCountDetailDTO detailDTO : countDetailDTOS) {
|
|
|
+ strs.removeIf(i -> i.equals(detailDTO.getName()));
|
|
|
+ }
|
|
|
+ for (String value : strs) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ } else if (countDetailDTOS.isEmpty()) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(firstName, countDetailDTOS);
|
|
|
+ } else {
|
|
|
+ detailDTOS.addAll(countDetailDTOS);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -416,7 +624,10 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNumberAnalysisDTOS(Aggregate agg, String field,Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNumberAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
|
|
|
+ EsCountDTO esCountDTO, String firstName,
|
|
|
+ Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
|
+ List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
|
List<RangeBucket> list = agg.range().buckets().array();
|
|
|
for (RangeBucket bucket : list) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -424,9 +635,46 @@ public class EsCountService {
|
|
|
dto.setName(bucket.key());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- detailDTOS.add(dto);
|
|
|
+ dto.setFirstName(firstName);
|
|
|
+ countDetailDTOS.add(dto);
|
|
|
+// if (dto.getNumber() > 0) {
|
|
|
+// detailDTOS.add(dto);
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> strs = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ strs.addAll(values);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(firstName)) {
|
|
|
+ countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
|
|
|
+ if (countDetailDTOS.size() != values.size()) {
|
|
|
+ for (EsCountDetailDTO detailDTO : countDetailDTOS) {
|
|
|
+ strs.removeIf(i -> i.equals(detailDTO.getName()));
|
|
|
+ }
|
|
|
+ for (String value : strs) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ } else if (countDetailDTOS.isEmpty()) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
}
|
|
|
+ map.put(firstName, countDetailDTOS);
|
|
|
+ } else {
|
|
|
+ detailDTOS.addAll(countDetailDTOS);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -473,7 +721,7 @@ public class EsCountService {
|
|
|
h1Count += histogramBucket.docCount();
|
|
|
dto.setNumber(h1Count);
|
|
|
}
|
|
|
- if (month.after(halfYearDate)){
|
|
|
+ if (month.after(halfYearDate)) {
|
|
|
h2Count += histogramBucket.docCount();
|
|
|
dto2.setNumber(h2Count);
|
|
|
}
|
|
@@ -489,6 +737,37 @@ public class EsCountService {
|
|
|
detailDTO.setNumber(sum);
|
|
|
esCountDetailDTOS.add(detailDTO);
|
|
|
}
|
|
|
+ } else if (StringUtils.isNotEmpty(format) && format.equals("季")) {
|
|
|
+ for (DateHistogramBucket bucket : list) {
|
|
|
+ String yearMonth = bucket.keyAsString();
|
|
|
+ String year = yearMonth.substring(0, yearMonth.indexOf("-"));
|
|
|
+ String firstQuarter = year + "-01";
|
|
|
+ String secondQuarter = year + "-04";
|
|
|
+ String thirdQuarter = year + "-07";
|
|
|
+ String forthQuarter = year + "-10";
|
|
|
+ String firstQ = year + "-Q1";
|
|
|
+ String secondQ = year + "-Q2";
|
|
|
+ String thirdQ = year + "-Q3";
|
|
|
+ String forthQ = year + "-Q4";
|
|
|
+ EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
+ dto.setField(field);
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
+ if (yearMonth.equals(firstQuarter)) {
|
|
|
+ dto.setName(firstQ);
|
|
|
+ } else if (yearMonth.equals(secondQuarter)) {
|
|
|
+ dto.setName(secondQ);
|
|
|
+ } else if (yearMonth.equals(thirdQuarter)) {
|
|
|
+ dto.setName(thirdQ);
|
|
|
+ } else if (yearMonth.equals(forthQuarter)) {
|
|
|
+ dto.setName(forthQ);
|
|
|
+ }
|
|
|
+ dto.setNumber(bucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
+ if (aggregate != null) {
|
|
|
+ dto.setNumber(aggregate.filter().docCount());
|
|
|
+ }
|
|
|
+ esCountDetailDTOS.add(dto);
|
|
|
+ }
|
|
|
} else {
|
|
|
list.forEach(bucket -> {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -500,9 +779,7 @@ public class EsCountService {
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- esCountDetailDTOS.add(dto);
|
|
|
- }
|
|
|
+ esCountDetailDTOS.add(dto);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -512,17 +789,18 @@ public class EsCountService {
|
|
|
detailDTOS.addAll(collect);
|
|
|
}
|
|
|
|
|
|
- EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
- countDTO.setField(field);
|
|
|
- countDTO.setName("其他");
|
|
|
- if (list.size() > topN) {
|
|
|
- countDTO.setNumber((long)(list.size() - topN));
|
|
|
-
|
|
|
- } else {
|
|
|
- countDTO.setNumber((long)0);
|
|
|
- }
|
|
|
- countDTO.setTopN(topN);
|
|
|
- detailDTOS.add(countDTO);
|
|
|
+// EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
+// countDTO.setField(field);
|
|
|
+// countDTO.setName("其他");
|
|
|
+// if (list.size() > topN) {
|
|
|
+// int sum = list.size() - topN;
|
|
|
+// countDTO.setNumber(Long.valueOf(String.valueOf(sum)));
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// countDTO.setNumber(0L);
|
|
|
+// }
|
|
|
+// countDTO.setTopN(topN);
|
|
|
+// detailDTOS.add(countDTO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -533,23 +811,59 @@ public class EsCountService {
|
|
|
* @param topN
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,EsCountDTO esCountDTO) {
|
|
|
+ public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
|
|
|
+ EsCountDTO esCountDTO, String firstName,
|
|
|
+ Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
|
List<RangeBucket> list1 = agg.dateRange().buckets().array();
|
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
|
for (RangeBucket bucket : list1) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
+ dto.setFirstName(firstName);
|
|
|
dto.setField(field);
|
|
|
dto.setName(bucket.key());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- esCountDetailDTOS.add(dto);
|
|
|
- }
|
|
|
+ esCountDetailDTOS.add(dto);
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(esCountDetailDTOS)) {
|
|
|
List<EsCountDetailDTO> collect = esCountDetailDTOS.stream()
|
|
|
.sorted(Comparator.comparing(EsCountDetailDTO::getName).reversed()).limit(topN).collect(Collectors.toList());
|
|
|
- detailDTOS.addAll(collect);
|
|
|
+
|
|
|
+ List<String> strs = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ strs.addAll(values);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(firstName)) {
|
|
|
+ collect.removeIf(dto -> dto.getName().equals("其他"));
|
|
|
+ if (collect.size() != values.size()) {
|
|
|
+ for (EsCountDetailDTO detailDTO : collect) {
|
|
|
+ strs.removeIf(i -> i.equals(detailDTO.getName()));
|
|
|
+ }
|
|
|
+ for (String value : strs) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ collect.add(detailDTO);
|
|
|
+ }
|
|
|
+ } else if (collect.isEmpty()) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ collect.add(detailDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(firstName, collect);
|
|
|
+ } else {
|
|
|
+ detailDTOS.addAll(collect);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -560,14 +874,17 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNestedCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNestedCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
|
|
|
+ EsCountDTO esCountDTO, String firstName,
|
|
|
+ Map<String, List<EsCountDetailDTO>> map, List<String> values) {
|
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
+ List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
countDTO.setField(field);
|
|
|
countDTO.setName("其他");
|
|
|
countDTO.setNumber(termsAgg.sterms().sumOtherDocCount());
|
|
|
countDTO.setTopN(topN);
|
|
|
- detailDTOS.add(countDTO);
|
|
|
+ countDetailDTOS.add(countDTO);
|
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -576,14 +893,50 @@ public class EsCountService {
|
|
|
dto.setName(bucket.key().stringValue());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
+ dto.setFirstName(firstName);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- detailDTOS.add(dto);
|
|
|
- }
|
|
|
+ countDetailDTOS.add(dto);
|
|
|
+// if (dto.getNumber() > 0) {
|
|
|
+// detailDTOS.add(dto);
|
|
|
+// }
|
|
|
});
|
|
|
- }
|
|
|
|
|
|
+ List<String> strs = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ strs.addAll(values);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(firstName)) {
|
|
|
+ countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
|
|
|
+ if (countDetailDTOS.size() != values.size()) {
|
|
|
+ for (EsCountDetailDTO detailDTO : countDetailDTOS) {
|
|
|
+ strs.removeIf(i -> i.equals(detailDTO.getName()));
|
|
|
+ }
|
|
|
+ for (String value : strs) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ } else if (countDetailDTOS.isEmpty()) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCountDetailDTO detailDTO = new EsCountDetailDTO();
|
|
|
+ detailDTO.setName(value);
|
|
|
+ detailDTO.setFirstName(firstName);
|
|
|
+ detailDTO.setField(field);
|
|
|
+ detailDTO.setNumber(0L);
|
|
|
+ detailDTO.setTopN(topN);
|
|
|
+ countDetailDTOS.add(detailDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(firstName, countDetailDTOS);
|
|
|
+ } else {
|
|
|
+ detailDTOS.addAll(countDetailDTOS);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|