chendayu %!s(int64=2) %!d(string=hai) anos
pai
achega
a77a3fb2d4
Modificáronse 1 ficheiros con 85 adicións e 37 borrados
  1. 85 37
      src/main/java/com/example/demo/service/UploadFromWebService.java

+ 85 - 37
src/main/java/com/example/demo/service/UploadFromWebService.java

@@ -514,6 +514,13 @@ public class UploadFromWebService {
     public List<PatentCell> getEPO(WebQueryDTO webQueryDTO) throws Exception {
         log.info("开始处理【下载欧专局专利数据】的业务,参数为:{}", webQueryDTO);
         List<PatentCell> patentCells = new ArrayList<>();
+        //当前任务执行情况
+//        QrtzTaskDetail qrtzTaskDetail = qrTaskDetailService.getById(webQueryDTO.getTaskId());
+//        Integer successNum = qrtzTaskDetail.getSuccessNum();
+//        int startPage = successNum / 5;
+//        int startNum = successNum % 5;
+//        //当前任务条件
+//        QrtzTask qrtzTask = qrTaskService.getById(qrtzTaskDetail.getTaskId());
 
         //1.从DTO中取出网站id、检索信息条件、下载字段、专题库id、报告id
         Integer webId = webQueryDTO.getWebConfigId();
@@ -548,6 +555,7 @@ public class UploadFromWebService {
             //3.2遍历专利
             for (PatentZhuLu patent : patents) {
                 PatentCell patentCell = new PatentCell();
+                patentCell.setProjectId(projectId);
                 PubNo pubNO = new PubNo();
                 //装载专利著录
                 if (cells.contains("1")) {
@@ -633,6 +641,23 @@ public class UploadFromWebService {
                 }
 
                 //4.保存专利信息(发送给专题库)
+                String res = outInterfaceService.importPatents(patentCell);
+                JSONObject jsonObject = JSONObject.parseObject(res);
+                if (jsonObject.get("code").toString().equals("500")) {
+//                    //任务执行情况状态设为失败,任务条件状态设为已完成(若是任务条件是定时任务则设为等待下一次执行)
+//                    qrtzTaskDetail.setTaskDetailState(3);
+//                    qrtzTaskDetail.setSuccessNum(successNum);
+//                    qrtzTaskDetail.setDefaultNum(count - successNum);
+//                    qrtzTaskDetail.setEndTime(new Date());
+//                    qrtzTaskDetail.updateById();
+//                    if (qrtzTask.getTaskType() == 1) {
+//                        qrtzTask.setTaskState(4);
+//                    } else {
+//                        qrtzTask.setTaskState(3);
+//                    }
+//                    qrtzTask.updateById();
+//                    return null;
+                }
                 patentCells.add(patentCell);
             }
         }
@@ -697,48 +722,71 @@ public class UploadFromWebService {
             byte[] buffer = outInterfaceService.getPatentFile(getFuTuParamsDTO);
             InputStream inputStream = new ByteArrayInputStream(buffer);
             streams[i - 1] = inputStream;
-//            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);
-//            switch (FuJianSuffix) {
-//                case ".pdf":
-//                    streams[i - 1] = new FileInputStream(fileDTO.getPath());
-//                    break;
-//                case ".jpeg":
-//                    patentCell.setPicUrl(fileDTO.getPath());
-//                    break;
-//                case ".tiff":
-//                    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文件
             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);
         }
@@ -837,7 +885,7 @@ public class UploadFromWebService {
             }
         }
         //装载申请日
-        patentCell.setApplicationDate(patent.getAppDate());
+        patentCell.setApplicationDate(patent.getAppDate().substring(0, patent.getAppDate().indexOf("T")));
         //装载国家/省市
         patentCell.setCountry(patent.getAppCountry());
         //装载公开号
@@ -850,7 +898,7 @@ public class UploadFromWebService {
         //装载专利号
         patentCell.setPatentNo(patentCell.getPublicNo());
         //装载公开日
-        patentCell.setPubilcDate(patent.getPubDate());
+        patentCell.setPubilcDate(patent.getPubDate().substring(0, patent.getPubDate().indexOf("T")));
         //装载授权公告号(未找到)
         //装载授权公告日(未找到)
         //装载主分类号
@@ -905,7 +953,7 @@ public class UploadFromWebService {
                     Priority priority = new Priority()
                             .setPriorityNo(number.getNumber().substring(2))
                             .setPriorityCountry(number.getNumber().substring(0, 2))
-                            .setPriorityDate(priorty.getDate());
+                            .setPriorityDate(priorty.getDate().substring(0, priorty.getDate().indexOf("T")));
                     priorities.add(priority);
                 }
             }