xiexiang 1 년 전
부모
커밋
48a6952b37

+ 4 - 5
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -22,6 +22,7 @@ import cn.cslg.pas.common.vo.business.EsAllCountVO;
 import cn.cslg.pas.common.vo.business.EsCountVO;
 import cn.cslg.pas.common.vo.business.PatentKinVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
+import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
 import cn.cslg.pas.factorys.businessFactory.Business;
 import cn.cslg.pas.factorys.businessFactory.BusinessFactory;
 import cn.cslg.pas.service.business.PDFExportFirstPageService;
@@ -77,8 +78,6 @@ public class PatentController {
     private PatentExportService patentExportService;
     @Autowired
     private PDFExportFirstPageService pdfExportFirstPageService;
-    @Autowired
-    private FileManagerService fileManagerService;
 
     @Operation(summary = "查询专利")
     @PostMapping("/queryPatent")
@@ -181,10 +180,10 @@ public class PatentController {
         return Response.success(id);
     }
 
-    @GetMapping("/exportPDFFirstPage")
+    @PostMapping("/exportPDFFirstPage")
     @Operation(summary = "导出专利PDF")
-    public ResponseEntity<InputStreamResource> exportPDFFirstPage(Integer projectId) throws IOException {
-        byte[] fileData = pdfExportFirstPageService.mergeAndExportPDFFirstPage(projectId);
+    public ResponseEntity<InputStreamResource> exportPDFFirstPage(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
+        byte[] fileData = pdfExportFirstPageService.mergePDFFirstPage(EsVO);
         //保存生成excel的地址
         String fileName = IdUtil.simpleUUID() + ".pdf";
         //文件原始名中的中文字符可能会乱码,对文件名进行URL编码

+ 143 - 22
src/main/java/cn/cslg/pas/service/business/PDFExportFirstPageService.java

@@ -2,9 +2,14 @@ package cn.cslg.pas.service.business;
 
 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.vo.business.PatentNoVO;
+import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
 import cn.cslg.pas.exception.XiaoShiException;
+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 lombok.extern.slf4j.Slf4j;
@@ -15,6 +20,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
@@ -34,33 +40,69 @@ public class PDFExportFirstPageService {
     private FileManagerService fileManagerService;
     @Autowired
     private EsService esService;
+    @Autowired
+    private EsCustomFieldService esCustomFieldService;
+    @Autowired
+    private EsPatentService patentService;
 
-    /**
-     * 1
-     * @param projectId
-     * @return
-     * @throws IOException
-     */
-    public byte[] mergeAndExportPDFFirstPage(Integer projectId) throws IOException {
-        //根据projectId查询专利信息
-        QueryRequest queryRequest = new QueryRequest();
-        queryRequest.setProjectId(projectId);
-        PatentDTO patentDTO;
+    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();
+        // 创建一个PDFMergerUtility实例
         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);
+            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 {
+                return new byte[0];
+            }
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
         }
-        return pdfData;
     }
 
+
+
+//    /**
+//     * 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
@@ -148,4 +190,83 @@ public class PDFExportFirstPageService {
         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) {
+                        String appNo = patentColumnDTO.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 {
+                                    // 加载输入的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();
+                                }
+                            } else {
+                                // 加载每个输入的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();
+                            }
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                            continue;//继续处理下一件专利
+                        }
+                    } else {
+                        continue;
+                    }
+                } else {
+                    continue;
+                }
+            } catch (Exception e) {
+                continue;
+            }
+        }
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        resultDocument.save(out);
+        resultDocument.close();
+        return out.toByteArray();
+    }
+
+
 }
+
+
+

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

@@ -109,13 +109,9 @@ public class PatentExportService {
                 if (patent == null) {
                     continue;
                 }
-//                String country = StrUtil.sub(patent.getPatentNo(), 0, 2);
 
-
-                //
                 for (int j = 0; j < columns.size(); j++) {
                     String column = columns.get(j);
-
                     PatentExportVO patentExportVO = selected.stream().filter(item -> item.getKey().equals(column)).findFirst().orElse(new PatentExportVO());
                     Object value = null;
                     switch (column) {