|
@@ -196,7 +196,7 @@ public class EsCountService {
|
|
}
|
|
}
|
|
} else if (childList.contains(field)) {
|
|
} else if (childList.contains(field)) {
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
- this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,taskId);
|
|
|
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,taskId,query);
|
|
} else {
|
|
} else {
|
|
this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
detailDTOS, esCountDTO, firstName, map, values);
|
|
detailDTOS, esCountDTO, firstName, map, values);
|
|
@@ -524,11 +524,12 @@ public class EsCountService {
|
|
* @param detailDTOS
|
|
* @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,Integer projectId, Integer taskId) throws Exception {
|
|
|
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId, Integer taskId,Query query) throws Exception {
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
list.forEach(bucket -> {
|
|
list.forEach(bucket -> {
|
|
|
|
+ String s = bucket.key().stringValue();
|
|
Aggregate aggregate = bucket.aggregations().get("termAgg");
|
|
Aggregate aggregate = bucket.aggregations().get("termAgg");
|
|
Aggregate filterAgg = aggregate.filter().aggregations().get("filterAgg");
|
|
Aggregate filterAgg = aggregate.filter().aggregations().get("filterAgg");
|
|
List<StringTermsBucket> termsBuckets = filterAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> termsBuckets = filterAgg.sterms().buckets().array();
|
|
@@ -538,37 +539,97 @@ public class EsCountService {
|
|
dto.setName(termsBucket.key().stringValue());
|
|
dto.setName(termsBucket.key().stringValue());
|
|
dto.setNumber(termsBucket.docCount());
|
|
dto.setNumber(termsBucket.docCount());
|
|
dto.setTopN(topN);
|
|
dto.setTopN(topN);
|
|
|
|
+ dto.setFieldId(s);
|
|
if (dto.getNumber() > 0) {
|
|
if (dto.getNumber() > 0) {
|
|
detailDTOS.add(dto);
|
|
detailDTOS.add(dto);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
if (fieldType == null || fieldType != 6) {
|
|
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);
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(detailDTOS)) {
|
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
|
+ detail.setField(field);
|
|
|
|
+ detail.setName("未选择");
|
|
|
|
+ detail.setNumber(0l);
|
|
|
|
+ detail.setTopN(topN);
|
|
|
|
+ if (!detailDTOS.contains(detail)) {
|
|
|
|
+ detailDTOS.add(detail);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String fieldId = detailDTOS.get(0).getFieldId();
|
|
|
|
+ GetUnselectedDTO unselectedDTO = this.getUnselectedCustomNum1(projectId, fieldId, query);
|
|
|
|
+ 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 GetUnselectedDTO getUnselectedCustomNum(Integer projectId, Integer taskId) throws Exception {
|
|
|
|
|
|
+ public GetUnselectedDTO getUnselectedCustomNum1(Integer projectId, String fieldId, Query query) throws Exception {
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
//设置查询索引
|
|
//设置查询索引
|
|
builder.index("patent");
|
|
builder.index("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(query);
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String id = hit.id();
|
|
|
|
+ list.add(id);
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ dto = this.ifExistChild1(list, projectId,fieldId);
|
|
}
|
|
}
|
|
|
|
+ return dto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public GetUnselectedDTO ifExistChild1(List<String> list, Integer projectId,String fieldId) 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 q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
|
|
|
|
+ Query q4 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
|
|
|
|
+ Query q5 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q2, q3,q4,q5));
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public GetUnselectedDTO getUnselectedCustomNum(Integer projectId,String fieldId) throws Exception {
|
|
|
|
+ GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q = null;
|
|
|
|
+ Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
|
|
|
|
+ q = QueryBuilders.hasChild(i -> i.type("project").query(query));
|
|
builder.size(9999);
|
|
builder.size(9999);
|
|
builder.query(q);
|
|
builder.query(q);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
@@ -579,12 +640,12 @@ public class EsCountService {
|
|
list.add(id);
|
|
list.add(id);
|
|
}
|
|
}
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
- dto = this.ifExistChild(list);
|
|
|
|
|
|
+ dto = this.ifExistChild(list,projectId,fieldId);
|
|
}
|
|
}
|
|
return dto;
|
|
return dto;
|
|
}
|
|
}
|
|
|
|
|
|
- public GetUnselectedDTO ifExistChild(List<String> list) throws IOException {
|
|
|
|
|
|
+ public GetUnselectedDTO ifExistChild(List<String> list, Integer projectId,String fieldId) throws IOException {
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
List<String> existChildIds = new ArrayList<>();
|
|
List<String> existChildIds = new ArrayList<>();
|
|
List<String> beinglessChildIds = new ArrayList<>();
|
|
List<String> beinglessChildIds = new ArrayList<>();
|
|
@@ -596,7 +657,9 @@ public class EsCountService {
|
|
Query q1 = QueryBuilders.parentId(i -> i.type("project_customfield").id(id));
|
|
Query q1 = QueryBuilders.parentId(i -> i.type("project_customfield").id(id));
|
|
Query q2 = QueryBuilders.exists(i -> i.field("custom_field"));
|
|
Query q2 = QueryBuilders.exists(i -> i.field("custom_field"));
|
|
Query q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
|
|
Query q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
|
|
- Query bool = QueryBuilders.bool(i -> i.must(q1, q2,q3));
|
|
|
|
|
|
+ Query q4 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
|
|
|
|
+ Query q5 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q2, q3,q4,q5));
|
|
builder.query(bool);
|
|
builder.query(bool);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
Long total = response.hits().total().value();
|
|
Long total = response.hits().total().value();
|