PatentStarApiService.java 56 KB

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