|
@@ -2,9 +2,14 @@ package cn.cslg.pas.service.business;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
import cn.cslg.pas.common.dto.PatentDTO;
|
|
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.model.request.QueryRequest;
|
|
import cn.cslg.pas.common.utils.FormatUtil;
|
|
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.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.business.es.EsService;
|
|
import cn.cslg.pas.service.common.FileManagerService;
|
|
import cn.cslg.pas.service.common.FileManagerService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -15,6 +20,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
|
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
@@ -34,33 +40,69 @@ public class PDFExportFirstPageService {
|
|
private FileManagerService fileManagerService;
|
|
private FileManagerService fileManagerService;
|
|
@Autowired
|
|
@Autowired
|
|
private EsService esService;
|
|
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 {
|
|
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
|
|
* @param pdfDocuments
|
|
@@ -148,4 +190,83 @@ public class PDFExportFirstPageService {
|
|
byte[][] pdfDataArray = new byte[pdfDatas.size()][];
|
|
byte[][] pdfDataArray = new byte[pdfDatas.size()][];
|
|
return pdfDatas.toArray(pdfDataArray);
|
|
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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|