|
@@ -1,5 +1,6 @@
|
|
|
package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
+import cn.cslg.pas.common.dto.GetUnselectedDTO;
|
|
|
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,7 +19,9 @@ 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.aggregations.*;
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
|
|
|
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.Hit;
|
|
@@ -30,6 +33,7 @@ import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -157,7 +161,7 @@ public class EsCountService {
|
|
|
}
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
- searchCondition = esService.parseCustomField(customFields);
|
|
|
+ searchCondition = esService.parseCustomField(customFields,projectId,taskId);
|
|
|
}
|
|
|
|
|
|
searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
@@ -260,7 +264,11 @@ public class EsCountService {
|
|
|
Integer finalFieldType = fieldType;
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN, detailDTOS, esCountDTO);
|
|
|
+ try {
|
|
|
+ this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN, detailDTOS, esCountDTO,projectId,taskId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
});
|
|
|
} else {
|
|
|
Integer finalFieldType1 = fieldType;
|
|
@@ -311,7 +319,7 @@ public class EsCountService {
|
|
|
}
|
|
|
} 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, projectId, taskId);
|
|
|
} else {
|
|
|
this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
|
detailDTOS, esCountDTO, firstName, map, values);
|
|
@@ -332,7 +340,7 @@ public class EsCountService {
|
|
|
String field = rangeVO.getField();
|
|
|
List<EsCustomFieldValueDTO> customFields = rangeVO.getCustomFields();
|
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
- searchCondition = esService.parseCustomField(customFields);
|
|
|
+ searchCondition = esService.parseCustomField(customFields, rangeVO.getProjectId(), rangeVO.getTaskId());
|
|
|
}
|
|
|
Integer taskId = rangeVO.getTaskId();
|
|
|
Integer projectId = rangeVO.getProjectId();
|
|
@@ -586,7 +594,7 @@ public class EsCountService {
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
|
- List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId, Integer taskId) throws Exception {
|
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
@@ -605,47 +613,77 @@ public class EsCountService {
|
|
|
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);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
+ if (fieldType == null || fieldType != 6) {
|
|
|
+ GetUnselectedDTO unselectedDTO = this.getUnselectedCustomNum(projectId, taskId);
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+ detail.setField(field);
|
|
|
+ detail.setName("未选择");
|
|
|
+ detail.setNumber(unselectedDTO.getNumber().longValue());
|
|
|
+ detail.setTopN(topN);
|
|
|
+ if (!detailDTOS.contains(detail)) {
|
|
|
+ detailDTOS.add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public Integer getUnselectedCustomNum(Integer projectId,Integer taskId) throws Exception {
|
|
|
- String condition = "";
|
|
|
- if (taskId != null) {
|
|
|
- condition = "taskId = " + taskId;
|
|
|
- } else {
|
|
|
- condition = "projectId = " + projectId;
|
|
|
- }
|
|
|
+ public GetUnselectedDTO getUnselectedCustomNum(Integer projectId, Integer taskId) throws Exception {
|
|
|
+ GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
builder.index("patent");
|
|
|
- treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
- //格式化检索式
|
|
|
- //3. 从es中检索数据
|
|
|
- Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ Query q = null;
|
|
|
+ if (taskId != null) {
|
|
|
+ Query query = QueryBuilders.term(i -> i.field("project_task.task_id").value(taskId));
|
|
|
+ q = QueryBuilders.hasChild(i -> i.type("task").query(query));
|
|
|
+ } else {
|
|
|
+ Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
|
|
|
+ q = QueryBuilders.hasChild(i -> i.type("project").query(query));
|
|
|
+ }
|
|
|
+ builder.size(9999);
|
|
|
builder.query(q);
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
- Long total = response.hits().total().value();
|
|
|
List<String> list = new ArrayList<>();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
String id = hit.id();
|
|
|
list.add(id);
|
|
|
}
|
|
|
- return null;
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ dto = this.ifExistChild(list);
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ public GetUnselectedDTO ifExistChild(List<String> list) throws IOException {
|
|
|
+ GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
|
+ List<String> existChildIds = new ArrayList<>();
|
|
|
+ List<String> beinglessChildIds = new ArrayList<>();
|
|
|
+ int count = 0;
|
|
|
+ for (String id : list) {
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ Query q1 = QueryBuilders.parentId(i -> i.type("project_customfield").id(id));
|
|
|
+ Query q2 = QueryBuilders.exists(i -> i.field("custom_field"));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q2));
|
|
|
+ builder.query(bool);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Long total = response.hits().total().value();
|
|
|
+ if (total > 0) {
|
|
|
+ existChildIds.add(id);
|
|
|
+ } else {
|
|
|
+ beinglessChildIds.add(id);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dto.setNumber(count);
|
|
|
+ dto.setExistChildIds(existChildIds);
|
|
|
+ dto.setBeinglessChildIds(beinglessChildIds);
|
|
|
+ return dto;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -684,20 +722,6 @@ public class EsCountService {
|
|
|
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);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
});
|
|
|
});
|
|
|
|