zero 1 рік тому
батько
коміт
bd9be43914

+ 6 - 4
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -87,7 +87,7 @@ public class EsCountService {
                         valueDTO.setFieldId(countVO.getFieldId());
                         valueDTO.setFieldValue(Arrays.asList("\""+value+"\""));
                         customFields.add(valueDTO);
-                        this.getReturnData(searchCondition, "",customFields, taskId, projectId,
+                        this.getDatas(searchCondition, "",customFields, taskId, projectId,
                                 esCountVOS, detailDTOS, esCountDTO, value, map);
                     }
                 }
@@ -99,18 +99,19 @@ public class EsCountService {
                     } else {
                         condition = countVO.getField() + " = " + "\""+value+"\"";
                     }
-                    this.getReturnData(searchCondition, condition, customFields, taskId, projectId,
+                    this.getDatas(searchCondition, condition, customFields, taskId, projectId,
                             esCountVOS, detailDTOS, esCountDTO, value, map);
                 }
             }
         } else {
-            this.getReturnData(searchCondition, "", customFields, taskId, projectId, countVOS,
+            this.getDatas(searchCondition, "", customFields, taskId, projectId, countVOS,
                     detailDTOS, esCountDTO, "", map);
         }
         esCountDTO.setDetailDTOS(detailDTOS);
         return esCountDTO;
     }
 
+/*
     public void getReturnData(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 {
@@ -301,8 +302,9 @@ public class EsCountService {
             esCountDTO.setAnalyseMap(map);
         }
     }
+*/
 
-    public void getReturnData1(String searchCondition,String condition, List<EsCustomFieldValueDTO> customFields, Integer taskId,
+    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 {
 

+ 97 - 164
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -164,38 +164,13 @@ public class EsService {
         if (!CollectionUtils.isEmpty(customFields)) {
             searchCondition = this.parseCustomField(customFields,projectId,taskId);
         }
-        if (taskId != null) {
-            if (searchCondition != null && !"".equals(searchCondition.trim())) {
-                searchCondition = "taskId = " + taskId + " AND " + searchCondition;
-            } else {
-                searchCondition = "taskId = " + taskId;
-            }
-        } else {
-            if (StringUtils.isNotEmpty(productFrom)) {
-                if (productId != null) {
-                    if (searchCondition != null && !"".equals(searchCondition.trim())) {
-                        searchCondition = "productId = " + productId + " AND " + searchCondition;
-                    } else {
-                        searchCondition = "productId = " + productId;
-                    }
-                }
-            } else {
-                if (projectId != null) {
-                    if (searchCondition != null && !"".equals(searchCondition.trim())) {
-                        searchCondition = "projectId = " + projectId + " AND " + searchCondition;
-                    } else {
-                        searchCondition = "projectId = " + projectId;
-                    }
-                }
-            }
-        }
-
+        String condition = this.appendIdsCondition(searchCondition, taskId, productFrom, projectId, productId);
 
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");
         //1. 解析检索条件
-        treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
+        treeNode tree = expressManager.getInstance().Parse(condition, false);
         //3. 从es中检索数据
         Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
         //判断同族分组
@@ -263,7 +238,6 @@ public class EsService {
             builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
         } else {
             builder.from(0).size(99999);
-
         }
 
         //解除最大条数限制
@@ -283,44 +257,7 @@ public class EsService {
                     String id = hit.id();
                     JsonData data = hit.source();
                     Patent patent1 = JSONObject.parseObject(String.valueOf(data), Patent.class);
-                    PatentColumnDTO columnDTO = new PatentColumnDTO();
-                    BeanUtils.copyProperties(patent1, columnDTO);
-                    if (projectId != null) {
-                        try {
-                            columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId, id));
-                        } catch (IOException e) {
-                            columnDTO.setMergeApplicant(new ArrayList<>());
-                        }
-                        try {
-                            columnDTO.setMergeRightHolder(esPatentService.getMergeRight(projectId, id));
-                        } catch (IOException e) {
-                            columnDTO.setMergeRightHolder(new ArrayList<>());
-                        }
-                        try {
-                            columnDTO.setMergeInventor(esPatentService.getMergeInventor(projectId, id));
-                        } catch (IOException e) {
-                            columnDTO.setMergeInventor(new ArrayList<>());
-                        }
-                    }
-                    if (ObjectUtils.isNotEmpty(patent1.getApplicantAddr())) {
-                        PersonAddress applicantAddr = patent1.getApplicantAddr();
-                        columnDTO.setAppAddress(applicantAddr.getAddress());
-                        columnDTO.setApplicantCountry(applicantAddr.getCountry());
-                        columnDTO.setAppProvince(applicantAddr.getProvince());
-                        columnDTO.setAppCity(applicantAddr.getCity());
-                        columnDTO.setAppDistrict(applicantAddr.getDistrict());
-                    }
-                    if (ObjectUtils.isNotEmpty(patent1.getRightHolderAddr())) {
-                        PersonAddress rightAddr = patent1.getRightHolderAddr();
-                        columnDTO.setRightAddress(rightAddr.getAddress());
-                        columnDTO.setRightCountry(rightAddr.getCountry());
-                        columnDTO.setRightProvince(rightAddr.getProvince());
-                        columnDTO.setRightCity(rightAddr.getCity());
-                        columnDTO.setRightDistrict(rightAddr.getDistrict());
-                    }
-                    columnDTO.setApplicant(esPatentService.loadName(patent1.getApplicant()));
-                    columnDTO.setRightHolder(esPatentService.loadName(patent1.getRightHolder()));
-                    columnDTO.setInventor(esPatentService.loadName(patent1.getInventor()));
+                    PatentColumnDTO columnDTO = this.getPatentColumnDTO(patent1, projectId, id);
                     list.add(columnDTO);
                 });
             }
@@ -330,47 +267,8 @@ public class EsService {
             for (Hit<Patent> hit : hits) {
                 String id = hit.id();
                 Patent esMess = hit.source();
-                PatentColumnDTO columnDTO = new PatentColumnDTO();
-//            columnDTO.setPatentNo(esMess.getPatentNo());
-                BeanUtils.copyProperties(esMess, columnDTO);
-                if (projectId != null) {
-                    try {
-                        columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId, id));
-                    } catch (IOException e) {
-                        columnDTO.setMergeApplicant(new ArrayList<>());
-                    }
-                    try {
-                        columnDTO.setMergeRightHolder(esPatentService.getMergeRight(projectId, id));
-                    } catch (IOException e) {
-                        columnDTO.setMergeRightHolder(new ArrayList<>());
-                    }
-                    try {
-                        columnDTO.setMergeInventor(esPatentService.getMergeInventor(projectId, id));
-                    } catch (IOException e) {
-                        columnDTO.setMergeInventor(new ArrayList<>());
-                    }
-                }
-                if (ObjectUtils.isNotEmpty(esMess.getApplicantAddr())) {
-                    PersonAddress applicantAddr = esMess.getApplicantAddr();
-                    columnDTO.setAppAddress(applicantAddr.getAddress());
-                    columnDTO.setApplicantCountry(applicantAddr.getCountry());
-                    columnDTO.setAppProvince(applicantAddr.getProvince());
-                    columnDTO.setAppCity(applicantAddr.getCity());
-                    columnDTO.setAppDistrict(applicantAddr.getDistrict());
-                }
-                if (ObjectUtils.isNotEmpty(esMess.getRightHolderAddr())) {
-                    PersonAddress rightAddr = esMess.getRightHolderAddr();
-                    columnDTO.setRightAddress(rightAddr.getAddress());
-                    columnDTO.setRightCountry(rightAddr.getCountry());
-                    columnDTO.setRightProvince(rightAddr.getProvince());
-                    columnDTO.setRightCity(rightAddr.getCity());
-                    columnDTO.setRightDistrict(rightAddr.getDistrict());
-                }
-                columnDTO.setApplicant(esPatentService.loadName(esMess.getApplicant()));
-                columnDTO.setRightHolder(esPatentService.loadName(esMess.getRightHolder()));
-                columnDTO.setInventor(esPatentService.loadName(esMess.getInventor()));
+                PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
                 list.add(columnDTO);
-
             }
         }
         this.loadCoulumnDTO(list);
@@ -381,6 +279,81 @@ public class EsService {
         return dto;
     }
 
+    //装载专利清单列表的数据
+    public PatentColumnDTO getPatentColumnDTO(Patent patent, Integer projectId, String id) {
+        PatentColumnDTO columnDTO = new PatentColumnDTO();
+        BeanUtils.copyProperties(patent, columnDTO);
+        if (projectId != null) {
+            try {
+                columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId, id));
+            } catch (IOException e) {
+                columnDTO.setMergeApplicant(new ArrayList<>());
+            }
+            try {
+                columnDTO.setMergeRightHolder(esPatentService.getMergeRight(projectId, id));
+            } catch (IOException e) {
+                columnDTO.setMergeRightHolder(new ArrayList<>());
+            }
+            try {
+                columnDTO.setMergeInventor(esPatentService.getMergeInventor(projectId, id));
+            } catch (IOException e) {
+                columnDTO.setMergeInventor(new ArrayList<>());
+            }
+        }
+        if (ObjectUtils.isNotEmpty(patent.getApplicantAddr())) {
+            PersonAddress applicantAddr = patent.getApplicantAddr();
+            columnDTO.setAppAddress(applicantAddr.getAddress());
+            columnDTO.setApplicantCountry(applicantAddr.getCountry());
+            columnDTO.setAppProvince(applicantAddr.getProvince());
+            columnDTO.setAppCity(applicantAddr.getCity());
+            columnDTO.setAppDistrict(applicantAddr.getDistrict());
+        }
+        if (ObjectUtils.isNotEmpty(patent.getRightHolderAddr())) {
+            PersonAddress rightAddr = patent.getRightHolderAddr();
+            columnDTO.setRightAddress(rightAddr.getAddress());
+            columnDTO.setRightCountry(rightAddr.getCountry());
+            columnDTO.setRightProvince(rightAddr.getProvince());
+            columnDTO.setRightCity(rightAddr.getCity());
+            columnDTO.setRightDistrict(rightAddr.getDistrict());
+        }
+        columnDTO.setApplicant(esPatentService.loadName(patent.getApplicant()));
+        columnDTO.setRightHolder(esPatentService.loadName(patent.getRightHolder()));
+        columnDTO.setInventor(esPatentService.loadName(patent.getInventor()));
+        return columnDTO;
+    }
+
+    //拼接专题库id或其他id条件
+    public String appendIdsCondition(String searchCondition,Integer taskId,String productFrom,Integer projectId,Integer productId) {
+        String condition = "";
+        if (taskId != null) {
+            if (searchCondition != null && !"".equals(searchCondition.trim())) {
+                searchCondition = "taskId = " + taskId + " AND " + searchCondition;
+            } else {
+                searchCondition = "taskId = " + taskId;
+            }
+        } else {
+            if (StringUtils.isNotEmpty(productFrom)) {
+                if (productId != null) {
+                    if (searchCondition != null && !"".equals(searchCondition.trim())) {
+                        searchCondition = "productId = " + productId + " AND " + searchCondition;
+                    } else {
+                        searchCondition = "productId = " + productId;
+                    }
+                }
+            } else {
+                if (projectId != null) {
+                    if (searchCondition != null && !"".equals(searchCondition.trim())) {
+                        searchCondition = "projectId = " + projectId + " AND " + searchCondition;
+                    } else {
+                        searchCondition = "projectId = " + projectId;
+                    }
+                }
+            }
+        }
+        condition = searchCondition;
+        return condition;
+    }
+
     /**
      * 解析自定义栏位和值
      *
@@ -474,46 +447,25 @@ public class EsService {
         }
     }
 
-    /**
-     * @param key
-     * @param page
-     * @param limit
-     * @return
-     */
-    public List<Patent> search(String key, Integer page, Integer limit) throws IOException {
-        SearchRequest.Builder builder = new SearchRequest.Builder();
-        //设置查询索引
-        builder.index("patent");
-        //组装查询条件
-        BoolQuery.Builder boolQuery = new BoolQuery.Builder();
-        boolQuery.should(q -> q.match(v -> v
-                .query(key)
-                //字段名
-                .field("patent_no")
-        ));
-
-        //多字段匹配
-//        boolQuery.should(q -> q.matchPhrasePrefix(m -> m.query(key).field("content")));
-
-        builder.query(q -> q.bool(boolQuery.build()));
-        //分页
-        if (page != null && limit != null) {
-            builder.from(page).size(limit);
-        }
-
-        //排序
-//        builder.sort(sortOptionsBuilder -> sortOptionsBuilder
-//                .field(fieldSortBuilder -> fieldSortBuilder
-//                        .field("createTime").order(SortOrder.Desc)));
-        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
-        List<Patent> list = new ArrayList<>();
-        List<Hit<Patent>> hits = response.hits().hits();
-        for (Hit<Patent> hit : hits) {
-            Patent esMess = hit.source();
-            list.add(esMess);
+    //拼接专利号
+    public String appendPatentNo(List<String> nos) {
+        String str = "NO = ";
+        if (nos.size() > 1) {
+            str = str + "(";
+            for (int i = 0; i < nos.size(); i++) {
+                String s = nos.get(i);
+                if (i != nos.size() - 1) {
+                    str = str + s + " " + "OR" + " ";
+                } else {
+                    str = str + s + ")";
+                }
+            }
+        } else {
+            for (String no : nos) {
+                str = str + no;
+            }
         }
-
-        return list;
+        return str;
     }
 
     //更新patent
@@ -1377,25 +1329,6 @@ public class EsService {
         return list;
     }
 
-    public String appendPatentNo(List<String> nos) {
-        String str = "NO = ";
-        if (nos.size() > 1) {
-            str = str + "(";
-            for (int i = 0; i < nos.size(); i++) {
-                String s = nos.get(i);
-                if (i != nos.size() - 1) {
-                    str = str + s + " " + "OR" + " ";
-                } else {
-                    str = str + s + ")";
-                }
-            }
-        } else {
-            for (String no : nos) {
-                str = str + no;
-            }
-        }
-        return str;
-    }
 }