Kaynağa Gözat

专利号导入任务

lwhhszx 1 yıl önce
ebeveyn
işleme
049a9bec52
31 değiştirilmiş dosya ile 582 ekleme ve 576 silme
  1. 5 2
      pas.iml
  2. 13 0
      src/main/java/cn/cslg/pas/common/config/WebSocketConfig.java
  3. 4 0
      src/main/java/cn/cslg/pas/common/dto/UploadPatentWebDTO.java
  4. 22 0
      src/main/java/cn/cslg/pas/common/utils/FileUtils.java
  5. 7 0
      src/main/java/cn/cslg/pas/common/utils/FormatUtil.java
  6. 17 0
      src/main/java/cn/cslg/pas/common/utils/MathUtils.java
  7. 55 6
      src/main/java/cn/cslg/pas/common/utils/ReadExcelUtils.java
  8. 8 0
      src/main/java/cn/cslg/pas/common/vo/ImportTaskAMVO.java
  9. 5 1
      src/main/java/cn/cslg/pas/common/vo/business/ImportTaskVO.java
  10. 3 1
      src/main/java/cn/cslg/pas/controller/ImportTaskController.java
  11. 6 0
      src/main/java/cn/cslg/pas/domain/business/ImportTask.java
  12. 15 9
      src/main/java/cn/cslg/pas/service/business/ImportTaskService.java
  13. 10 6
      src/main/java/cn/cslg/pas/service/business/es/EsService.java
  14. 5 0
      src/main/java/cn/cslg/pas/service/common/FileManagerService.java
  15. 8 6
      src/main/java/cn/cslg/pas/service/importPatent/GetCataloguingFromWebThread.java
  16. 0 61
      src/main/java/cn/cslg/pas/service/importPatent/GetPDFfromWebThread.java
  17. 2 2
      src/main/java/cn/cslg/pas/service/importPatent/GetPatentFromExcelThread.java
  18. 84 148
      src/main/java/cn/cslg/pas/service/importPatent/GetPatentPDFFromWebThread.java
  19. 17 13
      src/main/java/cn/cslg/pas/service/importPatent/GetPatentPictureFromExcelThread.java
  20. 22 120
      src/main/java/cn/cslg/pas/service/importPatent/GetPatentPictureFromWebThread.java
  21. 0 60
      src/main/java/cn/cslg/pas/service/importPatent/GetPictureFromWebThread.java
  22. 17 7
      src/main/java/cn/cslg/pas/service/importPatent/GetRightAndFullTextFromWebThread.java
  23. 140 76
      src/main/java/cn/cslg/pas/service/importPatent/ImportFromWebToEsService.java
  24. 11 14
      src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java
  25. 23 14
      src/main/java/cn/cslg/pas/service/importPatent/SchedulingTaskService.java
  26. 20 17
      src/main/java/cn/cslg/pas/service/importPatent/TaskThread.java
  27. 0 1
      src/main/java/cn/cslg/pas/service/query/FormatQueryService.java
  28. 39 0
      src/main/resources/jsons/importTask.json
  29. 1 1
      src/main/resources/mapper/ImportTaskMapper.xml
  30. 0 2
      src/test/java/cn/cslg/pas/service/EventServiceTests.java
  31. 23 9
      src/test/java/cn/cslg/pas/service/PatentStarServiceTests.java

+ 5 - 2
pas.iml

@@ -68,7 +68,6 @@
     <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-dom:1.14" level="project" />
     <orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
     <orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
-    <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
     <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-gvt:1.14" level="project" />
     <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-shared-resources:1.14" level="project" />
     <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-svggen:1.14" level="project" />
@@ -104,6 +103,7 @@
     <orderEntry type="library" name="Maven: org.unbescape:unbescape:1.1.6.RELEASE" level="project" />
     <orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.6.5" level="project" />
     <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.10.1" level="project" />
+    <orderEntry type="library" name="Maven: org.mybatis:mybatis-typehandlers-jsr310:1.0.2" level="project" />
     <orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-boot-starter:3.5.3.1" level="project" />
     <orderEntry type="library" name="Maven: com.baomidou:mybatis-plus:3.5.3.1" level="project" />
     <orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-extension:3.5.3.1" level="project" />
@@ -196,7 +196,6 @@
     <orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
     <orderEntry type="library" name="Maven: org.springframework:spring-core:6.0.11" level="project" />
     <orderEntry type="library" name="Maven: org.springframework:spring-jcl:6.0.11" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:6.0.11" level="project" />
     <orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.9.1" level="project" />
     <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-quartz:3.1.3" level="project" />
     <orderEntry type="library" name="Maven: org.springframework:spring-context-support:6.0.11" level="project" />
@@ -222,5 +221,9 @@
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.16" level="project" />
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.1.5" level="project" />
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.4.16" level="project" />
+    <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
+    <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
+    <orderEntry type="library" name="Maven: jaxen:jaxen:1.2.0" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-test:6.0.11" level="project" />
   </component>
 </module>

+ 13 - 0
src/main/java/cn/cslg/pas/common/config/WebSocketConfig.java

@@ -0,0 +1,13 @@
+package cn.cslg.pas.common.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+public class WebSocketConfig {
+//    @Bean
+//    public ServerEndpointExporter serverEndpointExporter() {
+//        return new ServerEndpointExporter();
+//    }
+}

+ 4 - 0
src/main/java/cn/cslg/pas/common/dto/UploadPatentWebDTO.java

@@ -15,4 +15,8 @@ public class UploadPatentWebDTO {
     private PictureData pictureData;
     private Boolean ifAddPatent;
     private Boolean ifAddPicture;
+    private Boolean shouldAddPicture;
+    private Boolean shouldAddPDF;
+    private Boolean ifAddPDF;
+    private Integer haveSaveCounter;
 }

+ 22 - 0
src/main/java/cn/cslg/pas/common/utils/FileUtils.java

@@ -8,6 +8,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
 
 @Service
@@ -62,6 +64,7 @@ public class FileUtils {
         }
         return last.toString();
     }
+
     public static   File  getFileByBytes(byte[] bytes, String prefix, String suffix) {
         BufferedOutputStream bos = null;
         FileOutputStream fos = null;
@@ -99,4 +102,23 @@ public class FileUtils {
             return  file;
         }
     }
+
+
+    public static  File getFileByUrl(String dataUrl) throws IOException {
+
+        URL url = new URL(dataUrl);  //想要读取的url地址
+        InputStream in = url.openStream();
+        File file = File.createTempFile("new_url", ".jpg");  //创建文件
+        OutputStream os = new FileOutputStream(file);  //创建文件输出流
+        int bytesRead;
+        byte[] buffer = new byte[8192];
+        int len = 8192;
+        while ((bytesRead = in.read(buffer, 0, len)) != -1) {
+            os.write(buffer, 0, bytesRead);
+        }
+        //关闭释放流
+        os.close();
+        in.close();
+        return file;
+    }
 }

+ 7 - 0
src/main/java/cn/cslg/pas/common/utils/FormatUtil.java

@@ -61,4 +61,11 @@ public class FormatUtil {
         return appAn+"_p";
 
     }
+
+    public  static String getPDFFormat(String appAn,Integer type){
+        if(type.equals(0))
+        {     return appAn+"_public";}
+       else
+        {     return appAn+"_grant";}
+    }
 }

+ 17 - 0
src/main/java/cn/cslg/pas/common/utils/MathUtils.java

@@ -32,4 +32,21 @@ public class MathUtils {
 
         return str;
     }
+    public static  int BinaryToDecimal(int binaryNumber){
+
+        int decimal = 0;
+        int p = 0;
+        while(true){
+            if(binaryNumber == 0){
+                break;
+            } else {
+                int temp = binaryNumber%10;
+                decimal += temp*Math.pow(2, p);
+                binaryNumber = binaryNumber/10;
+                p++;
+            }
+        }
+        return decimal;
+    }
+
 }

+ 55 - 6
src/main/java/cn/cslg/pas/common/utils/ReadExcelUtils.java

@@ -1,6 +1,7 @@
 package cn.cslg.pas.common.utils;
 
 import cn.cslg.pas.common.vo.PatentData;
+import cn.cslg.pas.domain.es.Patent;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.ss.usermodel.*;
@@ -13,10 +14,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @Author xiexiang
@@ -218,6 +216,7 @@ public class ReadExcelUtils {
 
         return null;
     }
+
     public static String getValue(Cell cell) {
         if (cell != null) {
             if (cell.getCellType() == CellType.NUMERIC && HSSFDateUtil.isCellDateFormatted(cell)) {
@@ -225,11 +224,61 @@ public class ReadExcelUtils {
                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                 String dateString = dateFormat.format(date);
                 return dateString;
-            }
-            else{
+            } else {
                 return cell.toString();
             }
         }
         return "";
     }
+
+
+    /**
+     * @param sheet
+     * @return
+     * @throws IOException
+     */
+    public static List<String> getPatentNoFromExcel(Sheet sheet) throws IOException {
+        List<String> patentNos = new ArrayList<>();
+        int rows = sheet.getPhysicalNumberOfRows();
+        Integer cellId = null;
+        //开始装载专利数据
+        Row firstRow = sheet.getRow(0);
+
+        //查找列
+        int columns = firstRow.getLastCellNum();
+        for (int t = 0; t < columns; t++) {
+            if (firstRow.getCell(t).toString().equals("专利号")) {
+                cellId = t;
+            }
+        }
+        for (int i = 1; i < rows; i++) {
+            Row row = sheet.getRow(i);
+            String patentNo = row.getCell(cellId).toString();
+            patentNos.add(patentNo);
+        }
+        return patentNos;
+    }
+
+
+    public static Integer testNoImport(Sheet sheet) throws IOException {
+        int rows = sheet.getPhysicalNumberOfRows();
+        Integer cellId = null;
+        //开始装载专利数据
+        Row firstRow = sheet.getRow(0);
+
+        //查找列
+        int columns = firstRow.getLastCellNum();
+        for (int t = 0; t < columns; t++) {
+            if (firstRow.getCell(t).toString().equals("专利号")) {
+                cellId = t;
+            }
+        }
+
+        if(cellId!=null&&rows==1){
+            cellId=-1;
+        }
+        return cellId;
+    }
+
+
 }

+ 8 - 0
src/main/java/cn/cslg/pas/common/vo/ImportTaskAMVO.java

@@ -84,4 +84,12 @@ public class ImportTaskAMVO {
     private Boolean ifAddPictureDone;
 
     private Boolean ifAddPatentDone;
+    private Boolean ifAddPDFDone;
+    private Integer messageDoneNum;
+    private Integer pdfDoneNum;
+    private Integer pictureDoneNum;
+
+    private Integer shouldSaveCounter;
+
+    private Integer haveSaveCounter;
 }

+ 5 - 1
src/main/java/cn/cslg/pas/common/vo/business/ImportTaskVO.java

@@ -40,6 +40,10 @@ public class ImportTaskVO {
      */
     private Integer defaultNum;
     /**
+     * 失败条数
+     */
+    private Integer doneNum;
+    /**
      * 任务类型
      * 1.excel导入 2.专利号导入 3.专利号文件导入 4.检索导入 5.pdf文档导入
      */
@@ -55,7 +59,7 @@ public class ImportTaskVO {
      *
      */
     private String crons;
-
+  private Long percentage;
 
     @Schema(description = "创建时间")
     private Date createTime;

+ 3 - 1
src/main/java/cn/cslg/pas/controller/ImportTaskController.java

@@ -59,11 +59,13 @@ public class ImportTaskController {
     }
 
     @Operation(summary = "任务状态更新")
-    @PostMapping("/updateImportTaskState")
+    @GetMapping("/updateImportTaskState")
     public Response updateImportTaskState(Integer taskId,Integer state) throws Exception {
         Business business = businessFactory.getClass("importTaskService");
         ImportTaskService importTaskService =(ImportTaskService)business;
         importTaskService.updateImportTaskState(taskId,state);
         return Response.success("id");
     }
+
+//
 }

+ 6 - 0
src/main/java/cn/cslg/pas/domain/business/ImportTask.java

@@ -92,4 +92,10 @@ public class ImportTask extends BaseEntity<ImportTask> {
     private Integer endNum;
     @TableField(value = "done_num")
     private Integer doneNum;
+    @TableField(value = "message_done_num")
+    private Integer messageDoneNum;
+    @TableField(value = "pdf_done_num")
+    private Integer pdfDoneNum;
+    @TableField(value = "picture_done_num")
+    private Integer pictureDoneNum;
 }

+ 15 - 9
src/main/java/cn/cslg/pas/service/business/ImportTaskService.java

@@ -8,10 +8,7 @@ import cn.cslg.pas.common.model.cronModel.Records;
 import cn.cslg.pas.common.model.cronModel.SystemFile;
 import cn.cslg.pas.common.model.request.GroupRequest;
 import cn.cslg.pas.common.model.request.QueryRequest;
-import cn.cslg.pas.common.utils.CacheUtils;
-import cn.cslg.pas.common.utils.LoginUtils;
-import cn.cslg.pas.common.utils.ReadExcelUtils;
-import cn.cslg.pas.common.utils.ThrowException;
+import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.vo.business.ImportTaskVO;
 import cn.cslg.pas.domain.business.*;
 import cn.cslg.pas.exception.UnLoginException;
@@ -142,7 +139,7 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         } else if (importTaskDTO.getImportToType().equals(2)) {
             importTaskCondition.setProductId(importTaskDTO.getImportToId());
         }
-
+    importTaskDTO.setImportContent(MathUtils.BinaryToDecimal (importTaskDTO.getImportContent()));
         importTaskCondition.setImportContent(importTaskDTO.getImportContent());
         importTaskCondition.setCrons(importTaskDTO.getCrons());
         importTaskCondition.setIfUpdate(importTaskDTO.getIfUpdate());
@@ -185,8 +182,7 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
             } catch (Exception e) {
                 throw new XiaoShiException("文件错误");
             }
-        }
-        if (importTaskCondition.getType().equals(2)) {
+        } else if (importTaskCondition.getType().equals(4)) {
             try {
                 PatentStarListDTO patentStarListDto = new PatentStarListDTO()
                         .setCurrentQuery(importTaskCondition.getSearchCondition())
@@ -205,8 +201,10 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
             } catch (Exception e) {
                 throw new XiaoShiException("文件错误");
             }
-        }
+        } else if (importTaskCondition.getType().equals(2) || importTaskCondition.getType().equals(3)) {
+
 
+        }
         importTask.setProgress(0.0);
         String taskName = this.setImportTaskName(importTaskCondition, personnelVO.getName());
         importTask.setName(taskName);
@@ -266,6 +264,10 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
             if (systemDict2 != null) {
                 importTaskVO.setStateStr(systemDict2.getLabel());
             }
+
+
+            long percentage = (long) Math.floor((importTaskVO.getDoneNum() + 0D) / importTaskVO.getAllNum() * 100D);
+            importTaskVO.setPercentage(percentage);
         }
 
 
@@ -322,9 +324,13 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
 
     public void updateImportTaskState(Integer taskId, Integer state) {
         ImportTask importTask = this.getById(taskId);
+        importTask.setState(state);
         importTask.updateById();
         if (state.equals(4)) {
-            schedulingTaskService.pauseTask(taskId);
+            schedulingTaskService.pauseTask(taskId, state);
+        }
+        if (state.equals(0)) {
+            schedulingTaskService.startTask();
         }
 
     }

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

@@ -146,13 +146,13 @@ public class EsService {
         //4. 返回数据
         //分页
         if (current != null && size != null) {
-            builder.from(current.intValue()).size(size.intValue());
+            builder.from(current.intValue()-1).size(size.intValue());
         }
         builder.query(q);
         //排序
-        builder.sort(sortOptionsBuilder -> sortOptionsBuilder
-                .field(fieldSortBuilder -> fieldSortBuilder
-                        .field("public_date").order(SortOrder.Desc)));
+//        builder.sort(sortOptionsBuilder -> sortOptionsBuilder
+//                .field(fieldSortBuilder -> fieldSortBuilder
+//                        .field("public_date").order(SortOrder.Desc)));
 
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         List<PatentColumnDTO> list = new ArrayList<>();
@@ -269,12 +269,16 @@ public class EsService {
      * @param projectId
      * @return
      */
-    public Boolean search(String parentId, Integer projectId){
+    public Boolean searchIfInProject(String parentId, Integer projectId) throws IOException {
         boolean flag = false;
         Query q1 = QueryBuilders.term(t -> t.field("project_id").value(projectId));
         Query q2 = QueryBuilders.parentId(parent -> parent.type("project").id(parentId));
         Query bool = QueryBuilders.bool(i -> i.must(q1, q2));
-        if (bool != null) {
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        builder.query(bool);
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        long total = response.hits().total().value();
+        if (total>0) {
             flag = true;
         }
         return flag;

+ 5 - 0
src/main/java/cn/cslg/pas/service/common/FileManagerService.java

@@ -172,4 +172,9 @@ public class FileManagerService {
         return Objects.requireNonNull(response.body()).string();
     }
 
+    /**
+     * 调用文件系统上传文件接口
+     *
+     * @param files 文件
+     */
 }

+ 8 - 6
src/main/java/cn/cslg/pas/service/importPatent/GetCataloguingFromWebThread.java

@@ -45,7 +45,7 @@ public class GetCataloguingFromWebThread extends Thread {
     @Override
     public void run() {
         try {
-            while ((!ifProductAll || uploadPatentWebDTOs.size() > 0) && importTaskAMVO.getProgressVO().equals(1)) {
+            while ((!ifProductAll || uploadPatentWebDTOs.size() > 0) && importTaskAMVO.getState().equals(1)) {
 
                 //判断任务队列是否有任务,若没有则线程等待唤醒
                 if (uploadPatentWebDTOs.size() == 0) {
@@ -55,10 +55,11 @@ public class GetCataloguingFromWebThread extends Thread {
                 //根据专利申请号查询著录并装载信息
                 UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOs.remove(0);
                 String patentZhuLuStr = "";
+                patentStarApiService=applicationContext.getBean(PatentStarApiService.class);
                 if (importTaskAMVO.getDbType().equals("CN")) {
-                    patentZhuLuStr = patentStarApiService.getCnBibApi(uploadPatentWebDTO.getPatent().getAppNo());
+                    patentZhuLuStr = patentStarApiService.getCnBibApi(uploadPatentWebDTO.getStarPatentVO().getRowApplicationNo());
                 } else {
-                    patentZhuLuStr = patentStarApiService.getENBibApi(uploadPatentWebDTO.getPatent().getAppNo());
+                    patentZhuLuStr = patentStarApiService.getENBibApi(uploadPatentWebDTO.getStarPatentVO().getRowApplicationNo());
                 }
                 if (patentZhuLuStr != null && !patentZhuLuStr.trim().equals("") && !patentZhuLuStr.equals("{}") && !patentZhuLuStr.contains("请求不合法")) {
                     this.loadPatent(uploadPatentWebDTO);
@@ -68,6 +69,7 @@ public class GetCataloguingFromWebThread extends Thread {
                         this.loadWorldPatent(patentZhuLuStr, uploadPatentWebDTO.getPatent());
                     }
                 }
+                //加入es保存队列
                 importFromWebToEsService.savePatentToEs(uploadPatentWebDTO);
             }
 
@@ -277,7 +279,7 @@ public class GetCataloguingFromWebThread extends Thread {
 
     //装载中国专利
     private void loadCNPatent(String chinaPatentZhuLuStr, Patent patent) {
-
+                  patent.setPatentNo(patent.getAppNo());
         if (chinaPatentZhuLuStr != null && !chinaPatentZhuLuStr.trim().equals("") && !chinaPatentZhuLuStr.equals("{}") && !chinaPatentZhuLuStr.contains("请求不合法")) {
             List<ChinaPatentZhuLu> chinaPatentZhuLus = JSON.parseArray(chinaPatentZhuLuStr, ChinaPatentZhuLu.class);
             ChinaPatentZhuLu chinaPatentZhuLu = chinaPatentZhuLus.get(0);
@@ -319,7 +321,7 @@ public class GetCataloguingFromWebThread extends Thread {
                 }
             }
             //装载优先权号、优先权国家、优先权日
-            if (patent.getPriorities() == null) {
+            if (patent.getPriorities() == null&&chinaPatentZhuLu.getPR()!=null&&chinaPatentZhuLu.getPR()!="") {
                 Priorities priorities = new Priorities();
                 priorities.setPriorityNo(chinaPatentZhuLu.getPR());
                 String pCountry = chinaPatentZhuLu.getPR().substring(0, 2);
@@ -417,7 +419,7 @@ public class GetCataloguingFromWebThread extends Thread {
         }
 
         //装载优先权号、优先权国家、优先权日
-        if (patent.getPriorities() == null) {
+        if (patent.getPriorities() == null&&worldPatentZhuLu.getPr()!=null&&worldPatentZhuLu.getPr()!="") {
             Priorities priorities = new Priorities();
             priorities.setPriorityNo(worldPatentZhuLu.getPr());
             String pCountry = worldPatentZhuLu.getPr().substring(0, 2);

+ 0 - 61
src/main/java/cn/cslg/pas/service/importPatent/GetPDFfromWebThread.java

@@ -1,61 +0,0 @@
-package cn.cslg.pas.service.importPatent;
-
-import cn.cslg.pas.common.dto.UploadPatentWebDTO;
-import cn.cslg.pas.common.vo.ChinaPatentZhuLu;
-import cn.cslg.pas.common.vo.ImportTaskAMVO;
-import cn.cslg.pas.service.common.PatentStarApiService;
-import com.alibaba.fastjson.JSON;
-import org.springframework.beans.factory.annotation.Configurable;
-import org.springframework.context.ApplicationContext;
-
-import java.util.List;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-@Configurable
-public class GetPDFfromWebThread extends Thread {
-
-    private ImportTaskAMVO importTaskAMVO;
-    private ApplicationContext applicationContext;
-    private ImportFromWebToEsService importFromWebToEsService;
-    private PatentStarApiService patentStarApiService;
-    private List<UploadPatentWebDTO> uploadPatentWebDTOs;
-    private final Lock taskLock = new ReentrantLock();
-    private final Condition taskCondition = taskLock.newCondition();
-    @Override
-    public void run() {
-        try {
-            while ( uploadPatentWebDTOs.size() > 0||importTaskAMVO.getProgressVO().equals(1)) {
-                //判断任务队列是否有任务,若没有则线程等待唤醒
-                if (uploadPatentWebDTOs.size() == 0) {
-                    taskLock.lock();
-                    taskCondition.await();
-                }
-                //根据专利申请号查询著录并装载信息
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-
-    public GetPDFfromWebThread(TaskThread taskThread, ImportFromWebToEsService importFromWebToEsService) {
-        this.importTaskAMVO = taskThread.getImportTaskAMVO();
-        this.importFromWebToEsService = importFromWebToEsService;
-        this.applicationContext = taskThread.getApplicationContext();
-    }
-    public void awakeTask(UploadPatentWebDTO uploadPatentWebDTO) {
-        uploadPatentWebDTOs.add(uploadPatentWebDTO);
-        if (taskLock.tryLock()) {
-            taskCondition.signalAll();
-            taskLock.unlock();
-        }
-    }
-
-
-    //装载权利要求
-
-
-}

+ 2 - 2
src/main/java/cn/cslg/pas/service/importPatent/GetPatentFromExcelThread.java

@@ -50,7 +50,7 @@ public class GetPatentFromExcelThread extends Thread {
                 IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
             }
             Integer total = importTaskAMVO.getAllNum();
-            Integer lastIndex = importTaskAMVO.getSuccessNum();
+            Integer lastIndex = importTaskAMVO.getDoneNum();
             Integer sourceId = importTaskAMVO.getSourceId();
             //解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
             ExcuteDataToVOService excuteDataToVOService = applicationContext.getBean(ExcuteDataToVOService.class);
@@ -60,7 +60,7 @@ public class GetPatentFromExcelThread extends Thread {
             Sheet sheet = ReadExcelUtils.readExcel(tempFile);
             //遍历专利总数量,在循环中将专利一个一个存入消费者专利队列
             for (int i = lastIndex; i < total; i++) {
-                if(importTaskAMVO.getProgressVO().getState().equals(1)){
+                if(!importTaskAMVO.getState().equals(1)){
                     System.out.println(importTaskAMVO.getId());
                     break;
                 }

+ 84 - 148
src/main/java/cn/cslg/pas/service/importPatent/GetPatentPDFFromWebThread.java

@@ -2,10 +2,13 @@ package cn.cslg.pas.service.importPatent;
 
 import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
 import cn.cslg.pas.common.dto.UploadPatentWebDTO;
+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.common.vo.StarPatentVO;
 import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.domain.es.Text;
+import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
 import org.dom4j.Document;
 import org.dom4j.Element;
@@ -14,6 +17,7 @@ import org.dom4j.io.SAXReader;
 import org.springframework.beans.factory.annotation.Configurable;
 import org.springframework.context.ApplicationContext;
 
+import java.io.File;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.ArrayList;
@@ -28,76 +32,93 @@ public class GetPatentPDFFromWebThread extends Thread {
     private ImportTaskAMVO importTaskAMVO;
     private ApplicationContext applicationContext;
     private ImportFromWebToEsService importFromWebToEsService;
-    private PatentStarApiService patentStarApiService;
-    private List<UploadPatentWebDTO> uploadPatentWebDTOs;
+    private List<UploadPatentWebDTO> uploadPatentWebDTOs =new ArrayList<>();
     private final Lock taskLock = new ReentrantLock();
     private final Condition taskCondition = taskLock.newCondition();
+    private Boolean ifProductAll = false;
+    private TaskThread taskThread;
+    private PatentStarApiService patentStarApiService;
+    private FileManagerService fileManagerService;
 
     @Override
     public void run() {
         try {
-//            while (uploadPatentWebDTOs.size() > 0 || importTaskAMVO.getProgressVO().equals(1)) {
-//                String usedPatentNo;
-//                UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOs.remove(0);
-//                StarPatentVO starPatentVO = uploadPatentWebDTO.getStarPatentVO();
-//                if (starPatentVO.getPublicNo() != null && !starPatentVO.getPublicNo().equals("")) {
-//                    usedPatentNo = starPatentVO.getPublicNo();
-//                } else {
-//                    usedPatentNo = starPatentVO.getPatentNo();
-//                }
-//
-//                String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
-//                //先根据公开号判断国家,若没有公开号再根据申请号判断,调用"获得中国专利pdf"接口,获得1个或2个pdf的url地址
-//                if ((starPatentVO.getPublicNo() != null && starPatentVO.getPublicNo().contains("CN")) || (starPatentVO.getPublicNo() == null && starPatentVO.getPatentNo().contains("CN"))) {
-//                    String pdfUrlStr = patentStarApiService.getCnPdfApi(starPatentVO.getRowApplicationNo());
-//
-//                    //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
-//                    if (pdfUrlStr.equals("")) {
-////                        recordQuestionPatent(starPatent.getApplicationNo(), task.getId(), 4);
-//                        return;
-//                    }
-//
-//                    if (pdfUrlStr.contains("|http")) {  //若包含公开和授权两个pdf
-//                        String[] pdfUrlArr = pdfUrlStr.split("\\|http");
-//                        pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
-//                        pdfUrlArr[1] = "http" + pdfUrlArr[1];
-//                        pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
-//
-//                        UploadFileDTO fileDTO = downLoadPdf(pdfUrl1);
-//                        UploadFileDTO fileDTO2 = downLoadPdf(pdfUrl2);
-//
-//                        if (pdfUrl1.contains("0A_CN_0.pdf")) {
-//                            uploadParamsVO.setPdf1FileDTO(fileDTO);
-//                            uploadParamsVO.setPdf2FileDTO(fileDTO2);
-//                        } else {
-//                            uploadParamsVO.setPdf1FileDTO(fileDTO2);
-//                            uploadParamsVO.setPdf2FileDTO(fileDTO);
-//                        }
-//                    } else {  //若只有一个
-//                        pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"), pdfUrlStr.indexOf("?"));
-//                        UploadFileDTO fileDTO = downLoadPdf(pdfUrl1);
-//                        if (pdfUrl1.contains("0A_CN_0.pdf")) {
-//                            uploadParamsVO.setPdf1FileDTO(fileDTO);
-//                        } else {
-//                            uploadParamsVO.setPdf2FileDTO(fileDTO);
-//                        }
-//                    }
-//
-//                    //根据专利号调用"获得世界专利pdf"接口,获得pdf的url地址
-//                } else {
-//                    pdfUrl = patentStarApiService.getEnPdfApi(usedPatentNo);
-//
-//                    //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
+            while ((!ifProductAll || uploadPatentWebDTOs.size() > 0) && importTaskAMVO.getState().equals(1)) {
+                String usedPatentNo;
+                if (uploadPatentWebDTOs.size() == 0) {
+                    taskLock.lock();
+                    taskCondition.await();
+                }
+                UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOs.remove(0);
+                StarPatentVO starPatentVO = uploadPatentWebDTO.getStarPatentVO();
+                if (starPatentVO.getPublicNo() != null && !starPatentVO.getPublicNo().equals("")) {
+                    usedPatentNo = starPatentVO.getPublicNo();
+                } else {
+                    usedPatentNo = starPatentVO.getPatentNo();
+                }
+
+                String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
+                //先根据公开号判断国家,若没有公开号再根据申请号判断,调用"获得中国专利pdf"接口,获得1个或2个pdf的url地址
+                if ((starPatentVO.getPublicNo() != null && starPatentVO.getPublicNo().contains("CN")) || (starPatentVO.getPublicNo() == null && starPatentVO.getPatentNo().contains("CN"))) {
+
+                    String pdfUrlStr = patentStarApiService.getCnPdfApi(starPatentVO.getRowApplicationNo());
+
+                    //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
+                    if (pdfUrlStr.equals("")) {
+//                        recordQuestionPatent(starPatent.getApplicationNo(), task.getId(), 4);
+                        return;
+                    }
+
+                    if (pdfUrlStr.contains("|http")) {  //若包含公开和授权两个pdf
+                        String[] pdfUrlArr = pdfUrlStr.split("\\|http");
+                        pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
+                        pdfUrlArr[1] = "http" + pdfUrlArr[1];
+                        pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
+
+
+                        if (pdfUrl1.contains("0A_CN_0.pdf")) {
+                            String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
+                            File file1 = FileUtils.getFileByUrl(pdfUrl1);
+                            fileManagerService.uploadFileWithGuid(file1, guid1);
+                            String guid2 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 1);
+                            File file2 = FileUtils.getFileByUrl(pdfUrl2);
+                            fileManagerService.uploadFileWithGuid(file2, guid2);
+                        } else {
+                            String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 1);
+                            File file1 = FileUtils.getFileByUrl(pdfUrl1);
+                            fileManagerService.uploadFileWithGuid(file1, guid1);
+                            String guid2 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
+                            File file2 = FileUtils.getFileByUrl(pdfUrl2);
+                            fileManagerService.uploadFileWithGuid(file2, guid2);
+                        }
+                    } else {  //若只有一个
+                        pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"), pdfUrlStr.indexOf("?"));
+                        if (pdfUrl1.contains("0A_CN_0.pdf")) {
+                            String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
+                            File file1 = FileUtils.getFileByUrl(pdfUrl1);
+                            fileManagerService.uploadFileWithGuid(file1, guid1);
+                        } else {
+                            String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 1);
+                            File file1 = FileUtils.getFileByUrl(pdfUrl1);
+                            fileManagerService.uploadFileWithGuid(file1, guid1);
+                        }
+                    }
+                    //根据专利号调用"获得世界专利pdf"接口,获得pdf的url地址
+                } else {
+                    pdfUrl = patentStarApiService.getEnPdfApi(usedPatentNo);
+                    //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
 //                    if (pdfUrl.equals("") || pdfUrl.equals("{}")) {
 //                        recordQuestionPatent(starPatent.getApplicationNo(), task.getId(), 4);
 //                        return;
 //                    }
-//
-//                    UploadFileDTO fileDTO = downLoadPdf(pdfUrl);
-//                    uploadParamsVO.setPdf1FileDTO(fileDTO);
-//                }
-//
-//            }
+                    String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
+                    File file1 = FileUtils.getFileByUrl(pdfUrl);
+                    fileManagerService.uploadFileWithGuid(file1, guid1);
+
+                }
+                taskThread.ifPatentDone(uploadPatentWebDTO);
+            }
+            taskThread.awakeTaskThread();
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -108,6 +129,9 @@ public class GetPatentPDFFromWebThread extends Thread {
         this.importTaskAMVO = taskThread.getImportTaskAMVO();
         this.importFromWebToEsService = importFromWebToEsService;
         this.applicationContext = taskThread.getApplicationContext();
+        this.patentStarApiService = applicationContext.getBean(PatentStarApiService.class);
+        this.fileManagerService = applicationContext.getBean(FileManagerService.class);
+        this.taskThread=taskThread;
     }
 
     public void awakeTask(UploadPatentWebDTO uploadPatentWebDTO) {
@@ -118,92 +142,4 @@ public class GetPatentPDFFromWebThread extends Thread {
         }
     }
 
-
-    //装载权利要求
-    private void loadClaim(UploadPatentWebDTO uploadPatentWebDTO,String cnFullXmlStr) {
-        Patent patent = uploadPatentWebDTO.getPatent();
-        try {
-            if(cnFullXmlStr!=null&&cnFullXmlStr!="") {
-                SAXReader reader = new SAXReader();
-                reader.setEntityResolver(new IgnoreDTDEntityResolver());
-                Reader stringReader = new StringReader(cnFullXmlStr);
-                Document document = reader.read(stringReader);
-                XPath xpath = document.createXPath("//claim-text");
-                List<Element> element = (List<Element>) xpath.selectNodes(document);
-                if (element.size() == 0) {
-                    xpath = document.createXPath("//business:ClaimText");
-                    element = (List<Element>) xpath.selectNodes(document);
-                }
-                List<String> reClaims = new ArrayList<>();
-                element.forEach(item -> {
-                    String claim = item.getText();
-                    reClaims.add(claim);
-                });
-                String reClaim = "";
-                if (reClaims.size() != 0) {
-                    reClaim = cn.cslg.pas.common.utils.StringUtils.join(reClaims, "\r\n");
-                }
-                //装载权利要求原文
-                Text text = new Text();
-                text.setLanguage(patent.getAppCountry());
-                text.setTextContent(reClaim);
-                text.setIfOrigin(true);
-                patent.setClaim(Arrays.asList(text));
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-
-    }
-
-     //装载说明书文档
-    private void loadFullText(UploadPatentWebDTO uploadPatentWebDTO,String cnFullXmlStr) {
-        Patent patent = uploadPatentWebDTO.getPatent();
-        try {
-            //若没有取到全文文本,即取不到说明书文本,则将当前申请号或专利号和备注信息记录到问题记录表
-            if (cnFullXmlStr.equals("")) {
-                return ;
-            }
-
-            SAXReader reader = new SAXReader();
-            reader.setEntityResolver(new IgnoreDTDEntityResolver());
-            Reader stringReader = new StringReader(cnFullXmlStr);
-            Document document = reader.read(stringReader);
-            XPath xpath = document.createXPath("//description//p");
-            List<Element> elements = (List<Element>) xpath.selectNodes(document);
-            if (elements.size() == 0) {
-                xpath = document.createXPath("//business:Description//base:Paragraphs");
-                elements = (List<Element>) xpath.selectNodes(document);
-            }
-            List<String> fullTexts = new ArrayList<>();
-            Integer count=1;
-            for (Element item:elements){
-                String fullText = item.getText().replaceAll("<br/>", "");
-                if (!fullText.trim().equals("技术领域")
-                        && !fullText.trim().equals("发明内容")
-                        && !fullText.trim().equals("附图说明")
-                        && !fullText.trim().equals("具体实施方式")
-                        &&!fullText.trim().equals("背景技术"))
-                {String formattedNum = String.format("%04d", count);
-                    fullText ="["+formattedNum+"]"+fullText;
-                    count++;
-                }
-                fullTexts.add(fullText);
-            }
-            String fullText = "";
-            if (fullTexts.size() != 0) {
-                fullText = cn.cslg.pas.common.utils.StringUtils.join(fullTexts, "\r\n");
-            }
-            Text text =new Text();
-            text.setIfOrigin(true);
-            text.setTextContent(fullText);
-            text.setLanguage(patent.getAppCountry());
-            patent.setPublicFullText(Arrays.asList(text));
-    } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-
-    }
 }

+ 17 - 13
src/main/java/cn/cslg/pas/service/importPatent/GetPatentPictureFromExcelThread.java

@@ -42,33 +42,37 @@ public class GetPatentPictureFromExcelThread extends Thread {
     private ApplicationContext applicationContext;
     private SavePatentToEsThread savePatentToEsThread;
     private Boolean ifProductAll = false;
-    private List<UploadPatentWebDTO> uploadPatentWebDTOS =new ArrayList<>();
+    private List<UploadPatentWebDTO> uploadPatentWebDTOS = new ArrayList<>();
     private TaskThread taskThread;
     private final Lock taskLock = new ReentrantLock();
     private final Condition taskCondition = taskLock.newCondition();
+
     @Override
     public void run() {
         try {
-            while ((!ifProductAll || uploadPatentWebDTOS.size() > 0 )&& importTaskAMVO.getState().equals(1)) {
+            while ((!ifProductAll || uploadPatentWebDTOS.size() > 0) && importTaskAMVO.getState().equals(1)) {
                 if (uploadPatentWebDTOS.size() == 0) {
                     taskLock.lock();
                     taskCondition.await();
                 }
                 UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOS.remove(0);
-                String guid = FormatUtil.getPictureFormat(uploadPatentWebDTO.getPatent().getAppNo());
-                PictureData pictureData =uploadPatentWebDTO.getPictureData();
-                String ext = pictureData.suggestFileExtension();
-                byte[] data = pictureData.getData();
-                String picName = IdUtil.simpleUUID() ;
-               File file = FileUtils.getFileByBytes(data,picName,"."+ext);
-               FileManagerService fileManagerService =applicationContext.getBean(FileManagerService.class);
-               fileManagerService.uploadFileWithGuid(file,guid);
-                uploadPatentWebDTO.setIfAddPicture(true);
+                String guid = FormatUtil.getPictureFormat(uploadPatentWebDTO.getStarPatentVO().getRowApplicationNo());
+                PictureData pictureData = uploadPatentWebDTO.getPictureData();
+                if(pictureData!=null){
+                    String ext = pictureData.suggestFileExtension();
+                    byte[] data = pictureData.getData();
+                    String picName = IdUtil.simpleUUID();
+                    File file = FileUtils.getFileByBytes(data, picName, "." + ext);
+                    FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
+                    fileManagerService.uploadFileWithGuid(file, guid);
+                }
                 taskThread.ifPatentDone(uploadPatentWebDTO);
             }
             importTaskAMVO.setIfAddPictureDone(true);
-               taskThread.awakeTaskThread();
+            taskThread.awakeTaskThread();
         } catch (Exception e) {
+            importTaskAMVO.setIfAddPictureDone(true);
+            taskThread.awakeTaskThread();
             e.printStackTrace();
         }
     }
@@ -77,7 +81,7 @@ public class GetPatentPictureFromExcelThread extends Thread {
         this.importTaskAMVO = taskThread.getImportTaskAMVO();
         this.savePatentToEsThread = savePatentToEsThread;
         this.applicationContext = taskThread.getApplicationContext();
-        this.taskThread =taskThread;
+        this.taskThread = taskThread;
     }
 
     public void awakeTask(UploadPatentWebDTO uploadPatentWebDTO) {

+ 22 - 120
src/main/java/cn/cslg/pas/service/importPatent/GetPatentPictureFromWebThread.java

@@ -2,11 +2,15 @@ package cn.cslg.pas.service.importPatent;
 
 import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
 import cn.cslg.pas.common.dto.UploadPatentWebDTO;
+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.common.vo.StarPatentVO;
 import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.domain.es.Text;
+import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
+import cn.hutool.core.util.IdUtil;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.dom4j.Document;
@@ -32,47 +36,32 @@ public class GetPatentPictureFromWebThread extends Thread {
     private ImportTaskAMVO importTaskAMVO;
     private ApplicationContext applicationContext;
     private ImportFromWebToEsService importFromWebToEsService;
-    private PatentStarApiService patentStarApiService;
-    private List<UploadPatentWebDTO> uploadPatentWebDTOs;
+    private List<UploadPatentWebDTO> uploadPatentWebDTOs = new ArrayList<>();
     private final Lock taskLock = new ReentrantLock();
     private final Condition taskCondition = taskLock.newCondition();
+    private Boolean ifProductAll = false;
+    private TaskThread taskThread;
 
     @Override
     public void run() {
         try {
-            while (uploadPatentWebDTOs.size() > 0 || importTaskAMVO.getProgressVO().equals(1)) {
-               UploadPatentWebDTO uploadPatentWebDTO= uploadPatentWebDTOs.remove(0);
-                String pictureUrl = patentStarApiService.getPictureApi(uploadPatentWebDTO.getStarPatentVO().getPublicNo());
-                URL url = new URL(pictureUrl);  //想要读取的url地址
-                InputStream in = url.openStream();
-                File file = File.createTempFile("new_url", ".jpg");  //创建文件
-                OutputStream os = new FileOutputStream(file);  //创建文件输出流
-                int bytesRead;
-                byte[] buffer = new byte[8192];
-                int len = 8192;
-                while ((bytesRead = in.read(buffer, 0, len)) != -1) {
-                    os.write(buffer, 0, bytesRead);
+            while ((!ifProductAll || uploadPatentWebDTOs.size() > 0) && importTaskAMVO.getState().equals(1)) {
+                if (uploadPatentWebDTOs.size() == 0) {
+                    taskLock.lock();
+                    taskCondition.await();
                 }
-                //关闭释放流
-                os.close();
-                in.close();
-
-                DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
-                FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
-                buffer = new byte[8192];
-                FileInputStream fis = new FileInputStream(file);
-                OutputStream fos = item.getOutputStream();
-                len = 8192;
-                while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
-                    fos.write(buffer, 0, bytesRead);
+                UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOs.remove(0);
+                PatentStarApiService patentStarApiService = applicationContext.getBean(PatentStarApiService.class);
+                String pictureUrl = patentStarApiService.getPictureApi(uploadPatentWebDTO.getStarPatentVO().getRowApplicationNo());
+                if (pictureUrl != null && pictureUrl != "{}") {
+                    File file = FileUtils.getFileByUrl(pictureUrl);
+                    FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
+                    String guid = FormatUtil.getPictureFormat(uploadPatentWebDTO.getStarPatentVO().getApplicationNo());
+                    fileManagerService.uploadFileWithGuid(file, guid);
                 }
-                //关闭释放流
-                fos.close();
-                fis.close();
-//                MultipartFile multipartFile = new MockMultipartFile(item);
-
+                taskThread.ifPatentDone(uploadPatentWebDTO);
             }
-
+            taskThread.awakeTaskThread();
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -83,6 +72,7 @@ public class GetPatentPictureFromWebThread extends Thread {
         this.importTaskAMVO = taskThread.getImportTaskAMVO();
         this.importFromWebToEsService = importFromWebToEsService;
         this.applicationContext = taskThread.getApplicationContext();
+        this.taskThread = taskThread;
     }
 
     public void awakeTask(UploadPatentWebDTO uploadPatentWebDTO) {
@@ -93,92 +83,4 @@ public class GetPatentPictureFromWebThread extends Thread {
         }
     }
 
-
-    //装载权利要求
-    private void loadClaim(UploadPatentWebDTO uploadPatentWebDTO,String cnFullXmlStr) {
-        Patent patent = uploadPatentWebDTO.getPatent();
-        try {
-            if(cnFullXmlStr!=null&&cnFullXmlStr!="") {
-                SAXReader reader = new SAXReader();
-                reader.setEntityResolver(new IgnoreDTDEntityResolver());
-                Reader stringReader = new StringReader(cnFullXmlStr);
-                Document document = reader.read(stringReader);
-                XPath xpath = document.createXPath("//claim-text");
-                List<Element> element = (List<Element>) xpath.selectNodes(document);
-                if (element.size() == 0) {
-                    xpath = document.createXPath("//business:ClaimText");
-                    element = (List<Element>) xpath.selectNodes(document);
-                }
-                List<String> reClaims = new ArrayList<>();
-                element.forEach(item -> {
-                    String claim = item.getText();
-                    reClaims.add(claim);
-                });
-                String reClaim = "";
-                if (reClaims.size() != 0) {
-                    reClaim = cn.cslg.pas.common.utils.StringUtils.join(reClaims, "\r\n");
-                }
-                //装载权利要求原文
-                Text text = new Text();
-                text.setLanguage(patent.getAppCountry());
-                text.setTextContent(reClaim);
-                text.setIfOrigin(true);
-                patent.setClaim(Arrays.asList(text));
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-
-    }
-
-     //装载说明书文档
-    private void loadFullText(UploadPatentWebDTO uploadPatentWebDTO,String cnFullXmlStr) {
-        Patent patent = uploadPatentWebDTO.getPatent();
-        try {
-            //若没有取到全文文本,即取不到说明书文本,则将当前申请号或专利号和备注信息记录到问题记录表
-            if (cnFullXmlStr.equals("")) {
-                return ;
-            }
-
-            SAXReader reader = new SAXReader();
-            reader.setEntityResolver(new IgnoreDTDEntityResolver());
-            Reader stringReader = new StringReader(cnFullXmlStr);
-            Document document = reader.read(stringReader);
-            XPath xpath = document.createXPath("//description//p");
-            List<Element> elements = (List<Element>) xpath.selectNodes(document);
-            if (elements.size() == 0) {
-                xpath = document.createXPath("//business:Description//base:Paragraphs");
-                elements = (List<Element>) xpath.selectNodes(document);
-            }
-            List<String> fullTexts = new ArrayList<>();
-            Integer count=1;
-            for (Element item:elements){
-                String fullText = item.getText().replaceAll("<br/>", "");
-                if (!fullText.trim().equals("技术领域")
-                        && !fullText.trim().equals("发明内容")
-                        && !fullText.trim().equals("附图说明")
-                        && !fullText.trim().equals("具体实施方式")
-                        &&!fullText.trim().equals("背景技术"))
-                {String formattedNum = String.format("%04d", count);
-                    fullText ="["+formattedNum+"]"+fullText;
-                    count++;
-                }
-                fullTexts.add(fullText);
-            }
-            String fullText = "";
-            if (fullTexts.size() != 0) {
-                fullText = cn.cslg.pas.common.utils.StringUtils.join(fullTexts, "\r\n");
-            }
-            Text text =new Text();
-            text.setIfOrigin(true);
-            text.setTextContent(fullText);
-            text.setLanguage(patent.getAppCountry());
-            patent.setPublicFullText(Arrays.asList(text));
-    } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-
-    }
 }

+ 0 - 60
src/main/java/cn/cslg/pas/service/importPatent/GetPictureFromWebThread.java

@@ -1,60 +0,0 @@
-package cn.cslg.pas.service.importPatent;
-
-import cn.cslg.pas.common.dto.UploadPatentWebDTO;
-import cn.cslg.pas.common.vo.ImportTaskAMVO;
-import cn.cslg.pas.service.common.PatentStarApiService;
-import org.springframework.beans.factory.annotation.Configurable;
-import org.springframework.context.ApplicationContext;
-
-import java.util.List;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-@Configurable
-public class GetPictureFromWebThread extends Thread {
-
-    private ImportTaskAMVO importTaskAMVO;
-    private ApplicationContext applicationContext;
-    private ImportFromWebToEsService importFromWebToEsService;
-    private PatentStarApiService patentStarApiService;
-    private List<UploadPatentWebDTO> uploadPatentWebDTOs;
-    private final Lock taskLock = new ReentrantLock();
-    private final Condition taskCondition = taskLock.newCondition();
-    @Override
-    public void run() {
-        try {
-            while ( uploadPatentWebDTOs.size() > 0||importTaskAMVO.getProgressVO().equals(1)) {
-
-                //判断任务队列是否有任务,若没有则线程等待唤醒
-                if (uploadPatentWebDTOs.size() == 0) {
-                    taskLock.lock();
-                    taskCondition.await();
-                }
-                //根据专利申请号查询著录并装载信息
-
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    public GetPictureFromWebThread(TaskThread taskThread, ImportFromWebToEsService importFromWebToEsService) {
-        this.importTaskAMVO = taskThread.getImportTaskAMVO();
-        this.importFromWebToEsService = importFromWebToEsService;
-        this.applicationContext = taskThread.getApplicationContext();
-    }
-    public void awakeTask(UploadPatentWebDTO uploadPatentWebDTO) {
-        uploadPatentWebDTOs.add(uploadPatentWebDTO);
-        if (taskLock.tryLock()) {
-            taskCondition.signalAll();
-            taskLock.unlock();
-        }
-    }
-
-
-    //装载权利要求
-
-
-}

+ 17 - 7
src/main/java/cn/cslg/pas/service/importPatent/GetRightAndFullTextFromWebThread.java

@@ -33,26 +33,30 @@ public class GetRightAndFullTextFromWebThread extends Thread {
     private ApplicationContext applicationContext;
     private ImportFromWebToEsService importFromWebToEsService;
     private PatentStarApiService patentStarApiService;
-    private List<UploadPatentWebDTO> uploadPatentWebDTOs;
+    private List<UploadPatentWebDTO> uploadPatentWebDTOs =new ArrayList<>();
     private final Lock taskLock = new ReentrantLock();
     private final Condition taskCondition = taskLock.newCondition();
 
     @Override
     public void run() {
         try {
-            while (uploadPatentWebDTOs.size() > 0 || importTaskAMVO.getProgressVO().equals(1)) {
-                UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOs.remove(0);
-                Patent patent = uploadPatentWebDTO.getPatent();
-                StarPatentVO starPatentVO =uploadPatentWebDTO.getStarPatentVO();
+            while (uploadPatentWebDTOs.size() > 0 || importTaskAMVO.getState().equals(1)) {
                 if (uploadPatentWebDTOs.size() == 0) {
                     taskLock.lock();
                     taskCondition.await();
                 }
-                if ((patent.getPublicNo() != null && patent.getPublicNo().contains("CN")) || (patent.getPublicNo() == null && patent.getPatentNo().contains("CN"))) {
+                UploadPatentWebDTO uploadPatentWebDTO = uploadPatentWebDTOs.remove(0);
+                Patent patent = uploadPatentWebDTO.getPatent();
+                StarPatentVO starPatentVO =uploadPatentWebDTO.getStarPatentVO();
+
+                if ((starPatentVO.getPublicNo() != null && starPatentVO.getPublicNo().contains("CN")) || (starPatentVO.getPublicNo() == null && starPatentVO.getPublicNo().contains("CN"))) {
+                   patentStarApiService =applicationContext.getBean(PatentStarApiService.class);
                     String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(starPatentVO.getRowApplicationNo());
                        this.loadClaim(uploadPatentWebDTO,cnFullXmlStr);
                        this.loadFullText(uploadPatentWebDTO,cnFullXmlStr);
                 }
+                //加入es保存队列
+                importFromWebToEsService.savePatentToEs(uploadPatentWebDTO);
             }
 
         } catch (Exception e) {
@@ -65,6 +69,7 @@ public class GetRightAndFullTextFromWebThread extends Thread {
         this.importTaskAMVO = taskThread.getImportTaskAMVO();
         this.importFromWebToEsService = importFromWebToEsService;
         this.applicationContext = taskThread.getApplicationContext();
+
     }
 
     public void awakeTask(UploadPatentWebDTO uploadPatentWebDTO) {
@@ -94,7 +99,9 @@ public class GetRightAndFullTextFromWebThread extends Thread {
                 List<String> reClaims = new ArrayList<>();
                 element.forEach(item -> {
                     String claim = item.getText();
+                    claim =   claim.replaceAll("\r\n|\r|\n| ", "");
                     reClaims.add(claim);
+
                 });
                 String reClaim = "";
                 if (reClaims.size() != 0) {
@@ -141,11 +148,14 @@ public class GetRightAndFullTextFromWebThread extends Thread {
                         && !fullText.trim().equals("发明内容")
                         && !fullText.trim().equals("附图说明")
                         && !fullText.trim().equals("具体实施方式")
-                        &&!fullText.trim().equals("背景技术"))
+                        &&!fullText.trim().equals("背景技术")
+                        &&!fullText.trim().equals("实用新型内容"))
+
                 {String formattedNum = String.format("%04d", count);
                     fullText ="["+formattedNum+"]"+fullText;
                     count++;
                 }
+                fullText =  fullText.replaceAll("\r\n|\r|\n| ", "");
                 fullTexts.add(fullText);
             }
             String fullText = "";

+ 140 - 76
src/main/java/cn/cslg/pas/service/importPatent/ImportFromWebToEsService.java

@@ -3,21 +3,28 @@ package cn.cslg.pas.service.importPatent;
 import cn.cslg.pas.common.dto.PatentStarListDTO;
 import cn.cslg.pas.common.dto.UploadPatentWebDTO;
 import cn.cslg.pas.common.model.cronModel.Calculate;
-import cn.cslg.pas.common.utils.DateUtils;
-import cn.cslg.pas.common.utils.MathUtils;
-import cn.cslg.pas.common.utils.ThrowException;
+import cn.cslg.pas.common.model.cronModel.SystemFile;
+import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.vo.ImportTaskAMVO;
 import cn.cslg.pas.common.vo.StarPatentVO;
 import cn.cslg.pas.common.vo.UploadParamsVO;
 import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.factorys.PatentImportFactory.PatentImportImp;
+import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
-import org.apache.commons.lang3.StringUtils;
+import com.alibaba.fastjson.JSONArray;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -35,14 +42,20 @@ public class ImportFromWebToEsService implements PatentImportImp {
 
     private GetCataloguingFromWebThread getCataloguingFromWebThread;
 
-    private GetPDFfromWebThread getPDFfromWebThread;
-    private GetPictureFromWebThread getPictureFromWebThread;
+    private GetPatentPDFFromWebThread getPatentPDFFromWebThread;
+    private GetPatentPictureFromWebThread getPatentPictureFromWebThread;
     private GetRightAndFullTextFromWebThread getRightAndFullTextFromWebThread;
-
+    private ApplicationContext applicationContext;
     @Override
     public void startPatentThread() {
+        //装载专利信息的计数器
+        Integer addPatentCounter = 0;
         //十进制转二进制
-        String imContents = MathUtils.fun(2, importTaskAMVO.getImportContent());
+        String imContents="0000";
+        if(!importTaskAMVO.getImportContent().equals(0)){
+            imContents = MathUtils.fun(2, importTaskAMVO.getImportContent());
+        }
+
         //下载字段
         char[] importCells = imContents.toCharArray();
         char ifCataloguing = importCells[0];
@@ -54,102 +67,153 @@ public class ImportFromWebToEsService implements PatentImportImp {
         importTaskAMVO.setIfAddPicture(ifAddPicture);
         importTaskAMVO.setIfAddFullText(ifFullText);
         importTaskAMVO.setIfAddPDF(ifPdf);
+        importTaskAMVO.setShouldSaveCounter(0);
+        importTaskAMVO.setHaveSaveCounter(0);
         int patentNum = 10000;
         savePatentToEsThread = new SavePatentToEsThread(taskThread, taskThread.getApplicationContext());
+        savePatentToEsThread.start();
         if (ifAddPicture == '1') {
-            getPictureFromWebThread = new GetPictureFromWebThread(taskThread, this);
-            getPictureFromWebThread.start();
+            getPatentPictureFromWebThread = new GetPatentPictureFromWebThread(taskThread, this);
+            getPatentPictureFromWebThread.start();
+            importTaskAMVO.setShouldSaveCounter(importTaskAMVO.getShouldSaveCounter() + 1);
         }
         if (ifFullText == '1') {
             getRightAndFullTextFromWebThread = new GetRightAndFullTextFromWebThread(taskThread, this);
             getRightAndFullTextFromWebThread.start();
+            addPatentCounter += 1;
         }
         if (ifPdf == '1') {
-            getPDFfromWebThread = new GetPDFfromWebThread(taskThread, this);
-            getPDFfromWebThread.start();
+            getPatentPDFFromWebThread = new GetPatentPDFFromWebThread(taskThread, this);
+            getPatentPDFFromWebThread.start();
+            importTaskAMVO.setShouldSaveCounter(importTaskAMVO.getShouldSaveCounter() + 1);
         }
-        if (importTaskAMVO.getEndNum() <= patentNum) {
-            if (ifCataloguing == '1') {
-                getCataloguingFromWebThread = new GetCataloguingFromWebThread(taskThread, this);
-                getCataloguingFromWebThread.start();
-            }
-            excuteLessThan10000(importTaskAMVO);
-        } else {
+
+        if (ifCataloguing == '1') {
+            getCataloguingFromWebThread = new GetCataloguingFromWebThread(taskThread, this);
+            getCataloguingFromWebThread.start();
+            addPatentCounter += 1;
         }
 
-        savePatentToEsThread.start();
+        if (ifCataloguing == '1' || ifFullText == '1') {
+            importTaskAMVO.setShouldSaveCounter(importTaskAMVO.getShouldSaveCounter() + 1);
+        }
+        excuteLessThan10000(importTaskAMVO,addPatentCounter);
+
+
     }
 
 
-    private void excuteLessThan10000(ImportTaskAMVO importTaskAMVO) {
+    private void excuteLessThan10000(ImportTaskAMVO importTaskAMVO,Integer addPatentCounter) {
         try {
-            Integer successNum = importTaskAMVO.getSuccessNum();  //成功条数(即上一次下载到的位置)
-            String conditions = importTaskAMVO.getSearchCondition();  //检索式
             String orderBy = importTaskAMVO.getOrderBy();  //排序字段
             String orderByType = importTaskAMVO.getOrderByType();  //排序类型
             String dbType = importTaskAMVO.getDbType();  //检索数据库类型
-            Integer importContent = importTaskAMVO.getImportContent();  //下载字段
-            Integer doneNum = 0;
+            Integer doneNum = importTaskAMVO.getDoneNum();
+            int patentNum = 10000;
+
+            //检索式
+            String conditions = importTaskAMVO.getSearchCondition();
+
+            //获得返回的的多个检索式 patentStarListDtos
+            List<PatentStarListDTO> patentStarListDtos = patentStarApiService.getSplitedConditions(new PatentStarListDTO()
+                    .setCurrentQuery(conditions)
+                    .setOrderBy(orderBy)
+                    .setOrderByType(orderByType)
+                    .setDBType(dbType), patentNum);
+
+            //当专利为专利号导入时
+            if (importTaskAMVO.getType().equals(2)) {
+                conditions = conditions.replaceAll(" +", "");  //去掉所有空格
+                List<String> patentNos = Arrays.asList(conditions.split("[,|,]"));  //生成专利号集合
+                String join = StringUtils.join(patentNos, " OR ");
+                conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
+                importTaskAMVO.setDbType("CN");
+            }
+
+            //当专利为专利号文件导入时
+            if (importTaskAMVO.getType().equals(3)) {
+                FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
+
+                String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskAMVO.getFileGuid()));
+                List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
+                SystemFile systemFile = systemFiles.get(0);
+                String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
+                //调用文件系统取出文件接口,获得文件流
+                byte[] bytes = fileManagerService.downloadSystemFileFromFMS(importTaskAMVO.getFileGuid());
+                //创建临时文件tempFile,并将文件读取到tempFile
+                File tempFile = File.createTempFile(systemFile.getFileName() + "temp", suffix);
+                try (
+                        InputStream inputStream = new ByteArrayInputStream(bytes);
+                        FileOutputStream outputStream = new FileOutputStream(tempFile)
+                ) {
+                    IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
+                }
+                Sheet sheet = ReadExcelUtils.readExcel(tempFile);
+                List<String> patentNos = ReadExcelUtils.getPatentNoFromExcel(sheet);
+                String join = StringUtils.join(patentNos, " OR ");
+                conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
+            }
+
             char ifCataloguing = importTaskAMVO.getIfAddCatalogue();
             char ifAddPicture = importTaskAMVO.getIfAddPicture();
             char ifAddFullText = importTaskAMVO.getIfAddFullText();
             char ifPdf = importTaskAMVO.getIfAddPDF();
-            //十进制转二进制
-            String imContents = MathUtils.fun(2, importContent);
             //下载字段
-            char[] importCells = imContents.toCharArray();
-            Calculate calculate = DateUtils.calculateFromStartAndEndNumber(doneNum, importTaskAMVO.getAllNum(), 50);
-            Integer startPage = calculate.getStartPage();
-            Integer startNum = calculate.getStartNum();
-            Integer endPage = calculate.getEndPage();
-
-            //根据计算出的起止页数,一页一页检索
-            for (int i = startPage; i <= endPage; i++) {
-                PatentStarListDTO patentStarListDto = new PatentStarListDTO()
-                        .setCurrentQuery(conditions)
-                        .setOrderBy(orderBy)
-                        .setOrderByType(orderByType)
-                        .setPageNum(i + 1)
-                        .setRowCount(50)
-                        .setDBType(dbType);
-                //调用一般接口返回一批专利著录相关数据
-                Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
-                if (resultMap == null || (Integer) resultMap.get("total") == 0) {
-                    ThrowException.throwXiaoShiException("未检索到相关专利");
-                }
-
-                List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
-                //遍历这一页的专利
-                for (int j = 0; j < starPatents.size(); j++) {
-                    UploadPatentWebDTO uploadPatentWebDTO = new UploadPatentWebDTO();
-                    Patent patent = new Patent();
 
-                    //装载start
-                    uploadPatentWebDTO.setStarPatentVO(starPatents.get(i));
-                    uploadPatentWebDTO.setPatent(patent);
-                    uploadPatentWebDTO.setCounter(0);
 
-                    if (ifCataloguing == '1') {
-                        getCataloguingFromWebThread.awakeTask(uploadPatentWebDTO);
-                        uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
-                    }
-                    if (ifAddPicture == '1') {
-                        getPictureFromWebThread.awakeTask(uploadPatentWebDTO);
-                        uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
-                    }
-                    if (ifAddFullText == '1') {
-                        getRightAndFullTextFromWebThread.awakeTask(uploadPatentWebDTO);
-                        uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
+            //已经跳过的数量
+            Integer overNum =0;
+            while (patentStarListDtos.size() > 0) {
+                PatentStarListDTO  patentStarListDto =  patentStarListDtos.remove(0);
+                Integer total=patentStarListDto.getTotal();
+                overNum+=total;
+                if(total<=doneNum){
+                    continue;
+                }
+                Integer startNum =overNum-doneNum;
+                Calculate calculate = DateUtils.calculateFromStartAndEndNumber(startNum, total, 50);
+                Integer startPage = calculate.getStartPage();
+                Integer endPage = calculate.getEndPage();
+                for (int i = startPage; i <= endPage; i++) {
+                    //调用一般接口返回一批专利著录相关数据
+                    Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
+                    if (resultMap == null || (Integer) resultMap.get("total") == 0) {
+                        ThrowException.throwXiaoShiException("未检索到相关专利");
                     }
-                    if(ifPdf=='1'){
-                        getPDFfromWebThread.awakeTask(uploadPatentWebDTO);
-                        uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
+
+                    List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
+                    //遍历这一页的专利
+                    for (int j = 0; j < starPatents.size(); j++) {
+                        if((i*50+j)<startNum){
+                            continue;
+                        }
+                        UploadPatentWebDTO uploadPatentWebDTO = new UploadPatentWebDTO();
+                        Patent patent = new Patent();
+
+                        //装载start
+                        uploadPatentWebDTO.setStarPatentVO(starPatents.get(i));
+                        uploadPatentWebDTO.setPatent(patent);
+                        uploadPatentWebDTO.setCounter(0);
+                        uploadPatentWebDTO.setTotalCounter(addPatentCounter);
+                        uploadPatentWebDTO.setHaveSaveCounter(0);
+                        if (ifCataloguing == '1') {
+                            getCataloguingFromWebThread.awakeTask(uploadPatentWebDTO);
+                        }
+                        if (ifAddPicture == '1') {
+                            getPatentPictureFromWebThread.awakeTask(uploadPatentWebDTO);
+                        }
+                        if (ifAddFullText == '1') {
+                            getRightAndFullTextFromWebThread.awakeTask(uploadPatentWebDTO);
+                        }
+                        if (ifPdf == '1') {
+                            getPatentPDFFromWebThread.awakeTask(uploadPatentWebDTO);
+                        }
                     }
+
                 }
 
             }
-
-        } catch (Exception e) {
+        }catch (Exception e) {
             e.printStackTrace();
             //生产消费到一半时,发生错误异常,将任务状态置为完成
 //            task = taskService.getById(task.getId());
@@ -161,16 +225,16 @@ public class ImportFromWebToEsService implements PatentImportImp {
     @Override
     public void setTaskThread(TaskThread taskThread) {
         this.taskThread = taskThread;
-        ApplicationContext applicationContext = taskThread.getApplicationContext();
+        this.applicationContext = taskThread.getApplicationContext();
         this.patentStarApiService = applicationContext.getBean(PatentStarApiService.class);
         this.importTaskAMVO = taskThread.getImportTaskAMVO();
     }
 
+    //加入es保存队列
     public void savePatentToEs(UploadPatentWebDTO uploadPatentWebDTO) {
+
         uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter() + 1);
         if (uploadPatentWebDTO.getTotalCounter().equals(uploadPatentWebDTO.getCounter())) {
-          uploadPatentWebDTO.setIfAddPatent(false);
-            uploadPatentWebDTO.setIfAddPicture(false);
             savePatentToEsThread.awakeTask(uploadPatentWebDTO);
         }
     }

+ 11 - 14
src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java

@@ -36,7 +36,6 @@ public class SavePatentToEsThread extends Thread {
     public void run() {
         while ((!ifProductAll || uploadPatentWebDTOS.size() > 0)&&importTaskAMVO.getState().equals(1)) {
             try {
-
                 //判断任务队列是否有任务,若没有则线程等待唤醒
                 if (uploadPatentWebDTOS.size() == 0) {
                     taskLock.lock();
@@ -59,7 +58,6 @@ public class SavePatentToEsThread extends Thread {
                     patentJoin.setName("patent");
                     patent.setPatentJoin(patentJoin);
                     patentId =  esService.addPatent(patent);
-
                 }
                 //判断是否和专题库或报告关联
                 ImportTaskAMVO importTaskAMVO = taskThread.getImportTaskAMVO();
@@ -68,27 +66,26 @@ public class SavePatentToEsThread extends Thread {
                 if (importTaskAMVO.getProjectId() != null) {
                     //根据projectId和专利id查询
                     if(patentId!=null){
-                        Patent patentChild =new Patent();
-                        PatentJoin patentJoin =new PatentJoin();
-                        patentJoin.setParent(patentId);
-                        patentJoin.setName("project");
-                        patentChild.setPatentJoin(patentJoin);
-                        patentChild.setProjectId(importTaskAMVO.getProjectId());
-                     esService.addChildPatent(patentChild ,patentId);
-
+                     Boolean ifInproject=  esService.searchIfInProject(patentId,importTaskAMVO.getProjectId());
+                     if(!ifInproject) {
+                         Patent patentChild = new Patent();
+                         PatentJoin patentJoin = new PatentJoin();
+                         patentJoin.setParent(patentId);
+                         patentJoin.setName("project");
+                         patentChild.setPatentJoin(patentJoin);
+                         patentChild.setProjectId(importTaskAMVO.getProjectId());
+                         esService.addChildPatent(patentChild, patentId);
+                     }
                     }
-
                 }
                 //导入完成,通知前台
                 MessageService messageService = applicationContext.getBean(MessageService.class);
-                importTaskAMVO.setDoneNum(importTaskAMVO.getDoneNum()+1);
                 messageService.sendWebsocketMessage(importTaskAMVO);
-                uploadPatentWebDTO.setIfAddPatent(true);
+                importTaskAMVO.setMessageDoneNum(importTaskAMVO.getMessageDoneNum()+1);
                 taskThread.ifPatentDone(uploadPatentWebDTO);
             } catch (Exception e) {
                 System.out.println(e);
             }
-
         }
         importTaskAMVO.setIfAddPatentDone(true);
         taskThread.awakeTaskThread();

+ 23 - 14
src/main/java/cn/cslg/pas/service/importPatent/SchedulingTaskService.java

@@ -32,7 +32,8 @@ public class SchedulingTaskService {
     @Autowired
     private ImportTaskConditionService importTaskConditionService;
 
-    private    List<ImportTaskAMVO> importTaskAMVOS;
+    private List<ImportTaskAMVO> importTaskAMVOS;
+
     public void startTask() {
         Integer freeCount = Constants.MAX_IMPORT_TASK_COUNT - executor.getActiveCount();
 
@@ -40,18 +41,26 @@ public class SchedulingTaskService {
         if (freeCount > 0) {
             //查找任务
             LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.in(ImportTask::getState, new ArrayList<>(Arrays.asList(0, 1)))
+            queryWrapper.in(ImportTask::getState, new ArrayList<>(Arrays.asList(0)))
                     .orderByDesc(ImportTask::getState);
             List<ImportTask> importTaskList = importTaskService.list(queryWrapper);
+            if (importTaskList.size() > freeCount) {
+                importTaskList = importTaskList.subList(0, freeCount - 1);
+            }
+
             if (importTaskList.size() > 0) {
                 // 装载任务信息
-              importTaskAMVOS = this.loadTaskAMVOS(importTaskList);
+                importTaskAMVOS = this.loadTaskAMVOS(importTaskList);
 
-                importTaskAMVOS.forEach(item -> {
-                    item.setState(1);
-                    TaskThread taskThread = new TaskThread(item,applicationContext);
+                for (int i = 0; i < importTaskAMVOS.size(); i++) {
+                    importTaskList.get(i).setState(1);
+                    importTaskList.get(i).updateById();
+                    importTaskAMVOS.get(i).setState(1);
+                    TaskThread taskThread = new TaskThread(importTaskAMVOS.get(i), applicationContext);
                     executor.execute(taskThread);
-                });
+                }
+
+
             }
 
         }
@@ -62,7 +71,7 @@ public class SchedulingTaskService {
         List<ImportTaskAMVO> importTaskAMVOS = new ArrayList<>();
         List<Integer> taskConditionIds = new ArrayList<>();
         List<ImportTaskCondition> importTaskConditions = new ArrayList<>();
-        taskConditionIds =importTaskList.stream().map(ImportTask::getImportTaskConditionId).collect(Collectors.toList());
+        taskConditionIds = importTaskList.stream().map(ImportTask::getImportTaskConditionId).collect(Collectors.toList());
         //根据taskid查询taskCondition
         if (taskConditionIds.size() != 0) {
             LambdaQueryWrapper<ImportTaskCondition> queryWrapper = new LambdaQueryWrapper<>();
@@ -74,7 +83,7 @@ public class SchedulingTaskService {
             ImportTaskCondition importTaskCondition = importTaskConditions.stream().filter(item -> item.getId().equals(importTask.getImportTaskConditionId())).findFirst().orElse(null);
             ImportTaskAMVO importTaskAMVO = new ImportTaskAMVO();
             BeanUtils.copyProperties(importTask, importTaskAMVO);
-            if(importTaskCondition!=null) {
+            if (importTaskCondition != null) {
                 importTaskAMVO.setFileGuid(importTaskCondition.getFileGuid());
                 importTaskAMVO.setSourceId(importTaskCondition.getSourceId());
                 importTaskAMVO.setProjectId(importTaskCondition.getProjectId());
@@ -84,7 +93,7 @@ public class SchedulingTaskService {
                 importTaskAMVO.setOrderBy(importTaskCondition.getOrderBy());
                 importTaskAMVO.setOrderByType(importTaskCondition.getOrderByType());
             }
-            ProgressVO progressVO =new ProgressVO();
+            ProgressVO progressVO = new ProgressVO();
             progressVO.setState(0);
             importTaskAMVO.setProgressVO(progressVO);
             importTaskAMVOS.add(importTaskAMVO);
@@ -95,9 +104,9 @@ public class SchedulingTaskService {
 
     }
 
-    public void pauseTask(Integer taskId){
-//根据id获得
-        ImportTaskAMVO  importTaskAMVO  =  importTaskAMVOS.stream().filter(item->item.getId().equals(taskId)).findFirst().orElse(null);
-        importTaskAMVO.getProgressVO().setState(1);
+    public void pauseTask(Integer taskId,Integer state) {
+        //根据id获得
+        ImportTaskAMVO importTaskAMVO = importTaskAMVOS.stream().filter(item -> item.getId().equals(taskId)).findFirst().orElse(null);
+        importTaskAMVO.setState(state);
     }
 }

+ 20 - 17
src/main/java/cn/cslg/pas/service/importPatent/TaskThread.java

@@ -58,39 +58,42 @@ public class TaskThread extends Thread {
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
+
         ImportTaskService importTaskService = applicationContext.getBean(ImportTaskService.class);
         ImportTask task = importTaskService.getById(importTaskAMVO.getId());
-        task.setState(2);
-        task.setEndNum(task.getAllNum());
+        if (importTaskAMVO.getState().equals(1)) {
+            task.setState(2);
+
+        } else {
+            task.setState(importTaskAMVO.getState());
+        }
+        task.setDoneNum(importTaskAMVO.getDoneNum());
         task.updateById();
         System.out.println("任务结束");
     }
 
 
     public void awakeTaskThread() {
-        if (importTaskAMVO.getType() == 1) {
-            if (importTaskAMVO.getIfAddPictureDone() != null && importTaskAMVO.getIfAddPatentDone() != null
-                    && importTaskAMVO.getIfAddPictureDone() && importTaskAMVO.getIfAddPatentDone()) {
-                if (taskThreadLock.tryLock()) {
-                    //taskLock.lock();
-                    taskThreadCondition.signalAll();
-                    taskThreadLock.unlock();
-                }
+        importTaskAMVO.setHaveSaveCounter(importTaskAMVO.getHaveSaveCounter() + 1);
+        if (importTaskAMVO.getShouldSaveCounter().equals(importTaskAMVO.getShouldSaveCounter())) {
+            if (taskThreadLock.tryLock()) {
+                //taskLock.lock();
+                taskThreadCondition.signalAll();
+                taskThreadLock.unlock();
             }
-
         }
-
     }
 
-    public void ifPatentDone(UploadPatentWebDTO uploadPatentWebDTO) {
-        if (importTaskAMVO.getType() == 1) {
-            if (uploadPatentWebDTO.getIfAddPicture() && uploadPatentWebDTO.getIfAddPicture()) {
-                importTaskAMVO.setDoneNum(importTaskAMVO.getDoneNum() + 1);
-            }
 
+    public void ifPatentDone(UploadPatentWebDTO uploadPatentWebDTO) {
+        uploadPatentWebDTO.setHaveSaveCounter(uploadPatentWebDTO.getHaveSaveCounter() + 1);
+        if (importTaskAMVO.getShouldSaveCounter().equals(uploadPatentWebDTO.getHaveSaveCounter())) {
+            importTaskAMVO.setDoneNum(importTaskAMVO.getDoneNum() + 1);
         }
+
     }
 
+
     public ImportTaskAMVO getImportTaskAMVO() {
         return this.importTaskAMVO;
     }

+ 0 - 1
src/main/java/cn/cslg/pas/service/query/FormatQueryService.java

@@ -428,7 +428,6 @@ public class FormatQueryService {
                 query = iQueryBuilder.creteQuery();
             }
         }
-
         return query;
     }
 }

+ 39 - 0
src/main/resources/jsons/importTask.json

@@ -84,6 +84,45 @@
     "ifAsCondition": "false"
   },
   {
+    "name": "总数",
+    "type": "Integer",
+    "value": "allNum",
+    "field": "allNum",
+    "sqlField": "it.all_num",
+    "sqlClass": "it.all_num",
+    "orderClass": "getComOrder",
+    "groupClass": "getTimeGroup",
+    "ifSearch": "true",
+    "ifGroup": "false",
+    "ifShow": "true"
+  },
+  {
+    "name": "完成条数",
+    "type": "Integer",
+    "value": "doneNum",
+    "field": "doneNum",
+    "sqlField": "it.done_num",
+    "sqlClass": "it.done_num",
+    "orderClass": "getComOrder",
+    "groupClass": "getTimeGroup",
+    "ifSearch": "true",
+    "ifGroup": "false",
+    "ifShow": "true"
+  },
+  {
+    "name": "进度",
+    "type": "Double",
+    "value": "percentage",
+    "field": "percentage",
+    "sqlField": "it.done_num",
+    "sqlClass": "it.done_num",
+    "orderClass": "getComOrder",
+    "groupClass": "getTimeGroup",
+    "ifSearch": "true",
+    "ifGroup": "false",
+    "ifShow": "true"
+  },
+  {
     "name": "创建人",
     "type": "String",
     "value": "createName",

+ 1 - 1
src/main/resources/mapper/ImportTaskMapper.xml

@@ -4,7 +4,7 @@
     <select id="getImportTask" resultType="cn.cslg.pas.common.vo.business.ImportTaskVO">
         select it.name as name, it.id,it.search_condition as searchCondition,it.all_num as allNum,it.success_num as successNum,
                it.default_num as defaultNum,it.type as type,it.create_id as
-        createId,it.create_time as createTime ,it.state as  state from import_task it left join import_task_condition itc on
+        createId,it.create_time as createTime ,it.state as  state,it.done_num as doneNum from import_task it left join import_task_condition itc on
         it.import_task_condition_id=itc.id
         <if test="sql1!=''">
 

+ 0 - 2
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -134,7 +134,5 @@ public class EventServiceTests {
 
     @Test
     void test12(){
-        Boolean bool = esService.search("YST6D4wBmB3pRkTj49Jn", 5);
-        System.out.println(bool);
     }
 }

+ 23 - 9
src/test/java/cn/cslg/pas/service/PatentStarServiceTests.java

@@ -69,7 +69,7 @@ public class PatentStarServiceTests {
 
     @Test
     void updatePatent() throws Exception {
-        String a = patentStarApiService.getCnFullXmlApi("201410391729");
+        String a = patentStarApiService.getCnFullXmlApi("CN2006200179281");
         SAXReader reader = new SAXReader();
         reader.setEntityResolver(new IgnoreDTDEntityResolver());
         Reader stringReader = new StringReader(a);
@@ -83,6 +83,8 @@ public class PatentStarServiceTests {
         List<String> reStrs = new ArrayList<>();
         element.forEach(item -> {
             String claim = item.getText();
+            claim = claim.replaceAll("\r\n|\r|\n| ", "");
+            claim = claim.replaceAll(" ", "");
             reStrs.add(claim);
         });
         String reStr = "";
@@ -90,8 +92,6 @@ public class PatentStarServiceTests {
             reStr = StringUtils.join(reStrs, "\r\n");
         }
 
-
-        System.out.println(reStr);
         Element root = document.getRootElement();
         //获取根元素的名称
         String rootName = root.getName();
@@ -112,19 +112,19 @@ public class PatentStarServiceTests {
             elements = (List<Element>) xpath.selectNodes(document);
         }
         List<String> reStrs = new ArrayList<>();
-        Integer count=1;
-        for (Element item:elements){
+        Integer count = 1;
+        for (Element item : elements) {
             String claim = item.getText().replaceAll("<br/>", "");
             if (!claim.trim().equals("技术领域")
                     && !claim.trim().equals("发明内容")
                     && !claim.trim().equals("附图说明")
                     && !claim.trim().equals("具体实施方式")
-                     &&!claim.trim().equals("背景技术"))
-            {String formattedNum = String.format("%04d", count);
-                claim ="["+formattedNum+"]"+claim;
+                    && !claim.trim().equals("背景技术")) {
+                String formattedNum = String.format("%04d", count);
+                claim = "[" + formattedNum + "]" + claim;
                 count++;
             }
-                reStrs.add(claim);
+            reStrs.add(claim);
         }
         String reStr = "";
         if (reStrs.size() != 0) {
@@ -145,4 +145,18 @@ public class PatentStarServiceTests {
         System.out.println(patentList);
         Thread.sleep(1000000);
     }
+
+    @Test
+    void getLegalEvent() throws Exception {
+        String a = patentStarApiService.getCnLegalApi("201210398357");
+        System.out.println(a);
+        Thread.sleep(1000000);
+    }
+
+    @Test
+    void getFamilyPatent() throws Exception {
+        String a = patentStarApiService.getCnLegalApi("201210398357");
+        System.out.println(a);
+        Thread.sleep(1000000);
+    }
 }