PatentStarApiService.java 33 KB

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