zero 9 months ago
parent
commit
e6e3c34d44

+ 102 - 11
src/main/java/cn/cslg/pas/service/business/PatentExportService.java

@@ -358,6 +358,35 @@ public class PatentExportService {
         return records;
     }
 
+    public Records queryPatents1(EsPatentCommonVO esPatentCommonVO) throws Exception {
+        List<PatentColumnDTO> patentList = new ArrayList<>();
+        Records records = new Records();
+        SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
+        SearchResponse<Patent> response = null;
+        try {
+            response = client.search(builder.build(), Patent.class);
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
+        }
+        List<Hit<Patent>> hits = response.hits().hits();
+        Long total = 0L;
+        if (org.apache.commons.lang3.StringUtils.isNotEmpty(esPatentCommonVO.getEsField())) {
+            Aggregate aggregate = response.aggregations().get("count");
+            total = aggregate.cardinality().value();
+        } else {
+            total = response.hits().total().value();
+        }
+        records.setTotal(total);
+        for (Hit<Patent> hit : hits) {
+            String id = hit.id();
+            Patent patent = hit.source();
+            PatentColumnDTO columnDTO = esService.getPatentColumnDTO(patent, esPatentCommonVO.getProjectId(), id, "1");
+            patentList.add(columnDTO);
+        }
+        records.setData(patentList);
+        return records;
+    }
+
     @Async
     public void exportPatent2(ExportTaskDTO exportTask, ImportTaskAMVO importTaskAMVO) throws Exception {
 
@@ -424,7 +453,7 @@ public class PatentExportService {
         EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
         esPatentCommonVO.setStartNum(startNum);
         esPatentCommonVO.setEndNum(toNum);
-        Records firstRecords = this.queryPatents(esPatentCommonVO);
+        Records firstRecords = this.queryPatents1(esPatentCommonVO);
 
         Long total = 0l;
         if (startNum != null && endNum != null) {
@@ -442,14 +471,14 @@ public class PatentExportService {
         }
 
         this.updateTaskStateToDoing(taskId,total);
-        List<Patent> firstPatentList = (List<Patent>) firstRecords.getData();
-        List<String> firstPatentNos = firstPatentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
+        List<PatentColumnDTO> firstPatentList = (List<PatentColumnDTO>) firstRecords.getData();
+        List<String> firstPatentNos = firstPatentList.stream().map(PatentColumnDTO::getPatentNo).collect(Collectors.toList());
 
         //查询自定义字段
         esQueryPatentFieldsDTO.setPatentNos(firstPatentNos);
         List<EsPatentFieldsVO> firstEsPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
         for (int i = 0; i < firstPatentList.size(); i++) {
-            Patent patent = firstPatentList.get(i);
+            PatentColumnDTO patent = firstPatentList.get(i);
             if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
                 continue;
             }
@@ -476,16 +505,15 @@ public class PatentExportService {
 
             esPatentCommonVO.setStartNum(startNum);
             esPatentCommonVO.setEndNum(toNum);
-            Records records = this.queryPatents(esPatentCommonVO);
+            Records records = this.queryPatents1(esPatentCommonVO);
 
-            List<Patent> patentList = (List<Patent>) records.getData();
-            List<String> patentNos = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
-            ;
+            List<PatentColumnDTO> patentList = (List<PatentColumnDTO>) records.getData();
+            List<String> patentNos = patentList.stream().map(PatentColumnDTO::getPatentNo).collect(Collectors.toList());
             //查询自定义字段
             esQueryPatentFieldsDTO.setPatentNos(patentNos);
             List<EsPatentFieldsVO> esPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
             for (int i = 0; i < patentList.size(); i++) {
-                Patent patent = patentList.get(i);
+                PatentColumnDTO patent = patentList.get(i);
                 if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
                     continue;
                 }
@@ -503,10 +531,11 @@ public class PatentExportService {
 
         esQueryPatentFieldsDTO.setPatentNos(inNos);
         List<EsPatentFieldsVO> esPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
-        List<Patent> patentList = esPatentService.getPatentsByNo(inNos, true, null, null);
+//        List<Patent> patentList = esPatentService.getPatentsByNo(inNos, true, null, null);
+        List<PatentColumnDTO> patentList = esPatentService.getPatentsByNo1(inNos, true, null, null,projectId);
         for (int i = 0; i < patentList.size(); i++) {
 
-            Patent patent = patentList.get(i);
+            PatentColumnDTO patent = patentList.get(i);
             if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
                 continue;
             }
@@ -575,6 +604,67 @@ e.printStackTrace();
         return commonCellStyle;
     }
 
+    public void loadPatentCell(PatentColumnDTO patent, List<PatentExportVO> patentExportVOS, List<PatentConfigVO> patentConfigVOS, List<EsPatentFieldsVO> esPatentFieldsVOs, HSSFSheet sheet, HSSFCellStyle commonCellStyle, Integer index) {
+
+        HSSFRow row = sheet.createRow(index + 1);
+        row.setHeight((short) 800);
+        for (int j = 0; j < patentExportVOS.size(); j++) {
+            String column = patentExportVOS.get(j).getValue();
+            String name = patentExportVOS.get(j).getName();
+            String type = patentExportVOS.get(j).getType();
+
+            List<String> types = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+
+            if (types.contains(type)) {
+                EsPatentFieldsVO esPatentFieldsVO = esPatentFieldsVOs.stream()
+                        .filter(item -> item.getPatentNo().equals(patent.getPatentNo()))
+                        .findFirst()
+                        .orElse(null);
+                if (esPatentFieldsVO != null) {
+                    List<InnerPatentFieldsVO> innerClassFields = esPatentFieldsVO.getInnerClassFields();
+                    if (!innerClassFields.isEmpty()) {
+                        InnerPatentFieldsVO innerPatentFieldsVO = innerClassFields.stream()
+                                .filter(item -> item.getField().equals(column) && item.getFieldType().equals(Integer.parseInt(type)))
+                                .findFirst()
+                                .orElse(null);
+                        if (innerPatentFieldsVO != null) {
+                            List<FieldValueVO> fieldValueVOS = innerPatentFieldsVO.getFieldValueVOS();
+                            if (!fieldValueVOS.isEmpty()) {
+                                StringBuffer sb = new StringBuffer();
+                                for (FieldValueVO fieldValueVO : fieldValueVOS) {
+                                    String valueStr = fieldValueVO.getValue();
+                                    sb.append(valueStr);
+                                }
+                                HSSFCell cell = row.createCell(j);
+                                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                                commonCellStyle.setWrapText(true);
+                                cell.setCellStyle(commonCellStyle);
+                                cell.setCellValue(sb.toString());
+
+
+                            }
+                        }
+                    }
+                }
+            } else {
+                // 使用反射获取属性值
+                Object value = GenerateObjectUtil.getPropertyValue(patent, column);
+                if (value != null) {
+                    PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
+                    String exportClass = patentConfigVO.getExportClass();
+                    GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
+                    if (getValueImp != null) {
+                        String reValue = getValueImp.getValue(value);
+                        HSSFCell cell = row.createCell(j);
+                        cell.setCellStyle(commonCellStyle);
+                        cell.setCellValue(reValue);
+                    }
+                }
+            }
+        }
+    }
+
     public void loadPatentCell(Patent patent, List<PatentExportVO> patentExportVOS, List<PatentConfigVO> patentConfigVOS, List<EsPatentFieldsVO> esPatentFieldsVOs, HSSFSheet sheet, HSSFCellStyle commonCellStyle, Integer index) {
 
         HSSFRow row = sheet.createRow(index + 1);
@@ -635,4 +725,5 @@ e.printStackTrace();
             }
         }
     }
+
 }

+ 64 - 15
src/main/java/cn/cslg/pas/service/business/es/EsPatentService.java

@@ -119,7 +119,7 @@ public class EsPatentService {
         List<Hit<Patent>> hits = response.hits().hits();
         for (Hit<Patent> hit : hits) {
             Patent esMess = hit.source();
-            dto = esService.getPatentColumnDTO(esMess, vo.getProjectId(), hit.id());
+            dto = esService.getPatentColumnDTO(esMess, vo.getProjectId(), hit.id(), "");
             //格式化权利要求
             List<Text> claims = dto.getClaim();
             if (claims != null && claims.size() > 0) {
@@ -567,7 +567,7 @@ public class EsPatentService {
      */
     public List<Patent> getPatentsByNo(List<String> patentNos, Boolean ifGetAll, Long current, Long size) throws Exception {
         List<Patent> patentList = new ArrayList<>();
-        if(patentNos==null||patentNos.size()==0){
+        if (patentNos == null || patentNos.size() == 0) {
             return patentList;
         }
         SearchRequest.Builder builder = new SearchRequest.Builder();
@@ -613,6 +613,56 @@ public class EsPatentService {
         return patentList;
     }
 
+    public List<PatentColumnDTO> getPatentsByNo1(List<String> patentNos, Boolean ifGetAll, Long current, Long size, Integer projectId) throws Exception {
+        List<PatentColumnDTO> patentList = new ArrayList<>();
+        if (patentNos == null || patentNos.size() == 0) {
+            return patentList;
+        }
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+        List<Query> querys = new ArrayList<>();
+        for (String patentNo : patentNos) {
+            Query q1 = QueryBuilders.term(t -> t.field("app_no.keyword").value(patentNo));
+            //公开号
+            Query q2 = QueryBuilders.term(t -> t.field("public_no.keyword").value(patentNo));
+            //授权号
+            Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
+            Query query = QueryBuilders.bool(i -> i.should(q1, q2, q3));
+            querys.add(query);
+        }
+        Query finalQuery = QueryBuilders.bool((i -> i.should(querys)));
+        builder.query(finalQuery);
+        if (!ifGetAll) {
+            List<String> reSources = this.rePatentSource();
+            builder.source(sourceOptionsBuilder -> sourceOptionsBuilder
+                    .filter(fieldSourceBuilder -> fieldSourceBuilder
+                            .includes(reSources)));
+        }
+        if (current != null && size != null && current > 0 && size > 0) {
+            builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
+        } else {
+            builder.from(0).size(10000);
+        }
+        SearchResponse<Patent> response = null;
+        try {
+            response = client.search(builder.build(), Patent.class);
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
+        }
+        List<Hit<Patent>> hits = response.hits().hits();
+        if (hits != null && hits.size() > 0) {
+            hits.forEach(item -> {
+                        Patent patent = item.source();
+                        String id = item.id();
+                        PatentColumnDTO columnDTO = esService.getPatentColumnDTO(patent, projectId, id, "1");
+                        patentList.add(columnDTO);
+                    }
+            );
+        }
+        return patentList;
+    }
+
 
     private List<String> rePatentSource() {
         List<String> rePatentSource = new ArrayList<>();
@@ -834,7 +884,7 @@ public class EsPatentService {
             //3. 从es中检索数据
             q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
         }
-        Query finalQ=q;
+        Query finalQ = q;
         Query reQuery = null;
         if (patentNos != null && patentNos.size() > 0) {
             List<Query> notInQuery = this.getNoNotInQuery(patentNos);
@@ -955,16 +1005,15 @@ public class EsPatentService {
     }
 
 
-
     public PatentNoWithIdVO addPatentToProject(PatentNoWithIdVO patentWithIdVO, Integer projectId) {
 
         try {
 
 
             String patentId = patentWithIdVO.getId();
-            if(patentId==null){
+            if (patentId == null) {
                 PatentWithIdVO patentWithIdVO1 = esService.getIdByPatentNo(patentWithIdVO.getPatentNo());
-                patentId =patentWithIdVO1.getId();
+                patentId = patentWithIdVO1.getId();
             }
             Boolean ifInproject = esService.searchPatent(patentId, projectId);
             if (!ifInproject) {
@@ -987,6 +1036,7 @@ public class EsPatentService {
     /**
      * lrj
      * 为导入专利向量建立的方法,不具有普遍性,其他功能勿用
+     *
      * @param queryRequest
      * @return
      * @throws Exception
@@ -1009,15 +1059,14 @@ public class EsPatentService {
                         .includes(reSources)));
         //解除最大条数限制
         builder.trackTotalHits(i -> i.enabled(true));
-        Query query =null;
-        if(projectId!=null) {
-            query= QueryBuilders.hasChild(child -> child.type("project")
+        Query query = null;
+        if (projectId != null) {
+            query = QueryBuilders.hasChild(child -> child.type("project")
                     .query(org.springframework.data.elasticsearch.client.elc.QueryBuilders.matchQueryAsQuery("project_id", projectId.toString(), null, null)));
+        } else {
+            query = QueryBuilders.exists(i -> i.field("patent_no"));
         }
-        else {
-            query=QueryBuilders.exists(i->i.field("patent_no"));
-        }
-            SearchResponse<Patent> response = null;
+        SearchResponse<Patent> response = null;
         builder.query(query);
 
         if (current > 0 && size > 0) {
@@ -1034,12 +1083,12 @@ public class EsPatentService {
         List<PatentColumnDTO> list = new ArrayList<>();
         List<Hit<Patent>> hits = response.hits().hits();
         long total = 0L;
-            total = response.hits().total().value();
+        total = response.hits().total().value();
         for (Hit<Patent> hit : hits) {
             String id = hit.id();
             Patent esMess = hit.source();
             PatentColumnDTO columnDTO = new PatentColumnDTO();
-            BeanUtils.copyProperties(esMess,columnDTO);
+            BeanUtils.copyProperties(esMess, columnDTO);
             columnDTO.setPatentId(id);
             list.add(columnDTO);
         }

+ 23 - 10
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -253,7 +253,7 @@ public class EsService {
             double four = Double.parseDouble(str);
             String id = hit.id();
             Patent esMess = hit.source();
-            PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
+            PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id, "");
             columnDTO.setScore(four);
             list.add(columnDTO);
         }
@@ -419,7 +419,7 @@ public class EsService {
     }
 
     //装载专利清单列表的数据
-    public PatentColumnDTO getPatentColumnDTO(Patent patent, Integer projectId, String id) {
+    public PatentColumnDTO getPatentColumnDTO(Patent patent, Integer projectId, String id, String typeStr) {
         PatentColumnDTO columnDTO = new PatentColumnDTO();
         columnDTO.setPatentId(id);
         BeanUtils.copyProperties(patent, columnDTO);
@@ -465,17 +465,30 @@ public class EsService {
         if (!CollectionUtils.isEmpty(patent.getPriorities())) {
             List<Priorities> priorities = patent.getPriorities();
             List<String> priorityCountrys = priorities.stream().map(Priorities::getPriorityCountry).distinct().collect(Collectors.toList());
-            String priorityCountry = String.join("<br>", priorityCountrys);
-            columnDTO.setPriorityCountry(priorityCountry);
             List<String> priorityNos = priorities.stream().map(Priorities::getPriorityNo).distinct().collect(Collectors.toList());
-            String priorityNo = String.join("<br>", priorityNos);
-            columnDTO.setPriorityNo(priorityNo);
             List<String> priorityDates = priorities.stream().map(Priorities::getPriorityDate).distinct().collect(Collectors.toList());
-            String priorityDate = String.join("<br>", priorityDates);
-            if (priorityDate.contains("null")) {
-                columnDTO.setPriorityDate("");
+            if (StringUtils.isNotEmpty(typeStr)) {
+                String priorityCountry = String.join(",", priorityCountrys);
+                columnDTO.setPriorityCountry(priorityCountry);
+                String priorityNo = String.join(",", priorityNos);
+                columnDTO.setPriorityNo(priorityNo);
+                String priorityDate = String.join(",", priorityDates);
+                if (priorityDate.contains("null")) {
+                    columnDTO.setPriorityDate("");
+                } else {
+                    columnDTO.setPriorityDate(priorityDate);
+                }
             } else {
-                columnDTO.setPriorityDate(priorityDate);
+                String priorityCountry = String.join("<br>", priorityCountrys);
+                columnDTO.setPriorityCountry(priorityCountry);
+                String priorityNo = String.join("<br>", priorityNos);
+                columnDTO.setPriorityNo(priorityNo);
+                String priorityDate = String.join("<br>", priorityDates);
+                if (priorityDate.contains("null")) {
+                    columnDTO.setPriorityDate("");
+                } else {
+                    columnDTO.setPriorityDate(priorityDate);
+                }
             }
         }
         columnDTO.setApplicant(esPatentService.loadName(patent.getApplicant()));

+ 1 - 2
src/main/resources/jsons/patent.json

@@ -292,8 +292,7 @@
     "ifStats": "false",
     "ifAsCondition": "false",
     "groupBy": "company",
-    "ifSort": "false",
-    "exportClass": "getNameValue"
+    "ifSort": "false"
   },
   {
     "name": "权利人",

+ 4 - 1
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -23,6 +23,7 @@ import cn.cslg.pas.controller.PatentController;
 import cn.cslg.pas.domain.es.FamilyPatent;
 import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.domain.es.PatentFamilyMessage;
+import cn.cslg.pas.domain.es.PatentPerson;
 import cn.cslg.pas.exception.ExceptionEnum;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.mapper.AssoProjectEventMapper;
@@ -915,7 +916,9 @@ public class EventServiceTests {
 
     @Test
     public void test120() throws Exception {
-
+        String result = "[PatentPerson(name=云南中烟工业有限责任公司, order=1, type=1)]";
+        List<PatentPerson> list = JSONArray.parseArray(result, PatentPerson.class);
+        System.out.println(list);
     }
 
 }