1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570 |
- package cn.cslg.pas.service.common;
- import cn.cslg.pas.common.config.XDns;
- import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
- import cn.cslg.pas.common.dto.*;
- import cn.cslg.pas.common.dto.business.SelectClaimDTO;
- import cn.cslg.pas.common.model.cronModel.PersonnelVO;
- import cn.cslg.pas.common.model.cronModel.Records;
- import cn.cslg.pas.common.model.importTaskModel.PatentApplicant;
- import cn.cslg.pas.common.utils.*;
- import cn.cslg.pas.common.vo.ContentVO;
- import cn.cslg.pas.common.vo.NoCacheVO;
- import cn.cslg.pas.common.vo.QueryExternalFamilyVO;
- import cn.cslg.pas.common.vo.StarPatentVO;
- import cn.cslg.pas.common.vo.business.PatentNoVO;
- import cn.cslg.pas.domain.WebLoginConfig;
- import cn.cslg.pas.domain.business.RetrieveRecord;
- import cn.cslg.pas.domain.es.*;
- import cn.cslg.pas.service.WebLoginConfigService;
- import cn.cslg.pas.service.importPatent.WebVOTransformService;
- import cn.cslg.pas.service.novelty.AssoRetrieveRecordProjectService;
- import cn.cslg.pas.service.query.FormatQueryService;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson2.JSON;
- import com.sun.istack.NotNull;
- import lombok.RequiredArgsConstructor;
- import lombok.experimental.Accessors;
- import lombok.extern.slf4j.Slf4j;
- import okhttp3.*;
- import okhttp3.Response;
- import org.apache.commons.lang3.ObjectUtils;
- import org.dom4j.Document;
- import org.dom4j.DocumentException;
- import org.dom4j.Element;
- import org.dom4j.XPath;
- import org.dom4j.io.SAXReader;
- import org.joda.time.DateTime;
- import org.joda.time.format.DateTimeFormat;
- import org.joda.time.format.DateTimeFormatter;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.io.IOException;
- import java.io.Reader;
- import java.io.StringReader;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- /**
- * 调用外部接口的Service类 PCS:权限系统
- *
- * @Author chenyu
- * @Date 2023/4/25
- */
- @RequiredArgsConstructor
- @Slf4j
- @Service
- public class PatentStarApiService {
- @Autowired
- private RetrieveRecordService retrieveRecordService;
- @Autowired
- private CacheUtils cacheUtils;
- @Autowired
- private LoginUtils loginUtils;
- @Autowired
- private WebLoginConfigService webLoginConfigService;
- @Autowired
- private FormatQueryService formatQueryService;
- @Autowired
- @Lazy
- private WebVOTransformService webVOTransformService;
- @Autowired
- private AssoRetrieveRecordProjectService assoRetrieveRecordProjectService;
- @Autowired
- private NOSCacheService cacheService;
- @Autowired
- private FileManagerService fileManagerService;
- public Records patentStarSearchLocal(PatentStarListDTO patentStarListDTO) throws IOException {
- RetrieveRecord retrieveRecord = retrieveRecordService.setRetrieveRecord(patentStarListDTO);
- String redisKey = patentStarListDTO.getRedisKey();
- List<String> nos = new ArrayList<>();
- Long total = 0L;
- if (StringUtils.isNotEmpty(patentStarListDTO.getNumberQuery())) {
- NoCacheVO cacheVO = cacheService.savaByList(patentStarListDTO);
- retrieveRecord.setConditions(patentStarListDTO.getNumberQuery());
- retrieveRecord.setSearchType(1);
- redisKey = cacheVO.getKey();
- total = cacheVO.getTotal();
- nos.addAll(cacheVO.getList());
- }
- if (Boolean.TRUE.equals(StringUtils.isEmpty(patentStarListDTO.getNumberQuery())) && StringUtils.isNotEmpty(redisKey)) {
- NoCacheVO cacheVO = cacheService.getByList(patentStarListDTO);
- retrieveRecord.setConditions(patentStarListDTO.getNumberQuery());
- retrieveRecord.setSearchType(1);
- nos.addAll(cacheVO.getList());
- total = cacheVO.getTotal();
- redisKey = cacheVO.getKey();
- }
- long start = System.currentTimeMillis();
- Map<String, Object> map = this.patentStarSearchApi(patentStarListDTO);
- long end = System.currentTimeMillis();
- System.out.println("search time:" + (end - start));
- if (map == null) {
- ThrowException.throwXiaoShiException("检索失败,请检查检索式");
- }
- retrieveRecord.setTotalNum(Integer.parseInt(map.get("total").toString()));
- if (patentStarListDTO.getRetrieveRecordId() == null) {
- retrieveRecord.insert();
- Integer projectId = patentStarListDTO.getProjectId();
- if (projectId != null) {
- assoRetrieveRecordProjectService.add(retrieveRecord.getId(), projectId);
- }
- } else {
- retrieveRecord = retrieveRecordService.getById(patentStarListDTO.getRetrieveRecordId());
- retrieveRecord.setRetrieveTime(new Date());
- retrieveRecord.updateById();
- }
- List<StarPatentVO> starPatentVOS = (List<StarPatentVO>) map.get("records");
- //装载starPatentVOS到 PatentColumnDTO
- Records records = new Records();
- records.setRetrieveRecordId(retrieveRecord.getId());
- records.setCurrent(Long.parseLong(map.get("current").toString()));
- records.setSize(Long.parseLong(map.get("size").toString()));
- // records.setData(this.loadPatent(starPatentVOS, patentStarListDTO.getDBType()));
- // records.setTotal(Long.parseLong(map.get("total").toString()));
- List<PatentColumnDTO> columnDTOS = this.loadPatent(starPatentVOS, patentStarListDTO.getDBType());
- records.setData(this.loadPatentList(columnDTOS, nos, patentStarListDTO.getDBType()));
- if (total != 0) {
- records.setTotal(total);
- } else {
- records.setTotal(Long.parseLong(map.get("total").toString()));
- }
- records.setRedisKey(redisKey);
- return records;
- }
- /**
- * 格式化条件后并请求外部接口
- *
- * @param PatentStarListDTO
- * @return
- * @throws IOException
- */
- public Map<String, Object> patentStarSearchApi(PatentStarListDTO PatentStarListDTO) throws IOException {
- try {
- if (PatentStarListDTO.getFormed() == null || PatentStarListDTO.getFormed() == false) {
- String formQuery = PatentStarListDTO.getCurrentQuery();
- PatentStarListDTO.setCurrentQuery(formatQueryService.reQuery(formQuery, "webSearchConfig"));
- if (PatentStarListDTO.getDBType().equals("WD")) {
- StringBuilder stringBuilder = new StringBuilder(PatentStarListDTO.getCurrentQuery());
- stringBuilder.insert(PatentStarListDTO.getCurrentQuery().length() - 1, "-CN/GJ");
- PatentStarListDTO.setCurrentQuery(stringBuilder.toString());
- }
- PatentStarListDTO.setFormed(true);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- JSONObject configObject = this.getConfigObject(4, 1);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- PatentStarDTO patentStarDto = new PatentStarDTO();
- BeanUtils.copyProperties(PatentStarListDTO, patentStarDto);
- if (patentStarDto.getOrderBy() == null) {
- patentStarDto.setOrderBy("AD");
- patentStarDto.setOrderByType("DESC");
- }
- String json = JSONObject.toJSONString(patentStarDto);
- String url = "http://s.patentstar.com.cn/SearchAPI/PatentSearch/ResultGet";
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(10, TimeUnit.SECONDS)
- .writeTimeout(10, TimeUnit.SECONDS)
- .readTimeout(10, TimeUnit.SECONDS)
- .addInterceptor(new PatentStarApiService.OkhttpInterceptor(3))
- .build();
- // 创建一个RequestBody(参数1:数据类型 参数2传递的json串)
- FormBody.Builder builder = new FormBody.Builder();
- builder.add("AppID", appId);
- builder.add("Stamp", currentTimeMillis.toString());
- builder.add("Sign", signMd5);
- builder.add("QueryJson", json);
- FormBody requestBody = builder.build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url).post(requestBody).build();
- // 发送请求获取响应
- try {
- long start = System.currentTimeMillis();
- Response response = okHttpClient.newCall(request).execute();
- long end = System.currentTimeMillis();
- System.out.println("search11time:" + (end - start));
- // 判断请求是否成功
- if (response.isSuccessful()) {
- JSONObject jsonObject = JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
- if (jsonObject.get("Ret").equals(500) || jsonObject.get("Data") == null) {
- return null;
- }
- JSONObject Data = (JSONObject) jsonObject.get("Data");
- List<StarPatentVO> starPatentVOS = JSONArray.parseArray(Data.get("List").toString(), StarPatentVO.class);
- Map<String, Object> reMap = new HashMap<>();
- reMap.put("size", PatentStarListDTO.getRowCount());
- reMap.put("current", PatentStarListDTO.getPageNum());
- reMap.put("records", starPatentVOS);
- reMap.put("total", Data.get("HitCount"));
- return reMap;
- }
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- return null;
- }
- private List<PatentColumnDTO> loadPatentList(List<PatentColumnDTO> columnDTOS, List<String> list, String dbType) {
- if (CollectionUtils.isEmpty(list) || CollectionUtils.isEmpty(columnDTOS)) {
- return list.isEmpty() ? columnDTOS : createNewDTOs(list);
- }
- List<PatentColumnDTO> result = new ArrayList<>(columnDTOS.size());
- Set<String> searchedNumbers = new HashSet<>(); // 用于跟踪已搜索的专利号
- for (String patentNo : list) {
- boolean found = false;
- String formattedNo = dbType.equals("CN") ? PatentNoUtil.formatApNo(patentNo) : patentNo;
- for (PatentColumnDTO columnDTO : columnDTOS) {
- if (containsNumber(columnDTO, formattedNo)) {
- PatentColumnDTO dto = new PatentColumnDTO();
- BeanUtils.copyProperties(columnDTO, dto);
- dto.setSearchNo(patentNo);
- result.add(dto);
- searchedNumbers.add(patentNo); // 标记为已搜索
- found = true;
- break; // 找到匹配项后跳出内层循环
- }
- }
- if (!found) {
- // 如果没有在columnDTOS中找到匹配项,则创建一个新的DTO
- PatentColumnDTO newDTO = new PatentColumnDTO();
- newDTO.setPatentNo(patentNo);
- newDTO.setSearchNo(patentNo);
- newDTO.setIfSearch(false);
- result.add(newDTO);
- }
- }
- return result;
- }
- private boolean containsNumber(PatentColumnDTO dto, String number) {
- String appNo = StringUtils.isNotEmpty(dto.getAppNo()) ? dto.getAppNo() : "";
- String publicNo = StringUtils.isNotEmpty(dto.getPublicNo()) ? dto.getPublicNo() : "";
- String grantNo = StringUtils.isNotEmpty(dto.getGrantNo()) ? dto.getGrantNo() : "";
- String rowAppNo = StringUtils.isNotEmpty(dto.getRowApplicationNo()) ? dto.getRowApplicationNo() : "";
- return appNo.contains(number) || publicNo.contains(number)
- || grantNo.contains(number) || rowAppNo.contains(number);
- }
- private List<PatentColumnDTO> createNewDTOs(List<String> list) {
- List<PatentColumnDTO> newDTOs = new ArrayList<>();
- for (String s : list) {
- PatentColumnDTO dto = new PatentColumnDTO();
- dto.setPatentNo(s);
- dto.setSearchNo(s);
- dto.setIfSearch(false);
- newDTOs.add(dto);
- }
- return newDTOs;
- }
- public String getFormatCondition(String condition) {
- String s = condition.substring(condition.indexOf("=") + 1);
- String s1 = s.replaceAll("[()]", "");
- String[] valueStrs = s1.split("[,,]|(\\r\\n)+|\\r+|\\n+");
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < valueStrs.length; i++) {
- final String value = valueStrs[i];
- if (i != valueStrs.length - 1) {
- stringBuilder.append(value).append(",");
- } else {
- stringBuilder.append(value);
- }
- }
- return stringBuilder.toString();
- }
- public List<PatentStarListDTO> getSplitedConditions(PatentStarListDTO patentStarListDTO, int patentNum) throws IOException {
- DateTime nowDate = new DateTime();
- DateTime date = DateUtils2.formStrToDateTime("1900-01-01");
- //超过1万的列表
- List<PatentStarListDTO> PatentStarListDTOs = new ArrayList<>();
- //返回的列表
- List<PatentStarListDTO> reDtos = new ArrayList<>();
- patentStarListDTO.setStartTime(date);
- patentStarListDTO.setEndTime(nowDate);
- patentStarListDTO.setOrginCondition(patentStarListDTO.getCurrentQuery());
- String formQuery = patentStarListDTO.getCurrentQuery();
- // patentStarListDTO.setOrginCondition(PatentStarApiService.formatQuery(formQuery));
- PatentStarListDTOs.add(patentStarListDTO);
- while (PatentStarListDTOs.size() > 0) {
- PatentStarListDTO dto = PatentStarListDTOs.get(0);
- PatentStarListDTOs.remove(dto);
- Map<String, Object> map1 = this.patentStarSearchApi(dto);
- Integer total1 = Integer.parseInt(map1.get("total").toString());
- dto.setTotal(total1);
- patentStarListDTO.setFormed(true);
- if (total1 > patentNum) {
- DateTime startTime1 = dto.getStartTime();
- DateTime endTime1 = dto.getEndTime();
- List<DateTime> dateTimes = DateUtils2.formStrToDateTime(startTime1, endTime1);
- PatentStarListDTO dto1 = new PatentStarListDTO();
- BeanUtils.copyProperties(dto, dto1);
- dto1.setStartTime(dateTimes.get(0));
- dto1.setEndTime(dateTimes.get(1));
- this.setConditions(dto1);
- PatentStarListDTO dto2 = new PatentStarListDTO();
- BeanUtils.copyProperties(dto, dto2);
- dto2.setStartTime(dateTimes.get(2));
- dto2.setEndTime(dateTimes.get(3));
- this.setConditions(dto2);
- PatentStarListDTOs.add(dto1);
- PatentStarListDTOs.add(dto2);
- } else if (total1 != 0) {
- reDtos.add(dto);
- }
- }
- return reDtos;
- }
- public void setConditions(PatentStarListDTO PatentStarListDTO) {
- PatentStarListDTO.setFormed(false);
- DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
- String startStr = formatter.print(PatentStarListDTO.getStartTime());
- String endStr = formatter.print(PatentStarListDTO.getEndTime());
- String cond = " AND AD=" + startStr + "~" + endStr;
- Integer len = PatentStarListDTO.getOrginCondition().length();
- StringBuilder stringBuilder = new StringBuilder(PatentStarListDTO.getOrginCondition());
- stringBuilder.insert(len - 1, cond);
- PatentStarListDTO.setCurrentQuery(stringBuilder.toString());
- }
- /**
- * @param appNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利著录
- */
- public String getCnBibApi(String appNo) {
- Long start = System.currentTimeMillis();
- String url = "https://api.patentstar.com.cn/api/Patent/CnBibo/" + appNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(5, TimeUnit.SECONDS)
- .writeTimeout(5, TimeUnit.SECONDS)
- .readTimeout(5, TimeUnit.SECONDS)
- .addInterceptor(new PatentStarApiService.OkhttpInterceptor(3))
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- Long end = System.currentTimeMillis();
- System.out.println("get zhulu cost" + (end - start));
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- /**
- * @param
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利摘要附图
- */
- public String getPictureApi(String appNo) {
- String url = "https://api.patentstar.com.cn/api/Patent/CnMainImage/" + appNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful() && response.code() == 200) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- return null;
- }
- /**
- * @param appNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利外观图
- */
- public String getWGPictureApi(String appNo) {
- String url = "https://api.patentstar.com.cn/api/Patent/CnWGImage/" + appNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- } else {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * @param appNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利法律状态
- */
- public String getCnLegalApi(String appNo) {
- String url = "https://api.patentstar.com.cn/api/Patent/CnLegal/" + appNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * @param appNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利全文图片
- */
- public String getCnPdfApi(String appNo) throws IOException {
- String url = "https://api.patentstar.com.cn/api/Patent/CnPdf/" + appNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- } else {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- /**
- * @param appNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利全文文本
- */
- public String getCnFullXmlApi(String appNo) throws IOException {
- String url = "https://api.patentstar.com.cn/api/Patent/CnFullXml/" + appNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- //获取权利要求文本
- public String getExternalClaim(String str) throws DocumentException {
- SAXReader reader = new SAXReader();
- reader.setEntityResolver(new IgnoreDTDEntityResolver());
- Reader stringReader = new StringReader(str);
- Document document = reader.read(stringReader);
- XPath xpath = document.createXPath("//claim-text");
- List<Element> element = (List<Element>) xpath.selectNodes(document);
- if (element.size() == 0) {
- xpath = document.createXPath("//business:ClaimText");
- element = (List<Element>) xpath.selectNodes(document);
- }
- List<String> reClaims = new ArrayList<>();
- element.forEach(item -> {
- String claim = item.getText();
- claim = claim.replaceAll("\r\n|\r|\n| ", "");
- reClaims.add(claim);
- });
- String reClaim = "";
- if (reClaims.size() != 0) {
- reClaim = cn.cslg.pas.common.utils.StringUtils.join(reClaims, "");
- }
- return reClaim;
- }
- //获取说明书文本
- public String getFullText(String str) throws DocumentException {
- SAXReader reader = new SAXReader();
- reader.setEntityResolver(new IgnoreDTDEntityResolver());
- Reader stringReader = new StringReader(str);
- Document document = reader.read(stringReader);
- XPath xpath = document.createXPath("//description//p");
- List<Element> elements = (List<Element>) xpath.selectNodes(document);
- if (elements.size() == 0) {
- xpath = document.createXPath("//business:Description//base:Paragraphs");
- elements = (List<Element>) xpath.selectNodes(document);
- }
- List<String> reStrs = new ArrayList<>();
- Integer count = 1;
- for (Element item : elements) {
- String claim = item.getText().replaceAll("<br/>", "");
- if (!claim.trim().equals("技术领域")
- && !claim.trim().equals("发明内容")
- && !claim.trim().equals("附图说明")
- && !claim.trim().equals("具体实施方式")
- && !claim.trim().equals("背景技术")) {
- String formattedNum = String.format("%04d", count);
- claim = "[" + formattedNum + "]" + claim;
- count++;
- }
- reStrs.add(claim);
- }
- String reStr = "";
- if (reStrs.size() != 0) {
- reStr = StringUtils.join(reStrs, "\r\n");
- }
- return reStr;
- }
- /**
- * @param patentNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取世界专利pdf
- */
- public String getEnPdfApi(String patentNo) {
- String url = " https://api.patentstar.com.cn/api/Patent/EnPdf/" + patentNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- // String appId = "1000046";
- // String appkey = "6AE6D4DC6AF94F26862501EDEE9E27A2";
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- } else {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- /**
- * @param patentNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取世界专利著录信息
- */
- public String getENBibApi(String patentNo) {
- String url = "https://api.patentstar.com.cn/api/Patent/EnBib/" + patentNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(5, TimeUnit.SECONDS)
- .writeTimeout(5, TimeUnit.SECONDS)
- .readTimeout(5, TimeUnit.SECONDS)
- .addInterceptor(new PatentStarApiService.OkhttpInterceptor(3))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- /**
- * @param patentNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取同族专利
- */
- public String getFamilyByPubNoApi(String patentNo) {
- Long start = System.currentTimeMillis();
- String url = "https://api.patentstar.com.cn/api/Patent/FamilyByPubNo/" + patentNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- Long end = System.currentTimeMillis();
- System.out.println("get family cost" + (end - start));
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- /**
- * @param patentNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 获得专利被引用次数api
- */
- public String getCitedNumByPubNoApi(String patentNo) throws IOException {
- String url = "https://api.patentstar.com.cn/api/Patent/CitedNumByPubNo/" + patentNo;
- JSONObject configObject = this.getConfigObject(4, 2);
- String appId = configObject.getString("appId");
- String appKey = configObject.getString("appKey");
- Long currentTimeMillis = System.currentTimeMillis() / 1000;
- String Sign = appId + appKey + currentTimeMillis.toString();
- String signMd5 = FormatUtil.MD5(Sign);
- // 创建一个OkHttpClient对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .build();
- // 创建一个请求对象
- Request request = new Request.Builder().url(url)
- .addHeader("_appid", appId)
- .addHeader("_timestamp", currentTimeMillis.toString())
- .addHeader("_sign", signMd5)
- .get().build();
- // 发送请求获取响应
- try {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- if (response.isSuccessful()) {
- // 打印服务端返回结果
- return Objects.requireNonNull(response.body()).string();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "{}";
- }
- public JSONObject getConfigObject(Integer webId, Integer webGroup) {
- WebLoginConfig webLoginConfig = webLoginConfigService.getConfig(webId, webGroup);
- if (webLoginConfig == null) {
- return null;
- }
- String config = webLoginConfig.getWebConfig();
- JSONObject jsonObject = JSONObject.parseObject(config);
- return jsonObject;
- }
- /**
- * @param originalList
- * @param patentStarListDTO
- * @param type 0申请号 1公开号或公告号 2专利号
- * @return
- */
- public List<PatentStarListDTO> splitPatentNoByType(List<String> originalList, PatentStarListDTO patentStarListDTO, Integer type) {
- List<PatentStarListDTO> patentStarListDTOS = new ArrayList<>();
- List<String> cnStrings = new ArrayList<>();
- List<String> wdStrings = new ArrayList<>();
- List<List<String>> result = new ArrayList<>();
- result.add(cnStrings);
- result.add(wdStrings);
- // 记录CN类型的字符串数量
- int cnCount = 0;
- // 记录WD类型的字符串数量
- int wdCount = 0;
- if (originalList == null || originalList.size() == 0) {
- return patentStarListDTOS;
- }
- //遍历初始集合
- for (String str : originalList) {
- if (str.startsWith("CN")) {
- if (str.length() == 12 && str.contains(".")) {
- String cnNumber = this.formatCnNumber(str);
- cnStrings.add(cnNumber);
- } else {
- cnStrings.add(str);
- }
- cnCount++;
- if (cnCount >= 100) {
- cnStrings = new ArrayList<>();
- result.add(cnStrings);
- cnCount = 0;
- }
- } else {
- wdStrings.add(str);
- wdCount++;
- if (wdCount >= 100) {
- wdStrings = new ArrayList<>();
- result.add(wdStrings);
- wdCount = 0;
- }
- }
- }
- result.forEach(item -> {
- if (item.size() > 0) {
- String dbType = "CN";
- String patentNo = item.get(0);
- if (!patentNo.startsWith("CN")) {
- dbType = "WD";
- }
- String join = StringUtils.join(item, " OR ");
- String conditions = "";
- if (type == 0) {
- conditions = "AN=(" + join + ")";
- } else if (type == 1) {
- conditions = " PN=(" + join + ") OR GN=(" + join + ")";
- } else {
- conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
- }
- PatentStarListDTO patentStarListDTO1 = new PatentStarListDTO();
- patentStarListDTO1.setOrderByType(patentStarListDTO.getOrderByType());
- patentStarListDTO1.setCurrentQuery(conditions);
- patentStarListDTO1.setPageNum(patentStarListDTO.getPageNum());
- patentStarListDTO1.setDBType(dbType);
- patentStarListDTO1.setCurrentQuery(conditions);
- patentStarListDTO1.setRowCount(50);
- patentStarListDTO1.setTotal(item.size());
- patentStarListDTO1.setNos(item);
- patentStarListDTOS.add(patentStarListDTO1);
- }
- });
- return patentStarListDTOS;
- }
- public String formatCnNumber(String str) {
- StringBuilder builder = new StringBuilder();
- builder.append(str, 0, 2);
- int num = Integer.parseInt(str.substring(2, 3));
- if (num > 6) {
- builder.append("19");
- } else {
- builder.append("20");
- }
- builder.append(str, 2, 5);
- builder.append("00");
- builder.append(str, 5, str.indexOf("."));
- String s = builder.toString();
- String s1 = s.substring(2);
- char c = this.calculateChecksum(s1);
- builder.append(".").append(c);
- return builder.toString();
- }
- public char calculateChecksum(String input) {
- int sum = 0;
- int[] weights = {2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5};
- // 遍历字符串中的每个字符,并计算乘积之和
- for (int i = 0; i < input.length(); i++) {
- char digit = input.charAt(i);
- int num = Character.getNumericValue(digit);
- sum += num * weights[i];
- }
- // 计算总和除以11的余数
- int remainder = sum % 11;
- // 根据余数确定校验位
- char checksum;
- if (remainder < 10) {
- checksum = (char) ('0' + remainder);
- } else {
- checksum = 'X';
- }
- return checksum;
- }
- public StarPatentVO getPatentByNo(String patentNo) {
- StarPatentVO starPatentVO = null;
- String condition = "AN=(" + patentNo + ") OR PN=(" + patentNo + ") OR GN=(" + patentNo + ") OR ANO=(" + patentNo + ")";
- String dbType = "CN";
- if (!patentNo.startsWith("CN")) {
- dbType = "WD";
- }
- PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
- patentStarListDTO.setCurrentQuery(condition);
- patentStarListDTO.setPageNum(1);
- patentStarListDTO.setRowCount(50);
- patentStarListDTO.setDBType(dbType);
- try {
- Map<String, Object> resultMap = this.patentStarSearchApi(patentStarListDTO);
- if (resultMap == null || (Integer) resultMap.get("total") == 0) {
- return starPatentVO;
- }
- List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
- starPatentVO = starPatents.get(0);
- } catch (Exception e) {
- }
- return starPatentVO;
- }
- private List<PatentColumnDTO> loadPatent(List<StarPatentVO> starPatentVOS, String dbType) {
- List<PatentColumnDTO> patentColumnDTOS = new ArrayList<>();
- starPatentVOS.forEach(item -> {
- UploadPatentWebDTO uploadPatentWebDTO = new UploadPatentWebDTO();
- uploadPatentWebDTO.setStarPatentVO(item);
- Patent patent = new Patent();
- uploadPatentWebDTO.setPatent(patent);
- webVOTransformService.loadPatent(uploadPatentWebDTO, false);
- if (dbType != null && dbType.equals("CN")) {
- webVOTransformService.loadCNPatentNo(uploadPatentWebDTO.getPatent());
- } else {
- webVOTransformService.loadWorldPatentNo(uploadPatentWebDTO.getPatent());
- }
- PatentColumnDTO patentColumnDTO = new PatentColumnDTO();
- BeanUtils.copyProperties(patent, patentColumnDTO);
- //装载权利要求
- List<Text> claimList = new ArrayList<>();
- Text claim = new Text();
- claim.setTextContent(item.getCL());
- claim.setIfOrigin(true);
- claimList.add(claim);
- patentColumnDTO.setClaim(claimList);
- //获取摘要附图
- // String pictureApi = this.getPictureApi(item.getRowApplicationNo());
- // patentColumnDTO.setPictureGuid(pictureApi);
- //获取外部专利原始申请号
- patentColumnDTO.setRowApplicationNo(item.getANO());
- //获取法律状态
- // String cnLegalApi = this.getCnLegalApi(item.getRowApplicationNo());
- // patentColumnDTO.setLegalStatus(Arrays.asList(cnLegalApi));
- //获取被引用次数
- //装载申请人
- if (item.getPA() != null && !item.getPA().trim().equals("")) {
- List<String> names = Arrays.asList(item.getPA().split(";"));
- patentColumnDTO.setApplicant(names);
- } else {
- patentColumnDTO.setApplicant(new ArrayList<>());
- }
- //装载发明人
- if (item.getIN() != null && !item.getIN().trim().equals("")) {
- List<String> names = Arrays.asList(item.getIN().split(";"));
- patentColumnDTO.setInventor(names);
- } else {
- patentColumnDTO.setInventor(new ArrayList<>());
- }
- //装载权利人
- if (item.getPE() != null && !item.getPE().trim().equals("")) {
- List<String> names = Arrays.asList(item.getPE().split(";"));
- patentColumnDTO.setRightHolder(names);
- } else {
- patentColumnDTO.setRightHolder(new ArrayList<>());
- }
- patentColumnDTOS.add(patentColumnDTO);
- });
- return patentColumnDTOS;
- }
- /**
- * 根据专利号查询外部权利要求
- *
- * @param appNo
- * @return
- * @throws IOException
- */
- public SelectClaimDTO queryExternalClaim(String appNo) throws IOException {
- List<Text> claimList = new ArrayList<>();
- //获取公开说明书
- String cnFullXmlApi = null;
- try {
- cnFullXmlApi = this.getCnFullXmlApi(appNo);
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- String fullText = this.getExternalClaim(cnFullXmlApi);
- Text pubText = new Text();
- if (fullText != null && !fullText.trim().equals("")) {
- fullText = PatentRightUtils.getFormatClaim(fullText, "CN");
- }
- pubText.setTextContent(fullText);
- pubText.setIfOrigin(true);
- claimList.add(pubText);
- } catch (Exception e) {
- // e.printStackTrace();
- }
- SelectClaimDTO dto = new SelectClaimDTO();
- if (!CollectionUtils.isEmpty(claimList)) {
- dto.setClaimContent(claimList);
- }
- return dto;
- }
- /**
- * 根据专利号查询外部权利要求
- *
- * @param vo
- * @return
- * @throws IOException
- */
- public PatentColumnDTO queryExternalDetail(QueryExternalFamilyVO vo) throws IOException {
- PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
- String condition = "AN=" + vo.getPatentNo() + " OR " + "PN=" + vo.getPatentNo();
- patentStarListDTO.setCurrentQuery(condition);
- String index = vo.getPatentNo().substring(0, 2);
- if (index.equals("CN")) {
- patentStarListDTO.setDBType("CN");
- } else {
- patentStarListDTO.setDBType("WD");
- }
- patentStarListDTO.setOrderBy("AD");
- patentStarListDTO.setOrderByType("DESC");
- patentStarListDTO.setPageNum(1);
- patentStarListDTO.setRowCount(10);
- Records records = this.patentStarSearchLocal(patentStarListDTO);
- Object data = records.getData();
- String s = JSONArray.toJSONString(data);
- List<PatentColumnDTO> list = JSONArray.parseArray(s, PatentColumnDTO.class);
- PatentColumnDTO dto = new PatentColumnDTO();
- if (!CollectionUtils.isEmpty(list)) {
- for (PatentColumnDTO columnDTO : list) {
- BeanUtils.copyProperties(columnDTO, dto);
- }
- }
- return dto;
- }
- /**
- * 查询外部专利同族专利
- *
- * @param vo
- * @return
- * @throws IOException
- */
- public Records queryExternalFamily(QueryExternalFamilyVO vo) throws IOException {
- Records records = new Records();
- String family = this.getFamilyByPubNoApi(vo.getPatentNo());
- QueryExternalFamilyDTO familyDTO = JSONObject.parseObject(family, QueryExternalFamilyDTO.class);
- String familyInfos = familyDTO.getFamilyinfo();
- List<String> publicNos = new ArrayList<>();
- if (StringUtils.isNotEmpty(familyInfos) && !familyInfos.equals("{}")) {
- publicNos = Arrays.asList(familyInfos.split(";"));
- }
- List<PatentColumnDTO> list = new ArrayList<>();
- if (!CollectionUtils.isEmpty(publicNos)) {
- for (String publicNo : publicNos) {
- PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
- String condition = "PN=" + publicNo;
- patentStarListDTO.setCurrentQuery(condition);
- String index = publicNo.substring(0, 2);
- if (index.equals("CN")) {
- patentStarListDTO.setDBType("CN");
- } else {
- patentStarListDTO.setDBType("WD");
- }
- patentStarListDTO.setOrderBy("AD");
- patentStarListDTO.setOrderByType("DESC");
- patentStarListDTO.setPageNum(vo.getPageNum());
- patentStarListDTO.setRowCount(vo.getPageSize());
- records = this.patentStarSearchLocal(patentStarListDTO);
- list.addAll((Collection<? extends PatentColumnDTO>) records.getData());
- }
- }
- Records record = new Records();
- record.setCurrent(vo.getPageNum().longValue());
- record.setSize(vo.getPageSize().longValue());
- record.setData(list);
- record.setTotal(Long.valueOf(String.valueOf(list.size())));
- return record;
- }
- /**
- * 获取公开说明书
- *
- * @param appNo
- * @return
- */
- public List<Text> getCnFullText(String appNo) {
- List<Text> pubTextList = new ArrayList<>();
- //获取公开说明书
- String cnFullXmlApi = null;
- try {
- cnFullXmlApi = this.getCnFullXmlApi(appNo);
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- String fullText = this.getFullText(cnFullXmlApi);
- Text pubText = new Text();
- pubText.setTextContent(fullText);
- pubText.setIfOrigin(true);
- pubTextList.add(pubText);
- } catch (Exception e) {
- // e.printStackTrace();
- }
- return pubTextList;
- }
- /**
- * 获得中国专利pdf全文
- *
- * @param appNo
- * @return
- * @throws IOException
- */
- public List<InnerPatentPdfDTO> getExternalTextPdf(String appNo, String rowApplicationNo, String publicNo, String grantNo) throws IOException {
- List<InnerPatentPdfDTO> list = new ArrayList<>();
- String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
- if (StringUtils.isNotEmpty(appNo) && appNo.contains("CN")) {
- String pdfUrlStr = this.getCnPdfApi(rowApplicationNo);
- //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
- if (StringUtils.isNotEmpty(pdfUrlStr)) {
- if (pdfUrlStr.contains("|http")) { //若包含公开和授权两个pdf
- String[] pdfUrlArr = pdfUrlStr.split("\\|http");
- pdfUrlArr[1] = "http" + pdfUrlArr[1];
- if (pdfUrlArr[0].contains("?") && pdfUrlArr[1].contains("?")) {
- pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
- pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
- } else {
- pdfUrl1 = pdfUrlArr[0];
- pdfUrl2 = pdfUrlArr[1];
- }
- if (pdfUrl1.contains("0A_CN_0.pdf")) {
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
- dto.setPdfGuid(pdfUrl1);
- dto.setType(0);
- list.add(dto);
- //授权说明书pdf
- InnerPatentPdfDTO dto1 = new InnerPatentPdfDTO();
- dto1.setPdfGuid(pdfUrl2);
- dto1.setType(1);
- list.add(dto1);
- } else {
- InnerPatentPdfDTO dto1 = new InnerPatentPdfDTO();
- dto1.setPdfGuid(pdfUrl1);
- dto1.setType(1);
- list.add(dto1);
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
- dto.setPdfGuid(pdfUrl2);
- dto.setType(0);
- list.add(dto);
- }
- } else { //若只有一个
- int i = pdfUrlStr.indexOf("http");
- if (i != -1) {
- pdfUrl1 = pdfUrlStr.substring(i);
- if (pdfUrl1.contains("0A_CN_0.pdf")) {
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
- dto.setPdfGuid(pdfUrl1);
- dto.setType(0);
- list.add(dto);
- } else {
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
- dto.setPdfGuid(pdfUrl1);
- dto.setType(1);
- list.add(dto);
- }
- }
- }
- }
- } else {
- String usedPatentNo;
- if (publicNo != null && !publicNo.equals("")) {
- usedPatentNo = publicNo;
- } else {
- usedPatentNo = grantNo;
- }
- if (usedPatentNo != null) {
- pdfUrl = this.getEnPdfApi(usedPatentNo);
- if (!pdfUrl.equals("")) {
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
- dto.setPdfGuid(pdfUrl);
- dto.setType(0);
- list.add(dto);
- }
- }
- }
- return list;
- }
- /**
- * 获取附图
- *
- * @param appNo
- * @return
- */
- public List<String> getExternalFigure(String appNo) throws IOException {
- List<String> list = new ArrayList<>();
- String wgPictureApi = this.getWGPictureApi(appNo);
- if (StringUtils.isNotEmpty(wgPictureApi)) {
- if (wgPictureApi.contains("|http")) {
- String[] urlArr = wgPictureApi.split("\\|");
- list.addAll(Arrays.asList(urlArr));
- } else {
- list.add(wgPictureApi);
- }
- }
- return list;
- }
- /**
- * 获取摘要附图
- *
- * @param appNo
- * @return
- */
- public String getPictureGuid(String appNo) {
- return this.getPictureApi(appNo);
- }
- /**
- * @param appNo
- * @return
- */
- public ExternalLegalInfoDTO getLegalStatus(String appNo) throws ParseException {
- ExternalLegalInfoDTO infoDTO = new ExternalLegalInfoDTO();
- List<String> list = new ArrayList<>();
- List<LegalEvent> legalEvents = new ArrayList<>();
- String cnLegalApi = this.getCnLegalApi(appNo);
- if (StringUtils.isNotEmpty(cnLegalApi) && !cnLegalApi.equals("{}") && !cnLegalApi.contains("408")) {
- List<ExternalLegalStatusDTO> statusDTOS = JSONArray.parseArray(cnLegalApi, ExternalLegalStatusDTO.class);
- if (!CollectionUtils.isEmpty(statusDTOS)) {
- List<ExternalLegalStatusDTO> statusList = statusDTOS.stream().sorted(Comparator.comparing(ExternalLegalStatusDTO::getLegalDate).reversed()).collect(Collectors.toList());
- if (!CollectionUtils.isEmpty(statusList)) {
- ExternalLegalStatusDTO statusDTO = statusList.get(0);
- list.add(statusDTO.getLegalStatus());
- }
- for (ExternalLegalStatusDTO dto : statusDTOS) {
- LegalEvent event = new LegalEvent();
- event.setCode(dto.getLegalCode());
- event.setName(dto.getLegalStatus());
- event.setDescription(dto.getLegalStatusInfo());
- if (StringUtils.isNotEmpty(dto.getLegalDate())) {
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
- Date date = format.parse(dto.getLegalDate());
- event.setEventDate(date);
- }
- legalEvents.add(event);
- }
- }
- }
- infoDTO.setLegalStatus(list);
- infoDTO.setLegalEvents(legalEvents);
- return infoDTO;
- }
- public SelectClaimDTO getOrginCalim(String appNo) throws IOException {
- List<Text> claimList = new ArrayList<>();
- //获取公开说明书
- String cnFullXmlApi = null;
- try {
- cnFullXmlApi = this.getCnFullXmlApi(appNo);
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- String fullText = this.getExternalClaim(cnFullXmlApi);
- Text pubText = new Text();
- pubText.setTextContent(fullText);
- pubText.setIfOrigin(true);
- claimList.add(pubText);
- } catch (DocumentException e) {
- e.printStackTrace();
- }
- SelectClaimDTO dto = new SelectClaimDTO();
- if (!CollectionUtils.isEmpty(claimList)) {
- dto.setClaimContent(claimList);
- }
- return dto;
- }
- public static class OkhttpInterceptor implements Interceptor {
- // 最大重试次数
- private int maxRentry;
- public OkhttpInterceptor(int maxRentry) {
- this.maxRentry = maxRentry;
- }
- @NotNull
- @Override
- public Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
- /* 递归 2次下发请求,如果仍然失败 则返回 null ,但是 intercept must not return null.
- * 返回 null 会报 IllegalStateException 异常
- * */
- return retry(chain, 0);//这个递归真的很舒服
- }
- Response retry(Chain chain, int retryCent) {
- Request request = chain.request();
- Response response = null;
- try {
- System.out.println("第" + (retryCent + 1) + "次执行发http请求.");
- response = chain.proceed(request);
- } catch (Exception e) {
- if (maxRentry > retryCent) {
- response = retry(chain, retryCent + 1);
- }
- } finally {
- return response;
- }
- }
- }
- /**
- * 根据专利号查询外部权利要求
- *
- * @param patentNo
- * @return
- * @throws IOException
- */
- public PatentInfoDTO queryPatentDetailByPatentNo(String patentNo) throws IOException {
- if (patentNo.length() == 13 || (patentNo.length() == 14 && patentNo.contains("."))) {
- patentNo = "CN" + patentNo;
- }
- PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
- String condition = "AN=" + patentNo + " OR " + "PN=" + patentNo + " OR " + "GN=" + patentNo;
- patentStarListDTO.setCurrentQuery(condition);
- String index = patentNo.substring(0, 2);
- if (index.equals("CN") || index.equals("ZL")) {
- patentStarListDTO.setDBType("CN");
- } else {
- patentStarListDTO.setDBType("WD");
- }
- patentStarListDTO.setOrderBy("AD");
- patentStarListDTO.setOrderByType("DESC");
- patentStarListDTO.setPageNum(1);
- patentStarListDTO.setRowCount(10);
- Records records = this.patentStarSearchLocal(patentStarListDTO);
- Object data = records.getData();
- String s = JSON.toJSONString(data);
- List<PatentColumnDTO> list = JSON.parseArray(s, PatentColumnDTO.class);
- PatentInfoDTO dto = new PatentInfoDTO();
- if (!CollectionUtils.isEmpty(list)) {
- for (PatentColumnDTO columnDTO : list) {
- BeanUtils.copyProperties(columnDTO, dto);
- }
- }
- String txtGuid = "";
- if (StringUtils.isNotEmpty(dto.getRowApplicationNo())) {
- try {
- txtGuid = this.getTxtGuid(dto.getRowApplicationNo(), patentNo);
- } catch (Exception ignored) {
- }
- }
- dto.setTxtGuid(txtGuid);
- List<InnerPatentPdfDTO> pdfList = null;
- try {
- pdfList = this.getExternalTextPdf(dto.getAppNo(), dto.getRowApplicationNo(), dto.getPublicNo(), dto.getGrantNo());
- } catch (Exception e) {
- pdfList = new ArrayList<>();
- }
- if (!CollectionUtils.isEmpty(pdfList)) {
- List<InnerPatentPdfDTO> pdfDTOS = new ArrayList<>();
- for (InnerPatentPdfDTO innerPatentPdfDTO : pdfList) {
- if (StringUtils.isNotEmpty(innerPatentPdfDTO.getPdfGuid())) {
- File file = FileUtils.getFileByUrl(innerPatentPdfDTO.getPdfGuid());
- List<String> guidList = fileManagerService.uploadFileGetGuid2(Collections.singletonList(file));
- if (!CollectionUtils.isEmpty(guidList)) {
- InnerPatentPdfDTO pdfDTO = new InnerPatentPdfDTO();
- pdfDTO.setPdfGuid(guidList.get(0));
- pdfDTO.setType(innerPatentPdfDTO.getType());
- pdfDTOS.add(pdfDTO);
- }
- }
- }
- dto.setPdfDTOS(pdfDTOS);
- } else {
- dto.setPdfDTOS(new ArrayList<>());
- }
- return dto;
- }
- public String getTxtGuid(String rowApplicationNo, String patentNo) throws IOException {
- StringBuilder builder = new StringBuilder();
- SelectClaimDTO externalClaim = this.queryExternalClaim(rowApplicationNo);
- if (ObjectUtils.isNotEmpty(externalClaim)) {
- List<Text> claimContent = externalClaim.getClaimContent();
- if (!CollectionUtils.isEmpty(claimContent)) {
- Text text = claimContent.stream().filter(i -> i.getIfOrigin().equals(true)).findFirst().orElse(null);
- if (ObjectUtils.isNotEmpty(text)) {
- String claim = text.getTextContent();
- String claimStr = claim.replaceAll("\t", "\n");
- builder.append(" 权利要求");
- builder.append("\n");
- builder.append(claimStr);
- }
- }
- }
- List<Text> fullText = this.getCnFullText(rowApplicationNo);
- if (!CollectionUtils.isEmpty(fullText)) {
- Text text = fullText.stream().filter(i -> i.getIfOrigin().equals(true)).findFirst().orElse(null);
- if (ObjectUtils.isNotEmpty(text)) {
- String specification = text.getTextContent();
- builder.append("\n");
- builder.append("\n");
- builder.append("\n");
- builder.append(" 说明书");
- builder.append("\n");
- builder.append(specification);
- }
- }
- String result = builder.toString();
- if (StringUtils.isNotEmpty(result)) {
- byte[] bytes = result.getBytes();
- MultipartFile multipartFile = FileUtils.convertBytesToMultipartFile(bytes, patentNo + "-" + "文本文档.txt");
- List<String> list = fileManagerService.uploadFileGetGuid(Collections.singletonList(multipartFile));
- if (!CollectionUtils.isEmpty(list)) {
- return list.get(0);
- }
- }
- return "";
- }
- }
|