ExcutePatentDataStar.java 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. package cn.cslg.pas.service.upLoadPatent;
  2. import cn.cslg.pas.common.model.dto.PatentDTO;
  3. import cn.cslg.pas.common.model.dto.UploadFileDTO;
  4. import cn.cslg.pas.common.model.outApi.PatentStarListDto;
  5. import cn.cslg.pas.common.model.vo.KeyValueVO;
  6. import cn.cslg.pas.common.model.vo.UploadParamsVO;
  7. import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
  8. import cn.cslg.pas.common.utils.FileUtils;
  9. import cn.cslg.pas.common.utils.RemoveHtmlTagsUtils;
  10. import cn.cslg.pas.common.utils.ThrowException;
  11. import cn.cslg.pas.domain.*;
  12. import cn.cslg.pas.domain.asso.TaskCondition;
  13. import cn.cslg.pas.service.TaskService;
  14. import cn.cslg.pas.service.UploadPatentBatchService;
  15. import cn.cslg.pas.service.asso.TaskConditionService;
  16. import cn.cslg.pas.service.getPatentStarPart.GetPatentStarPartService;
  17. import cn.cslg.pas.service.outApi.PatentStarApiService;
  18. import com.alibaba.fastjson.JSON;
  19. import com.alibaba.fastjson2.JSONObject;
  20. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  21. import lombok.RequiredArgsConstructor;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.commons.fileupload.FileItem;
  24. import org.apache.commons.fileupload.disk.DiskFileItemFactory;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import org.springframework.web.multipart.commons.CommonsMultipartFile;
  29. import java.io.*;
  30. import java.net.MalformedURLException;
  31. import java.net.URL;
  32. import java.text.ParseException;
  33. import java.text.SimpleDateFormat;
  34. import java.util.*;
  35. import java.util.regex.Matcher;
  36. import java.util.regex.Pattern;
  37. import java.util.stream.Collectors;
  38. /**
  39. * 专利之星类型任务解析获取专利类
  40. *
  41. * @Author chenyu
  42. * @Date 2023/6/25
  43. */
  44. @Slf4j
  45. @RequiredArgsConstructor
  46. @Service
  47. public class ExcutePatentDataStar implements IExcutePatentData {
  48. private final PatentStarApiService patentStarApiService;
  49. private final FileUtils fileUtils;
  50. private final PantentQueueService pantentQueueService;
  51. private final UploadPatentBatchService uploadPatentBatchService;
  52. private final TaskService taskService;
  53. private final TaskConditionService taskConditionService;
  54. private final QuestionRecordService questionRecordService;
  55. private Integer pTaskId = 0;
  56. private Integer pTaskStatus = 0;
  57. /**
  58. * 解析获取专利数据
  59. *
  60. * @param task 任务
  61. */
  62. @Override
  63. public void startExcute(Task task) throws IOException {
  64. //若本次下载任务是超过一万条专利的全部下载任务
  65. int patentNum = 10000;
  66. if (task.getEndNumber() > patentNum) {
  67. try {
  68. Integer total = task.getTotal(); //任务专利总数量
  69. Integer successNum = task.getSuccessNum();
  70. String orderBy = task.getOrderBy(); //排序字段
  71. String orderByType = task.getOrderByType(); //排序类型
  72. String dbType = task.getDBType(); //检索数据库类型
  73. List<String> cells = task.getConfigCells(); //下载字段
  74. Integer startNumber = task.getStartNumber(); //下载起始条数位置
  75. List<String> isDeletePatentNos = task.getIsDeletePatentNos(); //起止条数中不需要下载的专利号
  76. //如果完成数量大于0,则当前下载任务为暂停后的继续下载,则开始位置更新
  77. if (successNum > 0) {
  78. startNumber += successNum;
  79. }
  80. //获得返回的的多个检索式 patentStarListDtos
  81. List<PatentStarListDto> patentStarListDtos = patentStarApiService.getSplitedConditions(new PatentStarListDto()
  82. .setCurrentQuery(task.getConditions())
  83. .setOrderBy(orderBy)
  84. .setOrderByType(orderByType)
  85. .setDBType(dbType), patentNum);
  86. int produceSuccessNum = 0;
  87. int countForStart = 0; //定义变量countForStart,记录检索式的专利总数量(目的是找出下载开始位置专利所属的那个检索式)
  88. //第1层:遍历多个检索式
  89. for (PatentStarListDto patentStarListDto : patentStarListDtos) {
  90. //还没有到开始位置,则跳过,继续判断下一个检索式
  91. countForStart += patentStarListDto.getTotal();
  92. if (countForStart < startNumber) {
  93. continue;
  94. }
  95. //至此,即找到了当前检索式即为要下载的专利开始位置所属的检索式,重新计算开始位置startNumber(即要下载的专利的开始位置,对应了当前检索式中该专利位置)
  96. startNumber = startNumber - (countForStart - patentStarListDto.getTotal());
  97. //第一个检索式下载完成后,从第二个检索式开始 startNumber都是从1开始下载
  98. if (startNumber < 0) {
  99. startNumber = 1;
  100. }
  101. //调用方法,入参为开始位置和结束位置(即当前检索式最后一个专利的位置,即当前检索式的专利总数量total),获得开始页数、结束页数、开始页数的开始位置、结束页数的结束位置
  102. Calculate calculate = calculateFromStartAndEndNumber(startNumber, patentStarListDto.getTotal());
  103. Integer startPage = calculate.getStartPage();
  104. Integer startNum = calculate.getStartNum();
  105. Integer endPage = calculate.getEndPage();
  106. //第2层:遍历检索页数
  107. for (Integer i = startPage; i <= endPage; i++) {
  108. //调用一般检索接口,返回一批专利著录相关数据
  109. patentStarListDto
  110. .setPageNum(i)
  111. .setRowCount(50)
  112. .setFormed(true);
  113. Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
  114. if (resultMap == null || (Integer) resultMap.get("total") == 0) {
  115. ThrowException.throwXiaoShiException("未检索到相关专利");
  116. }
  117. List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
  118. //第3层:遍历专利
  119. for (int j = 0; j < starPatents.size(); j++) {
  120. //若任务状态为已暂停,则结束本次任务的下载
  121. if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
  122. return;
  123. }
  124. //若生产的数量达到了总数,则结束本次任务的下载
  125. if (produceSuccessNum == total) {
  126. return;
  127. }
  128. //如果还没到要下载的专利的开始位置,则跳过,继续判断下一个专利
  129. if (i.equals(startPage) && j < startNum - 1) {
  130. continue;
  131. }
  132. //如果当前遍历到的专利号是需要删除的专利,则跳过,不下载它
  133. if (isDeletePatentNos != null && isDeletePatentNos.size() > 0 && isDeletePatentNos.contains(starPatents.get(j).getApplicationNo())) {
  134. continue;
  135. }
  136. //将专利丢入各生产线程,进行生产和消费
  137. UploadParamsVO uploadParamsVO = new UploadParamsVO();
  138. uploadParamsVO.setPatent(new Patent());
  139. uploadParamsVO.getPatent().setPatentNo(starPatents.get(j).getPatentNo());
  140. uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
  141. PQueueData pQueueData = new PQueueData()
  142. .setTask(task)
  143. .setStarPatent(starPatents.get(j))
  144. .setUploadParamsVO(uploadParamsVO);
  145. //专利丢入著录生产者队列,并唤醒著录生产者线程
  146. if (cells.contains("1")) {
  147. pantentQueueService.zhuluToPQueue(pQueueData);
  148. }
  149. //专利丢入权要生产者队列,并唤醒权要生产者线程
  150. if (cells.contains("2")) {
  151. pantentQueueService.rightToPQueue(pQueueData);
  152. }
  153. //专利丢入说明书文本生产者队列,并唤醒说明书文本生产者线程
  154. if (cells.contains("3")) {
  155. pantentQueueService.instructionTextToPQueue(pQueueData);
  156. }
  157. //专利丢入说明书pdf生产者队列,并唤醒说明书pdf生产者线程
  158. if (cells.contains("4")) {
  159. pantentQueueService.instructionPDFToPQueue(pQueueData);
  160. }
  161. //专利丢入摘要附图生产者队列,并唤醒摘要附图生产者线程
  162. if (cells.contains("6")) {
  163. pantentQueueService.imageToPQueue(pQueueData);
  164. }
  165. produceSuccessNum++; //计数,每生产完一个,生产完成数量++
  166. }
  167. }
  168. }
  169. } catch (IOException e) {
  170. e.printStackTrace();
  171. //生产消费到一半时,发生错误异常,将任务状态置为完成
  172. task = taskService.getById(task.getId());
  173. if (task.getStatus().equals(1)) {
  174. task.setStatus(2);
  175. taskService.updateById(task);
  176. }
  177. }
  178. } else {
  179. excuteLessThan10000(task);
  180. }
  181. }
  182. private void excuteLessThan10000(Task task) {
  183. try {
  184. Integer successNum = task.getSuccessNum(); //成功条数(即上一次下载到的位置)
  185. String conditions = task.getConditions(); //检索式
  186. String orderBy = task.getOrderBy(); //排序字段
  187. String orderByType = task.getOrderByType(); //排序类型
  188. String dbType = task.getDBType(); //检索数据库类型
  189. List<String> cells = task.getConfigCells(); //下载字段
  190. Integer startNumber = task.getStartNumber(); //下载起始条数位置
  191. Integer endNumber = task.getEndNumber(); //下载终止条数位置
  192. List<String> isAddPatentNos = task.getIsAddPatentNos(); //需要额外下载的专利号
  193. List<String> isDeletePatentNos = task.getIsDeletePatentNos(); //起止条数中不需要下载的专利号
  194. //startToEndNum:起止条数中需要下载的专利总数量
  195. int startToEndNum = 0;
  196. if (endNumber > 0) {
  197. startToEndNum = endNumber - startNumber + 1;
  198. if (isDeletePatentNos != null && isDeletePatentNos.size() > 0) {
  199. startToEndNum = startToEndNum - isDeletePatentNos.size();
  200. }
  201. }
  202. //如果完成数量大于0,则当前下载任务为暂停后的继续下载,则开始位置更新
  203. if (successNum > 0) {
  204. if (startNumber == null) { //多个专利号导入任务没有startNumber这些值
  205. startNumber = 0;
  206. }
  207. startNumber += successNum;
  208. }
  209. //若有起止条数,并且完成条数在起止条数内(即起止条数中专利还没有下载完)
  210. if (endNumber > 0 && startNumber <= endNumber && successNum < startToEndNum) {
  211. Calculate calculate = calculateFromStartAndEndNumber(startNumber, endNumber);
  212. Integer startPage = calculate.getStartPage();
  213. Integer startNum = calculate.getStartNum();
  214. Integer endPage = calculate.getEndPage();
  215. Integer endNum = calculate.getEndNum();
  216. //根据计算出的起止页数,一页一页检索
  217. for (int i = startPage; i <= endPage; i++) {
  218. PatentStarListDto patentStarListDto = new PatentStarListDto()
  219. .setCurrentQuery(conditions)
  220. .setOrderBy(orderBy)
  221. .setOrderByType(orderByType)
  222. .setPageNum(i)
  223. .setRowCount(50)
  224. .setDBType(dbType);
  225. //调用一般接口返回一批专利著录相关数据
  226. Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
  227. if (resultMap == null || (Integer) resultMap.get("total") == 0) {
  228. ThrowException.throwXiaoShiException("未检索到相关专利");
  229. }
  230. List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
  231. //遍历这一页的专利
  232. for (int j = 0; j < starPatents.size(); j++) {
  233. //若任务状态为已暂停,则结束生产
  234. if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
  235. return;
  236. }
  237. //若还没到开始页的开始位置,则跳过,不下载它
  238. if (i == startPage && j < startNum - 1) {
  239. continue;
  240. }
  241. //若到了结束页的结束位置
  242. if (i == endPage && j == endNum) {
  243. break;
  244. }
  245. //若当前遍历到的专利号是需要删除的专利,则跳过,不下载它
  246. if (isDeletePatentNos != null && isDeletePatentNos.size() > 0 && isDeletePatentNos.contains(starPatents.get(j).getApplicationNo())) {
  247. continue;
  248. }
  249. //将专利丢入各生产线程,进行生产和消费
  250. UploadParamsVO uploadParamsVO = new UploadParamsVO();
  251. uploadParamsVO.setPatent(new Patent());
  252. uploadParamsVO.getPatent().setPatentNo(starPatents.get(j).getPatentNo());
  253. uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
  254. PQueueData pQueueData = new PQueueData()
  255. .setTask(task)
  256. .setStarPatent(starPatents.get(j))
  257. .setUploadParamsVO(uploadParamsVO);
  258. //专利丢入著录生产者队列,并唤醒著录生产者线程
  259. if (cells.contains("1")) {
  260. pantentQueueService.zhuluToPQueue(pQueueData);
  261. }
  262. //专利丢入权要生产者队列,并唤醒权要生产者线程
  263. if (cells.contains("2")) {
  264. pantentQueueService.rightToPQueue(pQueueData);
  265. }
  266. //专利丢入说明书文本生产者队列,并唤醒说明书文本生产者线程
  267. if (cells.contains("3")) {
  268. pantentQueueService.instructionTextToPQueue(pQueueData);
  269. }
  270. //专利丢入说明书pdf生产者队列,并唤醒说明书pdf生产者线程
  271. if (cells.contains("4")) {
  272. pantentQueueService.instructionPDFToPQueue(pQueueData);
  273. }
  274. //专利丢入摘要附图生产者队列,并唤醒摘要附图生产者线程
  275. if (cells.contains("6")) {
  276. pantentQueueService.imageToPQueue(pQueueData);
  277. }
  278. }
  279. }
  280. }
  281. //下载isAdd中的专利 / 下载多个专利号导入接口的专利 ↓
  282. if (isAddPatentNos != null && isAddPatentNos.size() > 0) {
  283. //判断isAdd中的多个专利号或申请号,即判断是检索页面手动勾选的多个专利下载/还是多个专利号导入的下载任务
  284. if (task.getIsAddType() != null && task.getIsAddType().equals(2)) {
  285. //若是多个专利号导入的下载
  286. String patentNoCondition = StringUtils.join(isAddPatentNos, " OR ");
  287. conditions = "AN=(" + patentNoCondition + ") OR PN=(" + patentNoCondition + ") OR GN=(" + patentNoCondition + ")";
  288. downLoadIsAddPatentNos(isAddPatentNos, task, orderBy, orderByType, dbType, cells, conditions);
  289. } else {
  290. //若是检索页面手动勾选的多个专利的下载
  291. downLoadIsAddPatentNos(isAddPatentNos, task, orderBy, orderByType, dbType, cells, null);
  292. }
  293. }
  294. } catch (IOException e) {
  295. e.printStackTrace();
  296. //生产消费到一半时,发生错误异常,将任务状态置为完成
  297. task = taskService.getById(task.getId());
  298. if (task.getStatus().equals(1)) {
  299. task.setStatus(2);
  300. taskService.updateById(task);
  301. }
  302. }
  303. }
  304. /**
  305. * 装载著录方法
  306. *
  307. * @param starPatent 专利之星著录对象
  308. * @param uploadParamsVO 专利实体类对象
  309. */
  310. public void setPatentZhuLu(StarPatentVO starPatent, UploadParamsVO uploadParamsVO) throws IOException {
  311. String usedPatentNo;
  312. if (starPatent.getPublicNo() != null && !starPatent.getPublicNo().equals("")) {
  313. usedPatentNo = starPatent.getPublicNo();
  314. } else {
  315. usedPatentNo = starPatent.getPatentNo();
  316. }
  317. //以下 ↓装载的是调用"一般检索"接口返回的专利相关数据
  318. //装载专利类型
  319. Integer patentType = starPatent.getPatentType();
  320. if (patentType != null) {
  321. if (patentType.equals(2) || patentType.equals(9)) {
  322. uploadParamsVO.getPatent().setType(1); //实用新型
  323. } else if (patentType.equals(1) || patentType.equals(8)) {
  324. uploadParamsVO.getPatent().setType(2); //发明
  325. } else if (patentType.equals(3)) {
  326. uploadParamsVO.getPatent().setType(3); //外观设计
  327. }
  328. }
  329. //装载申请人地址
  330. if (starPatent.getApplicationAddress() != null && !starPatent.getApplicationAddress().equals("")) {
  331. ArrayList<String> patentApplicantOriginalAddresss = new ArrayList<>();
  332. patentApplicantOriginalAddresss.add(starPatent.getApplicationAddress());
  333. uploadParamsVO.setPatentApplicantOriginalAddress(patentApplicantOriginalAddresss);
  334. }
  335. //装载IPC分类号
  336. if (starPatent.getIpcListStr() != null && !starPatent.getIpcListStr().equals("")) {
  337. String[] ipcArr = starPatent.getIpcListStr().split(";");
  338. //装载主分类号
  339. //uploadParamsVO.setMainIpc(ipcArr[0]);
  340. uploadParamsVO.setMainIpc(starPatent.getMainIpc());
  341. uploadParamsVO.setIpcList(Arrays.asList(ipcArr));
  342. }
  343. //装载公告日(公开授权日)
  344. if (starPatent.getPublicAccreditDate() != null && !starPatent.getPublicAccreditDate().equals("")) {
  345. int timeStamp = stringDateToTimeStamp(starPatent.getPublicAccreditDate());
  346. uploadParamsVO.getPatent().setPublicAccreditDate(timeStamp);
  347. }
  348. //装载摘要
  349. if (starPatent.getAbstractStr() != null && !starPatent.getAbstractStr().equals("")) {
  350. uploadParamsVO.getPatent().setAbstractStr(starPatent.getAbstractStr());
  351. }
  352. //装载申请日
  353. if (starPatent.getApplicationDate() != null && !starPatent.getApplicationDate().equals("")) {
  354. int timeStamp = stringDateToTimeStamp(starPatent.getApplicationDate());
  355. uploadParamsVO.getPatent().setApplicationDate(timeStamp);
  356. }
  357. //装载发明人
  358. if (starPatent.getInventorStr() != null && !starPatent.getInventorStr().equals("")) {
  359. List<String> patentInventorNames = Arrays.asList(starPatent.getInventorStr().split(";"));
  360. ArrayList<PatentInventor> patentInventors = new ArrayList<>();
  361. for (String patentInventorName : patentInventorNames) {
  362. PatentInventor patentInventor = new PatentInventor();
  363. patentInventor.setName(patentInventorName);
  364. patentInventors.add(patentInventor);
  365. }
  366. uploadParamsVO.setPatentInventorList(patentInventors);
  367. }
  368. //装载专利号
  369. if (starPatent.getPatentNo() != null && !starPatent.getPatentNo().equals("")) {
  370. uploadParamsVO.getPatent().setPatentNo(starPatent.getPatentNo());
  371. }
  372. //装载授权号(公开授权日)
  373. if (starPatent.getPublicAccreditNo() != null && !starPatent.getPublicAccreditNo().equals("")) {
  374. uploadParamsVO.getPatent().setPublicAccreditNo(starPatent.getPublicAccreditNo());
  375. }
  376. //装载代理机构地址
  377. if (starPatent.getAgencyStr() != null && !starPatent.getAgencyStr().equals("")) {
  378. String agencyAddress;
  379. if (starPatent.getAgencyStr().contains(" ")) {
  380. agencyAddress = starPatent.getAgencyStr().substring(0, starPatent.getAgencyStr().lastIndexOf(" "));
  381. } else {
  382. agencyAddress = starPatent.getAgencyStr();
  383. }
  384. uploadParamsVO.getPatent().setAgencyId(agencyAddress);
  385. }
  386. //装载申请号
  387. if (starPatent.getApplicationNo() != null && !starPatent.getApplicationNo().equals("")) {
  388. uploadParamsVO.getPatent().setApplicationNo(starPatent.getApplicationNo());
  389. }
  390. //装载申请人
  391. if (starPatent.getApplicantStr() != null && !starPatent.getApplicantStr().equals("")) {
  392. uploadParamsVO.setPatentApplicantOriginalName(Arrays.asList(starPatent.getApplicantStr().split(";")));
  393. }
  394. //装载代理人
  395. if (starPatent.getAgentStr() != null && !starPatent.getAgentStr().equals("")) {
  396. List<String> patentAgents = Arrays.asList(starPatent.getAgentStr().split(";"));
  397. ArrayList<PatentAgent> patentAgentList = new ArrayList<>();
  398. for (String n : patentAgents) {
  399. PatentAgent patentAgent = new PatentAgent();
  400. patentAgent.setName(n);
  401. patentAgentList.add(patentAgent);
  402. }
  403. uploadParamsVO.setPatentAgentList(patentAgentList);
  404. }
  405. //装载公开日
  406. if (starPatent.getPublicDate() != null && !starPatent.getPublicDate().equals("")) {
  407. int timeStamp = stringDateToTimeStamp(starPatent.getPublicDate());
  408. uploadParamsVO.getPatent().setPublicDate(timeStamp);
  409. }
  410. //装载标题
  411. if (starPatent.getName() != null && !starPatent.getName().equals("")) {
  412. uploadParamsVO.getPatent().setName(starPatent.getName());
  413. }
  414. //装载权利人
  415. if (starPatent.getCurrentApplicantStr() != null && !starPatent.getCurrentApplicantStr().equals("")) {
  416. uploadParamsVO.setPatentApplicantCurrentName(Arrays.asList(starPatent.getCurrentApplicantStr().split(";")));
  417. }
  418. //装载法律状态(os_patent表status字段值)
  419. Integer status = starPatent.getLG();
  420. if (status != null) {
  421. //有效(有权)
  422. if (status == 1) {
  423. uploadParamsVO.getPatent().setSimpleStatus(3);
  424. //失效(无权)
  425. } else if (status == 2) {
  426. uploadParamsVO.getPatent().setSimpleStatus(2);
  427. //审中(审中)
  428. } else if (status == 3) {
  429. uploadParamsVO.getPatent().setSimpleStatus(1);
  430. }
  431. }
  432. //装载公开号
  433. if (starPatent.getPublicNo() != null && !starPatent.getPublicNo().equals("")) {
  434. uploadParamsVO.getPatent().setPublicNo(starPatent.getPublicNo());
  435. }
  436. if (starPatent.getSimpleStatus() != null && !starPatent.getSimpleStatus().equals("")) {
  437. uploadParamsVO.setPatentSimpleStatus(starPatent.getSimpleStatus());
  438. uploadParamsVO.setSimpleStatus(starPatent.getSimpleStatus());
  439. }
  440. //装载优先权
  441. if (starPatent.getPriorityNo() != null && !starPatent.getPriorityNo().equals("")) {
  442. uploadParamsVO.getPatent().setPriorityNo(starPatent.getPriorityNo());
  443. }
  444. //装载优先权日
  445. if (starPatent.getPriorityDate() != null && !starPatent.getPriorityDate().equals("")) {
  446. int timeStamp = stringDateToTimeStamp(starPatent.getPriorityDate());
  447. uploadParamsVO.getPatent().setPriorityDate(timeStamp);
  448. }
  449. //装载受理局
  450. if (starPatent.getBureau() != null && !starPatent.getBureau().equals("")) {
  451. uploadParamsVO.getPatent().setBureau(starPatent.getBureau());
  452. }
  453. String appNo;
  454. if (starPatent.getApplicationNo().contains(".")) {
  455. appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
  456. } else {
  457. appNo = starPatent.getApplicationNo();
  458. }
  459. try {
  460. //以下 ↓装载的是调用"获得中国专利著录"接口返回的专利相关数据
  461. if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
  462. String chinaPatentZhuLuStr = patentStarApiService.getCnBibApi(appNo);
  463. if (chinaPatentZhuLuStr != null && !chinaPatentZhuLuStr.trim().equals("") && !chinaPatentZhuLuStr.equals("{}") && !chinaPatentZhuLuStr.contains("请求不合法")) {
  464. List<ChinaPatentZhuLu> chinaPatentZhuLus = JSON.parseArray(chinaPatentZhuLuStr, ChinaPatentZhuLu.class);
  465. ChinaPatentZhuLu chinaPatentZhuLu = chinaPatentZhuLus.get(0);
  466. //装载申请人地址
  467. if (uploadParamsVO.getPatentApplicantOriginalAddress() == null || uploadParamsVO.getPatentApplicantOriginalAddress().size() == 0) {
  468. if (chinaPatentZhuLu.getDZ() != null && !chinaPatentZhuLu.getDZ().equals("")) {
  469. List<String> patentApplicantOriginalAddresss = new ArrayList<>();
  470. if (chinaPatentZhuLu.getDZ().contains(" ")) {
  471. patentApplicantOriginalAddresss.add(chinaPatentZhuLu.getDZ().substring(chinaPatentZhuLu.getDZ().indexOf(" ") + 1));
  472. } else {
  473. patentApplicantOriginalAddresss.add(chinaPatentZhuLu.getDZ());
  474. }
  475. uploadParamsVO.setPatentApplicantOriginalAddress(patentApplicantOriginalAddresss);
  476. }
  477. }
  478. //装载代理人
  479. if (uploadParamsVO.getPatentAgentList() == null || uploadParamsVO.getPatentAgentList().size() == 0) {
  480. if (chinaPatentZhuLu.getAT() != null && !chinaPatentZhuLu.getAT().equals("")) {
  481. List<String> patentAgents = Arrays.asList(chinaPatentZhuLu.getAT().split(";"));
  482. ArrayList<PatentAgent> patentAgentList = new ArrayList<>();
  483. for (String n : patentAgents) {
  484. PatentAgent patentAgent = new PatentAgent();
  485. patentAgent.setName(n);
  486. patentAgentList.add(patentAgent);
  487. }
  488. uploadParamsVO.setPatentAgentList(patentAgentList);
  489. }
  490. }
  491. //装载代理机构地址
  492. if (uploadParamsVO.getPatent().getAgencyId() == null || uploadParamsVO.getPatent().getAgencyId().equals("")) {
  493. if (chinaPatentZhuLu.getAGN() != null && !chinaPatentZhuLu.getAGN().equals("")) {
  494. String agencyAddress;
  495. if (chinaPatentZhuLu.getAGN().contains(" ")) {
  496. agencyAddress = chinaPatentZhuLu.getAGN().substring(0, chinaPatentZhuLu.getAGN().lastIndexOf(" "));
  497. } else {
  498. agencyAddress = chinaPatentZhuLu.getAGN();
  499. }
  500. uploadParamsVO.getPatent().setAgencyId(agencyAddress);
  501. }
  502. }
  503. //装载发明人
  504. if (uploadParamsVO.getPatentInventorList() == null || uploadParamsVO.getPatentInventorList().size() == 0) {
  505. if (chinaPatentZhuLu.getIV() != null && !chinaPatentZhuLu.getIV().equals("")) {
  506. List<String> patentInventorNames = Arrays.asList(chinaPatentZhuLu.getIV().split(";"));
  507. ArrayList<PatentInventor> patentInventors = new ArrayList<>();
  508. for (String patentInventorName : patentInventorNames) {
  509. PatentInventor patentInventor = new PatentInventor();
  510. patentInventor.setName(patentInventorName);
  511. patentInventors.add(patentInventor);
  512. }
  513. uploadParamsVO.setPatentInventorList(patentInventors);
  514. }
  515. }
  516. //装载优先权号、优先权国家、优先权日
  517. if (uploadParamsVO.getPatent().getPriorityNo() == null || uploadParamsVO.getPatent().getPriorityNo().equals("")) {
  518. uploadParamsVO.getPatent().setPriorityNo(chinaPatentZhuLu.getPR());
  519. }
  520. }
  521. } else { //以下 ↓装载的是调用"获得世界专利著录"接口返回的专利相关数据
  522. String worldPatentZhuLuStr = patentStarApiService.getENBibApi(usedPatentNo);
  523. List<WorldPatentZhuLu> worldPatentZhuLus = JSON.parseArray(worldPatentZhuLuStr, WorldPatentZhuLu.class);
  524. WorldPatentZhuLu worldPatentZhuLu = worldPatentZhuLus.get(0);
  525. //装载公开号
  526. if (uploadParamsVO.getPatent().getPublicNo() == null || uploadParamsVO.getPatent().getPublicNo().equals("")) {
  527. uploadParamsVO.getPatent().setPatentNo(worldPatentZhuLu.getDocdbPubNo());
  528. }
  529. //装载申请号
  530. if (uploadParamsVO.getPatent().getApplicationNo() == null || uploadParamsVO.getPatent().getApplicationNo().equals("")) {
  531. uploadParamsVO.getPatent().setApplicationNo(worldPatentZhuLu.getEpoAppNo());
  532. }
  533. //装载申请日
  534. if (uploadParamsVO.getPatent().getApplicationDate() == null) {
  535. int timeStamp = stringDateToTimeStamp(worldPatentZhuLu.getAppDate());
  536. uploadParamsVO.getPatent().setApplicationDate(timeStamp);
  537. }
  538. //装载公开日
  539. if (uploadParamsVO.getPatent().getPublicDate() == null) {
  540. int timeStamp = stringDateToTimeStamp(worldPatentZhuLu.getPubDate());
  541. uploadParamsVO.getPatent().setPublicDate(timeStamp);
  542. }
  543. //装载IPC分类号
  544. if (uploadParamsVO.getIpcList() == null || uploadParamsVO.getIpcList().size() == 0) {
  545. String[] ipcArr = worldPatentZhuLu.getIpc().split(";");
  546. //装载主分类号
  547. if (uploadParamsVO.getMainIpc() == null || uploadParamsVO.getMainIpc().equals("")) {
  548. uploadParamsVO.setMainIpc(ipcArr[0]);
  549. }
  550. //装载IPC分类号
  551. uploadParamsVO.setIpcList(Arrays.asList(ipcArr));
  552. }
  553. //装载CPC分类号
  554. if (uploadParamsVO.getCpcList() == null || uploadParamsVO.getCpcList().size() == 0) {
  555. if (worldPatentZhuLu.getCpc() != null && !worldPatentZhuLu.getCpc().equals("")) {
  556. String[] cpcArr = worldPatentZhuLu.getCpc().split(";");
  557. uploadParamsVO.setCpcList(Arrays.asList(cpcArr));
  558. }
  559. }
  560. //装载申请人
  561. if (uploadParamsVO.getPatentApplicantOriginalName() == null || uploadParamsVO.getPatentApplicantOriginalName().size() == 0) {
  562. uploadParamsVO.setPatentApplicantOriginalName(Arrays.asList(worldPatentZhuLu.getPa().split(";")));
  563. }
  564. //装载发明人
  565. if (uploadParamsVO.getPatentInventorList() == null || uploadParamsVO.getPatentInventorList().size() == 0) {
  566. if (worldPatentZhuLu.getIv() != null && !worldPatentZhuLu.getIv().equals("")) {
  567. List<String> patentInventorNames = Arrays.asList(worldPatentZhuLu.getIv().split(";"));
  568. ArrayList<PatentInventor> patentInventors = new ArrayList<>();
  569. for (String patentInventorName : patentInventorNames) {
  570. PatentInventor patentInventor = new PatentInventor();
  571. patentInventor.setName(patentInventorName);
  572. patentInventors.add(patentInventor);
  573. }
  574. uploadParamsVO.setPatentInventorList(patentInventors);
  575. }
  576. }
  577. //装载优先权
  578. if (uploadParamsVO.getPatent().getPriorityNo() == null || uploadParamsVO.getPatent().getPriorityNo().equals("")) {
  579. uploadParamsVO.getPatent().setPriorityNo(worldPatentZhuLu.getPr());
  580. }
  581. //装载标题
  582. if (uploadParamsVO.getPatent().getName() == null || uploadParamsVO.getPatent().getName().equals("")) {
  583. uploadParamsVO.getPatent().setName(worldPatentZhuLu.getTitle());
  584. }
  585. //装载摘要
  586. if (uploadParamsVO.getPatent().getAbstractStr() == null || uploadParamsVO.getPatent().getAbstractStr().equals("")) {
  587. uploadParamsVO.getPatent().setAbstractStr(worldPatentZhuLu.getAbstract());
  588. }
  589. }
  590. } catch (Exception e) {
  591. e.printStackTrace();
  592. }
  593. //以下 ↓装载的是调用"获得同族专利"接口返回的专利相关数据
  594. try {
  595. if (starPatent.getPatentNo() != null && !starPatent.getPatentNo().equals("")) {
  596. String familyPatentNoStr = patentStarApiService.getFamilyByPubNoApi(usedPatentNo);
  597. if (!familyPatentNoStr.equals("no data") && !familyPatentNoStr.equals("{}")) {
  598. FamilyPatentNo familyPatentNo = JSON.parseObject(familyPatentNoStr, FamilyPatentNo.class);
  599. List<String> familyPatentNos = Arrays.asList(familyPatentNo.getFamilyinfo().split(";"));
  600. uploadParamsVO.setSimpleFamily(familyPatentNos);
  601. }
  602. }
  603. } catch (Exception e) {
  604. e.printStackTrace();
  605. }
  606. //以下 ↓装载的是调用"获得中国专利法律状态"接口返回的专利相关数据
  607. try {
  608. if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
  609. PatentAffair patentAffair = new PatentAffair();
  610. String cnLegalApiStr = patentStarApiService.getCnLegalApi(appNo);
  611. if (!cnLegalApiStr.equals("")) {
  612. List<ChinaLeagalStatus> chinaLeagalStatuses = JSON.parseArray(cnLegalApiStr, ChinaLeagalStatus.class);
  613. if (chinaLeagalStatuses != null && chinaLeagalStatuses.size() > 0) {
  614. ArrayList<KeyValueVO> lst = new ArrayList<>();
  615. HashMap<Integer, String> nameMap = new HashMap<>();
  616. HashMap<Integer, String> contentMap = new HashMap<>();
  617. nameMap.put(0, "发生日期");
  618. nameMap.put(1, "法律状态");
  619. nameMap.put(2, "详细法律状态");
  620. nameMap.put(3, "详细信息");
  621. for (int i = 0; i < chinaLeagalStatuses.size(); i++) {
  622. if (i == 0) {
  623. patentAffair.setStatus(chinaLeagalStatuses.get(i).getLegalStatus());
  624. }
  625. contentMap.put(0, chinaLeagalStatuses.get(i).getLegalDate());
  626. contentMap.put(1, chinaLeagalStatuses.get(i).getLegalStatus());
  627. contentMap.put(2, chinaLeagalStatuses.get(i).getLegalStatusInfo());
  628. contentMap.put(3, chinaLeagalStatuses.get(i).getDETAIL());
  629. ArrayList<KeyValueVO.InpadocData> inpadocDatas = new ArrayList<>();
  630. for (int j = 0; j < 4; j++) {
  631. KeyValueVO.InpadocData inpadocData = new KeyValueVO.InpadocData();
  632. inpadocData.setName(nameMap.get(j));
  633. inpadocData.setContent(contentMap.get(j));
  634. inpadocDatas.add(inpadocData);
  635. }
  636. KeyValueVO keyValueVO = new KeyValueVO();
  637. keyValueVO.setInpadocData(inpadocDatas);
  638. lst.add(keyValueVO);
  639. }
  640. //装载事务表的status(公开|授权|驳回|权力转移。。。)
  641. String content = JSONObject.toJSONString(lst);
  642. patentAffair.setContent(content);
  643. uploadParamsVO.setPatentAffair(patentAffair);
  644. }
  645. }
  646. }
  647. } catch (Exception e) {
  648. e.printStackTrace();
  649. }
  650. }
  651. /**
  652. * 装载权要方法
  653. *
  654. * @param starPatent 专利之星著录对象
  655. * @param uploadParamsVO 专利实体类对象
  656. */
  657. public Boolean setPatentClaim(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, PQueueData pQueueData) throws IOException {
  658. try {
  659. if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
  660. String applicationNo = starPatent.getApplicationNo() + "";
  661. String appNo;
  662. if (starPatent.getApplicationNo().contains(".")) {
  663. appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
  664. } else {
  665. appNo = starPatent.getApplicationNo();
  666. }
  667. //根据申请号调用"获得中国专利全文文本"接口,获得包含各种xml标签的专利全文内容的长字符串 cnFullXmlStr
  668. String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(appNo);
  669. //若没有取到全文文本即取不到权要,则将该专利检索专利之星接口次数+1,重新丢入权要生产队列,将当前申请号或专利号和备注信息记录到问题记录表,返回false
  670. if (cnFullXmlStr.equals("")) {
  671. if (pQueueData != null && pQueueData.getCallNum() < 2) {
  672. pQueueData.setCallNum(pQueueData.getCallNum() + 1);
  673. pantentQueueService.rightToPQueue(pQueueData);
  674. return false;
  675. }
  676. recordQuestionPatent(applicationNo, pQueueData.getTask().getId(), 2);
  677. return true;
  678. }
  679. //使用正则表达式拼接出权要原文
  680. String regex = "(?<=<claim id=.{1,110}>)[\\w\\W]+?(?=</claim>)";
  681. Pattern compile = Pattern.compile(regex);
  682. Matcher matcher = compile.matcher(cnFullXmlStr);
  683. StringBuilder builder = new StringBuilder();
  684. while (matcher.find()) {
  685. String macherGroup = matcher.group();
  686. String right = macherGroup.replaceAll("<!--.*?-->", "").trim();
  687. right = right.replaceAll("<.*?>", "").trim();
  688. right = right.replaceAll(" +", "");
  689. right = right.replace("\r\n", "").replace("\n", "");
  690. builder.append(right).append("\r\n");
  691. }
  692. String patentRightText = builder + "";
  693. //使用工具类去除字符串文本中的所有HTML格式标签
  694. patentRightText = RemoveHtmlTagsUtils.removeHtmlTags(patentRightText);
  695. patentRightText = patentRightText.trim();
  696. //装载权利要求原文
  697. PatentRight patentRight = new PatentRight();
  698. patentRight.setContent(patentRightText);
  699. uploadParamsVO.setPatentRight(patentRight);
  700. }
  701. } catch (Exception e) {
  702. e.printStackTrace();
  703. return true;
  704. }
  705. return true;
  706. }
  707. /**
  708. * 装载说明书文本
  709. *
  710. * @param starPatent 专利之星著录对象
  711. * @param uploadParamsVO 专利实体类对象
  712. */
  713. public Boolean setPatentInstructionText(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, PQueueData pQueueData) throws IOException {
  714. try {
  715. if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
  716. String applicationNo = starPatent.getApplicationNo() + "";
  717. String appNo;
  718. if (starPatent.getApplicationNo().contains(".")) {
  719. appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
  720. } else {
  721. appNo = starPatent.getApplicationNo();
  722. }
  723. //根据申请号调用"获得中国专利全文文本"接口,获得包含各种xml标签的专利全文内容的长字符串 cnFullXmlStr
  724. String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(appNo);
  725. //若没有取到全文文本,即取不到说明书文本,则将当前申请号或专利号和备注信息记录到问题记录表
  726. if (cnFullXmlStr.equals("")) {
  727. if (pQueueData != null && pQueueData.getCallNum() < 2) {
  728. pQueueData.setCallNum(pQueueData.getCallNum() + 1);
  729. pantentQueueService.rightToPQueue(pQueueData);
  730. return false;
  731. }
  732. recordQuestionPatent(applicationNo, pQueueData.getTask().getId(), 3);
  733. return true;
  734. }
  735. //使用正则表达式拼接出说明书文本全文
  736. String regex = "(?<=<description>)[\\w\\W]+?(?=</description>)";
  737. Pattern compile = Pattern.compile(regex);
  738. Matcher matcher = compile.matcher(cnFullXmlStr);
  739. String text = "";
  740. while (matcher.find()) {
  741. text = matcher.group();
  742. text = text.replaceAll("<invention-title[^>]*>.*?(\\n{0,}|\\s{0,}?)</invention-title>", "");
  743. text = text.replaceAll("<br/>", "");
  744. text = text.replaceAll("\\s", "");
  745. }
  746. //装载说明书文本全文
  747. PatentInstructionText patentInstructionText = new PatentInstructionText();
  748. patentInstructionText.setManual(text.trim());
  749. uploadParamsVO.setPatentInstructionText(patentInstructionText);
  750. }
  751. } catch (Exception e) {
  752. e.printStackTrace();
  753. return true;
  754. }
  755. return true;
  756. }
  757. /**
  758. * 装载说明书pdf
  759. *
  760. * @param starPatent 专利之星著录对象
  761. * @param uploadParamsVO 专利实体类对象
  762. */
  763. public void setPatentInstructionPDF(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, Task task) throws IOException {
  764. String usedPatentNo;
  765. if (starPatent.getPublicNo() != null && !starPatent.getPublicNo().equals("")) {
  766. usedPatentNo = starPatent.getPublicNo();
  767. } else {
  768. usedPatentNo = starPatent.getPatentNo();
  769. }
  770. try {
  771. String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
  772. if ((starPatent.getPatentNo() != null && !starPatent.getPatentNo().equals("")) || (starPatent.getApplicationNo() != null && !starPatent.getApplicationNo().equals(""))) {
  773. //先根据公开号判断国家,若没有公开号再根据申请号判断,调用"获得中国专利pdf"接口,获得1个或2个pdf的url地址
  774. if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
  775. String appNo = starPatent.getApplicationNo();
  776. if (appNo.contains(".")) {
  777. appNo = appNo.substring(0, appNo.lastIndexOf("."));
  778. }
  779. String pdfUrlStr = patentStarApiService.getCnPdfApi(appNo);
  780. //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
  781. if (pdfUrlStr.equals("")) {
  782. recordQuestionPatent(starPatent.getPatentNo(), task.getId(), 4);
  783. return;
  784. }
  785. if (pdfUrlStr.contains("|http")) { //若包含公开和授权两个pdf
  786. String[] pdfUrlArr = pdfUrlStr.split("\\|http");
  787. pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
  788. pdfUrlArr[1] = "http" + pdfUrlArr[1];
  789. pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
  790. UploadFileDTO fileDTO = downLoadPdf(pdfUrl1);
  791. UploadFileDTO fileDTO2 = downLoadPdf(pdfUrl2);
  792. if (pdfUrl1.contains("0A_CN_0.pdf")) {
  793. uploadParamsVO.setPdf1FileDTO(fileDTO);
  794. uploadParamsVO.setPdf2FileDTO(fileDTO2);
  795. } else {
  796. uploadParamsVO.setPdf1FileDTO(fileDTO2);
  797. uploadParamsVO.setPdf2FileDTO(fileDTO);
  798. }
  799. } else { //若只有一个
  800. pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"), pdfUrlStr.indexOf("?"));
  801. UploadFileDTO fileDTO = downLoadPdf(pdfUrl1);
  802. if (pdfUrl1.contains("0A_CN_0.pdf")) {
  803. uploadParamsVO.setPdf1FileDTO(fileDTO);
  804. } else {
  805. uploadParamsVO.setPdf2FileDTO(fileDTO);
  806. }
  807. }
  808. //根据专利号调用"获得世界专利pdf"接口,获得pdf的url地址
  809. } else {
  810. pdfUrl = patentStarApiService.getEnPdfApi(usedPatentNo);
  811. //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
  812. if (pdfUrl.equals("") || pdfUrl.equals("{}")) {
  813. recordQuestionPatent(starPatent.getPatentNo(), task.getId(), 4);
  814. return;
  815. }
  816. UploadFileDTO fileDTO = downLoadPdf(pdfUrl);
  817. uploadParamsVO.setPdf1FileDTO(fileDTO);
  818. }
  819. }
  820. } catch (Exception e) {
  821. e.printStackTrace();
  822. }
  823. }
  824. /**
  825. * 装载摘要附图
  826. *
  827. * @param starPatent 专利之星著录对象
  828. * @param uploadParamsVO 专利实体类对象
  829. */
  830. public void setPatentPicture(StarPatentVO starPatent, UploadParamsVO uploadParamsVO) throws IOException {
  831. try {
  832. //调用"获取中国专利摘要附图"接口
  833. String appNo = starPatent.getApplicationNo();
  834. if (appNo.contains(".")) {
  835. appNo = appNo.substring(0, appNo.lastIndexOf("."));
  836. }
  837. if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
  838. String pictureUrl = patentStarApiService.getPictureApi(appNo);
  839. URL url = new URL(pictureUrl); //想要读取的url地址
  840. InputStream in = url.openStream();
  841. File file = File.createTempFile("new_url", ".jpg"); //创建文件
  842. OutputStream os = new FileOutputStream(file); //创建文件输出流
  843. int bytesRead;
  844. byte[] buffer = new byte[8192];
  845. int len = 8192;
  846. while ((bytesRead = in.read(buffer, 0, len)) != -1) {
  847. os.write(buffer, 0, bytesRead);
  848. }
  849. //关闭释放流
  850. os.close();
  851. in.close();
  852. DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
  853. FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
  854. buffer = new byte[8192];
  855. FileInputStream fis = new FileInputStream(file);
  856. OutputStream fos = item.getOutputStream();
  857. len = 8192;
  858. while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
  859. fos.write(buffer, 0, bytesRead);
  860. }
  861. //关闭释放流
  862. fos.close();
  863. fis.close();
  864. MultipartFile multipartFile = new CommonsMultipartFile(item);
  865. UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
  866. uploadParamsVO.setPictureFileDTO(fileDTO);
  867. }
  868. } catch (Exception e) {
  869. e.printStackTrace();
  870. }
  871. }
  872. /**
  873. * 下载指定多个专利号专利
  874. *
  875. * @param isAddPatentNos 起止条数以外,用户手动勾选的多个专利号
  876. */
  877. public void downLoadIsAddPatentNos(List<String> isAddPatentNos, Task task, String orderBy, String orderByType, String dbType, List<String> cells, String conditions) throws IOException {
  878. if (conditions == null) {
  879. conditions = "AN=(" + StringUtils.join(isAddPatentNos, " OR ") + ")";
  880. }
  881. int pageNum = 1;
  882. for (int i = 0; i < isAddPatentNos.size(); i += 50) {
  883. PatentStarListDto patentStarListDto = new PatentStarListDto()
  884. .setCurrentQuery(conditions)
  885. .setOrderBy(orderBy)
  886. .setOrderByType(orderByType)
  887. .setPageNum(pageNum++)
  888. .setRowCount(50)
  889. .setDBType(dbType);
  890. Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
  891. if (resultMap == null || (Integer) resultMap.get("total") == 0) {
  892. ThrowException.throwXiaoShiException("发生未知错误,一般接口未检索出专利");
  893. }
  894. List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
  895. //遍历这一页的专利
  896. for (StarPatentVO starPatent : starPatents) {
  897. //判断若任务状态为已暂停,则结束生产
  898. if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
  899. return;
  900. }
  901. try {
  902. UploadParamsVO uploadParamsVO = new UploadParamsVO();
  903. Patent patent = new Patent();
  904. uploadParamsVO.setPatent(patent);
  905. uploadParamsVO.getPatent().setPatentNo(starPatent.getPatentNo());
  906. uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
  907. PQueueData pQueueData = new PQueueData()
  908. .setTask(task)
  909. .setStarPatent(starPatent)
  910. .setUploadParamsVO(uploadParamsVO);
  911. //装载专利著录
  912. if (cells.contains("1")) {
  913. pantentQueueService.zhuluToPQueue(pQueueData);
  914. }
  915. //装载权要
  916. if (cells.contains("2")) {
  917. pantentQueueService.rightToPQueue(pQueueData);
  918. }
  919. //装载说明书文本
  920. if (cells.contains("3")) {
  921. pantentQueueService.instructionTextToPQueue(pQueueData);
  922. }
  923. //装载说明书pdf
  924. if (cells.contains("4")) {
  925. pantentQueueService.instructionPDFToPQueue(pQueueData);
  926. }
  927. //装载摘要附图
  928. if (cells.contains("6")) {
  929. pantentQueueService.imageToPQueue(pQueueData);
  930. }
  931. } catch (Exception e) {
  932. e.printStackTrace();
  933. }
  934. }
  935. }
  936. }
  937. public UploadFileDTO downLoadPdf(String pdfUrl) throws IOException {
  938. URL url = new URL(pdfUrl); //想要读取的url地址
  939. InputStream in = url.openStream();
  940. File file = File.createTempFile("new_url", ".pdf"); //创建文件
  941. OutputStream os = new FileOutputStream(file); //创建文件输出流
  942. int bytesRead;
  943. byte[] buffer = new byte[8192];
  944. int len = 8192;
  945. while ((bytesRead = in.read(buffer, 0, len)) != -1) {
  946. os.write(buffer, 0, bytesRead);
  947. }
  948. //关闭释放流
  949. os.close();
  950. in.close();
  951. DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
  952. FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
  953. buffer = new byte[8192];
  954. FileInputStream fis = new FileInputStream(file);
  955. OutputStream fos = item.getOutputStream();
  956. len = 8192;
  957. while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
  958. fos.write(buffer, 0, bytesRead);
  959. }
  960. //关闭释放流
  961. fos.close();
  962. fis.close();
  963. MultipartFile multipartFile = new CommonsMultipartFile(item);
  964. UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
  965. return fileDTO;
  966. }
  967. /**
  968. * 专利之星返回日期格式为字符串 yyyyMMdd,如 "20230713",本方法将其转成10位数字时间戳
  969. *
  970. * @param dateStr yyyyMMdd格式字符串日期
  971. * @return 返回10位数字时间戳
  972. */
  973. public int stringDateToTimeStamp(String dateStr) {
  974. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
  975. Date date;
  976. try {
  977. date = dateFormat.parse(dateStr);
  978. } catch (ParseException e) {
  979. //日期格式转换异常
  980. e.printStackTrace();
  981. return Integer.parseInt(dateStr);
  982. }
  983. long timeStamp = date.getTime() / 1000;
  984. return (int) timeStamp;
  985. }
  986. /**
  987. * 根据起止条数计算开始页数、开始页数的开始位置、结束页数、结束页数的结束位置
  988. *
  989. * @param startNumber 起始条数
  990. * @param endNumber 终止条数
  991. * @return 返回计算结果对象(开始页数、开始页数的开始位置、结束页数、结束页数的结束位置)
  992. */
  993. public Calculate calculateFromStartAndEndNumber(Integer startNumber, Integer endNumber) {
  994. int startPage; //检索开始页数
  995. int startNum; //检索开始页数的开始专利位置
  996. int endPage; //检索结束页数
  997. int endNum; //检索结束页数的结束专利位置
  998. if (startNumber % 50 != 0) {
  999. startPage = startNumber / 50 + 1;
  1000. startNum = startNumber % 50;
  1001. } else {
  1002. startPage = startNumber / 50;
  1003. startNum = 50;
  1004. }
  1005. if (endNumber % 50 != 0) {
  1006. endPage = endNumber / 50 + 1;
  1007. endNum = endNumber % 50;
  1008. } else {
  1009. endPage = endNumber / 50;
  1010. endNum = 50;
  1011. }
  1012. Calculate calculate = new Calculate()
  1013. .setStartPage(startPage)
  1014. .setStartNum(startNum)
  1015. .setEndPage(endPage)
  1016. .setEndNum(endNum);
  1017. return calculate;
  1018. }
  1019. /**
  1020. * 记录没有数据的专利信息
  1021. *
  1022. * @param applicationNoOrPatentNo 公开号/申请号
  1023. * @param taskId 任务id
  1024. * @param cell 失败字段(1著录 2权要 3说明书文本 4说明书pdf 5摘要附图)
  1025. */
  1026. public void recordQuestionPatent(String applicationNoOrPatentNo, Integer taskId, int cell) {
  1027. QuestionRecord questionRecord = new QuestionRecord()
  1028. .setPatentNo(applicationNoOrPatentNo)
  1029. .setCell(cell)
  1030. .setTaskId(taskId)
  1031. .setRemark("该申请号的该字段(2权要 3说明书文本 4说明书pdf)接口检索返回原始数据为空");
  1032. List<QuestionRecord> questionRecords = questionRecordService.list(new LambdaQueryWrapper<QuestionRecord>().eq(QuestionRecord::getPatentNo, applicationNoOrPatentNo).eq(QuestionRecord::getCell, cell));
  1033. if (questionRecords == null || questionRecords.size() == 0) {
  1034. questionRecordService.save(questionRecord);
  1035. }
  1036. }
  1037. public void setTaskStatus(Integer taskId, Integer taskStatus) {
  1038. this.pTaskId = taskId;
  1039. this.pTaskStatus = taskStatus;
  1040. }
  1041. public Integer getpTaskId() {
  1042. return pTaskId;
  1043. }
  1044. public Integer getpTaskStatus() {
  1045. return pTaskStatus;
  1046. }
  1047. }