chendayu %!s(int64=2) %!d(string=hai) anos
pai
achega
b1ded7d608

+ 3 - 3
src/main/java/com/example/demo/domain/entity/QrtzTaskDetail.java

@@ -18,7 +18,7 @@ import java.util.Date;
 @TableName(value = "qrtz_task_detail")
 @Accessors(chain = true)
 @Data
-public class QrtzTaskDetail extends BaseEntity<QrtzTaskDetail>{
+public class QrtzTaskDetail extends BaseEntity<QrtzTaskDetail> {
     /**
      * 所属任务条件id
      */
@@ -70,14 +70,14 @@ public class QrtzTaskDetail extends BaseEntity<QrtzTaskDetail>{
     private Date endTime;
 
     /**
-     * 结束时间
+     * 创建时间
      */
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @TableField(value = "create_time")
     private Date createTime;
     /**
-     * 任务顺序
+     * 失败原因
      */
     @TableField(value = "failure")
     private String failure;

+ 76 - 61
src/main/java/com/example/demo/service/UploadFromWebService.java

@@ -1,6 +1,5 @@
 package com.example.demo.service;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.example.demo.domain.dto.*;
 import com.example.demo.domain.entity.*;
@@ -73,7 +72,7 @@ public class UploadFromWebService {
             //根据id 获得网站配置
             WebConfig webConfig = webConfigService.getConfigById(id);
             //根据网站id和用户的租户获得登录信息
-            WebLoginConfig webLoginConfig = webLoginConfigService.getLoginConfig(webConfig.getId(),qrtzTask.getTenantId());
+            WebLoginConfig webLoginConfig = webLoginConfigService.getLoginConfig(webConfig.getId(), qrtzTask.getTenantId());
             if (webLoginConfig == null) {
                 qrtzTaskDetail.setTaskDetailState(3);
                 qrtzTaskDetail.setSuccessNum(successNum);
@@ -529,7 +528,7 @@ public class UploadFromWebService {
         //根据id 获得网站配置
         WebConfig webConfig = webConfigService.getConfigById(webId);
         //根据网站id和用户的租户获得登录信息
-        WebLoginConfig webLoginConfig = webLoginConfigService.getLoginConfig(webConfig.getId(),qrtzTask.getTenantId());
+        WebLoginConfig webLoginConfig = webLoginConfigService.getLoginConfig(webConfig.getId(), qrtzTask.getTenantId());
         if (webLoginConfig == null) {
             qrtzTaskDetail.setTaskDetailState(3);
             qrtzTaskDetail.setSuccessNum(successNum);
@@ -612,25 +611,11 @@ public class UploadFromWebService {
                 }
                 //装载权要
                 if (cells.contains("2")) {
-                    try {
-                        setPatentClaim(patentCell, pubNO);
-                    } catch (XiaoShiException e) {
-                        //权要接口不支持检索该国家类型专利则跳过该专利,继续下一个专利
-                        //continue;
-                        //虽然拿不到权要,但是可以拿其他的,能拿到啥都返回
-                        log.info(e.getMessage());
-                    }
+                    setPatentClaim(patentCell, pubNO);
                 }
                 //装载说明书文本
                 if (cells.contains("3")) {
-                    try {
-                        setPatentInstructionText(patentCell, pubNO);
-                    } catch (XiaoShiException e) {
-                        //说明书接口不支持检索该国家类型专利则跳过该专利,继续下一个专利
-                        //continue;
-                        //虽然拿不到说明书,但是可以拿其他的,能拿到啥都返回
-                        log.info(e.getMessage());
-                    }
+                    setPatentInstructionText(patentCell, pubNO);
                 }
 
                 //以下代码是在准备一会要调用拿取各种附图的接口所需的参数(FullDocument->说明书pdf、Drawing->其他附图、FirstPageClipping->摘要附图)
@@ -718,8 +703,9 @@ public class UploadFromWebService {
                             .setUrl("")
                             .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "null");
                 } catch (XiaoShiException e) {
-                    //虽然拿不到所有附图,但是可以拿其他的,能拿到啥是啥
                     log.info(e.getMessage());
+                } catch (Exception e) {
+                    //虽然拿不到所有附图,但是可以拿其他的,能拿到啥是啥
                     qrtzTaskDetail.setTaskDetailState(3);
                     qrtzTaskDetail.setSuccessNum(successNum);
                     qrtzTaskDetail.setDefaultNum(qrtzTaskDetail.getAllNum() - successNum);
@@ -776,40 +762,6 @@ public class UploadFromWebService {
     }
 
     /**
-     * 装载其他附件方法
-     *
-     * @param link       附件链接
-     * @param page       附件页数
-     * @param type       附件类型
-     * @param patentCell 实体类对象
-     */
-//    private void setOtherImage(String link, Integer page, String type, PatentCell patentCell) throws IOException {
-//        GetFuTuParamsDTO getFuTuParamsDTO = new GetFuTuParamsDTO()
-//                .setLink(link)
-//                .setPage(page)
-//                .setType(type);
-//        outInterfaceService.getPatentFile(getFuTuParamsDTO);
-//
-//    }
-
-    /**
-     * 装载摘要附图方法
-     *
-     * @param link       附件链接
-     * @param page       附件页数
-     * @param type       附件类型
-     * @param patentCell 实体类对象
-     */
-//    private void setAbstractImage(String link, Integer page, String type, PatentCell patentCell) throws IOException {
-//        GetFuTuParamsDTO getFuTuParamsDTO = new GetFuTuParamsDTO()
-//                .setLink(link)
-//                .setPage(page)
-//                .setType(type);
-//        outInterfaceService.getPatentFile(getFuTuParamsDTO);
-//
-//    }
-
-    /**
      * 装载说明书附件pdf方法
      *
      * @param link       附件链接
@@ -865,15 +817,71 @@ public class UploadFromWebService {
 //                    otherUrls.add(fileDTO.getPath());
 //                    break;
 //            }
+            //如果不是说明书pdf
+            if (!FuJianSuffix.equals(".pdf")) {
+                File file = File.createTempFile("new_url", FuJianSuffix);
+                FileOutputStream out = new FileOutputStream(file);
+                out.write(buffer);
+                out.close();
+                streams[i - 1] = new FileInputStream(file);
+                DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
+                FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
+                int bytesRead = 0;
+                buffer = new byte[8192];
+                try {
+                    FileInputStream fis = new FileInputStream(file);
+                    OutputStream os = item.getOutputStream();
+                    int len = 8192;
+                    while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
+                        os.write(buffer, 0, bytesRead);
+                    }
+                    os.close();
+                    fis.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+                MultipartFile multipartFile = new CommonsMultipartFile(item);
+                UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
+                //如果是摘要附图
+                if (FuJianSuffix.equals(".jpeg")) {
+                    patentCell.setPicUrl(fileDTO.getPath());
+                }
+                //如果是其他附图
+                if (FuJianSuffix.equals(".tiff")) {
+                    otherUrls.add(fileDTO.getPath());
+                }
+            }
         }
 
+        //如果是说明书pdf
         if (FuJianSuffix.equals(".pdf")) {
-            //合并 说明书多个pdf文件
+            //合并说明书多个pdf文件
             PdfDocumentBase doc = PdfDocument.mergeFiles(streams);
             //保存结果文件
             doc.save("merge.pdf", FileFormat.PDF);
-
             doc.close();
+
+            //手动将合并后的pdf文件转成MultipartFile,上传文件并获取path装载到patentCell
+            File file = new File("merge.pdf");
+            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
+            FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
+            int bytesRead = 0;
+            byte[] buffer = new byte[8192];
+            try {
+                FileInputStream fis = new FileInputStream(file);
+                OutputStream os = item.getOutputStream();
+                int len = 8192;
+                while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
+                    os.write(buffer, 0, bytesRead);
+                }
+                os.close();
+                fis.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            MultipartFile multipartFile = new CommonsMultipartFile(item);
+            UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
+            patentCell.setPdf(fileDTO);
         } else if (FuJianSuffix.equals(".tiff")) {
             patentCell.setOtherUrls(otherUrls);
         }
@@ -915,7 +923,9 @@ public class UploadFromWebService {
         JSONObject jsonObject = JSONObject.parseObject(res);
         if (!jsonObject.get("status").toString().equals("200")) {
             //若发生类似400、500等异常(杰哥处理)
-            ThrowException.throwXiaoShiException("说明书接口无法检索该国家专利");
+            //ThrowException.throwXiaoShiException("说明书接口无法检索该国家专利");
+            log.info("说明书接口无法检索该国家专利");
+            return;
         }
         //拿到检索结果(未格式化的含有页面等标签的说明书)
         //String unformatInstructionText = JSONObject.parseObject(jsonObject.get("data").toString(), String.class);
@@ -947,7 +957,9 @@ public class UploadFromWebService {
         JSONObject jsonObject = JSONObject.parseObject(res);
         if (!jsonObject.get("status").toString().equals("200")) {
             //若发生类似400、500等异常(杰哥处理)
-            ThrowException.throwXiaoShiException("权要接口无法检索该国家专利");
+            //ThrowException.throwXiaoShiException("权要接口无法检索该国家专利");
+            log.info("权要接口无法检索该国家专利");
+            return;
         }
         //拿到检索结果(未格式化的含有页面等标签的权要)并格式化权要
         //String unformatRight = JSONObject.parseObject(jsonObject.get("data").toString(), String.class);
@@ -992,16 +1004,19 @@ public class UploadFromWebService {
         List<String> ipCs = patent.getIpCs();
         List<String> cpCs = patent.getCpCs();
         ipCs.addAll(cpCs);
-        if(ipCs!=null&&ipCs.size()>0) {
+        if (ipCs != null && ipCs.size() > 0) {
             patentCell.setMainIpc(ipCs.get(0));
         }
         //装载分类号
-        if(ipCs!=null&&ipCs.size()>0) {
+        if (ipCs != null && ipCs.size() > 0) {
             patentCell.setIpc(ipCs);
         }
         //装载申请人
         ArrayList<String> applicationPersons = new ArrayList<>();
         for (Application application : patent.getApplications()) {
+            if (application.getOriginalName().contains("(标:)")) {
+                application.setOriginalName(application.getOriginalName().substring(0, application.getOriginalName().indexOf("(标:)")));
+            }
             applicationPersons.add(application.getOriginalName());
         }
         patentCell.setApplicationPersons(applicationPersons);
@@ -1079,7 +1094,7 @@ public class UploadFromWebService {
      * @throws IOException
      * @throws InterruptedException
      */
-    public List<PatentCell> getPatentya(String patentVO) throws  InterruptedException {
+    public List<PatentCell> getPatentya(String patentVO) throws InterruptedException {
         //1.获得驱动
         System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
         // 2.页面最大化

+ 13 - 3
src/main/java/com/example/demo/service/WebUploadJob.java

@@ -3,12 +3,14 @@ package com.example.demo.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.example.demo.domain.entity.QrtzTask;
 import com.example.demo.domain.entity.QrtzTaskDetail;
+import com.example.demo.exception.XiaoShiException;
 import com.example.demo.model.dto.TaskWebSocketDTO;
 import com.example.demo.model.dto.WebQueryDTO;
 import com.example.demo.util.MathUtils;
 import com.example.demo.util.Response;
 import com.example.demo.util.ResponseEnum;
 import com.example.demo.util.WebSocketServer;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.quartz.DisallowConcurrentExecution;
@@ -25,7 +27,7 @@ import java.util.List;
 /**
  * 定义任务
  */
-
+@Slf4j
 @DisallowConcurrentExecution
 public class WebUploadJob extends QuartzJobBean {
 
@@ -79,11 +81,19 @@ public class WebUploadJob extends QuartzJobBean {
                 try {
                     //专利之星
                     if (webQueryDTO.getWebConfigId() == 1 || webQueryDTO.getWebConfigId() == 4) {
-                       uploadFromWebService.getPatentStar(webQueryDTO);
+                        uploadFromWebService.getPatentStar(webQueryDTO);
                         //欧专局
                     } else if (webQueryDTO.getWebConfigId() == 2) {
-                         uploadFromWebService.getEPO(webQueryDTO);
+                        uploadFromWebService.getEPO(webQueryDTO);
                     }
+                } catch (XiaoShiException e) {
+                    qrtzTaskDetail.setTaskDetailState(3);
+                    qrtzTaskDetail.setFailure(e.getMessage());
+                    qrtzTaskDetail.setEndTime(new Date());
+                    qrtzTaskDetail.updateById();
+                    qrtzTask.setTaskState(3);
+                    qrtzTask.updateById();
+                    e.printStackTrace();
                 } catch (Exception e) {
                     qrtzTaskDetail.setTaskDetailState(3);
                     qrtzTaskDetail.setFailure("拉取节点失败");