PatentStarApiService.java 56 KB

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