|
@@ -1,6 +1,7 @@
|
|
|
package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.GetUnselectedDTO;
|
|
|
+import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
|
|
|
import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
@@ -18,11 +19,14 @@ import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.IEsCountAnalysisBuilder
|
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
+import co.elastic.clients.elasticsearch._types.SortOptions;
|
|
|
+import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
+import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
|
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -71,6 +75,7 @@ public class EsCountService {
|
|
|
List<EsCustomFieldValueDTO> customFields = vo.getCustomFields();
|
|
|
Integer taskId = vo.getTaskId();
|
|
|
Integer projectId = vo.getProjectId();
|
|
|
+ String groupField = vo.getGroupField();
|
|
|
EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
HashMap<String, List<EsCountDetailDTO>> map = new HashMap<>();
|
|
|
List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
@@ -88,7 +93,7 @@ public class EsCountService {
|
|
|
valueDTO.setFieldValue(Arrays.asList("\""+value+"\""));
|
|
|
customFields.add(valueDTO);
|
|
|
this.getDatas(searchCondition, "",customFields, taskId, projectId,
|
|
|
- esCountVOS, detailDTOS, esCountDTO, value, map);
|
|
|
+ esCountVOS, detailDTOS, esCountDTO, value, map,groupField);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -100,12 +105,12 @@ public class EsCountService {
|
|
|
condition = countVO.getField() + " = " + "\""+value+"\"";
|
|
|
}
|
|
|
this.getDatas(searchCondition, condition, customFields, taskId, projectId,
|
|
|
- esCountVOS, detailDTOS, esCountDTO, value, map);
|
|
|
+ esCountVOS, detailDTOS, esCountDTO, value, map,groupField);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
this.getDatas(searchCondition, "", customFields, taskId, projectId, countVOS,
|
|
|
- detailDTOS, esCountDTO, "", map);
|
|
|
+ detailDTOS, esCountDTO, "", map,groupField);
|
|
|
}
|
|
|
esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
return esCountDTO;
|
|
@@ -113,7 +118,7 @@ public class EsCountService {
|
|
|
|
|
|
public void getDatas(String searchCondition,String condition, List<EsCustomFieldValueDTO> customFields, Integer taskId,
|
|
|
Integer projectId, List<EsCountVO> countVOS, List<EsCountDetailDTO> detailDTOS,
|
|
|
- EsCountDTO esCountDTO, String firstName, Map<String, List<EsCountDetailDTO>> map) throws Exception {
|
|
|
+ EsCountDTO esCountDTO, String firstName, Map<String, List<EsCountDetailDTO>> map,String groupField) throws Exception {
|
|
|
|
|
|
if (StringUtils.isNotEmpty(condition)) {
|
|
|
if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
@@ -132,11 +137,11 @@ public class EsCountService {
|
|
|
}
|
|
|
}
|
|
|
searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
-
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
builder.index("patent");
|
|
|
Query query = null;
|
|
|
+// String esGroupField = "";
|
|
|
if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
//1. 解析检索条件
|
|
|
treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
@@ -144,75 +149,88 @@ public class EsCountService {
|
|
|
//3. 从es中检索数据
|
|
|
query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
|
|
|
builder.query(query);
|
|
|
+// if (StringUtils.isNotEmpty(groupField) && !groupField.equals("0")) {
|
|
|
+// String esField = esService.getGroupField(groupField);
|
|
|
+// esGroupField = esField;
|
|
|
+// Query existQ = QueryBuilders.exists(i -> i.field(esField));
|
|
|
+// Query finalQuery = query;
|
|
|
+// Query bool = QueryBuilders.bool(i -> i.must(finalQuery, existQ));
|
|
|
+// builder.query(bool);
|
|
|
+// FieldCollapse collapse = FieldCollapse.of(i -> i.field(esField));
|
|
|
+// builder.collapse(collapse);
|
|
|
+// } else {
|
|
|
+// builder.query(query);
|
|
|
+// }
|
|
|
}
|
|
|
+ if (query != null) {
|
|
|
+ for (EsCountVO countVO : countVOS) {
|
|
|
+ String field = countVO.getField();
|
|
|
+ String fieldId = countVO.getFieldId();
|
|
|
+ Integer topN = countVO.getTopN();
|
|
|
+ String valueOne = countVO.getValueOne();
|
|
|
+ String valueTwo = countVO.getValueTwo();
|
|
|
+ Integer fieldType = null;
|
|
|
+ String type = countVO.getFieldType();
|
|
|
+ if (StringUtils.isNotEmpty(type) && type.equals("tree")) {
|
|
|
+ fieldType = 6;
|
|
|
+ }
|
|
|
+ String format = countVO.getFormat();
|
|
|
+ List<String> values = countVO.getValues();
|
|
|
+ Aggregation aggregation = this.getAggregation(countVO, projectId, taskId);
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+ //解除最大条数限制
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
|
|
|
- for (EsCountVO countVO : countVOS) {
|
|
|
- String field = countVO.getField();
|
|
|
- String fieldId = countVO.getFieldId();
|
|
|
- Integer topN = countVO.getTopN();
|
|
|
- String valueOne = countVO.getValueOne();
|
|
|
- String valueTwo = countVO.getValueTwo();
|
|
|
- Integer fieldType = null;
|
|
|
- String type = countVO.getFieldType();
|
|
|
- if (StringUtils.isNotEmpty(type) && type.equals("tree")) {
|
|
|
- fieldType = 6;
|
|
|
- }
|
|
|
- String format = countVO.getFormat();
|
|
|
- List<String> values = countVO.getValues();
|
|
|
- Aggregation aggregation = this.getAggregation(countVO, projectId, taskId);
|
|
|
- builder.aggregations("Agg", aggregation);
|
|
|
- //解除最大条数限制
|
|
|
- builder.trackTotalHits(i -> i.enabled(true));
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
- Aggregate agg = response.aggregations().get("Agg");
|
|
|
+ if (StringUtils.isNotEmpty(field)) {
|
|
|
+ if (dateList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ this.getDateCountDTOS(agg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
+ } else {
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
+ } else if (nestedList.contains(field)) {
|
|
|
+ this.getNestedCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
+ }
|
|
|
+ } else if (nestDateList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
+ this.getDateCountDTOS(termsAgg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
+ } else {
|
|
|
+ Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
+ this.getDateAnalysisDTOS(termsAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
+ } else if (nestChildList.contains(field)) {
|
|
|
+ Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
+ this.getNestedCountDTOS(childAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ esCountDTO.setAllNumber(childAgg.nested().docCount());
|
|
|
+ }
|
|
|
+ } else if (childList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query,null);
|
|
|
+ } else {
|
|
|
+ this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
|
+ detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
+ } else if (numberList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(field)) {
|
|
|
- if (dateList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getDateCountDTOS(agg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
+ } else {
|
|
|
+ this.getNumberAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
- }
|
|
|
- } else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
- if (!CollectionUtils.isEmpty(values)) {
|
|
|
- esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
- }
|
|
|
- } else if (nestDateList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
- Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
- this.getDateCountDTOS(termsAgg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
- } else {
|
|
|
- Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
- this.getDateAnalysisDTOS(termsAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
- }
|
|
|
- } else if (nestChildList.contains(field)) {
|
|
|
- Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
- this.getNestedCountDTOS(childAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
- if (!CollectionUtils.isEmpty(values)) {
|
|
|
- esCountDTO.setAllNumber(childAgg.nested().docCount());
|
|
|
- }
|
|
|
- } else if (childList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query);
|
|
|
- } else {
|
|
|
- this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
|
- detailDTOS, esCountDTO, firstName, map, values);
|
|
|
- }
|
|
|
- } else if (numberList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
-
|
|
|
- } else {
|
|
|
- this.getNumberAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ this.getTermCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
}
|
|
|
} else {
|
|
|
- this.getTermCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
+ this.getFilterCountDTO(agg, searchCondition, detailDTOS);
|
|
|
}
|
|
|
- } else {
|
|
|
- this.getFilterCountDTO(agg, searchCondition, detailDTOS);
|
|
|
+ esCountDTO.setCondition(searchCondition);
|
|
|
+ esCountDTO.setAnalyseMap(map);
|
|
|
}
|
|
|
- esCountDTO.setCondition(searchCondition);
|
|
|
- esCountDTO.setAnalyseMap(map);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -522,7 +540,8 @@ public class EsCountService {
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
|
- List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId, String fieldId,Query query) throws Exception {
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId,
|
|
|
+ String fieldId,Query query,String esField) throws Exception {
|
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
@@ -544,7 +563,7 @@ public class EsCountService {
|
|
|
});
|
|
|
});
|
|
|
if (fieldType == null || fieldType != 6) {
|
|
|
- GetUnselectedDTO unselectedDTO = this.getUnselectedCustomNum1(projectId, fieldId, query);
|
|
|
+ GetUnselectedDTO unselectedDTO = this.getUnselectedCustomNum1(projectId, fieldId, query,esField);
|
|
|
EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
detail.setField(field);
|
|
|
detail.setName("未选择");
|
|
@@ -561,13 +580,21 @@ public class EsCountService {
|
|
|
}
|
|
|
|
|
|
//统计未选择数量
|
|
|
- public GetUnselectedDTO getUnselectedCustomNum1(Integer projectId, String fieldId, Query query) throws Exception {
|
|
|
+ public GetUnselectedDTO getUnselectedCustomNum1(Integer projectId, String fieldId, Query query,String esField) throws Exception {
|
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
builder.index("patent");
|
|
|
builder.size(9999);
|
|
|
- builder.query(query);
|
|
|
+ if (StringUtils.isNotEmpty(esField)) {
|
|
|
+ Query existQ = QueryBuilders.exists(i -> i.field(esField));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(query, existQ));
|
|
|
+ builder.query(bool);
|
|
|
+ FieldCollapse collapse = FieldCollapse.of(i -> i.field(esField));
|
|
|
+ builder.collapse(collapse);
|
|
|
+ } else {
|
|
|
+ builder.query(query);
|
|
|
+ }
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
List<String> list = new ArrayList<>();
|