ExcutePatentDataEpo.java 27 KB

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