|
@@ -65,21 +65,7 @@ public class EsCountService {
|
|
|
}
|
|
|
Integer taskId = vo.getTaskId();
|
|
|
Integer projectId = vo.getProjectId();
|
|
|
- if (taskId != null) {
|
|
|
- if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
- searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
|
- } else {
|
|
|
- searchCondition = "taskId = " + taskId;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (projectId != null) {
|
|
|
- if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
- searchCondition = "projectId = " + projectId + " AND " + searchCondition;
|
|
|
- } else {
|
|
|
- searchCondition = "projectId = " + projectId;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ searchCondition = this.getCondition(taskId, projectId);
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
@@ -100,39 +86,14 @@ public class EsCountService {
|
|
|
for (EsCountVO countVO : countVOS) {
|
|
|
String field = countVO.getField();
|
|
|
Integer topN = countVO.getTopN();
|
|
|
- Boolean ifHaveChild = countVO.getIfHaveChild();
|
|
|
- String fieldId = countVO.getFieldId();
|
|
|
- Integer fieldType = countVO.getFieldType();
|
|
|
+ Integer fieldType = null;
|
|
|
+ String type = countVO.getFieldType();
|
|
|
+ if (StringUtils.isNotEmpty(type) && type.equals("tree")) {
|
|
|
+ fieldType = 6;
|
|
|
+ }
|
|
|
String format = countVO.getFormat();
|
|
|
- String valueOne = countVO.getValueOne();
|
|
|
- String valueTwo = countVO.getValueTwo();
|
|
|
List<String> values = countVO.getValues();
|
|
|
-
|
|
|
- IEsCountAnalysisBuilder iEsCountAnalysisBuilder = null;
|
|
|
- String json = CommonService.readJsonFile("esCountAnalysis.json");
|
|
|
- List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
- EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getField().equals(field))
|
|
|
- .findFirst().orElse(null);
|
|
|
-
|
|
|
- Aggregation aggregation = null;
|
|
|
- if (esConfigVO != null) {
|
|
|
- iEsCountAnalysisBuilder = esCountAnalysisBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
- iEsCountAnalysisBuilder.setField(esConfigVO.getEsField());
|
|
|
- iEsCountAnalysisBuilder.setValueOne(valueOne);
|
|
|
- iEsCountAnalysisBuilder.setValueTwo(valueTwo);
|
|
|
- iEsCountAnalysisBuilder.setValues(values);
|
|
|
- iEsCountAnalysisBuilder.setFieldId(fieldId);
|
|
|
- iEsCountAnalysisBuilder.setFieldType(String.valueOf(fieldType));
|
|
|
- iEsCountAnalysisBuilder.setTopN(topN);
|
|
|
- iEsCountAnalysisBuilder.setFormat(format);
|
|
|
- iEsCountAnalysisBuilder.setIfHaveChild(ifHaveChild);
|
|
|
- if (iEsCountAnalysisBuilder.getField().contains(".")) {
|
|
|
- String path = iEsCountAnalysisBuilder.getField()
|
|
|
- .substring(0, iEsCountAnalysisBuilder.getField().indexOf("."));
|
|
|
- iEsCountAnalysisBuilder.setPath(path);
|
|
|
- }
|
|
|
- aggregation = iEsCountAnalysisBuilder.createCountAnalyseAgg();
|
|
|
- }
|
|
|
+ Aggregation aggregation = this.getAggregation(countVO);
|
|
|
if (query != null) {
|
|
|
Query finalQuery = query;
|
|
|
Aggregation finalAggregation = aggregation;
|
|
@@ -180,16 +141,18 @@ public class EsCountService {
|
|
|
});
|
|
|
} else if (childList.contains(field)) {
|
|
|
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, detailDTOS,esCountDTO);
|
|
|
+ this.getChildCountDTOS(filtersAgg, field, finalFieldType, 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, detailDTOS,esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, detailDTOS, esCountDTO);
|
|
|
});
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
@@ -226,9 +189,9 @@ public class EsCountService {
|
|
|
}
|
|
|
} else if (childList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getChildCountDTOS(agg, field, detailDTOS,esCountDTO);
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType, detailDTOS, esCountDTO);
|
|
|
} else {
|
|
|
- this.getChildAnalysisDTOS(agg, field, detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(agg, field, fieldType, detailDTOS, esCountDTO);
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
|
this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
@@ -243,6 +206,81 @@ public class EsCountService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 查询共用Aggregation
|
|
|
+ * @param countVO
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Aggregation getAggregation(EsCountVO countVO) throws Exception {
|
|
|
+ String field = countVO.getField();
|
|
|
+ Integer topN = countVO.getTopN();
|
|
|
+ Boolean ifHaveChild = countVO.getIfHaveChild();
|
|
|
+ String fieldId = countVO.getFieldId();
|
|
|
+ Integer fieldType = null;
|
|
|
+ String type = countVO.getFieldType();
|
|
|
+ if (StringUtils.isNotEmpty(type) && type.equals("tree")) {
|
|
|
+ fieldType = 6;
|
|
|
+ }
|
|
|
+ String format = countVO.getFormat();
|
|
|
+ String valueOne = countVO.getValueOne();
|
|
|
+ String valueTwo = countVO.getValueTwo();
|
|
|
+ List<String> values = countVO.getValues();
|
|
|
+
|
|
|
+ IEsCountAnalysisBuilder iEsCountAnalysisBuilder = null;
|
|
|
+ String json = CommonService.readJsonFile("esCountAnalysis.json");
|
|
|
+ List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
+ EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getField().equals(field))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+
|
|
|
+ Aggregation aggregation = null;
|
|
|
+ if (esConfigVO != null) {
|
|
|
+ iEsCountAnalysisBuilder = esCountAnalysisBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
+ iEsCountAnalysisBuilder.setField(esConfigVO.getEsField());
|
|
|
+ iEsCountAnalysisBuilder.setValueOne(valueOne);
|
|
|
+ iEsCountAnalysisBuilder.setValueTwo(valueTwo);
|
|
|
+ iEsCountAnalysisBuilder.setValues(values);
|
|
|
+ iEsCountAnalysisBuilder.setFieldId(fieldId);
|
|
|
+ iEsCountAnalysisBuilder.setFieldType(String.valueOf(fieldType));
|
|
|
+ iEsCountAnalysisBuilder.setTopN(topN);
|
|
|
+ iEsCountAnalysisBuilder.setFormat(format);
|
|
|
+ iEsCountAnalysisBuilder.setIfHaveChild(ifHaveChild);
|
|
|
+ if (iEsCountAnalysisBuilder.getField().contains(".")) {
|
|
|
+ String path = iEsCountAnalysisBuilder.getField()
|
|
|
+ .substring(0, iEsCountAnalysisBuilder.getField().indexOf("."));
|
|
|
+ iEsCountAnalysisBuilder.setPath(path);
|
|
|
+ }
|
|
|
+ aggregation = iEsCountAnalysisBuilder.createCountAnalyseAgg();
|
|
|
+ }
|
|
|
+ return aggregation;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取筛选条件
|
|
|
+ * @param taskId
|
|
|
+ * @param projectId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getCondition(Integer taskId, Integer projectId) {
|
|
|
+ String searchCondition = "";
|
|
|
+ if (taskId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "taskId = " + taskId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (projectId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "projectId = " + projectId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "projectId = " + projectId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return searchCondition;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取Filter聚合返回数据
|
|
|
*
|
|
|
* @param agg
|
|
@@ -290,7 +328,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ public void getChildCountDTOS(Aggregate agg, String field,Integer fieldType, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
@@ -308,13 +346,15 @@ public class EsCountService {
|
|
|
dto.setNumber(count);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
- Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
- EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
- detail.setField(field);
|
|
|
- detail.setName("未选择");
|
|
|
- detail.setNumber(docCount);
|
|
|
- if (!detailDTOS.contains(detail)) {
|
|
|
- detailDTOS.add(detail);
|
|
|
+ if (fieldType != 6) {
|
|
|
+ Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+ detail.setField(field);
|
|
|
+ detail.setName("未选择");
|
|
|
+ detail.setNumber(docCount);
|
|
|
+ if (!detailDTOS.contains(detail)) {
|
|
|
+ detailDTOS.add(detail);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -329,7 +369,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildAnalysisDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ public void getChildAnalysisDTOS(Aggregate agg, String field,Integer fieldType, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
@@ -343,13 +383,15 @@ public class EsCountService {
|
|
|
dto.setNumber(termsBucket.docCount());
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
- Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
- EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
- detail.setField(field);
|
|
|
- detail.setName("未选择");
|
|
|
- detail.setNumber(docCount);
|
|
|
- if (!detailDTOS.contains(detail)) {
|
|
|
- detailDTOS.add(detail);
|
|
|
+ if (fieldType != 6) {
|
|
|
+ Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+ detail.setField(field);
|
|
|
+ detail.setName("未选择");
|
|
|
+ detail.setNumber(docCount);
|
|
|
+ if (!detailDTOS.contains(detail)) {
|
|
|
+ detailDTOS.add(detail);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|