|
@@ -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();
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|