xiexiang 1 рік тому
батько
коміт
f3d194c463

+ 7 - 2
src/main/java/cn/cslg/pas/common/utils/ParseByteToFileUtils.java

@@ -33,10 +33,15 @@ public class ParseByteToFileUtils {
         return multipartFile;
     }
 
-    public String uploadFile(byte[] fileData) throws IOException {
+    public String uploadFile(byte[] fileData, Integer type) throws IOException {
         List<MultipartFile> multipartFiles = new ArrayList<>();
         //保存生成地址
-        String fileName = IdUtil.simpleUUID() + ".xls";
+        String fileName = "";
+        if (type.equals(1)) {
+            fileName = IdUtil.simpleUUID() + ".xls";
+        } else if (type.equals(2)) {
+            fileName = IdUtil.simpleUUID() + ".pdf";
+        }
         //文件原始名中的中文字符可能会乱码,对文件名进行URL编码
         String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
         MultipartFile multipartFile = this.convertBytesToMultipartFile(fileData, encodedFileName);

+ 3 - 1
src/main/java/cn/cslg/pas/common/utils/ResponseEnum.java

@@ -16,7 +16,9 @@ public enum ResponseEnum {
     COMPARE_LITERATURE_BATCH(600,"批量上传对比文献"),
     COMPARE_LITERATURE_BATCH_DONE(601,"批量上传对比文献完成"),
     PATENT_EXPORT_TASK(602,"导出专利信息"),
-    PATENT_EXPORT_TASK_DONE(603,"导出专利信息完成") ;
+    PATENT_EXPORT_TASK_DONE(603,"导出专利信息完成"),
+    PATENT_PDF_EXPORT_TASK(604,"导出PDF首页"),
+    PATENT_PDF_EXPORT_TASK_DONE(605,"导出PDF首页完成");
 
     private Integer code;
     private String message;

+ 7 - 26
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -226,38 +226,19 @@ public class PatentController {
     //--------------------导出-----------------------
     @PostMapping("/exportPDFFirstPage")
     @Operation(summary = "导出专利PDF")
-    public ResponseEntity<InputStreamResource> exportPDFFirstPage(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
-        byte[] fileData = pdfExportFirstPageService.mergePdfFirstPage(EsVO);
-        //保存生成excel的地址
-        String fileName = IdUtil.simpleUUID() + ".pdf";
-        //文件原始名中的中文字符可能会乱码,对文件名进行URL编码
-        String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
-        return ResponseEntity.ok().contentLength(fileData.length)
-                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\"")
-                .contentType(MediaType.parseMediaType("application/octet-stream"))
-                .body(new InputStreamResource(new ByteArrayInputStream(fileData)));
+    public Response exportPDFFirstPage(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
+        pdfExportFirstPageService.mergePdfFirstPage(EsVO);
+        Records records = new Records();
+        records.setData("正在导出PDF首页");
+        return Response.success(records);
     }
 
-//    @PostMapping("/exportPatentExcel")
-//    @Operation(summary = "导出专利")
-//    public ResponseEntity<InputStreamResource> export(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
-//        byte[] fileData = patentExportService.exportPatent(EsVO);
-//        //保存生成excel的地址
-//        String fileName = IdUtil.simpleUUID() + ".xls";
-//        //文件原始名中的中文字符可能会乱码,对文件名进行URL编码
-//        String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
-//        return ResponseEntity.ok().contentLength(fileData.length)
-//                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\"")
-//                .contentType(MediaType.parseMediaType("application/octet-stream"))
-//                .body(new InputStreamResource(new ByteArrayInputStream(fileData)));
-//    }
-
     @PostMapping("/exportPatentExcel")
     @Operation(summary = "导出专利")
-    public Response export(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
+    public Response exportPatentExcel(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
         patentExportService.exportPatent(EsVO);
         Records records = new Records();
-        records.setData("导出成功");
+        records.setData("正在导出专利");
         return Response.success(records);
     }
 }

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

@@ -386,7 +386,7 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
 
     }
 
-    public Integer addExportExcel(ExportTaskDTO exportTaskDTO){
+    public Integer addExportTask(ExportTaskDTO exportTaskDTO){
         if (exportTaskDTO == null) {
             throw new XiaoShiException("入参不能为空");
         }

+ 108 - 200
src/main/java/cn/cslg/pas/service/business/PDFExportFirstPageService.java

@@ -1,10 +1,13 @@
 package cn.cslg.pas.service.business;
 
+import cn.cslg.pas.common.dto.ExportTaskDTO;
 import cn.cslg.pas.common.dto.PatentColumnDTO;
 import cn.cslg.pas.common.dto.PatentDTO;
 import cn.cslg.pas.common.dto.es.EsCustomFieldDTO;
 import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.utils.FormatUtil;
+import cn.cslg.pas.common.utils.ParseByteToFileUtils;
+import cn.cslg.pas.common.vo.WebSocketMessageVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
 import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
 import cn.cslg.pas.exception.XiaoShiException;
@@ -12,6 +15,7 @@ import cn.cslg.pas.service.business.es.EsCustomFieldService;
 import cn.cslg.pas.service.business.es.EsPatentService;
 import cn.cslg.pas.service.business.es.EsService;
 import cn.cslg.pas.service.common.FileManagerService;
+import cn.cslg.pas.service.common.MessageService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.input.XmlStreamReaderException;
 import org.apache.pdfbox.multipdf.PDFMergerUtility;
@@ -20,6 +24,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -40,209 +45,38 @@ public class PDFExportFirstPageService {
     @Autowired
     private FileManagerService fileManagerService;
     @Autowired
-    private EsService esService;
-    @Autowired
     private EsCustomFieldService esCustomFieldService;
     @Autowired
     private EsPatentService patentService;
 
+    @Autowired
+    private ParseByteToFileUtils parseByteToFileUtils;
 
-    public byte[] mergePdfFirstPage(EsCustomFieldBatchVO EsVO){
-        try {
-            List<String> patentNos = this.getPatentNo(EsVO);
-            byte[] result = this.mergePerPatentPDF(patentNos);
-            return result;
-        } catch (Exception e) {
-            throw new XiaoShiException("合并错误");
-        }
-    }
+    @Autowired
+    private ImportTaskService importTaskService;
 
-    /**
-     * 获取专利号
-     * @param EsVO
-     * @return
-     * @throws IOException
-     */
-    public List<String> getPatentNo(EsCustomFieldBatchVO EsVO) throws IOException {
-        //初始化
-        Integer startNum = EsVO.getStartNumber();
-        Integer endNum = EsVO.getEndNumber();
-        List<String> isAdd = EsVO.getIsAdd();
-        List<String> isDel = EsVO.getIsDelete();
+    @Autowired
+    private MessageService messageService;
+
+
+    @Async
+    public void mergePdfFirstPage(EsCustomFieldBatchVO EsVO){
         try {
-            if (!CollectionUtils.isEmpty(isAdd) && startNum <= 1 && endNum < 1) {
-                isAdd.removeAll(isDel);
-                //创建一个输出流
-                return isAdd;
-            } else if (startNum > 1 && endNum > 0){
-                List<String> patentNos = new ArrayList<>();
+            List<String> patentNos = this.getPatentNo(EsVO);
+            Integer total = patentNos.size();
+            Integer defaultNum = 0;
+            PDFMergerUtility merger = new PDFMergerUtility();
+            PDDocument resultDocument = new PDDocument();
+            for (int i = 0; i < patentNos.size(); i++) {
+                PatentNoVO patentNoVO = new PatentNoVO();
+                patentNoVO.setPatentNo(patentNos.get(i));
+                PatentColumnDTO patentColumnDTO = new PatentColumnDTO();
                 try {
-                    patentNos = esCustomFieldService.getPatentNos(EsVO);
-                    return patentNos;
+                    patentColumnDTO = patentService.selectPatentDetail(patentNoVO);
                 } catch (Exception e) {
-                    throw new XiaoShiException("");
+                    defaultNum++;
+                    continue;
                 }
-            } else {
-                throw new XiaoShiException("入参错误");
-            }
-        } catch (Exception e) {
-            throw new XiaoShiException("获取专利号错误");
-        }
-    }
-
-//    public byte[] mergePDFFirstPage(EsCustomFieldBatchVO EsVO) throws IOException {
-//        //初始化
-//        Integer startNum = EsVO.getStartNumber();
-//        Integer endNum = EsVO.getEndNumber();
-//        List<String> isAdd = EsVO.getIsAdd();
-//        List<String> isDel = EsVO.getIsDelete();
-//        try {
-//            if (!CollectionUtils.isEmpty(isAdd) && startNum <= 1 && endNum < 1) {
-//                isAdd.removeAll(isDel);
-//                //创建一个输出流
-//                byte[] result = this.mergePerPatentPDF(isAdd);
-//                return result;
-//            } else if (startNum > 1 && endNum > 0){
-//                List<String> patentNos = new ArrayList<>();
-//                try {
-//                    patentNos = esCustomFieldService.getPatentNos(EsVO);
-//                    byte[] result = this.mergePerPatentPDF(patentNos);
-//                    return result;
-//                } catch (Exception e) {
-//                    throw new XiaoShiException("");
-//                }
-//            } else {
-//                throw new XiaoShiException("入参错误");
-//            }
-//        } catch (FileNotFoundException e) {
-//            throw new FileNotFoundException();
-//        }
-//    }
-
-
-
-//    /**
-//     * 1
-//     * @param EsVO
-//     * @return
-//     * @throws IOException
-//     */
-//    public byte[] mergeAndExportPDFFirstPage(EsCustomFieldBatchVO EsVO) throws IOException {
-//        //根据projectId查询专利信息
-//        QueryRequest queryRequest = new QueryRequest();
-//        queryRequest.setProjectId(projectId);
-//        PatentDTO patentDTO;
-//        try {
-//            patentDTO = esService.esSearch(queryRequest);
-//        } catch (Exception e) {
-//            throw new XiaoShiException("检索专利错误");
-//        }
-//        List<PatentColumnDTO> patents = patentDTO.getPatents();
-//        byte[][] pdfDocuments = this.getPDFByteByAppNo(patents);
-//        byte[] pdfData = new byte[0];
-//        // 判断 byte[][] 数组是否为空
-//        if (!this.isByteEmpty(pdfDocuments)) {
-//            pdfData = this.mergeFirstPage(pdfDocuments);
-//        }
-//        return pdfData;
-//    }
-
-//    /**
-//     * 判断文件数组是否为空
-//     * @param pdfDocuments
-//     * @return
-//     */
-//    private boolean isByteEmpty(byte[][] pdfDocuments) {
-//        return pdfDocuments == null || pdfDocuments.length == 0 || Arrays.stream(pdfDocuments).allMatch(array -> array == null || array.length == 0);
-//    }
-
-//    /**
-//     * 3
-//     * @param pdfDatas
-//     * @return
-//     * @throws IOException
-//     */
-//    public byte[] mergeFirstPage(byte[][] pdfDatas) throws IOException{
-//        //创建一个输出流
-//        try {
-//            // 创建一个PDFMergerUtility实例
-//            PDFMergerUtility merger = new PDFMergerUtility();
-//            PDDocument resultDocument = new PDDocument();
-//            //逐个处理每个pdf文件
-//            for (byte[] pdfData : pdfDatas) {
-//                // 加载每个输入的PDF文档
-//                PDDocument document = PDDocument.load(pdfData);
-//                // 获取第一页
-//                PDPage firstPage = document.getPage(0);
-//                // 创建一个新的文档用于保存第一页
-//                PDDocument firstPageDocument = new PDDocument();
-//                firstPageDocument.addPage(firstPage);
-//                // 将第一页添加到合并器中
-//                merger.appendDocument(resultDocument, firstPageDocument);
-//                // 关闭当前处理的文档
-//                document.close();
-//                firstPageDocument.close();
-//            }
-//            ByteArrayOutputStream out = new ByteArrayOutputStream();
-//            resultDocument.save(out);
-//            resultDocument.close();
-//            return out.toByteArray();
-//        } catch (FileNotFoundException e) {
-//            throw new FileNotFoundException();
-//        }
-//    }
-
-//    /**
-//     * 2
-//     * 根据查询到的专利信息获取它公告或公开专利的pdf文档数据流
-//     * @param patents
-//     * @return
-//     */
-//    public byte[][] getPDFByteByAppNo(List<PatentColumnDTO> patents){
-//        List<byte[]> pdfDatas = new ArrayList<>();
-//        //遍历传入专利集合
-//        for (PatentColumnDTO item : patents) {
-//            //判断申请号是否为空
-//            if (item.getAppNo() != null) {
-//                String appNo = item.getAppNo();
-//                Integer type = 1;
-//                //获取公告专利pdf文档guid
-//                String pdfGuid = FormatUtil.getPDFFormat(appNo, type);
-//
-//                byte[] pdfData = new byte[0];
-//                try {
-//                    pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid);
-//                    if (pdfData == null  || pdfData.length == 0) {
-//                        //获取公开专利pdf文档guid
-//                        Integer type2 = 0;
-//                        String pdfGuid2 = FormatUtil.getPDFFormat(appNo, type2);
-//                        pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid2);
-//                        if (pdfData == null  || pdfData.length == 0) {
-//                            continue;
-//                        } else {
-//                            pdfDatas.add(pdfData);
-//                        }
-//                    } else {
-//                        pdfDatas.add(pdfData);
-//                    }
-//                } catch (IOException e) {
-//                    e.printStackTrace();
-//                    continue;//继续处理下一件专利
-//                }
-//            }
-//        }
-//        byte[][] pdfDataArray = new byte[pdfDatas.size()][];
-//        return pdfDatas.toArray(pdfDataArray);
-//    }
-
-    public byte[] mergePerPatentPDF(List<String> patentNos) throws IOException {
-        PDFMergerUtility merger = new PDFMergerUtility();
-        PDDocument resultDocument = new PDDocument();
-        for (String patentNo : patentNos) {
-            PatentNoVO patentNoVO = new PatentNoVO();
-            patentNoVO.setPatentNo(patentNo);
-            try {
-                PatentColumnDTO patentColumnDTO = patentService.selectPatentDetail(patentNoVO);
                 if (patentColumnDTO != null) {
                     //判断申请号是否为空
                     if (patentColumnDTO.getAppNo() != null) {
@@ -250,7 +84,6 @@ public class PDFExportFirstPageService {
                         Integer type = 1;
                         //获取公告专利pdf文档guid
                         String pdfGuid = FormatUtil.getPDFFormat(appNo, type);
-
                         byte[] pdfData = new byte[0];
                         try {
                             pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid);
@@ -260,6 +93,7 @@ public class PDFExportFirstPageService {
                                 String pdfGuid2 = FormatUtil.getPDFFormat(appNo, type2);
                                 pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid2);
                                 if (pdfData == null || pdfData.length == 0) {
+                                    defaultNum++;
                                     continue;
                                 } else {
                                     // 加载输入的PDF文档
@@ -274,6 +108,14 @@ public class PDFExportFirstPageService {
                                     // 关闭当前处理的文档
                                     document.close();
                                     firstPageDocument.close();
+                                    WebSocketMessageVO webSocketMessageVO =new WebSocketMessageVO();
+                                    webSocketMessageVO.setProjectId(EsVO.getProjectId());
+                                    webSocketMessageVO.setCreateId("328");
+                                    webSocketMessageVO.setCode(604);
+                                    webSocketMessageVO.setAllNum(total);
+                                    webSocketMessageVO.setCurrentNum(i+1);
+                                    webSocketMessageVO.setState(1);
+                                    messageService.sendPatentExportMessage(webSocketMessageVO);
                                 }
                             } else {
                                 // 加载每个输入的PDF文档
@@ -288,28 +130,94 @@ public class PDFExportFirstPageService {
                                 // 关闭当前处理的文档
                                 document.close();
                                 firstPageDocument.close();
+                                WebSocketMessageVO webSocketMessageVO =new WebSocketMessageVO();
+                                webSocketMessageVO.setProjectId(EsVO.getProjectId());
+                                webSocketMessageVO.setCreateId("328");
+                                webSocketMessageVO.setCode(604);
+                                webSocketMessageVO.setAllNum(total);
+                                webSocketMessageVO.setCurrentNum(i+1);
+                                webSocketMessageVO.setState(1);
+                                messageService.sendPatentExportMessage(webSocketMessageVO);
                             }
                         } catch (IOException e) {
                             e.printStackTrace();
+                            defaultNum++;
                             continue;//继续处理下一件专利
                         }
                     } else {
+                        defaultNum++;
                         continue;
                     }
                 } else {
+                    defaultNum++;
                     continue;
                 }
-            } catch (Exception e) {
-                continue;
             }
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            resultDocument.save(out);
+            resultDocument.close();
+            WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
+            webSocketMessageVO.setProjectId(EsVO.getProjectId());
+            webSocketMessageVO.setCreateId("328");
+            webSocketMessageVO.setCode(605);
+            webSocketMessageVO.setAllNum(total);
+            webSocketMessageVO.setCurrentNum(total);
+            webSocketMessageVO.setState(2);
+            messageService.sendPatentExportMessage(webSocketMessageVO);
+            String fileGuid = "";
+            if (out.toByteArray() != null && out.toByteArray().length != 0) {
+                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 2);
+            }
+            ExportTaskDTO exportTaskDTO = new ExportTaskDTO();
+            exportTaskDTO.setProjectId(EsVO.getProjectId());
+            exportTaskDTO.setType(7);
+            exportTaskDTO.setFileGuid(fileGuid);
+            exportTaskDTO.setAllNum(total);
+            exportTaskDTO.setDefaultNum(defaultNum);
+            Integer taskId = importTaskService.addExportTask(exportTaskDTO);
+            if (taskId == null) {
+                throw new XiaoShiException("导出记录失败");
+            }
+        } catch (Exception e) {
+            throw new XiaoShiException("合并错误");
+        }
+    }
+
+    /**
+     * 获取专利号
+     * @param EsVO
+     * @return
+     * @throws IOException
+     */
+    public List<String> getPatentNo(EsCustomFieldBatchVO EsVO) throws IOException {
+        //初始化
+        Integer startNum = EsVO.getStartNumber();
+        Integer endNum = EsVO.getEndNumber();
+        List<String> isAdd = EsVO.getIsAdd();
+        List<String> isDel = EsVO.getIsDelete();
+        try {
+            if (!CollectionUtils.isEmpty(isAdd) && startNum <= 1 && endNum < 1) {
+                isAdd.removeAll(isDel);
+                //创建一个输出流
+                return isAdd;
+            } else if (startNum > 1 && endNum > 0){
+                List<String> patentNos = new ArrayList<>();
+                try {
+                    patentNos = esCustomFieldService.getPatentNos(EsVO);
+                    return patentNos;
+                } catch (Exception e) {
+                    throw new XiaoShiException("");
+                }
+            } else {
+                throw new XiaoShiException("入参错误");
+            }
+        } catch (Exception e) {
+            throw new XiaoShiException("获取专利号错误");
         }
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        resultDocument.save(out);
-        resultDocument.close();
-        return out.toByteArray();
     }
 
 
+
 }
 
 

+ 4 - 3
src/main/java/cn/cslg/pas/service/business/PatentExportService.java

@@ -164,16 +164,17 @@ public class PatentExportService {
                 messageService.sendPatentExportMessage(webSocketMessageVO);
             }
             hssfWorkbook.write(out);
-            WebSocketMessageVO webSocketMessageVO =new WebSocketMessageVO();
+            WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
             webSocketMessageVO.setProjectId(EsVO.getProjectId());
             webSocketMessageVO.setCreateId("328");
+            webSocketMessageVO.setCode(603);
             webSocketMessageVO.setAllNum(total);
             webSocketMessageVO.setCurrentNum(total);
             webSocketMessageVO.setState(2);
             messageService.sendPatentExportMessage(webSocketMessageVO);
             String fileGuid = "";
             if (out.toByteArray() != null && out.toByteArray().length != 0) {
-                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray());
+                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
             }
             ExportTaskDTO exportTaskDTO = new ExportTaskDTO();
             exportTaskDTO.setProjectId(EsVO.getProjectId());
@@ -181,7 +182,7 @@ public class PatentExportService {
             exportTaskDTO.setFileGuid(fileGuid);
             exportTaskDTO.setAllNum(total);
             exportTaskDTO.setDefaultNum(defaultNum);
-            Integer taskId = importTaskService.addExportExcel(exportTaskDTO);
+            Integer taskId = importTaskService.addExportTask(exportTaskDTO);
             if (taskId == null) {
                 throw new XiaoShiException("导出记录失败");
             }

+ 5 - 1
src/main/java/cn/cslg/pas/service/business/ScratchWordsService.java

@@ -18,7 +18,9 @@ import com.github.pagehelper.PageInfo;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.data.annotation.AccessType;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -34,7 +36,9 @@ import java.util.stream.Collectors;
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class ScratchWordsService extends ServiceImpl<ScratchWordsMapper, ScratchWords> {
-    private final ScratchWordsMapper scratchWordsMapper;
+    @Autowired
+    private ScratchWordsMapper scratchWordsMapper;
+
     private final CacheUtils cacheUtils;
     private final LoginUtils loginUtils;
     private final ProjectService projectService;