Kaynağa Gözat

fixed 专利

zero 1 yıl önce
ebeveyn
işleme
c39a49fba9

+ 15 - 0
src/main/java/cn/cslg/pas/common/dto/GetUnselectedDTO.java

@@ -0,0 +1,15 @@
+package cn.cslg.pas.common.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class GetUnselectedDTO {
+
+    private Integer number;
+
+    private List<String> existChildIds;
+
+    private List<String> beinglessChildIds;
+}

+ 67 - 41
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -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.*;
@@ -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);
@@ -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,79 @@ 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");
+//            IdsQuery idsQuery = IdsQuery.of(i -> i.values(list));
+//            Query q1 = QueryBuilders.hasParent(i -> i.parentType("patent").query(j -> j.ids(idsQuery)));
+            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 +724,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);
-//                        }
-//                    }
-//                }
             });
         });
 

+ 3 - 0
src/main/java/cn/cslg/pas/service/business/es/EsPatentService.java

@@ -128,6 +128,9 @@ public class EsPatentService {
             if (!CollectionUtils.isEmpty(esMess.getInventor())) {
                 dto.setInventor(this.loadName(esMess.getInventor()));
             }
+            if (esMess.getPatentNo().equals(vo.getPatentNo())) {
+                break;
+            }
         }
         dto.setPictureGuid(FormatUtil.getPictureFormat(dto.getAppNo()));
         List<LegalEvent> legalEvents = this.getLegalEvents(dto.getPatentNo());