|
@@ -2,30 +2,55 @@ package cn.cslg.pas.service;
|
|
|
|
|
|
|
|
|
import cn.cslg.pas.common.core.base.Constants;
|
|
|
+import cn.cslg.pas.common.model.dto.PatentDTO;
|
|
|
import cn.cslg.pas.common.model.dto.UploadFileDTO;
|
|
|
import cn.cslg.pas.common.model.vo.PatentInstructionVO;
|
|
|
+import cn.cslg.pas.common.model.vo.PatentVO;
|
|
|
+import cn.cslg.pas.common.model.vo.SystemFile;
|
|
|
import cn.cslg.pas.common.utils.*;
|
|
|
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
|
import cn.cslg.pas.domain.Patent;
|
|
|
import cn.cslg.pas.domain.PatentInstruction;
|
|
|
+import cn.cslg.pas.domain.Task;
|
|
|
import cn.cslg.pas.mapper.PatentInstructionMapper;
|
|
|
+import cn.cslg.pas.service.upLoadPatent.MessageService;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
|
+import org.apache.commons.fileupload.FileItem;
|
|
|
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
+import org.apache.pdfbox.multipdf.PDFMergerUtility;
|
|
|
+import org.apache.pdfbox.multipdf.Splitter;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.pdmodel.PDPage;
|
|
|
+import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
|
|
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
|
|
+import org.apache.pdfbox.pdmodel.font.PDFont;
|
|
|
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
|
|
+import org.apache.pdfbox.rendering.ImageType;
|
|
|
+import org.apache.pdfbox.rendering.PDFRenderer;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.RenderedImage;
|
|
|
+import java.io.*;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -37,9 +62,14 @@ import java.util.stream.Collectors;
|
|
|
* @author 王岩
|
|
|
* @since 2022-03-02
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class PatentInstructionService extends ServiceImpl<PatentInstructionMapper, PatentInstruction> {
|
|
|
+ private final PatentService patentService;
|
|
|
+ private final TaskService taskService;
|
|
|
+ private final MessageService messageService;
|
|
|
+ private final FileManagerService fileManagerService;
|
|
|
private final FileUtils fileUtils;
|
|
|
private final LoginUtils loginUtils;
|
|
|
|
|
@@ -280,4 +310,185 @@ public class PatentInstructionService extends ServiceImpl<PatentInstructionMappe
|
|
|
FileUtil.del(fileUtils.getSystemPath(item.getUrl()));
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+// public void queryPatentPdfFirstPages(PatentVO params) throws IOException {
|
|
|
+// log.info("开始处理【导出多件专利pdf首页】的业务,业务参数为:{}", params);
|
|
|
+//
|
|
|
+// //根据筛选条件分页查询专利清单(这一次查询目的只是获得专利总数和总页数)
|
|
|
+// IPage<PatentDTO> pageList0 = patentService.getPageList(params);
|
|
|
+// int total = (int) pageList0.getTotal(); //专利总数(作为任务进度总数)
|
|
|
+// long pages = pageList0.getPages(); //总页数(用来计算要检索几次)
|
|
|
+//
|
|
|
+// ArrayList<String> filePaths = new ArrayList<>(); //存放所有临时文件(说明书pdf首页的文件)路径
|
|
|
+// String mergedFilePath = StringUtils.getUUID() + ".pdf"; //合并后的pdf文件路径
|
|
|
+// PDFMergerUtility pdfMerger = new PDFMergerUtility(); //pdf合并工具
|
|
|
+//
|
|
|
+// //上传任务
|
|
|
+// Task task = new Task()
|
|
|
+// .setFileName(mergedFilePath)
|
|
|
+// .setProjectId(params.getProjectId())
|
|
|
+// .setType(6)
|
|
|
+// .setCreateBy(loginUtils.getId())
|
|
|
+// .setStartTime(DateUtils.getDateTime())
|
|
|
+// .setTotal(total)
|
|
|
+// .setStatus(6)
|
|
|
+// .setDefaultNum(0)
|
|
|
+// .setSuccessNum(0)
|
|
|
+// .setTrueSuccessNum(0);
|
|
|
+// taskService.save(task);
|
|
|
+//
|
|
|
+// //一页一页检索
|
|
|
+// for (long i = 1; i <= pages; i++) {
|
|
|
+// params.setCurrent(i);
|
|
|
+// IPage<PatentDTO> pageList = patentService.getPageList(params); //根据筛选条件分页查询专利清单
|
|
|
+// List<PatentDTO> patents = pageList.getRecords(); //取出专利清单
|
|
|
+// List<String> patentNos = patents.stream().map(PatentDTO::getPatentNo).collect(Collectors.toList()); //过滤取出专利号
|
|
|
+//
|
|
|
+// //根据专利号patentNos查询出所有pdf文档数据
|
|
|
+// List<PatentInstruction> patentInstructions = this.list(new LambdaQueryWrapper<PatentInstruction>().in(PatentInstruction::getPatentNo, patentNos));
|
|
|
+//
|
|
|
+// //遍历当前专利号清单
|
|
|
+// for (String patentNo : patentNos) {
|
|
|
+// List<PatentInstruction> patentInstructionList = patentInstructions.stream().filter(item -> item.getPatentNo().equals(patentNo)).collect(Collectors.toList());
|
|
|
+// //若没有说明书pdf
|
|
|
+// if (patentInstructionList.size() == 0) {
|
|
|
+// //创建文件,设置页码
|
|
|
+// PDDocument doc = new PDDocument();
|
|
|
+// PDPage pageOne = new PDPage(PDRectangle.A4);
|
|
|
+// doc.addPage(pageOne);
|
|
|
+// //创建页面内容流
|
|
|
+// PDPageContentStream contents = new PDPageContentStream(doc, pageOne);
|
|
|
+// //设置要使用的字体
|
|
|
+// PDFont font = PDType1Font.COURIER_BOLD_OBLIQUE;
|
|
|
+// contents.setFont(font,18);
|
|
|
+// contents.beginText();
|
|
|
+// //直接写入内容即可
|
|
|
+// contents.showText("patentNo " + patentNo + " mission");
|
|
|
+// contents.endText();
|
|
|
+// //记得关闭流对象要不然是无法成功保存pdf文档的
|
|
|
+// contents.close();
|
|
|
+// String newFilePath = StringUtils.getUUID() + ".pdf";
|
|
|
+// doc.save(newFilePath);
|
|
|
+// filePaths.add(newFilePath);
|
|
|
+// pdfMerger.addSource(newFilePath);
|
|
|
+// doc.close();
|
|
|
+// //更新任务表(完成数量+1)并发送进度
|
|
|
+// task.setSuccessNum(task.getSuccessNum() + 1);
|
|
|
+// task.setTrueSuccessNum(task.getTrueSuccessNum() + 1);
|
|
|
+// sendMessage(total, task);
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// //若有说明书pdf
|
|
|
+// PatentInstruction patentInstruction;
|
|
|
+// if (patentInstructionList.size() > 1) { //若有多个,则过滤取出授权文档
|
|
|
+// patentInstruction = patentInstructionList.stream().filter(item -> item.getType() == 2).collect(Collectors.toList()).get(0);
|
|
|
+// } else { //若只有一个pdf,则直接取出
|
|
|
+// patentInstruction = patentInstructionList.get(0);
|
|
|
+// }
|
|
|
+//
|
|
|
+// String filePath = fileUtils.getSystemPath() + patentInstruction.getUrl();
|
|
|
+// if (!new File(filePath).exists()) { //如果说明书文档不存在了,则跳过,继续下一个
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// PDDocument doc = PDDocument.load(new File(filePath));
|
|
|
+// Splitter splitter = new Splitter();
|
|
|
+// splitter.setStartPage(1);
|
|
|
+// splitter.setEndPage(1);
|
|
|
+// PDDocument needDoc = splitter.split(doc).get(0);
|
|
|
+// String newFilePath = StringUtils.getUUID() + ".pdf";
|
|
|
+// needDoc.save(newFilePath);
|
|
|
+// filePaths.add(newFilePath);
|
|
|
+// pdfMerger.addSource(newFilePath);
|
|
|
+// needDoc.close();
|
|
|
+// doc.close();
|
|
|
+// //更新任务表(完成数量+1)并发送进度
|
|
|
+// task.setSuccessNum(task.getSuccessNum() + 1);
|
|
|
+// task.setTrueSuccessNum(task.getTrueSuccessNum() + 1);
|
|
|
+// sendMessage(total, task);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 设置合并生成pdf文件名称
|
|
|
+// pdfMerger.setDestinationFileName(mergedFilePath);
|
|
|
+// // 合并PDF
|
|
|
+// pdfMerger.mergeDocuments();
|
|
|
+//
|
|
|
+// if (!new File(mergedFilePath).exists()) {
|
|
|
+// ThrowException.throwXiaoShiException("当前批次所有专利的说明书文档丢失");
|
|
|
+// }
|
|
|
+//
|
|
|
+// //File文件转成MultipartFile
|
|
|
+// MultipartFile multipartFile = FileToMultipartFileUtiles.fileToMultipartFile(mergedFilePath);
|
|
|
+// ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
|
|
|
+// multipartFiles.add(multipartFile);
|
|
|
+//
|
|
|
+// String res = fileManagerService.uploadFile(multipartFiles);
|
|
|
+// JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+// List<Integer> fileIds = JSONArray.parseArray(jsonObject.get("data").toString(), Integer.class);
|
|
|
+// res = fileManagerService.getSystemFileFromFMS(fileIds);
|
|
|
+// List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
|
|
|
+// SystemFile systemFile = systemFiles.get(0);
|
|
|
+// Task updateTask = new Task();
|
|
|
+// updateTask.setId(task.getId());
|
|
|
+// updateTask.setSystemFileId(fileIds.get(0));
|
|
|
+// updateTask.setUrl(systemFile.getFilePath().substring(systemFile.getFilePath().indexOf("file") + 4));
|
|
|
+// updateTask.setFileSize(Long.valueOf(systemFile.getFileLength()));
|
|
|
+// taskService.updateById(updateTask);
|
|
|
+//
|
|
|
+// //最后要记得删除所有PDF首页临时文件
|
|
|
+// for (String filePath : filePaths) { //删除每个pdf首页文件
|
|
|
+// new File(filePath).delete();
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 更新任务表(完成数量+1)、发送websocket进度
|
|
|
+// *
|
|
|
+// * @param total 任务专利总数量
|
|
|
+// * @param task 任务对象
|
|
|
+// */
|
|
|
+// private void sendMessage(int total, Task task) {
|
|
|
+// //更新任务表(完成数量+1),并发送进度+1
|
|
|
+// Task updateTask = new Task();
|
|
|
+// updateTask.setId(task.getId());
|
|
|
+// updateTask.setSuccessNum(task.getSuccessNum());
|
|
|
+// updateTask.setTrueSuccessNum(task.getTrueSuccessNum());
|
|
|
+// taskService.updateById(updateTask);
|
|
|
+// long percentage = (long) Math.floor((task.getSuccessNum() + 0D) / total * 100D);
|
|
|
+// //当全部完成时
|
|
|
+// if (task.getSuccessNum().equals(total)) {
|
|
|
+// percentage = 100L;
|
|
|
+// //任务表更新最终数据
|
|
|
+// task.setStatus(2);
|
|
|
+// updateTask.setStatus(task.getStatus());
|
|
|
+// updateTask.setEndTime(DateUtils.getDateTime());
|
|
|
+// taskService.updateById(updateTask);
|
|
|
+// }
|
|
|
+// //websocket发送进度
|
|
|
+// messageService.sendWebsocketMessage(task, total, task.getSuccessNum(), percentage);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public void generateBookIamge(File inputFile, File outputFile) {
|
|
|
+//
|
|
|
+// try {
|
|
|
+// PDDocument doc = PDDocument.load(inputFile);
|
|
|
+// PDFRenderer pdfRenderer = new PDFRenderer(doc);
|
|
|
+// // 提取的页码
|
|
|
+// int pageNumber = 0;
|
|
|
+// // 以300 dpi 读取存入 BufferedImage 对象
|
|
|
+// int dpi = 300;
|
|
|
+// RenderedImage buffImage = pdfRenderer.renderImageWithDPI(pageNumber, dpi, ImageType.RGB);
|
|
|
+// // 将 BufferedImage 写入到 png
|
|
|
+// ImageIO.write(buffImage, "png", outputFile);
|
|
|
+//
|
|
|
+// // 关闭文档
|
|
|
+// doc.close();
|
|
|
+//
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
}
|