PatentStarApiService.java 54 KB

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