PatentStarApiService.java 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. package cn.cslg.pas.service.common;
  2. import cn.cslg.pas.common.config.XDns;
  3. import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
  4. import cn.cslg.pas.common.dto.*;
  5. import cn.cslg.pas.common.dto.business.SelectClaimDTO;
  6. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  7. import cn.cslg.pas.common.model.cronModel.Records;
  8. import cn.cslg.pas.common.model.importTaskModel.PatentApplicant;
  9. import cn.cslg.pas.common.utils.*;
  10. import cn.cslg.pas.common.vo.ContentVO;
  11. import cn.cslg.pas.common.vo.QueryExternalFamilyVO;
  12. import cn.cslg.pas.common.vo.StarPatentVO;
  13. import cn.cslg.pas.common.vo.business.PatentNoVO;
  14. import cn.cslg.pas.domain.WebLoginConfig;
  15. import cn.cslg.pas.domain.business.RetrieveRecord;
  16. import cn.cslg.pas.domain.es.*;
  17. import cn.cslg.pas.service.WebLoginConfigService;
  18. import cn.cslg.pas.service.importPatent.ImportFromWebToEsService;
  19. import cn.cslg.pas.service.query.FormatQueryService;
  20. import com.alibaba.fastjson.JSONArray;
  21. import com.alibaba.fastjson.JSONObject;
  22. import lombok.RequiredArgsConstructor;
  23. import lombok.experimental.Accessors;
  24. import lombok.extern.slf4j.Slf4j;
  25. import okhttp3.FormBody;
  26. import okhttp3.OkHttpClient;
  27. import okhttp3.Request;
  28. import okhttp3.Response;
  29. import org.dom4j.Document;
  30. import org.dom4j.DocumentException;
  31. import org.dom4j.Element;
  32. import org.dom4j.XPath;
  33. import org.dom4j.io.SAXReader;
  34. import org.joda.time.DateTime;
  35. import org.joda.time.format.DateTimeFormat;
  36. import org.joda.time.format.DateTimeFormatter;
  37. import org.springframework.beans.BeanUtils;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.context.ApplicationContext;
  40. import org.springframework.stereotype.Service;
  41. import org.springframework.util.CollectionUtils;
  42. import java.io.File;
  43. import java.io.IOException;
  44. import java.io.Reader;
  45. import java.io.StringReader;
  46. import java.text.ParseException;
  47. import java.text.SimpleDateFormat;
  48. import java.util.*;
  49. import java.util.concurrent.TimeUnit;
  50. import java.util.regex.Matcher;
  51. import java.util.regex.Pattern;
  52. import java.util.stream.Collectors;
  53. /**
  54. * 调用外部接口的Service类 PCS:权限系统
  55. *
  56. * @Author chenyu
  57. * @Date 2023/4/25
  58. */
  59. @RequiredArgsConstructor
  60. @Slf4j
  61. @Service
  62. public class PatentStarApiService {
  63. private ApplicationContext applicationContext;
  64. private PatentStarApiService patentStarApiService;
  65. @Autowired
  66. private RetrieveRecordService retrieveRecordService;
  67. @Autowired
  68. private CacheUtils cacheUtils;
  69. @Autowired
  70. private LoginUtils loginUtils;
  71. @Autowired
  72. private WebLoginConfigService webLoginConfigService;
  73. @Autowired
  74. private FormatQueryService formatQueryService;
  75. public Records patentStarSearchLocal(PatentStarListDTO patentStarListDTO) throws IOException {
  76. RetrieveRecord retrieveRecord = new RetrieveRecord();
  77. retrieveRecord.setConditions(patentStarListDTO.getCurrentQuery());
  78. if (patentStarListDTO.getRetrieveRecordId() != null) {
  79. retrieveRecord = retrieveRecordService.getById(patentStarListDTO.getRetrieveRecordId());
  80. patentStarListDTO.setCurrentQuery(retrieveRecord.getConditions());
  81. patentStarListDTO.setDBType(retrieveRecord.getDbType());
  82. }
  83. Map<String, Object> map = this.patentStarSearchApi(patentStarListDTO);
  84. if (map == null) {
  85. ThrowException.throwXiaoShiException("检索失败,请检查检索式");
  86. }
  87. //记录检索历史
  88. retrieveRecord.setRetrieveTime(new Date());
  89. retrieveRecord.setTotalNum(Integer.parseInt(map.get("total").toString()));
  90. retrieveRecord.setDbType(patentStarListDTO.getDBType());
  91. // if (patentStarListDTO.getRetrieveRecordId() == null) {
  92. // //获取创建人信息
  93. // PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  94. // retrieveRecord.setCreateTime(new Date());
  95. // retrieveRecord.setCreateId(personnelVO.getId());
  96. // retrieveRecord.setTenantId(personnelVO.getTenantId());
  97. // retrieveRecord.insert();
  98. // }
  99. // else {
  100. // retrieveRecord.updateById();
  101. // }
  102. List<StarPatentVO> starPatentVOS = (List<StarPatentVO>) map.get("records");
  103. //装载starPatentVOS到 PatentColumnDTO
  104. Records records = new Records();
  105. records.setRetrieveRecordId(retrieveRecord.getId());
  106. records.setCurrent(Long.parseLong(map.get("current").toString()));
  107. records.setSize(Long.parseLong(map.get("size").toString()));
  108. records.setData(this.loadPatent(starPatentVOS));
  109. records.setTotal(Long.parseLong(map.get("total").toString()));
  110. return records;
  111. }
  112. public Map<String, Object> patentStarSearchApi(PatentStarListDTO PatentStarListDTO) throws IOException {
  113. try {
  114. if (PatentStarListDTO.getFormed() == null || PatentStarListDTO.getFormed() == false) {
  115. String formQuery = PatentStarListDTO.getCurrentQuery();
  116. PatentStarListDTO.setCurrentQuery(formatQueryService.reQuery(formQuery, "webSearchConfig"));
  117. if (PatentStarListDTO.getDBType().equals("WD")) {
  118. StringBuilder stringBuilder = new StringBuilder(PatentStarListDTO.getCurrentQuery());
  119. stringBuilder.insert(PatentStarListDTO.getCurrentQuery().length() - 1, "-CN/GJ");
  120. PatentStarListDTO.setCurrentQuery(stringBuilder.toString());
  121. }
  122. }
  123. } catch (Exception e) {
  124. return null;
  125. }
  126. JSONObject configObject = this.getConfigObject(4, 1);
  127. String appId = configObject.getString("appId");
  128. String appKey = configObject.getString("appKey");
  129. PatentStarDTO patentStarDto = new PatentStarDTO();
  130. BeanUtils.copyProperties(PatentStarListDTO, patentStarDto);
  131. String json = JSONObject.toJSONString(patentStarDto);
  132. String url = "http://s.patentstar.com.cn/SearchAPI/PatentSearch/ResultGet";
  133. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  134. String Sign = appKey + currentTimeMillis.toString();
  135. String signMd5 = FormatUtil.MD5(Sign);
  136. // 创建一个OkHttpClient对象
  137. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  138. .connectTimeout(60, TimeUnit.SECONDS)
  139. .writeTimeout(60, TimeUnit.SECONDS)
  140. .readTimeout(60, TimeUnit.SECONDS)
  141. .dns(new XDns(100000))
  142. .build();
  143. // 创建一个RequestBody(参数1:数据类型 参数2传递的json串)
  144. FormBody.Builder builder = new FormBody.Builder();
  145. builder.add("AppID", appId);
  146. builder.add("Stamp", currentTimeMillis.toString());
  147. builder.add("Sign", signMd5);
  148. builder.add("QueryJson", json);
  149. FormBody requestBody = builder.build();
  150. // 创建一个请求对象
  151. Request request = new Request.Builder().url(url).post(requestBody).build();
  152. // 发送请求获取响应
  153. try {
  154. Response response = okHttpClient.newCall(request).execute();
  155. // 判断请求是否成功
  156. if (response.isSuccessful()) {
  157. JSONObject jsonObject = JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
  158. if (jsonObject.get("Ret").equals(500) || jsonObject.get("Data") == null) {
  159. return null;
  160. }
  161. JSONObject Data = (JSONObject) jsonObject.get("Data");
  162. List<StarPatentVO> starPatentVOS = JSONArray.parseArray(Data.get("List").toString(), StarPatentVO.class);
  163. Map<String, Object> reMap = new HashMap<>();
  164. reMap.put("size", PatentStarListDTO.getRowCount());
  165. reMap.put("current", PatentStarListDTO.getPageNum());
  166. reMap.put("records", starPatentVOS);
  167. reMap.put("total", Data.get("HitCount"));
  168. return reMap;
  169. }
  170. } catch (IOException e) {
  171. e.printStackTrace();
  172. return null;
  173. }
  174. return null;
  175. }
  176. public List<PatentStarListDTO> getSplitedConditions(PatentStarListDTO patentStarListDTO, int patentNum) throws IOException {
  177. DateTime nowDate = new DateTime();
  178. DateTime date = DateUtils2.formStrToDateTime("1900-01-01");
  179. //超过1万的列表
  180. List<PatentStarListDTO> PatentStarListDTOs = new ArrayList<>();
  181. //返回的列表
  182. List<PatentStarListDTO> reDtos = new ArrayList<>();
  183. patentStarListDTO.setStartTime(date);
  184. patentStarListDTO.setEndTime(nowDate);
  185. String formQuery = patentStarListDTO.getCurrentQuery();
  186. // patentStarListDTO.setOrginCondition(PatentStarApiService.formatQuery(formQuery));
  187. PatentStarListDTOs.add(patentStarListDTO);
  188. while (PatentStarListDTOs.size() > 0) {
  189. PatentStarListDTO dto = PatentStarListDTOs.get(0);
  190. PatentStarListDTOs.remove(dto);
  191. Map<String, Object> map1 = this.patentStarSearchApi(dto);
  192. Integer total1 = Integer.parseInt(map1.get("total").toString());
  193. dto.setTotal(total1);
  194. patentStarListDTO.setFormed(true);
  195. if (total1 > patentNum) {
  196. DateTime startTime1 = dto.getStartTime();
  197. DateTime endTime1 = dto.getEndTime();
  198. List<DateTime> dateTimes = DateUtils2.formStrToDateTime(startTime1, endTime1);
  199. PatentStarListDTO dto1 = new PatentStarListDTO();
  200. BeanUtils.copyProperties(dto, dto1);
  201. dto1.setStartTime(dateTimes.get(0));
  202. dto1.setEndTime(dateTimes.get(1));
  203. this.setConditions(dto1);
  204. PatentStarListDTO dto2 = new PatentStarListDTO();
  205. BeanUtils.copyProperties(dto, dto2);
  206. dto2.setStartTime(dateTimes.get(2));
  207. dto2.setEndTime(dateTimes.get(3));
  208. this.setConditions(dto2);
  209. PatentStarListDTOs.add(dto1);
  210. PatentStarListDTOs.add(dto2);
  211. } else if (total1 != 0) {
  212. reDtos.add(dto);
  213. }
  214. }
  215. return reDtos;
  216. }
  217. public void setConditions(PatentStarListDTO PatentStarListDTO) {
  218. DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
  219. String startStr = formatter.print(PatentStarListDTO.getStartTime());
  220. String endStr = formatter.print(PatentStarListDTO.getEndTime());
  221. String cond = "*(" + startStr + ">" + endStr + "/" + "AD)";
  222. Integer len = PatentStarListDTO.getOrginCondition().length();
  223. StringBuilder stringBuilder = new StringBuilder(PatentStarListDTO.getOrginCondition());
  224. stringBuilder.insert(len - 1, cond);
  225. PatentStarListDTO.setCurrentQuery(stringBuilder.toString());
  226. }
  227. /**
  228. * @param appNo
  229. * @return
  230. * @throws IOException
  231. * @author 李仁杰
  232. * 从专利之星获取中国专利著录
  233. */
  234. public String getCnBibApi(String appNo) {
  235. String url = "https://api.patentstar.com.cn/api/Patent/CnBibo/" + appNo;
  236. JSONObject configObject = this.getConfigObject(4, 2);
  237. String appId = configObject.getString("appId");
  238. String appKey = configObject.getString("appKey");
  239. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  240. String Sign = appId + appKey + currentTimeMillis.toString();
  241. String signMd5 = FormatUtil.MD5(Sign);
  242. // 创建一个OkHttpClient对象
  243. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  244. .connectTimeout(60, TimeUnit.SECONDS)
  245. .writeTimeout(60, TimeUnit.SECONDS)
  246. .readTimeout(60, TimeUnit.SECONDS)
  247. .dns(new XDns(100000))
  248. .build();
  249. // 创建一个请求对象
  250. Request request = new Request.Builder().url(url)
  251. .addHeader("_appid", appId)
  252. .addHeader("_timestamp", currentTimeMillis.toString())
  253. .addHeader("_sign", signMd5)
  254. .get().build();
  255. // 发送请求获取响应
  256. try {
  257. Response response = okHttpClient.newCall(request).execute();
  258. // 判断请求是否成功
  259. if (response.isSuccessful()) {
  260. // 打印服务端返回结果
  261. return Objects.requireNonNull(response.body()).string();
  262. }
  263. } catch (IOException e) {
  264. e.printStackTrace();
  265. }
  266. return "{}";
  267. }
  268. /**
  269. * @param
  270. * @return
  271. * @throws IOException
  272. * @author 李仁杰
  273. * 从专利之星获取中国专利摘要附图
  274. */
  275. public String getPictureApi(String appNo) {
  276. String url = "https://api.patentstar.com.cn/api/Patent/CnMainImage/" + appNo;
  277. JSONObject configObject = this.getConfigObject(4, 2);
  278. String appId = configObject.getString("appId");
  279. String appKey = configObject.getString("appKey");
  280. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  281. String Sign = appId + appKey + currentTimeMillis.toString();
  282. String signMd5 = FormatUtil.MD5(Sign);
  283. // 创建一个OkHttpClient对象
  284. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  285. .connectTimeout(60, TimeUnit.SECONDS)
  286. .writeTimeout(60, TimeUnit.SECONDS)
  287. .readTimeout(60, TimeUnit.SECONDS)
  288. .dns(new XDns(100000))
  289. .build();
  290. // 创建一个请求对象
  291. Request request = new Request.Builder().url(url)
  292. .addHeader("_appid", appId)
  293. .addHeader("_timestamp", currentTimeMillis.toString())
  294. .addHeader("_sign", signMd5)
  295. .get().build();
  296. // 发送请求获取响应
  297. try {
  298. Response response = okHttpClient.newCall(request).execute();
  299. // 判断请求是否成功
  300. if (response.isSuccessful() && response.code() == 200) {
  301. // 打印服务端返回结果
  302. return Objects.requireNonNull(response.body()).string();
  303. }
  304. } catch (IOException e) {
  305. e.printStackTrace();
  306. return null;
  307. }
  308. return "{}";
  309. }
  310. /**
  311. * @param appNo
  312. * @return
  313. * @throws IOException
  314. * @author 李仁杰
  315. * 从专利之星获取中国专利外观图
  316. */
  317. public String getWGPictureApi(String appNo) throws IOException {
  318. String url = "https://api.patentstar.com.cn/api/Patent/CnWGImage/" + appNo;
  319. JSONObject configObject = this.getConfigObject(4, 2);
  320. String appId = configObject.getString("appId");
  321. String appKey = configObject.getString("appKey");
  322. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  323. String Sign = appId + appKey + currentTimeMillis.toString();
  324. String signMd5 = FormatUtil.MD5(Sign);
  325. // 创建一个OkHttpClient对象
  326. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  327. .connectTimeout(60, TimeUnit.SECONDS)
  328. .writeTimeout(60, TimeUnit.SECONDS)
  329. .readTimeout(60, TimeUnit.SECONDS)
  330. .dns(new XDns(100000))
  331. .build();
  332. // 创建一个请求对象
  333. Request request = new Request.Builder().url(url)
  334. .addHeader("_appid", appId)
  335. .addHeader("_timestamp", currentTimeMillis.toString())
  336. .addHeader("_sign", signMd5)
  337. .get().build();
  338. // 发送请求获取响应
  339. try {
  340. Response response = okHttpClient.newCall(request).execute();
  341. // 判断请求是否成功
  342. if (response.isSuccessful()) {
  343. // 打印服务端返回结果
  344. return Objects.requireNonNull(response.body()).string();
  345. }
  346. } catch (IOException e) {
  347. e.printStackTrace();
  348. }
  349. return "{}";
  350. }
  351. /**
  352. * @param appNo
  353. * @return
  354. * @throws IOException
  355. * @author 李仁杰
  356. * 从专利之星获取中国专利法律状态
  357. */
  358. public String getCnLegalApi(String appNo) {
  359. String url = "https://api.patentstar.com.cn/api/Patent/CnLegal/" + appNo;
  360. JSONObject configObject = this.getConfigObject(4, 2);
  361. String appId = configObject.getString("appId");
  362. String appKey = configObject.getString("appKey");
  363. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  364. String Sign = appId + appKey + currentTimeMillis.toString();
  365. String signMd5 = FormatUtil.MD5(Sign);
  366. // 创建一个OkHttpClient对象
  367. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  368. .connectTimeout(60, TimeUnit.SECONDS)
  369. .writeTimeout(60, TimeUnit.SECONDS)
  370. .readTimeout(60, TimeUnit.SECONDS)
  371. .dns(new XDns(100000))
  372. .build();
  373. // 创建一个请求对象
  374. Request request = new Request.Builder().url(url)
  375. .addHeader("_appid", appId)
  376. .addHeader("_timestamp", currentTimeMillis.toString())
  377. .addHeader("_sign", signMd5)
  378. .get().build();
  379. // 发送请求获取响应
  380. try {
  381. Response response = okHttpClient.newCall(request).execute();
  382. // 判断请求是否成功
  383. if (response.isSuccessful()) {
  384. // 打印服务端返回结果
  385. return Objects.requireNonNull(response.body()).string();
  386. }
  387. } catch (IOException e) {
  388. e.printStackTrace();
  389. }
  390. return "{}";
  391. }
  392. /**
  393. * @param appNo
  394. * @return
  395. * @throws IOException
  396. * @author 李仁杰
  397. * 从专利之星获取中国专利全文图片
  398. */
  399. public String getCnPdfApi(String appNo) throws IOException {
  400. String url = "https://api.patentstar.com.cn/api/Patent/CnPdf/" + appNo;
  401. JSONObject configObject = this.getConfigObject(4, 2);
  402. String appId = configObject.getString("appId");
  403. String appKey = configObject.getString("appKey");
  404. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  405. String Sign = appId + appKey + currentTimeMillis.toString();
  406. String signMd5 = FormatUtil.MD5(Sign);
  407. // 创建一个OkHttpClient对象
  408. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  409. .connectTimeout(60, TimeUnit.SECONDS)
  410. .writeTimeout(60, TimeUnit.SECONDS)
  411. .readTimeout(60, TimeUnit.SECONDS)
  412. .dns(new XDns(100000))
  413. .build();
  414. // 创建一个请求对象
  415. Request request = new Request.Builder().url(url)
  416. .addHeader("_appid", appId)
  417. .addHeader("_timestamp", currentTimeMillis.toString())
  418. .addHeader("_sign", signMd5)
  419. .get().build();
  420. // 发送请求获取响应
  421. try {
  422. Response response = okHttpClient.newCall(request).execute();
  423. // 判断请求是否成功
  424. if (response.isSuccessful()) {
  425. // 打印服务端返回结果
  426. return Objects.requireNonNull(response.body()).string();
  427. }
  428. } catch (IOException e) {
  429. e.printStackTrace();
  430. }
  431. return "{}";
  432. }
  433. /**
  434. * @param appNo
  435. * @return
  436. * @throws IOException
  437. * @author 李仁杰
  438. * 从专利之星获取中国专利全文文本
  439. */
  440. public String getCnFullXmlApi(String appNo) throws IOException {
  441. String url = "https://api.patentstar.com.cn/api/Patent/CnFullXml/" + appNo;
  442. JSONObject configObject = this.getConfigObject(4, 2);
  443. String appId = configObject.getString("appId");
  444. String appKey = configObject.getString("appKey");
  445. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  446. String Sign = appId + appKey + currentTimeMillis.toString();
  447. String signMd5 = FormatUtil.MD5(Sign);
  448. // 创建一个OkHttpClient对象
  449. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  450. .connectTimeout(60, TimeUnit.SECONDS)
  451. .writeTimeout(60, TimeUnit.SECONDS)
  452. .readTimeout(60, TimeUnit.SECONDS)
  453. .dns(new XDns(100000))
  454. .build();
  455. // 创建一个请求对象
  456. Request request = new Request.Builder().url(url)
  457. .addHeader("_appid", appId)
  458. .addHeader("_timestamp", currentTimeMillis.toString())
  459. .addHeader("_sign", signMd5)
  460. .get().build();
  461. // 发送请求获取响应
  462. try {
  463. Response response = okHttpClient.newCall(request).execute();
  464. // 判断请求是否成功
  465. if (response.isSuccessful()) {
  466. // 打印服务端返回结果
  467. return Objects.requireNonNull(response.body()).string();
  468. }
  469. } catch (IOException e) {
  470. e.printStackTrace();
  471. }
  472. return "{}";
  473. }
  474. //获取权利要求文本
  475. public String getExternalClaim(String str) throws DocumentException {
  476. SAXReader reader = new SAXReader();
  477. reader.setEntityResolver(new IgnoreDTDEntityResolver());
  478. Reader stringReader = new StringReader(str);
  479. Document document = reader.read(stringReader);
  480. XPath xpath = document.createXPath("//claim-text");
  481. List<Element> element = (List<Element>) xpath.selectNodes(document);
  482. if (element.size() == 0) {
  483. xpath = document.createXPath("//business:ClaimText");
  484. element = (List<Element>) xpath.selectNodes(document);
  485. }
  486. List<String> reClaims = new ArrayList<>();
  487. element.forEach(item -> {
  488. String claim = item.getText();
  489. claim = claim.replaceAll("\r\n|\r|\n| ", "");
  490. reClaims.add(claim);
  491. });
  492. String reClaim = "";
  493. if (reClaims.size() != 0) {
  494. reClaim = cn.cslg.pas.common.utils.StringUtils.join(reClaims, "");
  495. }
  496. return reClaim;
  497. }
  498. //获取说明书文本
  499. public String getFullText(String str) throws DocumentException {
  500. SAXReader reader = new SAXReader();
  501. reader.setEntityResolver(new IgnoreDTDEntityResolver());
  502. Reader stringReader = new StringReader(str);
  503. Document document = reader.read(stringReader);
  504. XPath xpath = document.createXPath("//description//p");
  505. List<Element> elements = (List<Element>) xpath.selectNodes(document);
  506. if (elements.size() == 0) {
  507. xpath = document.createXPath("//business:Description//base:Paragraphs");
  508. elements = (List<Element>) xpath.selectNodes(document);
  509. }
  510. List<String> reStrs = new ArrayList<>();
  511. Integer count = 1;
  512. for (Element item : elements) {
  513. String claim = item.getText().replaceAll("<br/>", "");
  514. if (!claim.trim().equals("技术领域")
  515. && !claim.trim().equals("发明内容")
  516. && !claim.trim().equals("附图说明")
  517. && !claim.trim().equals("具体实施方式")
  518. && !claim.trim().equals("背景技术")) {
  519. String formattedNum = String.format("%04d", count);
  520. claim = "[" + formattedNum + "]" + claim;
  521. count++;
  522. }
  523. reStrs.add(claim);
  524. }
  525. String reStr = "";
  526. if (reStrs.size() != 0) {
  527. reStr = StringUtils.join(reStrs, "\r\n");
  528. }
  529. return reStr;
  530. }
  531. /**
  532. * @param patentNo
  533. * @return
  534. * @throws IOException
  535. * @author 李仁杰
  536. * 从专利之星获取世界专利pdf
  537. */
  538. public String getEnPdfApi(String patentNo) {
  539. String url = " https://api.patentstar.com.cn/api/Patent/EnPdf/" + patentNo;
  540. JSONObject configObject = this.getConfigObject(4, 2);
  541. String appId = configObject.getString("appId");
  542. String appKey = configObject.getString("appKey");
  543. // String appId = "1000046";
  544. // String appkey = "6AE6D4DC6AF94F26862501EDEE9E27A2";
  545. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  546. String Sign = appId + appKey + currentTimeMillis.toString();
  547. String signMd5 = FormatUtil.MD5(Sign);
  548. // 创建一个OkHttpClient对象
  549. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  550. .connectTimeout(60, TimeUnit.SECONDS)
  551. .writeTimeout(60, TimeUnit.SECONDS)
  552. .readTimeout(60, TimeUnit.SECONDS)
  553. .dns(new XDns(100000))
  554. .build();
  555. // 创建一个请求对象
  556. Request request = new Request.Builder().url(url)
  557. .addHeader("_appid", appId)
  558. .addHeader("_timestamp", currentTimeMillis.toString())
  559. .addHeader("_sign", signMd5)
  560. .get().build();
  561. // 发送请求获取响应
  562. try {
  563. Response response = okHttpClient.newCall(request).execute();
  564. // 判断请求是否成功
  565. if (response.isSuccessful()) {
  566. // 打印服务端返回结果
  567. return Objects.requireNonNull(response.body()).string();
  568. }
  569. } catch (IOException e) {
  570. e.printStackTrace();
  571. }
  572. return "{}";
  573. }
  574. /**
  575. * @param patentNo
  576. * @return
  577. * @throws IOException
  578. * @author 李仁杰
  579. * 从专利之星获取世界专利著录信息
  580. */
  581. public String getENBibApi(String patentNo) {
  582. String url = "https://api.patentstar.com.cn/api/Patent/EnBib/" + patentNo;
  583. JSONObject configObject = this.getConfigObject(4, 2);
  584. String appId = configObject.getString("appId");
  585. String appKey = configObject.getString("appKey");
  586. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  587. String Sign = appId + appKey + currentTimeMillis.toString();
  588. String signMd5 = FormatUtil.MD5(Sign);
  589. // 创建一个OkHttpClient对象
  590. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  591. .connectTimeout(60, TimeUnit.SECONDS)
  592. .writeTimeout(60, TimeUnit.SECONDS)
  593. .readTimeout(60, TimeUnit.SECONDS)
  594. .dns(new XDns(100000))
  595. .build();
  596. // 创建一个请求对象
  597. Request request = new Request.Builder().url(url)
  598. .addHeader("_appid", appId)
  599. .addHeader("_timestamp", currentTimeMillis.toString())
  600. .addHeader("_sign", signMd5)
  601. .get().build();
  602. // 发送请求获取响应
  603. try {
  604. Response response = okHttpClient.newCall(request).execute();
  605. // 判断请求是否成功
  606. if (response.isSuccessful()) {
  607. // 打印服务端返回结果
  608. return Objects.requireNonNull(response.body()).string();
  609. }
  610. } catch (IOException e) {
  611. e.printStackTrace();
  612. }
  613. return "{}";
  614. }
  615. /**
  616. * @param patentNo
  617. * @return
  618. * @throws IOException
  619. * @author 李仁杰
  620. * 从专利之星获取同族专利
  621. */
  622. public String getFamilyByPubNoApi(String patentNo) {
  623. String url = "https://api.patentstar.com.cn/api/Patent/FamilyByPubNo/" + patentNo;
  624. JSONObject configObject = this.getConfigObject(4, 2);
  625. String appId = configObject.getString("appId");
  626. String appKey = configObject.getString("appKey");
  627. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  628. String Sign = appId + appKey + currentTimeMillis.toString();
  629. String signMd5 = FormatUtil.MD5(Sign);
  630. // 创建一个OkHttpClient对象
  631. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  632. .connectTimeout(60, TimeUnit.SECONDS)
  633. .writeTimeout(60, TimeUnit.SECONDS)
  634. .readTimeout(60, TimeUnit.SECONDS)
  635. .dns(new XDns(100000))
  636. .build();
  637. // 创建一个请求对象
  638. Request request = new Request.Builder().url(url)
  639. .addHeader("_appid", appId)
  640. .addHeader("_timestamp", currentTimeMillis.toString())
  641. .addHeader("_sign", signMd5)
  642. .get().build();
  643. // 发送请求获取响应
  644. try {
  645. Response response = okHttpClient.newCall(request).execute();
  646. // 判断请求是否成功
  647. if (response.isSuccessful()) {
  648. // 打印服务端返回结果
  649. return Objects.requireNonNull(response.body()).string();
  650. }
  651. } catch (IOException e) {
  652. e.printStackTrace();
  653. }
  654. return "{}";
  655. }
  656. /**
  657. * @param patentNo
  658. * @return
  659. * @throws IOException
  660. * @author 李仁杰
  661. * 获得专利被引用次数api
  662. */
  663. public String getCitedNumByPubNoApi(String patentNo) throws IOException {
  664. String url = "https://api.patentstar.com.cn/api/Patent/CitedNumByPubNo/" + patentNo;
  665. JSONObject configObject = this.getConfigObject(4, 2);
  666. String appId = configObject.getString("appId");
  667. String appKey = configObject.getString("appKey");
  668. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  669. String Sign = appId + appKey + currentTimeMillis.toString();
  670. String signMd5 = FormatUtil.MD5(Sign);
  671. // 创建一个OkHttpClient对象
  672. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  673. .connectTimeout(60, TimeUnit.SECONDS)
  674. .writeTimeout(60, TimeUnit.SECONDS)
  675. .readTimeout(60, TimeUnit.SECONDS)
  676. .dns(new XDns(100000))
  677. .build();
  678. // 创建一个请求对象
  679. Request request = new Request.Builder().url(url)
  680. .addHeader("_appid", appId)
  681. .addHeader("_timestamp", currentTimeMillis.toString())
  682. .addHeader("_sign", signMd5)
  683. .get().build();
  684. // 发送请求获取响应
  685. try {
  686. Response response = okHttpClient.newCall(request).execute();
  687. // 判断请求是否成功
  688. if (response.isSuccessful()) {
  689. // 打印服务端返回结果
  690. return Objects.requireNonNull(response.body()).string();
  691. }
  692. } catch (IOException e) {
  693. e.printStackTrace();
  694. }
  695. return "{}";
  696. }
  697. public JSONObject getConfigObject(Integer webId, Integer webGroup) {
  698. WebLoginConfig webLoginConfig = webLoginConfigService.getConfig(webId, webGroup);
  699. if (webLoginConfig == null) {
  700. return null;
  701. }
  702. String config = webLoginConfig.getWebConfig();
  703. JSONObject jsonObject = JSONObject.parseObject(config);
  704. return jsonObject;
  705. }
  706. public List<PatentStarListDTO> splitPatentNoByType(List<String> originalList, PatentStarListDTO patentStarListDTO) {
  707. List<String> cnStrings = new ArrayList<>();
  708. List<String> wdStrings = new ArrayList<>();
  709. List<List<String>> result = new ArrayList<>();
  710. result.add(cnStrings);
  711. result.add(wdStrings);
  712. // 记录CN类型的字符串数量
  713. int cnCount = 0;
  714. // 记录WD类型的字符串数量
  715. int wdCount = 0;
  716. List<PatentStarListDTO> patentStarListDTOS = new ArrayList<>();
  717. //遍历初始集合
  718. for (String str : originalList) {
  719. if (str.startsWith("CN")) {
  720. cnStrings.add(str);
  721. cnCount++;
  722. if (cnCount >= 100) {
  723. cnStrings = new ArrayList<>();
  724. result.add(cnStrings);
  725. cnCount = 0;
  726. }
  727. } else {
  728. wdStrings.add(str);
  729. wdCount++;
  730. if (wdCount >= 100) {
  731. wdStrings = new ArrayList<>();
  732. result.add(wdStrings);
  733. wdCount = 0;
  734. }
  735. }
  736. }
  737. result.forEach(item -> {
  738. if (item.size() > 0) {
  739. String dbType = "CN";
  740. String patentNo = item.get(0);
  741. if (!patentNo.startsWith("CN")) {
  742. dbType = "WD";
  743. }
  744. String join = StringUtils.join(item, " OR ");
  745. String conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
  746. PatentStarListDTO patentStarListDTO1 = new PatentStarListDTO();
  747. patentStarListDTO1.setOrderByType(patentStarListDTO.getOrderByType());
  748. patentStarListDTO1.setCurrentQuery(conditions);
  749. patentStarListDTO1.setPageNum(patentStarListDTO.getPageNum());
  750. patentStarListDTO1.setDBType(dbType);
  751. patentStarListDTO1.setCurrentQuery(conditions);
  752. patentStarListDTO1.setRowCount(50);
  753. patentStarListDTO1.setTotal(item.size());
  754. patentStarListDTOS.add(patentStarListDTO1);
  755. }
  756. });
  757. return patentStarListDTOS;
  758. }
  759. public StarPatentVO getPatentByNo(String patentNo) {
  760. StarPatentVO starPatentVO = null;
  761. String condition = "AN=(" + patentNo + ") OR PN=(" + patentNo + ") OR GN=(" + patentNo + ")";
  762. String dbType = "CN";
  763. if (!patentNo.startsWith("CN")) {
  764. dbType = "WD";
  765. }
  766. PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
  767. patentStarListDTO.setCurrentQuery(condition);
  768. patentStarListDTO.setPageNum(1);
  769. patentStarListDTO.setRowCount(50);
  770. patentStarListDTO.setDBType(dbType);
  771. try {
  772. Map<String, Object> resultMap = this.patentStarSearchApi(patentStarListDTO);
  773. if (resultMap == null || (Integer) resultMap.get("total") == 0) {
  774. return starPatentVO;
  775. }
  776. List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
  777. starPatentVO = starPatents.get(0);
  778. } catch (Exception e) {
  779. }
  780. return starPatentVO;
  781. }
  782. private List<PatentColumnDTO> loadPatent(List<StarPatentVO> starPatentVOS) {
  783. List<PatentColumnDTO> patentColumnDTOS = new ArrayList<>();
  784. starPatentVOS.forEach(item -> {
  785. PatentColumnDTO patentColumnDTO = new PatentColumnDTO();
  786. //申请号
  787. patentColumnDTO.setAppNo(item.getApplicationNo());
  788. //装载公开号
  789. patentColumnDTO.setPublicNo(item.getPublicNo());
  790. //装载公告号
  791. patentColumnDTO.setGrantNo(item.getPublicAccreditNo());
  792. //装载专利状态
  793. if (item.getLG() != null) {
  794. patentColumnDTO.setSimpleStatus(item.getLG().toString());
  795. }
  796. //装载摘要
  797. List<Text> abstractList = new ArrayList<>();
  798. Text text = new Text();
  799. text.setTextContent(item.getAbstractStr());
  800. text.setIfOrigin(true);
  801. abstractList.add(text);
  802. patentColumnDTO.setAbstractStr(abstractList);
  803. //装载标题
  804. List<Text> titleList = new ArrayList<>();
  805. Text title = new Text();
  806. title.setTextContent(item.getName());
  807. title.setIfOrigin(true);
  808. titleList.add(title);
  809. // text.setLanguage(patent.getAppCountry());
  810. patentColumnDTO.setTitle(titleList);
  811. //装载权利要求
  812. List<Text> claimList = new ArrayList<>();
  813. Text claim = new Text();
  814. claim.setTextContent(item.getClaimStr());
  815. claim.setIfOrigin(true);
  816. claimList.add(claim);
  817. patentColumnDTO.setClaim(claimList);
  818. //装载专利号
  819. if (patentColumnDTO.getAppNo() != null) {
  820. if (patentColumnDTO.getAppNo().trim().startsWith("CN")) {
  821. patentColumnDTO.setPatentNo(patentColumnDTO.getAppNo());
  822. } else {
  823. if (patentColumnDTO.getPublicNo() != null) {
  824. patentColumnDTO.setPatentNo(patentColumnDTO.getPublicNo());
  825. } else if (patentColumnDTO.getGrantNo() != null) {
  826. patentColumnDTO.setPatentNo(patentColumnDTO.getGrantNo());
  827. } else {
  828. patentColumnDTO.setPatentNo(patentColumnDTO.getAppNo());
  829. }
  830. }
  831. }
  832. //装载申请日
  833. if (item.getApplicationDate() != null && !item.getApplicationDate().trim().equals("")) {
  834. patentColumnDTO.setAppDate(DateUtils.strToDate(item.getApplicationDate()));
  835. }
  836. //装载申请人地址
  837. PersonAddress appAddress = new PersonAddress();
  838. appAddress.setAddress(item.getApplicationAddress());
  839. appAddress.setProvince(item.getProvinceStr());
  840. patentColumnDTO.setApplicantAddr(appAddress);
  841. //装载ipc(主)分类号
  842. PatentClassify mipcClassify = new PatentClassify();
  843. mipcClassify.setLevel5(item.getMainIpc());
  844. patentColumnDTO.setMipc(mipcClassify);
  845. //装载ipc分类号
  846. List<PatentClassify> classifies = new ArrayList<>();
  847. String[] split = item.getIpcListStr().split(";");
  848. for (String ipc : split) {
  849. PatentClassify ipcClassify = new PatentClassify();
  850. ipcClassify.setLevel5(ipc);
  851. }
  852. patentColumnDTO.setIpc(classifies);
  853. //获取摘要附图
  854. // String pictureApi = this.getPictureApi(item.getRowApplicationNo());
  855. // patentColumnDTO.setPictureGuid(pictureApi);
  856. //获取外部专利原始申请号
  857. patentColumnDTO.setRowApplicationNo(item.getRowApplicationNo());
  858. //获取法律状态
  859. // String cnLegalApi = this.getCnLegalApi(item.getRowApplicationNo());
  860. // patentColumnDTO.setLegalStatus(Arrays.asList(cnLegalApi));
  861. //获取被引用次数
  862. //装载公开日
  863. if (item.getPublicDate() != null && !item.getPublicDate().trim().equals("")) {
  864. patentColumnDTO.setPublicDate(DateUtils.strToDate(item.getPublicDate()));
  865. }
  866. //装载申请人
  867. if (item.getApplicantStr() != null && !item.getApplicantStr().trim().equals("")) {
  868. List<String> names = Arrays.asList(item.getApplicantStr().split(";"));
  869. patentColumnDTO.setApplicant(names);
  870. }
  871. //装载发明人
  872. if (item.getInventorStr() != null && !item.getInventorStr().trim().equals("")) {
  873. List<String> names = Arrays.asList(item.getInventorStr().split(";"));
  874. patentColumnDTO.setInventor(names);
  875. }
  876. //装载权利人
  877. if (item.getCurrentApplicantStr() != null && !item.getCurrentApplicantStr().trim().equals("")) {
  878. List<String> names = Arrays.asList(item.getCurrentApplicantStr().split(";"));
  879. patentColumnDTO.setRightHolder(names);
  880. }
  881. //装载代理人
  882. if (item.getAgentStr() != null && !item.getAgentStr().trim().equals("")) {
  883. List<String> names = Arrays.asList(item.getAgentStr().split(";"));
  884. patentColumnDTO.setAgent(names);
  885. }
  886. //装载代理机构
  887. if (item.getAgencyStr() != null && !item.getAgencyStr().trim().equals("")) {
  888. patentColumnDTO.setAgency(item.getAgencyStr());
  889. }
  890. patentColumnDTOS.add(patentColumnDTO);
  891. });
  892. return patentColumnDTOS;
  893. }
  894. /**
  895. * 根据专利号查询外部权利要求
  896. *
  897. * @param appNo
  898. * @return
  899. * @throws IOException
  900. */
  901. public SelectClaimDTO queryExternalClaim(String appNo) throws IOException {
  902. List<Text> claimList = new ArrayList<>();
  903. //获取公开说明书
  904. String cnFullXmlApi = null;
  905. try {
  906. cnFullXmlApi = this.getCnFullXmlApi(appNo);
  907. } catch (IOException e) {
  908. e.printStackTrace();
  909. }
  910. try {
  911. String fullText = this.getExternalClaim(cnFullXmlApi);
  912. Text pubText = new Text();
  913. if (fullText != null && !fullText.trim().equals("")) {
  914. fullText = PatentRightUtils.getFormatClaim(fullText, "CN");
  915. }
  916. pubText.setTextContent(fullText);
  917. pubText.setIfOrigin(true);
  918. claimList.add(pubText);
  919. } catch (DocumentException e) {
  920. e.printStackTrace();
  921. }
  922. SelectClaimDTO dto = new SelectClaimDTO();
  923. if (!CollectionUtils.isEmpty(claimList)) {
  924. dto.setClaimContent(claimList);
  925. }
  926. return dto;
  927. }
  928. /**
  929. * 根据专利号查询外部权利要求
  930. *
  931. * @param vo
  932. * @return
  933. * @throws IOException
  934. */
  935. public PatentColumnDTO queryExternalDetail(QueryExternalFamilyVO vo) throws IOException {
  936. PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
  937. String condition = "AN=" + vo.getPatentNo() + " OR " + "PN=" + vo.getPatentNo();
  938. patentStarListDTO.setCurrentQuery(condition);
  939. String index = vo.getPatentNo().substring(0, 2);
  940. if (index.equals("CN")) {
  941. patentStarListDTO.setDBType("CN");
  942. } else {
  943. patentStarListDTO.setDBType("WD");
  944. }
  945. patentStarListDTO.setOrderBy("AD");
  946. patentStarListDTO.setOrderByType("DESC");
  947. patentStarListDTO.setPageNum(1);
  948. patentStarListDTO.setRowCount(10);
  949. Records records = this.patentStarSearchLocal(patentStarListDTO);
  950. Object data = records.getData();
  951. String s = JSONArray.toJSONString(data);
  952. List<PatentColumnDTO> list = JSONArray.parseArray(s, PatentColumnDTO.class);
  953. PatentColumnDTO dto = new PatentColumnDTO();
  954. if (!CollectionUtils.isEmpty(list)) {
  955. for (PatentColumnDTO columnDTO : list) {
  956. BeanUtils.copyProperties(columnDTO, dto);
  957. }
  958. }
  959. return dto;
  960. }
  961. /**
  962. * 查询外部专利同族专利
  963. *
  964. * @param vo
  965. * @return
  966. * @throws IOException
  967. */
  968. public Records queryExternalFamily(QueryExternalFamilyVO vo) throws IOException {
  969. Records records = new Records();
  970. String family = this.getFamilyByPubNoApi(vo.getPatentNo());
  971. QueryExternalFamilyDTO familyDTO = JSONObject.parseObject(family, QueryExternalFamilyDTO.class);
  972. String familyInfos = familyDTO.getFamilyinfo();
  973. List<String> publicNos = new ArrayList<>();
  974. if (StringUtils.isNotEmpty(familyInfos) && familyInfos.equals("{}")) {
  975. publicNos = Arrays.asList(familyInfos.split(";"));
  976. }
  977. String pubNo = "";
  978. if (!CollectionUtils.isEmpty(publicNos)) {
  979. int count = publicNos.size() - 1;
  980. for (int i = 0; i < publicNos.size(); i++) {
  981. String s = publicNos.get(i);
  982. if (i == count) {
  983. pubNo = pubNo + s;
  984. } else {
  985. pubNo = pubNo + s + " " + "OR" + " ";
  986. }
  987. }
  988. }
  989. if (StringUtils.isNotEmpty(pubNo)) {
  990. PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
  991. String condition = "PN=" + "(" + pubNo + ")";
  992. patentStarListDTO.setCurrentQuery(condition);
  993. patentStarListDTO.setDBType("CN");
  994. patentStarListDTO.setOrderBy("AD");
  995. patentStarListDTO.setOrderByType("DESC");
  996. patentStarListDTO.setPageNum(vo.getPageNum());
  997. patentStarListDTO.setRowCount(vo.getPageSize());
  998. records = this.patentStarSearchLocal(patentStarListDTO);
  999. }
  1000. return records;
  1001. }
  1002. /**
  1003. * 获取公开说明书
  1004. *
  1005. * @param appNo
  1006. * @return
  1007. */
  1008. public List<Text> getCnFullText(String appNo) {
  1009. List<Text> pubTextList = new ArrayList<>();
  1010. //获取公开说明书
  1011. String cnFullXmlApi = null;
  1012. try {
  1013. cnFullXmlApi = this.getCnFullXmlApi(appNo);
  1014. } catch (IOException e) {
  1015. e.printStackTrace();
  1016. }
  1017. try {
  1018. String fullText = this.getFullText(cnFullXmlApi);
  1019. Text pubText = new Text();
  1020. pubText.setTextContent(fullText);
  1021. pubText.setIfOrigin(true);
  1022. pubTextList.add(pubText);
  1023. } catch (DocumentException e) {
  1024. e.printStackTrace();
  1025. }
  1026. return pubTextList;
  1027. }
  1028. /**
  1029. * 获得中国专利pdf全文
  1030. *
  1031. * @param appNo
  1032. * @return
  1033. * @throws IOException
  1034. */
  1035. public List<InnerPatentPdfDTO> getExternalTextPdf(String appNo, String rowApplicationNo) throws IOException {
  1036. List<InnerPatentPdfDTO> list = new ArrayList<>();
  1037. String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
  1038. if (StringUtils.isNotEmpty(appNo) && appNo.contains("CN")) {
  1039. String pdfUrlStr = this.getCnPdfApi(rowApplicationNo);
  1040. //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
  1041. if (StringUtils.isNotEmpty(pdfUrlStr)) {
  1042. if (pdfUrlStr.contains("|http")) { //若包含公开和授权两个pdf
  1043. String[] pdfUrlArr = pdfUrlStr.split("\\|http");
  1044. pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("|"));
  1045. pdfUrlArr[1] = "http" + pdfUrlArr[1];
  1046. pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("|"));
  1047. if (pdfUrl1.contains("0A_CN_0.pdf")) {
  1048. String guid1 = FormatUtil.getPDFFormat(appNo, 0);
  1049. if (StringUtils.isNotEmpty(guid1)) {
  1050. InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
  1051. dto.setPdfGuid(guid1);
  1052. dto.setType(0);
  1053. list.add(dto);
  1054. }
  1055. //授权说明书pdf
  1056. String guid2 = FormatUtil.getPDFFormat(appNo, 1);
  1057. if (StringUtils.isNotEmpty(guid2)) {
  1058. InnerPatentPdfDTO dto1 = new InnerPatentPdfDTO();
  1059. dto1.setPdfGuid(guid2);
  1060. dto1.setType(1);
  1061. list.add(dto1);
  1062. }
  1063. } else {
  1064. String guid1 = FormatUtil.getPDFFormat(appNo, 1);
  1065. if (StringUtils.isNotEmpty(guid1)) {
  1066. InnerPatentPdfDTO dto1 = new InnerPatentPdfDTO();
  1067. dto1.setPdfGuid(guid1);
  1068. dto1.setType(1);
  1069. list.add(dto1);
  1070. }
  1071. String guid2 = FormatUtil.getPDFFormat(appNo, 0);
  1072. if (StringUtils.isNotEmpty(guid2)) {
  1073. InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
  1074. dto.setPdfGuid(guid2);
  1075. dto.setType(0);
  1076. list.add(dto);
  1077. }
  1078. }
  1079. } else { //若只有一个
  1080. pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"));
  1081. // pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"), pdfUrlStr.indexOf("?"));
  1082. if (pdfUrl1.contains("0A_CN_0.pdf")) {
  1083. String guid1 = FormatUtil.getPDFFormat(appNo, 0);
  1084. if (StringUtils.isNotEmpty(guid1)) {
  1085. InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
  1086. dto.setPdfGuid(guid1);
  1087. dto.setType(0);
  1088. list.add(dto);
  1089. }
  1090. } else {
  1091. String guid1 = FormatUtil.getPDFFormat(appNo, 1);
  1092. if (StringUtils.isNotEmpty(guid1)) {
  1093. InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
  1094. dto.setPdfGuid(guid1);
  1095. dto.setType(1);
  1096. list.add(dto);
  1097. }
  1098. }
  1099. }
  1100. }
  1101. }
  1102. return list;
  1103. }
  1104. /**
  1105. * 获取附图
  1106. *
  1107. * @param appNo
  1108. * @return
  1109. */
  1110. public List<String> getExternalFigure(String appNo) throws IOException {
  1111. List<String> list = new ArrayList<>();
  1112. String wgPictureApi = this.getWGPictureApi(appNo);
  1113. if (StringUtils.isNotEmpty(wgPictureApi)) {
  1114. if (wgPictureApi.contains("|http")) {
  1115. String[] urlArr = wgPictureApi.split("\\|");
  1116. list.addAll(Arrays.asList(urlArr));
  1117. } else {
  1118. list.add(wgPictureApi);
  1119. }
  1120. }
  1121. return list;
  1122. }
  1123. /**
  1124. * 获取摘要附图
  1125. *
  1126. * @param appNo
  1127. * @return
  1128. */
  1129. public String getPictureGuid(String appNo) {
  1130. return this.getPictureApi(appNo);
  1131. }
  1132. /**
  1133. * @param appNo
  1134. * @return
  1135. */
  1136. public ExternalLegalInfoDTO getLegalStatus(String appNo) throws ParseException {
  1137. ExternalLegalInfoDTO infoDTO = new ExternalLegalInfoDTO();
  1138. List<String> list = new ArrayList<>();
  1139. List<LegalEvent> legalEvents = new ArrayList<>();
  1140. String cnLegalApi = this.getCnLegalApi(appNo);
  1141. if (StringUtils.isNotEmpty(cnLegalApi) && !cnLegalApi.equals("{}") && !cnLegalApi.contains("408")) {
  1142. List<ExternalLegalStatusDTO> statusDTOS = JSONArray.parseArray(cnLegalApi, ExternalLegalStatusDTO.class);
  1143. if (!CollectionUtils.isEmpty(statusDTOS)) {
  1144. List<ExternalLegalStatusDTO> statusList = statusDTOS.stream().sorted(Comparator.comparing(ExternalLegalStatusDTO::getLegalDate).reversed()).collect(Collectors.toList());
  1145. if (!CollectionUtils.isEmpty(statusList)) {
  1146. ExternalLegalStatusDTO statusDTO = statusList.get(0);
  1147. list.add(statusDTO.getLegalStatus());
  1148. }
  1149. for (ExternalLegalStatusDTO dto : statusDTOS) {
  1150. LegalEvent event = new LegalEvent();
  1151. event.setCode(dto.getLegalCode());
  1152. event.setName(dto.getLegalStatus());
  1153. event.setDescription(dto.getLegalStatusInfo());
  1154. if (StringUtils.isNotEmpty(dto.getLegalDate())) {
  1155. SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
  1156. Date date = format.parse(dto.getLegalDate());
  1157. event.setEventDate(date);
  1158. }
  1159. legalEvents.add(event);
  1160. }
  1161. }
  1162. }
  1163. infoDTO.setLegalStatus(list);
  1164. infoDTO.setLegalEvents(legalEvents);
  1165. return infoDTO;
  1166. }
  1167. public SelectClaimDTO getOrginCalim(String appNo) throws IOException {
  1168. List<Text> claimList = new ArrayList<>();
  1169. //获取公开说明书
  1170. String cnFullXmlApi = null;
  1171. try {
  1172. cnFullXmlApi = this.getCnFullXmlApi(appNo);
  1173. } catch (IOException e) {
  1174. e.printStackTrace();
  1175. }
  1176. try {
  1177. String fullText = this.getExternalClaim(cnFullXmlApi);
  1178. Text pubText = new Text();
  1179. pubText.setTextContent(fullText);
  1180. pubText.setIfOrigin(true);
  1181. claimList.add(pubText);
  1182. } catch (DocumentException e) {
  1183. e.printStackTrace();
  1184. }
  1185. SelectClaimDTO dto = new SelectClaimDTO();
  1186. if (!CollectionUtils.isEmpty(claimList)) {
  1187. dto.setClaimContent(claimList);
  1188. }
  1189. return dto;
  1190. }
  1191. }