Browse Source

6/6 修改装载优先权日

lwhhszx 1 year ago
parent
commit
715f93c89d

+ 2 - 0
src/main/java/cn/cslg/pas/common/vo/es/EsPatentCommonVO.java

@@ -31,4 +31,6 @@ public class EsPatentCommonVO {
 
     private List<String> isDelete;
     private List<String> isAdd;
+    private Long startNum;
+    private Long endNum;
 }

+ 23 - 30
src/main/java/cn/cslg/pas/service/business/es/EsPatentService.java

@@ -587,10 +587,13 @@ public class EsPatentService {
         Long current = queryRequest.getCurrent();
         Long size = queryRequest.getSize();
         EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
-
+              esPatentCommonVO.setStartNum(current);
+              esPatentCommonVO.setEndNum(current+size);
+              esPatentCommonVO.setCurrent(null);
+              esPatentCommonVO.setSize(null);
+        SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
         Records records = new Records();
         if (esPatentCommonVO.getEsField() == null || esPatentCommonVO.getEsField().equals("")) {
-            SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
             SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
             List<Hit<Patent>> hits = response.hits().hits();
             for (Hit<Patent> hit : hits) {
@@ -600,7 +603,6 @@ public class EsPatentService {
             }
             records.setTotal(response.hits().total().value());
         } else {
-            SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
             SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
             Aggregate statsAgg = response.aggregations().get("statsBucket");
             Long total = statsAgg.statsBucket().count();
@@ -749,8 +751,6 @@ public class EsPatentService {
         Integer taskId = commonVO.getTaskId();
         String searchCondition = commonVO.getSearchCondition();
         String productFrom = commonVO.getProductFrom();
-        List<String> isAdd = commonVO.getIsAdd();
-        List<String> isDelete = commonVO.getIsDelete();
         List<EsCustomFieldValueDTO> customFields = commonVO.getCustomFields();
         if (!CollectionUtils.isEmpty(customFields)) {
             String customFieldCondition = esService.parseCustomField(customFields, projectId, taskId);
@@ -765,14 +765,7 @@ public class EsPatentService {
         treeNode tree = expressManager.getInstance().Parse(condition, false);
         //3. 从es中检索数据
         Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
-        Query reQuery = null;
-        if (isDelete != null && isDelete.size() > 0) {
-            List<Query> notInQuery = this.getNoNotInQuery(isDelete);
-            reQuery = QueryBuilders.bool(i -> i.must(q).mustNot(notInQuery));
-        } else {
-            reQuery = QueryBuilders.bool(i -> i.must(q));
-        }
-        return reQuery;
+        return q;
     }
 
     /**
@@ -808,25 +801,23 @@ public class EsPatentService {
 
         EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
         esPatentCommonVO.setIsDelete(patentNos);
-
+        esPatentCommonVO.setStartNum(startNum);
+        esPatentCommonVO.setEndNum(endNum);
+        SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
         if (esPatentCommonVO.getEsField() == null || esPatentCommonVO.getEsField().equals("")) {
-            SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
-            if (startNum > 0 && endNum > 0) {
-                builder.from(startNum.intValue() - 1).size((endNum.intValue() - startNum.intValue()) + 1);
-            }
+
             SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
             List<Hit<Patent>> hits = response.hits().hits();
             for (Hit<Patent> hit : hits) {
-                PatentNoWithIdVO patentWithIdVO = new PatentNoWithIdVO();
-                patentWithIdVO.setId(hit.id());
-                patentWithIdVO.setPatentNo(hit.source().getPatentNo());
-                patentWithIdVOS.add(patentWithIdVO);
+                if ((patentNos == null || patentNos.size() == 0) || (!patentNos.contains(hit.source().getPatentNo()))) {
+
+                    PatentNoWithIdVO patentWithIdVO = new PatentNoWithIdVO();
+                    patentWithIdVO.setId(hit.id());
+                    patentWithIdVO.setPatentNo(hit.source().getPatentNo());
+                    patentWithIdVOS.add(patentWithIdVO);
+                }
             }
         } else {
-            SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
-            if (startNum > 0 && endNum > 0) {
-                builder.from(startNum.intValue() - 1).size((endNum.intValue() - startNum.intValue()) + 1);
-            }
             SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
             Aggregate agg = response.aggregations().get("Agg");
             List<StringTermsBucket> termsBuckets = agg.sterms().buckets().array();
@@ -834,10 +825,12 @@ public class EsPatentService {
             for (StringTermsBucket termsBucket : termsBuckets) {
                 String key = termsBucket.key().stringValue();
                 PatentWithIdVO patentWithIdVO = esService.getPatentColumnDTOByGroup2(key, esPatentCommonVO.getProjectId(), esPatentCommonVO.getEsField());
-                PatentNoWithIdVO patentNoWithIdVO = new PatentNoWithIdVO();
-                patentNoWithIdVO.setId(patentWithIdVO.getId());
-                patentNoWithIdVO.setPatentNo(patentWithIdVO.getPatent().getPatentNo());
-                patentWithIdVOS.add(patentNoWithIdVO);
+                if ((patentNos == null || patentNos.size() == 0) || (!patentNos.contains(patentWithIdVO.getPatent().getPatentNo()))) {
+                    PatentNoWithIdVO patentNoWithIdVO = new PatentNoWithIdVO();
+                    patentNoWithIdVO.setId(patentWithIdVO.getId());
+                    patentNoWithIdVO.setPatentNo(patentWithIdVO.getPatent().getPatentNo());
+                    patentWithIdVOS.add(patentNoWithIdVO);
+                }
             }
         }
         return patentWithIdVOS;

+ 18 - 1
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -230,8 +230,23 @@ public class EsService {
     //获取通用检索专利方法--服务检索专利清单
     public SearchRequest.Builder getCommonPatent(EsPatentCommonVO commonVO) throws Exception {
         String esField = commonVO.getEsField();
+
+        //计算分页信息
         Long current = commonVO.getCurrent();
         Long size = commonVO.getSize();
+        Long startNum = commonVO.getStartNum();
+        Long endNum = commonVO.getEndNum();
+        Integer temPageFrom = 0;
+        Integer temPageSize = 100000;
+        if (current != null && size != null) {
+            temPageFrom = (current.intValue() - 1) * size.intValue();
+            temPageSize = size.intValue();
+        } else if (startNum != null && endNum != null) {
+            temPageFrom = startNum.intValue() - 1;
+            temPageSize = (endNum.intValue() - startNum.intValue()) + 1;
+        }
+        Integer pageFrom = temPageFrom;
+        Integer pageSize = temPageSize;
 
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
@@ -244,7 +259,7 @@ public class EsService {
             List<SortOptions> options = new ArrayList<>();
             SortOptions appDate = SortOptions.of(i -> i.field(j -> j.field("app_date").order(SortOrder.Asc)));
             options.add(appDate);
-            Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from((current.intValue() - 1) * size.intValue()).size(size.intValue()));
+            Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from(pageFrom).size(pageSize));
             Aggregation aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
                     .field(esField).size(100000).build())
                     .aggregations(new HashMap() {{
@@ -257,6 +272,8 @@ public class EsService {
             BucketsPath bucketsPath = BucketsPath.of(i -> i.single("termAgg>_count"));
             Aggregation statsBucket = AggregationBuilders.statsBucket(i -> i.bucketsPath(bucketsPath));
             builder.aggregations("statsBucket", statsBucket);
+        } else {
+            builder.from(pageFrom).size(pageSize);
         }
 
         //排序

+ 22 - 13
src/main/java/cn/cslg/pas/service/importPatent/ImportPDFBatchThread.java

@@ -4,7 +4,9 @@ import cn.cslg.pas.common.model.cronModel.SystemFile;
 import cn.cslg.pas.common.utils.FileUtils;
 import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.vo.ImportTaskAMVO;
+import cn.cslg.pas.domain.business.ImportTask;
 import cn.cslg.pas.domain.es.Patent;
+import cn.cslg.pas.service.business.ImportTaskService;
 import cn.cslg.pas.service.business.es.EsPatentService;
 import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
@@ -32,9 +34,15 @@ public class ImportPDFBatchThread extends Thread {
     @Override
     public void run() {
         String tempPath = null;
+
+         ImportTaskService importTaskService =applicationContext.getBean(ImportTaskService.class);
+        ImportTask task = importTaskService.getById(importTaskAMVO.getId());
+        task.setState(1);
+        task.updateById();
         try {
+
             importTaskAMVO.getFileGuid();
-            Integer pdfType =importTaskAMVO.getPdfType();
+            Integer pdfType = importTaskAMVO.getPdfType();
             FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
             String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskAMVO.getFileGuid()));
             List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
@@ -56,31 +64,32 @@ public class ImportPDFBatchThread extends Thread {
             if (!tempDirectory.exists()) {
                 tempDirectory.mkdir();
             }
-            ZipUtil.unzip(tempFile,tempDirectory);
+            ZipUtil.unzip(tempFile, tempDirectory);
             tempFile.delete();
             List<File> fileList = FileUtil.loopFiles(tempPath).stream().filter(item -> FileUtil.getType(item).equals("pdf")).collect(Collectors.toList());
+
             for (int i = 0; i < fileList.size(); i++) {
                 File file = fileList.get(i);
-                String fileName = file.getName();
                 String patentNo = FileUtil.getPrefix(file);
                 System.out.println(patentNo);
-                EsPatentService esPatentService =applicationContext.getBean(EsPatentService.class);
-             List<Patent> patentList=   esPatentService.getPatentsByNo(Arrays.asList(patentNo),true,null,null);
-               if(patentList!=null&&patentList.size()>0){
-                   Patent patent =patentList.get(0);
-                   String guid1 = FormatUtil.getPDFFormat(patent.getPatentNo(), pdfType);
-                   fileManagerService.uploadFileWithGuid(file, guid1);
-               }
+                EsPatentService esPatentService = applicationContext.getBean(EsPatentService.class);
+                List<Patent> patentList = esPatentService.getPatentsByNo(Arrays.asList(patentNo), true, null, null);
 
+                if (patentList != null && patentList.size() > 0) {
+                    Patent patent = patentList.get(0);
+                    String guid1 = FormatUtil.getPDFFormat(patent.getPatentNo(), pdfType);
+                    fileManagerService.uploadFileWithGuid(file, guid1);
+                }
+                taskThread.updateProcess(false, 4, patentNo);
             }
 
-
-            taskThread.awakeTaskThread();
         } catch (Exception e) {
+
+           importTaskAMVO.setState(7);
             e.printStackTrace();
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         } finally {
             FileUtil.del(tempPath);
+            taskThread.awakeTaskThread();
         }
     }