PatentStarApiService.java 63 KB

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