PatentStarApiService.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. package com.example.xiaoshiweixinback.service.importPatent;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.example.xiaoshiweixinback.business.config.XDns;
  5. import com.example.xiaoshiweixinback.business.utils.DateUtils2;
  6. import com.example.xiaoshiweixinback.business.utils.FormatUtil;
  7. import com.example.xiaoshiweixinback.business.utils.StringUtils;
  8. import com.example.xiaoshiweixinback.entity.dto.patent.PatentStarDTO;
  9. import com.example.xiaoshiweixinback.entity.dto.patent.PatentStarListDTO;
  10. import com.example.xiaoshiweixinback.entity.dto.patent.StarPatentVO;
  11. import lombok.RequiredArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import okhttp3.FormBody;
  14. import okhttp3.OkHttpClient;
  15. import okhttp3.Request;
  16. import okhttp3.Response;
  17. import org.dom4j.Document;
  18. import org.dom4j.DocumentException;
  19. import org.dom4j.Element;
  20. import org.dom4j.XPath;
  21. import org.dom4j.io.SAXReader;
  22. import org.joda.time.DateTime;
  23. import org.joda.time.format.DateTimeFormat;
  24. import org.joda.time.format.DateTimeFormatter;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.context.ApplicationContext;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.util.CollectionUtils;
  30. import java.io.IOException;
  31. import java.io.Reader;
  32. import java.io.StringReader;
  33. import java.text.ParseException;
  34. import java.text.SimpleDateFormat;
  35. import java.util.*;
  36. import java.util.concurrent.TimeUnit;
  37. import java.util.stream.Collectors;
  38. /**
  39. * 调用外部接口的Service类 PCS:权限系统
  40. *
  41. * @Author chenyu
  42. * @Date 2023/4/25
  43. */
  44. @RequiredArgsConstructor
  45. @Slf4j
  46. @Service
  47. public class PatentStarApiService {
  48. private ApplicationContext applicationContext;
  49. @Autowired
  50. private FormatQueryService formatQueryService;
  51. public Map<String, Object> patentStarSearchApi(PatentStarListDTO PatentStarListDTO) throws IOException {
  52. try {
  53. if (PatentStarListDTO.getFormed() == null || PatentStarListDTO.getFormed() == false) {
  54. String formQuery = PatentStarListDTO.getCurrentQuery();
  55. PatentStarListDTO.setCurrentQuery(formatQueryService.reQuery(formQuery, "webSearchConfig"));
  56. if (PatentStarListDTO.getDBType().equals("WD")) {
  57. StringBuilder stringBuilder = new StringBuilder(PatentStarListDTO.getCurrentQuery());
  58. stringBuilder.insert(PatentStarListDTO.getCurrentQuery().length() - 1, "-CN/GJ");
  59. PatentStarListDTO.setCurrentQuery(stringBuilder.toString());
  60. }
  61. PatentStarListDTO.setFormed(true);
  62. }
  63. } catch (Exception e) {
  64. return null;
  65. }
  66. JSONObject configObject = this.getConfigObject(4, 1);
  67. String appId = configObject.getString("appId");
  68. String appKey = configObject.getString("appKey");
  69. PatentStarDTO patentStarDto = new PatentStarDTO();
  70. BeanUtils.copyProperties(PatentStarListDTO, patentStarDto);
  71. String json = JSONObject.toJSONString(patentStarDto);
  72. String url = "http://s.patentstar.com.cn/SearchAPI/PatentSearch/ResultGet";
  73. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  74. String Sign = appKey + currentTimeMillis.toString();
  75. String signMd5 = FormatUtil.MD5(Sign);
  76. // 创建一个OkHttpClient对象
  77. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  78. .connectTimeout(60, TimeUnit.SECONDS)
  79. .writeTimeout(60, TimeUnit.SECONDS)
  80. .readTimeout(60, TimeUnit.SECONDS)
  81. .dns(new XDns(100000))
  82. .build();
  83. // 创建一个RequestBody(参数1:数据类型 参数2传递的json串)
  84. FormBody.Builder builder = new FormBody.Builder();
  85. builder.add("AppID", appId);
  86. builder.add("Stamp", currentTimeMillis.toString());
  87. builder.add("Sign", signMd5);
  88. builder.add("QueryJson", json);
  89. FormBody requestBody = builder.build();
  90. // 创建一个请求对象
  91. Request request = new Request.Builder().url(url).post(requestBody).build();
  92. // 发送请求获取响应
  93. try {
  94. Response response = okHttpClient.newCall(request).execute();
  95. // 判断请求是否成功
  96. if (response.isSuccessful()) {
  97. JSONObject jsonObject = JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
  98. if (jsonObject.get("Ret").equals(500) || jsonObject.get("Data") == null) {
  99. return null;
  100. }
  101. JSONObject Data = (JSONObject) jsonObject.get("Data");
  102. List<StarPatentVO> starPatentVOS = JSONArray.parseArray(Data.get("List").toString(), StarPatentVO.class);
  103. Map<String, Object> reMap = new HashMap<>();
  104. reMap.put("size", PatentStarListDTO.getRowCount());
  105. reMap.put("current", PatentStarListDTO.getPageNum());
  106. reMap.put("records", starPatentVOS);
  107. reMap.put("total", Data.get("HitCount"));
  108. return reMap;
  109. }
  110. } catch (IOException e) {
  111. e.printStackTrace();
  112. return null;
  113. }
  114. return null;
  115. }
  116. public List<PatentStarListDTO> getSplitedConditions(PatentStarListDTO patentStarListDTO, int patentNum) throws IOException {
  117. DateTime nowDate = new DateTime();
  118. DateTime date = DateUtils2.formStrToDateTime("1900-01-01");
  119. //超过1万的列表
  120. List<PatentStarListDTO> PatentStarListDTOs = new ArrayList<>();
  121. //返回的列表
  122. List<PatentStarListDTO> reDtos = new ArrayList<>();
  123. patentStarListDTO.setStartTime(date);
  124. patentStarListDTO.setEndTime(nowDate);
  125. patentStarListDTO.setOrginCondition(patentStarListDTO.getCurrentQuery());
  126. String formQuery = patentStarListDTO.getCurrentQuery();
  127. // patentStarListDTO.setOrginCondition(PatentStarApiService.formatQuery(formQuery));
  128. PatentStarListDTOs.add(patentStarListDTO);
  129. while (PatentStarListDTOs.size() > 0) {
  130. PatentStarListDTO dto = PatentStarListDTOs.get(0);
  131. PatentStarListDTOs.remove(dto);
  132. Map<String, Object> map1 = this.patentStarSearchApi(dto);
  133. Integer total1 = Integer.parseInt(map1.get("total").toString());
  134. dto.setTotal(total1);
  135. patentStarListDTO.setFormed(true);
  136. if (total1 > patentNum) {
  137. DateTime startTime1 = dto.getStartTime();
  138. DateTime endTime1 = dto.getEndTime();
  139. List<DateTime> dateTimes = DateUtils2.formStrToDateTime(startTime1, endTime1);
  140. PatentStarListDTO dto1 = new PatentStarListDTO();
  141. BeanUtils.copyProperties(dto, dto1);
  142. dto1.setStartTime(dateTimes.get(0));
  143. dto1.setEndTime(dateTimes.get(1));
  144. this.setConditions(dto1);
  145. PatentStarListDTO dto2 = new PatentStarListDTO();
  146. BeanUtils.copyProperties(dto, dto2);
  147. dto2.setStartTime(dateTimes.get(2));
  148. dto2.setEndTime(dateTimes.get(3));
  149. this.setConditions(dto2);
  150. PatentStarListDTOs.add(dto1);
  151. PatentStarListDTOs.add(dto2);
  152. } else if (total1 != 0) {
  153. reDtos.add(dto);
  154. }
  155. }
  156. return reDtos;
  157. }
  158. public void setConditions(PatentStarListDTO PatentStarListDTO) {
  159. PatentStarListDTO.setFormed(false);
  160. DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
  161. String startStr = formatter.print(PatentStarListDTO.getStartTime());
  162. String endStr = formatter.print(PatentStarListDTO.getEndTime());
  163. String cond = " AND AD=" + startStr + "~" + endStr;
  164. Integer len = PatentStarListDTO.getOrginCondition().length();
  165. StringBuilder stringBuilder = new StringBuilder(PatentStarListDTO.getOrginCondition());
  166. stringBuilder.insert(len - 1, cond);
  167. PatentStarListDTO.setCurrentQuery(stringBuilder.toString());
  168. }
  169. /**
  170. * @param appNo
  171. * @return
  172. * @throws IOException
  173. * @author 李仁杰
  174. * 从专利之星获取中国专利著录
  175. */
  176. public String getCnBibApi(String appNo) {
  177. String url = "https://api.patentstar.com.cn/api/Patent/CnBibo/" + appNo;
  178. JSONObject configObject = this.getConfigObject(4, 2);
  179. String appId = configObject.getString("appId");
  180. String appKey = configObject.getString("appKey");
  181. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  182. String Sign = appId + appKey + currentTimeMillis.toString();
  183. String signMd5 = FormatUtil.MD5(Sign);
  184. // 创建一个OkHttpClient对象
  185. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  186. .connectTimeout(60, TimeUnit.SECONDS)
  187. .writeTimeout(60, TimeUnit.SECONDS)
  188. .readTimeout(60, TimeUnit.SECONDS)
  189. .dns(new XDns(100000))
  190. .build();
  191. // 创建一个请求对象
  192. Request request = new Request.Builder().url(url)
  193. .addHeader("_appid", appId)
  194. .addHeader("_timestamp", currentTimeMillis.toString())
  195. .addHeader("_sign", signMd5)
  196. .get().build();
  197. // 发送请求获取响应
  198. try {
  199. Response response = okHttpClient.newCall(request).execute();
  200. // 判断请求是否成功
  201. if (response.isSuccessful()) {
  202. // 打印服务端返回结果
  203. return Objects.requireNonNull(response.body()).string();
  204. }
  205. } catch (IOException e) {
  206. e.printStackTrace();
  207. }
  208. return "{}";
  209. }
  210. /**
  211. * @param
  212. * @return
  213. * @throws IOException
  214. * @author 李仁杰
  215. * 从专利之星获取中国专利摘要附图
  216. */
  217. public String getPictureApi(String appNo) {
  218. String url = "https://api.patentstar.com.cn/api/Patent/CnMainImage/" + appNo;
  219. JSONObject configObject = this.getConfigObject(4, 2);
  220. String appId = configObject.getString("appId");
  221. String appKey = configObject.getString("appKey");
  222. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  223. String Sign = appId + appKey + currentTimeMillis.toString();
  224. String signMd5 = FormatUtil.MD5(Sign);
  225. // 创建一个OkHttpClient对象
  226. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  227. .connectTimeout(60, TimeUnit.SECONDS)
  228. .writeTimeout(60, TimeUnit.SECONDS)
  229. .readTimeout(60, TimeUnit.SECONDS)
  230. .dns(new XDns(100000))
  231. .build();
  232. // 创建一个请求对象
  233. Request request = new Request.Builder().url(url)
  234. .addHeader("_appid", appId)
  235. .addHeader("_timestamp", currentTimeMillis.toString())
  236. .addHeader("_sign", signMd5)
  237. .get().build();
  238. // 发送请求获取响应
  239. try {
  240. Response response = okHttpClient.newCall(request).execute();
  241. // 判断请求是否成功
  242. if (response.isSuccessful() && response.code() == 200) {
  243. // 打印服务端返回结果
  244. return Objects.requireNonNull(response.body()).string();
  245. }
  246. } catch (IOException e) {
  247. e.printStackTrace();
  248. return null;
  249. }
  250. return "{}";
  251. }
  252. /**
  253. * @param appNo
  254. * @return
  255. * @throws IOException
  256. * @author 李仁杰
  257. * 从专利之星获取中国专利外观图
  258. */
  259. public String getWGPictureApi(String appNo) throws IOException {
  260. String url = "https://api.patentstar.com.cn/api/Patent/CnWGImage/" + appNo;
  261. JSONObject configObject = this.getConfigObject(4, 2);
  262. String appId = configObject.getString("appId");
  263. String appKey = configObject.getString("appKey");
  264. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  265. String Sign = appId + appKey + currentTimeMillis.toString();
  266. String signMd5 = FormatUtil.MD5(Sign);
  267. // 创建一个OkHttpClient对象
  268. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  269. .connectTimeout(60, TimeUnit.SECONDS)
  270. .writeTimeout(60, TimeUnit.SECONDS)
  271. .readTimeout(60, TimeUnit.SECONDS)
  272. .dns(new XDns(100000))
  273. .build();
  274. // 创建一个请求对象
  275. Request request = new Request.Builder().url(url)
  276. .addHeader("_appid", appId)
  277. .addHeader("_timestamp", currentTimeMillis.toString())
  278. .addHeader("_sign", signMd5)
  279. .get().build();
  280. // 发送请求获取响应
  281. try {
  282. Response response = okHttpClient.newCall(request).execute();
  283. // 判断请求是否成功
  284. if (response.isSuccessful()) {
  285. // 打印服务端返回结果
  286. return Objects.requireNonNull(response.body()).string();
  287. }
  288. } catch (IOException e) {
  289. e.printStackTrace();
  290. }
  291. return "{}";
  292. }
  293. /**
  294. * @param appNo
  295. * @return
  296. * @throws IOException
  297. * @author 李仁杰
  298. * 从专利之星获取中国专利法律状态
  299. */
  300. public String getCnLegalApi(String appNo) {
  301. String url = "https://api.patentstar.com.cn/api/Patent/CnLegal/" + appNo;
  302. JSONObject configObject = this.getConfigObject(4, 2);
  303. String appId = configObject.getString("appId");
  304. String appKey = configObject.getString("appKey");
  305. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  306. String Sign = appId + appKey + currentTimeMillis.toString();
  307. String signMd5 = FormatUtil.MD5(Sign);
  308. // 创建一个OkHttpClient对象
  309. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  310. .connectTimeout(60, TimeUnit.SECONDS)
  311. .writeTimeout(60, TimeUnit.SECONDS)
  312. .readTimeout(60, TimeUnit.SECONDS)
  313. .dns(new XDns(100000))
  314. .build();
  315. // 创建一个请求对象
  316. Request request = new Request.Builder().url(url)
  317. .addHeader("_appid", appId)
  318. .addHeader("_timestamp", currentTimeMillis.toString())
  319. .addHeader("_sign", signMd5)
  320. .get().build();
  321. // 发送请求获取响应
  322. try {
  323. Response response = okHttpClient.newCall(request).execute();
  324. // 判断请求是否成功
  325. if (response.isSuccessful()) {
  326. // 打印服务端返回结果
  327. return Objects.requireNonNull(response.body()).string();
  328. }
  329. } catch (IOException e) {
  330. e.printStackTrace();
  331. }
  332. return "{}";
  333. }
  334. /**
  335. * @param appNo
  336. * @return
  337. * @throws IOException
  338. * @author 李仁杰
  339. * 从专利之星获取中国专利全文图片
  340. */
  341. public String getCnPdfApi(String appNo) throws IOException {
  342. String url = "https://api.patentstar.com.cn/api/Patent/CnPdf/" + appNo;
  343. JSONObject configObject = this.getConfigObject(4, 2);
  344. String appId = configObject.getString("appId");
  345. String appKey = configObject.getString("appKey");
  346. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  347. String Sign = appId + appKey + currentTimeMillis.toString();
  348. String signMd5 = FormatUtil.MD5(Sign);
  349. // 创建一个OkHttpClient对象
  350. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  351. .connectTimeout(60, TimeUnit.SECONDS)
  352. .writeTimeout(60, TimeUnit.SECONDS)
  353. .readTimeout(60, TimeUnit.SECONDS)
  354. .dns(new XDns(100000))
  355. .build();
  356. // 创建一个请求对象
  357. Request request = new Request.Builder().url(url)
  358. .addHeader("_appid", appId)
  359. .addHeader("_timestamp", currentTimeMillis.toString())
  360. .addHeader("_sign", signMd5)
  361. .get().build();
  362. // 发送请求获取响应
  363. try {
  364. Response response = okHttpClient.newCall(request).execute();
  365. // 判断请求是否成功
  366. if (response.isSuccessful()) {
  367. // 打印服务端返回结果
  368. return Objects.requireNonNull(response.body()).string();
  369. }
  370. } catch (IOException e) {
  371. e.printStackTrace();
  372. }
  373. return "{}";
  374. }
  375. /**
  376. * @param appNo
  377. * @return
  378. * @throws IOException
  379. * @author 李仁杰
  380. * 从专利之星获取中国专利全文文本
  381. */
  382. public String getCnFullXmlApi(String appNo) throws IOException {
  383. String url = "https://api.patentstar.com.cn/api/Patent/CnFullXml/" + appNo;
  384. JSONObject configObject = this.getConfigObject(4, 2);
  385. String appId = configObject.getString("appId");
  386. String appKey = configObject.getString("appKey");
  387. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  388. String Sign = appId + appKey + currentTimeMillis.toString();
  389. String signMd5 = FormatUtil.MD5(Sign);
  390. // 创建一个OkHttpClient对象
  391. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  392. .connectTimeout(60, TimeUnit.SECONDS)
  393. .writeTimeout(60, TimeUnit.SECONDS)
  394. .readTimeout(60, TimeUnit.SECONDS)
  395. .dns(new XDns(100000))
  396. .build();
  397. // 创建一个请求对象
  398. Request request = new Request.Builder().url(url)
  399. .addHeader("_appid", appId)
  400. .addHeader("_timestamp", currentTimeMillis.toString())
  401. .addHeader("_sign", signMd5)
  402. .get().build();
  403. // 发送请求获取响应
  404. try {
  405. Response response = okHttpClient.newCall(request).execute();
  406. // 判断请求是否成功
  407. if (response.isSuccessful()) {
  408. // 打印服务端返回结果
  409. return Objects.requireNonNull(response.body()).string();
  410. }
  411. } catch (IOException e) {
  412. e.printStackTrace();
  413. }
  414. return "{}";
  415. }
  416. /**
  417. * @param patentNo
  418. * @return
  419. * @throws IOException
  420. * @author 李仁杰
  421. * 从专利之星获取世界专利pdf
  422. */
  423. public String getEnPdfApi(String patentNo) {
  424. String url = " https://api.patentstar.com.cn/api/Patent/EnPdf/" + patentNo;
  425. JSONObject configObject = this.getConfigObject(4, 2);
  426. String appId = configObject.getString("appId");
  427. String appKey = configObject.getString("appKey");
  428. // String appId = "1000046";
  429. // String appkey = "6AE6D4DC6AF94F26862501EDEE9E27A2";
  430. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  431. String Sign = appId + appKey + currentTimeMillis.toString();
  432. String signMd5 = FormatUtil.MD5(Sign);
  433. // 创建一个OkHttpClient对象
  434. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  435. .connectTimeout(60, TimeUnit.SECONDS)
  436. .writeTimeout(60, TimeUnit.SECONDS)
  437. .readTimeout(60, TimeUnit.SECONDS)
  438. .dns(new XDns(100000))
  439. .build();
  440. // 创建一个请求对象
  441. Request request = new Request.Builder().url(url)
  442. .addHeader("_appid", appId)
  443. .addHeader("_timestamp", currentTimeMillis.toString())
  444. .addHeader("_sign", signMd5)
  445. .get().build();
  446. // 发送请求获取响应
  447. try {
  448. Response response = okHttpClient.newCall(request).execute();
  449. // 判断请求是否成功
  450. if (response.isSuccessful()) {
  451. // 打印服务端返回结果
  452. return Objects.requireNonNull(response.body()).string();
  453. }
  454. } catch (IOException e) {
  455. e.printStackTrace();
  456. }
  457. return "{}";
  458. }
  459. /**
  460. * @param patentNo
  461. * @return
  462. * @throws IOException
  463. * @author 李仁杰
  464. * 从专利之星获取世界专利著录信息
  465. */
  466. public String getENBibApi(String patentNo) {
  467. String url = "https://api.patentstar.com.cn/api/Patent/EnBib/" + patentNo;
  468. JSONObject configObject = this.getConfigObject(4, 2);
  469. String appId = configObject.getString("appId");
  470. String appKey = configObject.getString("appKey");
  471. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  472. String Sign = appId + appKey + currentTimeMillis.toString();
  473. String signMd5 = FormatUtil.MD5(Sign);
  474. // 创建一个OkHttpClient对象
  475. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  476. .connectTimeout(60, TimeUnit.SECONDS)
  477. .writeTimeout(60, TimeUnit.SECONDS)
  478. .readTimeout(60, TimeUnit.SECONDS)
  479. .dns(new XDns(100000))
  480. .build();
  481. // 创建一个请求对象
  482. Request request = new Request.Builder().url(url)
  483. .addHeader("_appid", appId)
  484. .addHeader("_timestamp", currentTimeMillis.toString())
  485. .addHeader("_sign", signMd5)
  486. .get().build();
  487. // 发送请求获取响应
  488. try {
  489. Response response = okHttpClient.newCall(request).execute();
  490. // 判断请求是否成功
  491. if (response.isSuccessful()) {
  492. // 打印服务端返回结果
  493. return Objects.requireNonNull(response.body()).string();
  494. }
  495. } catch (IOException e) {
  496. e.printStackTrace();
  497. }
  498. return "{}";
  499. }
  500. /**
  501. * @param patentNo
  502. * @return
  503. * @throws IOException
  504. * @author 李仁杰
  505. * 从专利之星获取同族专利
  506. */
  507. public String getFamilyByPubNoApi(String patentNo) {
  508. String url = "https://api.patentstar.com.cn/api/Patent/FamilyByPubNo/" + patentNo;
  509. JSONObject configObject = this.getConfigObject(4, 2);
  510. String appId = configObject.getString("appId");
  511. String appKey = configObject.getString("appKey");
  512. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  513. String Sign = appId + appKey + currentTimeMillis.toString();
  514. String signMd5 = FormatUtil.MD5(Sign);
  515. // 创建一个OkHttpClient对象
  516. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  517. .connectTimeout(60, TimeUnit.SECONDS)
  518. .writeTimeout(60, TimeUnit.SECONDS)
  519. .readTimeout(60, TimeUnit.SECONDS)
  520. .dns(new XDns(100000))
  521. .build();
  522. // 创建一个请求对象
  523. Request request = new Request.Builder().url(url)
  524. .addHeader("_appid", appId)
  525. .addHeader("_timestamp", currentTimeMillis.toString())
  526. .addHeader("_sign", signMd5)
  527. .get().build();
  528. // 发送请求获取响应
  529. try {
  530. Response response = okHttpClient.newCall(request).execute();
  531. // 判断请求是否成功
  532. if (response.isSuccessful()) {
  533. // 打印服务端返回结果
  534. return Objects.requireNonNull(response.body()).string();
  535. }
  536. } catch (IOException e) {
  537. e.printStackTrace();
  538. }
  539. return "{}";
  540. }
  541. /**
  542. * @param patentNo
  543. * @return
  544. * @throws IOException
  545. * @author 李仁杰
  546. * 获得专利被引用次数api
  547. */
  548. public String getCitedNumByPubNoApi(String patentNo) throws IOException {
  549. String url = "https://api.patentstar.com.cn/api/Patent/CitedNumByPubNo/" + patentNo;
  550. JSONObject configObject = this.getConfigObject(4, 2);
  551. String appId = configObject.getString("appId");
  552. String appKey = configObject.getString("appKey");
  553. Long currentTimeMillis = System.currentTimeMillis() / 1000;
  554. String Sign = appId + appKey + currentTimeMillis.toString();
  555. String signMd5 = FormatUtil.MD5(Sign);
  556. // 创建一个OkHttpClient对象
  557. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  558. .connectTimeout(60, TimeUnit.SECONDS)
  559. .writeTimeout(60, TimeUnit.SECONDS)
  560. .readTimeout(60, TimeUnit.SECONDS)
  561. .dns(new XDns(100000))
  562. .build();
  563. // 创建一个请求对象
  564. Request request = new Request.Builder().url(url)
  565. .addHeader("_appid", appId)
  566. .addHeader("_timestamp", currentTimeMillis.toString())
  567. .addHeader("_sign", signMd5)
  568. .get().build();
  569. // 发送请求获取响应
  570. try {
  571. Response response = okHttpClient.newCall(request).execute();
  572. // 判断请求是否成功
  573. if (response.isSuccessful()) {
  574. // 打印服务端返回结果
  575. return Objects.requireNonNull(response.body()).string();
  576. }
  577. } catch (IOException e) {
  578. e.printStackTrace();
  579. }
  580. return "{}";
  581. }
  582. public JSONObject getConfigObject(Integer webId, Integer webGroup) {
  583. String config ="";
  584. if(webId==4&&webGroup==1){
  585. config="{\"appId\":\"K8FFB741E163BE6536\",\"appKey\":\"FNYJD7902206FFB741E163BE6536C3689D55\"}";
  586. }
  587. else {
  588. config="{\"appId\":\"1000046\",\"appKey\":\"6AE6D4DC6AF94F26862501EDEE9E27A2\"}";
  589. }
  590. JSONObject jsonObject = JSONObject.parseObject(config);
  591. return jsonObject;
  592. }
  593. public List<PatentStarListDTO> splitPatentNoByType(List<String> originalList, PatentStarListDTO patentStarListDTO) {
  594. List<String> cnStrings = new ArrayList<>();
  595. List<String> wdStrings = new ArrayList<>();
  596. List<List<String>> result = new ArrayList<>();
  597. result.add(cnStrings);
  598. result.add(wdStrings);
  599. // 记录CN类型的字符串数量
  600. int cnCount = 0;
  601. // 记录WD类型的字符串数量
  602. int wdCount = 0;
  603. List<PatentStarListDTO> patentStarListDTOS = new ArrayList<>();
  604. //遍历初始集合
  605. for (String str : originalList) {
  606. if (str.startsWith("CN")) {
  607. cnStrings.add(str);
  608. cnCount++;
  609. if (cnCount >= 100) {
  610. cnStrings = new ArrayList<>();
  611. result.add(cnStrings);
  612. cnCount = 0;
  613. }
  614. } else {
  615. wdStrings.add(str);
  616. wdCount++;
  617. if (wdCount >= 100) {
  618. wdStrings = new ArrayList<>();
  619. result.add(wdStrings);
  620. wdCount = 0;
  621. }
  622. }
  623. }
  624. result.forEach(item -> {
  625. if (item.size() > 0) {
  626. String dbType = "CN";
  627. String patentNo = item.get(0);
  628. if (!patentNo.startsWith("CN")) {
  629. dbType = "WD";
  630. }
  631. String join = StringUtils.join(item, " OR ");
  632. String conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
  633. PatentStarListDTO patentStarListDTO1 = new PatentStarListDTO();
  634. patentStarListDTO1.setOrderByType(patentStarListDTO.getOrderByType());
  635. patentStarListDTO1.setCurrentQuery(conditions);
  636. patentStarListDTO1.setPageNum(patentStarListDTO.getPageNum());
  637. patentStarListDTO1.setDBType(dbType);
  638. patentStarListDTO1.setCurrentQuery(conditions);
  639. patentStarListDTO1.setRowCount(50);
  640. patentStarListDTO1.setTotal(item.size());
  641. patentStarListDTO1.setNos(item);
  642. patentStarListDTOS.add(patentStarListDTO1);
  643. }
  644. });
  645. return patentStarListDTOS;
  646. }
  647. public StarPatentVO getPatentByNo(String patentNo) {
  648. StarPatentVO starPatentVO = null;
  649. String condition = "AN=(" + patentNo + ") OR PN=(" + patentNo + ") OR GN=(" + patentNo + ") OR ANO=(" + patentNo + ")";
  650. String dbType = "CN";
  651. if (!patentNo.startsWith("CN")) {
  652. dbType = "WD";
  653. }
  654. PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
  655. patentStarListDTO.setCurrentQuery(condition);
  656. patentStarListDTO.setPageNum(1);
  657. patentStarListDTO.setRowCount(50);
  658. patentStarListDTO.setDBType(dbType);
  659. try {
  660. Map<String, Object> resultMap = this.patentStarSearchApi(patentStarListDTO);
  661. if (resultMap == null || (Integer) resultMap.get("total") == 0) {
  662. return starPatentVO;
  663. }
  664. List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
  665. starPatentVO = starPatents.get(0);
  666. } catch (Exception e) {
  667. }
  668. return starPatentVO;
  669. }
  670. /**
  671. * 获取附图
  672. *
  673. * @param appNo
  674. * @return
  675. */
  676. public List<String> getExternalFigure(String appNo) throws IOException {
  677. List<String> list = new ArrayList<>();
  678. String wgPictureApi = this.getWGPictureApi(appNo);
  679. if (StringUtils.isNotEmpty(wgPictureApi)) {
  680. if (wgPictureApi.contains("|http")) {
  681. String[] urlArr = wgPictureApi.split("\\|");
  682. list.addAll(Arrays.asList(urlArr));
  683. } else {
  684. list.add(wgPictureApi);
  685. }
  686. }
  687. return list;
  688. }
  689. /**
  690. * 获取摘要附图
  691. *
  692. * @param appNo
  693. * @return
  694. */
  695. public String getPictureGuid(String appNo) {
  696. return this.getPictureApi(appNo);
  697. }
  698. }