ExcutePatentDataEpo.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. package cn.cslg.pas.service.upLoadPatent;
  2. import cn.cslg.pas.common.model.PatentCell;
  3. import cn.cslg.pas.common.model.dto.*;
  4. import cn.cslg.pas.common.model.vo.UploadParamsVO;
  5. import cn.cslg.pas.common.utils.FileUtils;
  6. import cn.cslg.pas.common.utils.StringUtils;
  7. import cn.cslg.pas.common.utils.ThrowException;
  8. import cn.cslg.pas.domain.*;
  9. import cn.cslg.pas.domain.asso.TaskCondition;
  10. import cn.cslg.pas.exception.XiaoShiException;
  11. import cn.cslg.pas.service.*;
  12. import cn.cslg.pas.service.asso.AssoOsTaskQrtzTaskService;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  15. import com.spire.pdf.FileFormat;
  16. import com.spire.pdf.PdfDocument;
  17. import com.spire.pdf.PdfDocumentBase;
  18. import lombok.RequiredArgsConstructor;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.apache.commons.fileupload.FileItem;
  21. import org.apache.commons.fileupload.disk.DiskFileItemFactory;
  22. import org.springframework.beans.BeanUtils;
  23. import org.springframework.stereotype.Service;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import org.springframework.web.multipart.commons.CommonsMultipartFile;
  26. import java.io.*;
  27. import java.text.SimpleDateFormat;
  28. import java.util.ArrayList;
  29. import java.util.Arrays;
  30. import java.util.Date;
  31. import java.util.List;
  32. /**
  33. * Epo类型任务解析获取专利类
  34. *
  35. * @Author chenyu
  36. * @Date 2023/6/16
  37. */
  38. @Slf4j
  39. @RequiredArgsConstructor
  40. @Service
  41. public class ExcutePatentDataEpo implements IExcutePatentData {
  42. private final FileUtils fileUtils;
  43. private final PantentQueueService pantentQueueService;
  44. private final AssoOsTaskQrtzTaskService assoOsTaskQrtzTaskService;
  45. private final OutInterfaceService outInterfaceService;
  46. private final PatentInstructionService patentInstructionService;
  47. private final PatentAgencyService patentAgencyService;
  48. private final PatentAffairService patentAffairService;
  49. private final ProjectPatentLinkService projectPatentLinkService;
  50. private final PatentService patentService;
  51. private final PatentImageService patentImageService;
  52. private Integer pTaskId = 0;
  53. private Integer pTaskStatus = 0;
  54. /**
  55. * 解析获取专利数据
  56. *
  57. * @param task 任务
  58. */
  59. @Override
  60. public void startExcute(Task task) throws IOException {
  61. //从任务关联网站导入任务表中取出当前任务
  62. List<TaskCondition> taskConditions = assoOsTaskQrtzTaskService.list(new LambdaQueryWrapper<TaskCondition>().eq(TaskCondition::getTaskId, task.getId()));
  63. TaskCondition taskCondition = taskConditions.get(0);
  64. //从任务数据中获取下载字段、检索式
  65. String cellsStr = taskCondition.getConfigCells();
  66. List<String> cells = Arrays.asList(cellsStr.split(","));
  67. String conditions = taskCondition.getConditions();
  68. //定义每次检索的专利数量(每次检索50件)
  69. int size = 50;
  70. //获得专利总数量
  71. Integer count = task.getTotal();
  72. //1.根据专利总数量count遍历检索专利
  73. for (int i = 1; i <= count; i += size) {
  74. //根据检索式conditions、专利开始数i、专利最后数i + size - 1检索专利著录信息
  75. SerachBiblioData serachBiblioData = getSerachBiblioData(conditions, i, i + size - 1);
  76. //获取检索结果中的所有专利著录信息
  77. if (serachBiblioData == null || serachBiblioData.getTotals() == 0) {
  78. continue;
  79. }
  80. List<PatentZhuLu> patents = serachBiblioData.getPatents();
  81. //2.遍历专利
  82. for (PatentZhuLu patent : patents) {
  83. //判断若任务状态为已暂停,则结束生产
  84. if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
  85. return;
  86. }
  87. PatentCell patentCell = new PatentCell();
  88. patentCell.setProjectId(task.getProjectId());
  89. PubNo pubNO = new PubNo();
  90. //装载专利著录
  91. if (cells.contains("1")) {
  92. setPatentZhuLu(patentCell, patent, pubNO);
  93. }
  94. //装载权要
  95. if (cells.contains("2")) {
  96. setPatentClaim(patentCell, pubNO);
  97. }
  98. //装载说明书文本
  99. if (cells.contains("3")) {
  100. setPatentInstructionText(patentCell, pubNO);
  101. }
  102. //以下代码是在准备一会要调用拿取各种附图的接口所需的参数(FullDocument->说明书pdf、Drawing->其他附图、FirstPageClipping->摘要附图)
  103. String fullDocumentLink = "", fullDocumentType = "", drawingLink = "", drawingType = "", firstPageClippingLink = "", firstPageClippingType = "";
  104. Integer fullDocumentPage = 0, drawingPage = 0, firstPageClippingPage = 0;
  105. //根据当前专利号调用接口获取一会调用拿取各种附图的接口的参数
  106. try {
  107. ImageInfo imageInfo = getImage(pubNO);
  108. for (Image image : imageInfo.getImages()) {
  109. //如果附件类型是说明书
  110. if (image.getImageType().equals("FullDocument")) {
  111. fullDocumentLink = image.getUrlLink();
  112. fullDocumentPage = image.getNumberOfPages();
  113. for (String formatOption : image.getFormatOptions()) {
  114. if (formatOption.contains("pdf")) {
  115. fullDocumentType = formatOption;
  116. }
  117. }
  118. }
  119. //如果附件类型是其他附件
  120. if (image.getImageType().equals("Drawing")) {
  121. drawingLink = image.getUrlLink();
  122. drawingPage = image.getNumberOfPages();
  123. for (String formatOption : image.getFormatOptions()) {
  124. if (formatOption.contains("tiff")) {
  125. drawingType = formatOption;
  126. }
  127. }
  128. }
  129. //如果附件类型是摘要附图
  130. if (image.getImageType().equals("FirstPageClipping")) {
  131. firstPageClippingLink = image.getUrlLink();
  132. firstPageClippingPage = image.getNumberOfPages();
  133. for (String formatOption : image.getFormatOptions()) {
  134. if (formatOption.contains("jpeg")) {
  135. firstPageClippingType = formatOption;
  136. }
  137. }
  138. }
  139. }
  140. //装载说明书pdf
  141. if (cells.contains("4")) {
  142. setFuJian(fullDocumentLink, fullDocumentPage, fullDocumentType, patentCell, ".pdf");
  143. }
  144. //装载摘要附图
  145. if (cells.contains("6")) {
  146. setFuJian(firstPageClippingLink, firstPageClippingPage, firstPageClippingType, patentCell, ".jpeg");
  147. }
  148. //装载其他附图
  149. if (cells.contains("7")) {
  150. setFuJian(drawingLink, drawingPage, drawingType, patentCell, ".tiff");
  151. }
  152. //先将部分入库,再将其余扔给消费者来入库(消费者方更改任务状态发送进度通知)
  153. if (patentCell.getPatentNo() != null) {
  154. UploadParamsVO uploadParamsVO = new UploadParamsVO();
  155. Patent patent2 = new Patent();
  156. //设置专利号
  157. patent2.setPatentNo(patentCell.getPatentNo());
  158. //设置摘要
  159. patent2.setAbstractStr(patentCell.getAbstrText());
  160. //设置标题
  161. patent2.setName(patentCell.getTitle());
  162. //设置公开日
  163. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  164. if (patentCell.getPubilcDate() != null) {
  165. Date date = simpleDateFormat.parse(patentCell.getPubilcDate());
  166. Integer ts = (int) date.getTime();
  167. patent2.setPublicDate(ts);
  168. }
  169. //设置申请号
  170. patent2.setApplicationNo(patentCell.getApplicationNo());
  171. //设置申请日
  172. if (patentCell.getApplicationDate() != null) {
  173. Date date = simpleDateFormat.parse(patentCell.getApplicationDate());
  174. Integer ts = (int) date.getTime();
  175. patent2.setApplicationDate(ts);
  176. }
  177. //设置摘要附图
  178. patent2.setAbstractPath(patentCell.getPicUrl());
  179. //设置pdf文档
  180. if (patentCell.getPdf() != null) {
  181. patentInstructionService.edit(patentCell.getPatentNo(), patentCell.getPdf());
  182. }
  183. //设置公开号
  184. patent2.setPublicNo(patentCell.getPublicNo());
  185. uploadParamsVO.setSimpleStatus(patentCell.getStatue());
  186. uploadParamsVO.setPatent(patent2);
  187. getOneOrInsertOne(uploadParamsVO);
  188. //摘要附图上传专利附图表"os_patent_img"根据专利id删除该专利的摘要图片数据,以免上传重复
  189. patentImageService.deleteByPatentIdAndStatus(uploadParamsVO.getPatent().getId(), 1);
  190. PatentImage patentImage = new PatentImage();
  191. patentImage.setStatus(1);
  192. patentImage.setPatentId(uploadParamsVO.getPatent().getId());
  193. patentImage.setUrl(patentCell.getPicUrl());
  194. patentImage.setFileName(patentCell.getFileName());
  195. //摘要附图数据入库
  196. patentImage.insert();
  197. if (patentCell.getAgency() != null && !patentCell.getAgency().equals("")) {
  198. uploadParamsVO.getPatent().setAgencyId(patentAgencyService.getAgencyStringIdByName(patentCell.getAgency()));
  199. }
  200. uploadParamsVO.setPatentRight(new PatentRight());
  201. uploadParamsVO.getPatentRight().setContent(StringUtils.join(patentCell.getRights(), ""));
  202. uploadParamsVO.setSelfContent(patentCell.getMainRignt());
  203. uploadParamsVO.setPatentInstructionText(new PatentInstructionText());
  204. uploadParamsVO.getPatentInstructionText().setManual(patentCell.getPatentInstructionText());
  205. //发明人
  206. List<String> inventors = patentCell.getInventors();
  207. if (inventors != null && inventors.size() > 0) {
  208. ArrayList<PatentInventor> patentInventors = new ArrayList<>();
  209. for (String inventor : inventors) {
  210. PatentInventor patentInventor = new PatentInventor();
  211. patentInventor.setName(inventor);
  212. patentInventors.add(patentInventor);
  213. }
  214. uploadParamsVO.setPatentInventorList(patentInventors);
  215. }
  216. uploadParamsVO.setPatentApplicantCurrentName(patentCell.getApplicationCurrents());
  217. uploadParamsVO.setPatentApplicantOriginalName(patentCell.getApplicationPersons());
  218. uploadParamsVO.setPatentApplicantOriginalAddress(patentCell.getApplicationAddress());
  219. uploadParamsVO.setIpcList(patentCell.getIpc());
  220. uploadParamsVO.setMainIpc(patentCell.getMainIpc());
  221. //代理人
  222. List<String> agencyPersons = patentCell.getAgencyPersons();
  223. if (agencyPersons != null && agencyPersons.size() > 0) {
  224. ArrayList<PatentAgent> patentAgents = new ArrayList<>();
  225. for (String agencyPerson : agencyPersons) {
  226. PatentAgent patentAgent = new PatentAgent();
  227. patentAgent.setName(agencyPerson);
  228. patentAgents.add(patentAgent);
  229. }
  230. uploadParamsVO.setPatentAgentList(patentAgents);
  231. }
  232. //事务信息 OS_PATENT_AFFAIR
  233. if (patentCell.getPatentAffairs() != null && patentCell.getPatentAffairs().size() > 0) {
  234. patentAffairService.updatePatientAffairs(patentCell.getPatentAffairs(), uploadParamsVO.getPatent().getId());
  235. }
  236. //当专题库id不为null时添加专利到专题库
  237. if (patentCell.getProjectId() != null) {
  238. projectPatentLinkService.updateProjectPatent(patentCell.getProjectId(), uploadParamsVO.getPatent().getId());
  239. }
  240. pantentQueueService.patentToQueue(task, uploadParamsVO);
  241. }
  242. } catch (XiaoShiException e) {
  243. //虽然拿不到所有附图,但已经拿到了专利著录,能拿到啥是啥
  244. log.info(e.getMessage());
  245. } catch (Exception e) {
  246. }
  247. }
  248. }
  249. }
  250. //调用外部接口获取一批专利著录信息
  251. public SerachBiblioData getSerachBiblioData(String conditions, Integer start, Integer size) throws IOException {
  252. GetSearchBiblioParamsDTO getSearchBiblioParamsDTO = new GetSearchBiblioParamsDTO()
  253. .setQuery(conditions)
  254. .setStart(start)
  255. .setEnd(size);
  256. String res = outInterfaceService.getSearchBiblio(getSearchBiblioParamsDTO);
  257. if (res == null || res.equals("")) {
  258. return null;
  259. }
  260. JSONObject jsonObject = JSONObject.parseObject(res);
  261. if (!jsonObject.get("status").toString().equals("200")) {
  262. //若发生类似400、500等异常(杰哥处理)
  263. return null;
  264. }
  265. //返回检索结果data
  266. return JSONObject.parseObject(jsonObject.get("data").toString(), SerachBiblioData.class);
  267. }
  268. /**
  269. * 装载著录方法
  270. *
  271. * @param patentCell 实体类对象
  272. * @param patent 专利对象
  273. * @param pubNo 公开号对象
  274. */
  275. private void setPatentZhuLu(PatentCell patentCell, PatentZhuLu patent, PubNo pubNo) {
  276. //装载申请号
  277. for (AppNo appNo : patent.getAppNos()) {
  278. if (appNo.getType().equals("docdb")) {
  279. patentCell.setApplicationNo(appNo.getCountry() + appNo.getNumber() + appNo.getKind());
  280. }
  281. }
  282. //装载申请日
  283. patentCell.setApplicationDate(patent.getAppDate());
  284. //装载国家/省市
  285. patentCell.setCountry(patent.getAppCountry());
  286. //装载公开号
  287. for (PubNo n : patent.getPubNos()) {
  288. if (n.getType().equals("docdb")) {
  289. BeanUtils.copyProperties(n, pubNo);
  290. patentCell.setPublicNo(n.getCountry() + n.getNumber() + n.getKind());
  291. }
  292. }
  293. //装载专利号
  294. patentCell.setPatentNo(patentCell.getPublicNo());
  295. //装载公开日
  296. patentCell.setPubilcDate(patent.getPubDate());
  297. //装载授权公告号(未找到)
  298. //装载授权公告日(未找到)
  299. //装载主分类号
  300. List<String> ipCs = patent.getIpCs();
  301. List<String> cpCs = patent.getCpCs();
  302. ipCs.addAll(cpCs);
  303. if (ipCs != null && ipCs.size() > 0) {
  304. patentCell.setMainIpc(ipCs.get(0));
  305. }
  306. //装载分类号
  307. if (ipCs != null && ipCs.size() > 0) {
  308. patentCell.setIpc(ipCs);
  309. }
  310. //装载申请人
  311. ArrayList<String> applicationPersons = new ArrayList<>();
  312. for (Application application : patent.getApplications()) {
  313. if (application.getOriginalName().contains("(标:)")) {
  314. application.setOriginalName(application.getOriginalName().substring(0, application.getOriginalName().indexOf("(标:)")));
  315. }
  316. applicationPersons.add(application.getOriginalName());
  317. }
  318. patentCell.setApplicationPersons(applicationPersons);
  319. //装载申请人地址(未找到)
  320. //装载发明人
  321. ArrayList<String> inventors = new ArrayList<>();
  322. for (Inventor inventor : patent.getInventors()) {
  323. inventors.add(inventor.getOriginalName());
  324. }
  325. patentCell.setInventors(inventors);
  326. //装载当前权利人(未找到)
  327. //装载代理人(未找到)
  328. //装载代理机构(未找到)
  329. //装载范畴分类(未找到)
  330. //装载当前状态(未找到)
  331. //装载同族号
  332. patentCell.setFamilyId(patent.getFamilyId());
  333. //装载著录标题
  334. String olTitle = patent.getOlTitle();
  335. String enTitle = patent.getEnTitle();
  336. if (olTitle == null) {
  337. patentCell.setTitle(enTitle);
  338. } else {
  339. patentCell.setTitle(olTitle);
  340. }
  341. //装载摘要
  342. String olAbstract = patent.getOlAbstract();
  343. String enAbstract = patent.getEnAbstract();
  344. if (olAbstract == null) {
  345. patentCell.setAbstrText(enAbstract);
  346. } else {
  347. patentCell.setAbstrText(olAbstract);
  348. }
  349. //装载优先权号、优先权国家、优先权日
  350. ArrayList<Priority> priorities = new ArrayList<>();
  351. List<Priorityy> priorties = patent.getPriorties();
  352. for (Priorityy priorty : priorties) {
  353. for (PriorityNumber number : priorty.getNumbers()) {
  354. if (number.getType().equals("epodoc")) {
  355. Priority priority = new Priority()
  356. .setPriorityNo(number.getNumber().substring(2))
  357. .setPriorityCountry(number.getNumber().substring(0, 2))
  358. .setPriorityDate(priorty.getDate());
  359. priorities.add(priority);
  360. }
  361. }
  362. }
  363. patentCell.setPriorities(priorities);
  364. }
  365. /**
  366. * 装载权要方法
  367. *
  368. * @param patentCell 实体类对象
  369. * @param pubNo 公开号对象
  370. */
  371. private void setPatentClaim(PatentCell patentCell, PubNo pubNo) throws IOException {
  372. GetClaimsInfoParamsDTO getClaimsInfoParamsDTO = new GetClaimsInfoParamsDTO()
  373. .setCc(pubNo.getCountry())
  374. .setNumber(pubNo.getNumber())
  375. .setKind(pubNo.getKind());
  376. String res = outInterfaceService.getClaimsInfo(getClaimsInfoParamsDTO);
  377. JSONObject jsonObject = JSONObject.parseObject(res);
  378. if (!jsonObject.get("status").toString().equals("200")) {
  379. //若发生类似400、500等异常(杰哥处理)
  380. //ThrowException.throwXiaoShiException("权要接口无法检索该国家专利");
  381. log.info("权要接口无法检索该国家专利");
  382. return;
  383. }
  384. //拿到检索结果(未格式化的含有页面等标签的权要)并格式化权要
  385. //String unformatRight = JSONObject.parseObject(jsonObject.get("data").toString(), String.class);
  386. ArrayList<String> unformatRights = JSONObject.parseObject(jsonObject.get("data").toString(), ArrayList.class);
  387. //String[] rightArr = unformatRight.split("\n");
  388. //ArrayList<String> rights = new ArrayList<>(Arrays.asList(rightArr));
  389. patentCell.setRights(unformatRights);
  390. }
  391. /**
  392. * 装载说明书方法
  393. *
  394. * @param patentCell 实体类对象
  395. * @param pubNo 公开号对象
  396. */
  397. private void setPatentInstructionText(PatentCell patentCell, PubNo pubNo) throws IOException {
  398. GetDescriptionInfoParamsDTO getDescriptionInfoParamsDTO = new GetDescriptionInfoParamsDTO()
  399. .setCc(pubNo.getCountry())
  400. .setNumber(pubNo.getNumber())
  401. .setKind(pubNo.getKind());
  402. String res = outInterfaceService.getDescriptionInfo(getDescriptionInfoParamsDTO);
  403. JSONObject jsonObject = JSONObject.parseObject(res);
  404. if (!jsonObject.get("status").toString().equals("200")) {
  405. //若发生类似400、500等异常(杰哥处理)
  406. //ThrowException.throwXiaoShiException("说明书接口无法检索该国家专利");
  407. log.info("说明书接口无法检索该国家专利");
  408. return;
  409. }
  410. //拿到检索结果(未格式化的含有页面等标签的说明书)
  411. //String unformatInstructionText = JSONObject.parseObject(jsonObject.get("data").toString(), String.class);
  412. List<String> unformatInstructionText = JSONObject.parseObject(jsonObject.get("data").toString(), List.class);
  413. StringBuilder builder = new StringBuilder();
  414. for (String n : unformatInstructionText) {
  415. builder.append(n);
  416. }
  417. // String regex = "<p>(.+?)</p>";
  418. // Matcher matcher = Pattern.compile(regex).matcher(unformatInstructionText);
  419. // if (matcher.find()) {
  420. // patentCell.setPatentInstructionText(matcher.group());
  421. // }
  422. patentCell.setPatentInstructionText(builder + "");
  423. }
  424. /**
  425. * 获取Image信息方法(从信息中获取三种附图的检索参数)
  426. *
  427. * @param pubNo 公开号对象
  428. */
  429. private ImageInfo getImage(PubNo pubNo) throws IOException {
  430. String res = outInterfaceService.getImagesInfo(pubNo);
  431. JSONObject jsonObject = JSONObject.parseObject(res);
  432. if (!jsonObject.get("status").toString().equals("200")) {
  433. //若发生类似400、500等异常(杰哥处理)
  434. ThrowException.throwXiaoShiException("Image信息接口无法检索该国家专利");
  435. }
  436. //拿到检索结果(未格式化的含有页面等标签的说明书)
  437. String unFormatData = jsonObject.get("data").toString();
  438. String data = unFormatData.substring(unFormatData.indexOf("[") + 1, unFormatData.lastIndexOf("]"));
  439. ImageInfo imageInfo = JSONObject.parseObject(data, ImageInfo.class);
  440. return imageInfo;
  441. }
  442. /**
  443. * 装载说明书附件pdf方法
  444. *
  445. * @param link 附件链接
  446. * @param page 附件页数
  447. * @param type 附件类型
  448. * @param patentCell 实体类对象
  449. */
  450. private void setFuJian(String link, Integer page, String type, PatentCell patentCell, String FuJianSuffix) throws Exception {
  451. //合并说明书pdf文档时所需的读取流数组
  452. InputStream[] streams = new InputStream[page];
  453. //其他附图url数组
  454. ArrayList<String> otherUrls = new ArrayList<>();
  455. //遍历附件页数
  456. for (int i = 1; i <= page; i++) {
  457. GetFuTuParamsDTO getFuTuParamsDTO = new GetFuTuParamsDTO()
  458. .setLink(link)
  459. .setPage(i)
  460. .setType(type);
  461. byte[] buffer = outInterfaceService.getPatentFile(getFuTuParamsDTO);
  462. InputStream inputStream = new ByteArrayInputStream(buffer);
  463. streams[i - 1] = inputStream;
  464. //如果不是说明书pdf
  465. if (!FuJianSuffix.equals(".pdf")) {
  466. File file = File.createTempFile("new_url", FuJianSuffix);
  467. FileOutputStream out = new FileOutputStream(file);
  468. out.write(buffer);
  469. out.close();
  470. streams[i - 1] = new FileInputStream(file);
  471. DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
  472. FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
  473. int bytesRead = 0;
  474. buffer = new byte[8192];
  475. try {
  476. FileInputStream fis = new FileInputStream(file);
  477. OutputStream os = item.getOutputStream();
  478. int len = 8192;
  479. while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
  480. os.write(buffer, 0, bytesRead);
  481. }
  482. os.close();
  483. fis.close();
  484. } catch (IOException e) {
  485. e.printStackTrace();
  486. }
  487. MultipartFile multipartFile = new CommonsMultipartFile(item);
  488. UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
  489. //如果是摘要附图
  490. if (FuJianSuffix.equals(".jpeg")) {
  491. patentCell.setPicUrl(fileDTO.getPath());
  492. patentCell.setFileName(fileDTO.getFileName());
  493. }
  494. //如果是其他附图
  495. if (FuJianSuffix.equals(".tiff")) {
  496. otherUrls.add(fileDTO.getPath());
  497. }
  498. }
  499. }
  500. //如果是说明书pdf
  501. if (FuJianSuffix.equals(".pdf")) {
  502. //合并说明书多个pdf文件
  503. PdfDocumentBase doc = PdfDocument.mergeFiles(streams);
  504. //保存结果文件
  505. doc.save("merge.pdf", FileFormat.PDF);
  506. doc.close();
  507. //手动将合并后的pdf文件转成MultipartFile,上传文件并获取path装载到patentCell
  508. File file = new File("merge.pdf");
  509. DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
  510. FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
  511. int bytesRead = 0;
  512. byte[] buffer = new byte[8192];
  513. try {
  514. FileInputStream fis = new FileInputStream(file);
  515. OutputStream os = item.getOutputStream();
  516. int len = 8192;
  517. while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
  518. os.write(buffer, 0, bytesRead);
  519. }
  520. os.close();
  521. fis.close();
  522. } catch (IOException e) {
  523. e.printStackTrace();
  524. }
  525. MultipartFile multipartFile = new CommonsMultipartFile(item);
  526. UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
  527. patentCell.setPdf(fileDTO);
  528. } else if (FuJianSuffix.equals(".tiff")) {
  529. patentCell.setOtherUrls(otherUrls);
  530. }
  531. }
  532. /**
  533. * @param uploadParamsVO 全局类
  534. * @date 2022-7-11
  535. * @name 工具方法
  536. * @description 查询数据是否存在 如果存在 返回该条数据 如果不存在 新增一条数据
  537. */
  538. public void getOneOrInsertOne(UploadParamsVO uploadParamsVO) {
  539. if (uploadParamsVO.getPatent() != null) {
  540. uploadParamsVO.getPatent().setPatentNo(uploadParamsVO.getPatent().getPatentNo().trim());
  541. //用专利号查询该条数据是否存在
  542. Patent patent = patentService.getByPatentNo(uploadParamsVO.getPatent().getPatentNo());
  543. //如果不存在就新增一条
  544. if (patent == null) {
  545. uploadParamsVO.getPatent().insert();
  546. } else {
  547. uploadParamsVO.getPatent().setId(patent.getId());
  548. }
  549. }
  550. }
  551. public void setTaskStatus(Integer taskId, Integer taskStatus) {
  552. this.pTaskId = taskId;
  553. this.pTaskStatus = taskStatus;
  554. }
  555. }