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