12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397 |
- 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.exception.XiaoShiException;
- import cn.cslg.pas.service.WebLoginConfigService;
- import cn.cslg.pas.service.query.FormatQueryService;
- import cn.hutool.core.util.IdUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import lombok.RequiredArgsConstructor;
- import lombok.experimental.Accessors;
- import lombok.extern.slf4j.Slf4j;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.Response;
- 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.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- 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
- private NOSCacheService cacheService;
- public Records patentStarSearchLocal(PatentStarListDTO patentStarListDTO) throws IOException {
- RetrieveRecord retrieveRecord = new RetrieveRecord();
- retrieveRecord.setConditions(patentStarListDTO.getCurrentQuery());
- retrieveRecord.setSearchType(0);
- if (patentStarListDTO.getRetrieveRecordId() != null) {
- retrieveRecord = retrieveRecordService.getById(patentStarListDTO.getRetrieveRecordId());
- patentStarListDTO.setCurrentQuery(retrieveRecord.getConditions());
- patentStarListDTO.setDBType(retrieveRecord.getDbType());
- }
- 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();
- }
- Map<String, Object> map = this.patentStarSearchApi(patentStarListDTO);
- if (map == null) {
- throw new XiaoShiException("检索失败,请检查检索式");
- }
- //记录检索历史
- retrieveRecord.setRetrieveTime(new Date());
- retrieveRecord.setTotalNum(Integer.parseInt(map.get("total").toString()));
- retrieveRecord.setDbType(patentStarListDTO.getDBType());
- if (patentStarListDTO.getRetrieveRecordId() == null) {
- //获取创建人信息
- PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- retrieveRecord.setCreateTime(new Date());
- retrieveRecord.setCreateId(personnelVO.getId());
- retrieveRecord.setTenantId(personnelVO.getTenantId());
- retrieveRecord.insert();
- } else {
- 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()));
- List<PatentColumnDTO> columnDTOS = this.loadPatent(starPatentVOS);
- 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);
- 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(60, TimeUnit.SECONDS)
- .writeTimeout(60, TimeUnit.SECONDS)
- .readTimeout(60, TimeUnit.SECONDS)
- .dns(new XDns(100000))
- .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 {
- Response response = okHttpClient.newCall(request).execute();
- // 判断请求是否成功
- 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;
- throw new XiaoShiException("外部接口检索超时");
- }
- return null;
- }
- //封装patent column数据返回
- 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) {
- return dto.getAppNo().contains(number) || dto.getPublicNo().contains(number)
- || dto.getGrantNo().contains(number) || dto.getRowApplicationNo().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 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) {
- 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(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 "{}";
- }
- /**
- * @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 "{}";
- }
- /**
- * @param appNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取中国专利外观图
- */
- public String getWGPictureApi(String appNo) throws IOException {
- 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 "{}";
- }
- /**
- * @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 "{}";
- }
- /**
- * @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(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 "{}";
- }
- /**
- * @param patentNo
- * @return
- * @throws IOException
- * @author 李仁杰
- * 从专利之星获取同族专利
- */
- public String getFamilyByPubNoApi(String patentNo) {
- 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();
- // 判断请求是否成功
- 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;
- }
- public List<PatentStarListDTO> splitPatentNoByType(List<String> originalList, PatentStarListDTO patentStarListDTO) {
- 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;
- List<PatentStarListDTO> patentStarListDTOS = new ArrayList<>();
- //遍历初始集合
- for (String str : originalList) {
- if (str.startsWith("CN")) {
- 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 = "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 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) {
- List<PatentColumnDTO> patentColumnDTOS = new ArrayList<>();
- starPatentVOS.forEach(item -> {
- PatentColumnDTO patentColumnDTO = new PatentColumnDTO();
- //申请号
- patentColumnDTO.setAppNo(item.getApplicationNo());
- //装载公开号
- patentColumnDTO.setPublicNo(item.getPublicNo());
- //装载公告号
- patentColumnDTO.setGrantNo(item.getPublicAccreditNo());
- //装载专利状态
- if (item.getLG() != null) {
- patentColumnDTO.setSimpleStatus(item.getLG().toString());
- }
- //装载专利类型
- if (item.getPatentType() != null) {
- patentColumnDTO.setPatentType(item.getPatentType().toString());
- }
- //装载摘要
- List<Text> abstractList = new ArrayList<>();
- Text text = new Text();
- text.setTextContent(item.getAbstractStr());
- text.setIfOrigin(true);
- abstractList.add(text);
- patentColumnDTO.setAbstractStr(abstractList);
- //装载标题
- List<Text> titleList = new ArrayList<>();
- Text title = new Text();
- title.setTextContent(item.getName());
- title.setIfOrigin(true);
- titleList.add(title);
- // text.setLanguage(patent.getAppCountry());
- patentColumnDTO.setTitle(titleList);
- //装载权利要求
- List<Text> claimList = new ArrayList<>();
- Text claim = new Text();
- claim.setTextContent(item.getClaimStr());
- claim.setIfOrigin(true);
- claimList.add(claim);
- patentColumnDTO.setClaim(claimList);
- //装载专利号
- if (patentColumnDTO.getAppNo() != null) {
- if (patentColumnDTO.getAppNo().trim().startsWith("CN")) {
- patentColumnDTO.setPatentNo(patentColumnDTO.getAppNo());
- } else {
- if (patentColumnDTO.getPublicNo() != null) {
- patentColumnDTO.setPatentNo(patentColumnDTO.getPublicNo());
- } else if (patentColumnDTO.getGrantNo() != null) {
- patentColumnDTO.setPatentNo(patentColumnDTO.getGrantNo());
- } else {
- patentColumnDTO.setPatentNo(patentColumnDTO.getAppNo());
- }
- }
- }
- //装载申请日
- if (item.getApplicationDate() != null && !item.getApplicationDate().trim().equals("")) {
- patentColumnDTO.setAppDate(DateUtils.strToDate(item.getApplicationDate()));
- }
- // patentColumnDTO.setAppCountry(item.getBureau());
- //装载申请人地址
- PersonAddress appAddress = new PersonAddress();
- appAddress.setAddress(item.getApplicationAddress());
- appAddress.setProvince(item.getProvinceStr());
- patentColumnDTO.setApplicantAddr(appAddress);
- patentColumnDTO.setAppAddress(item.getApplicationAddress());
- // patentColumnDTO.setApplicantCountry(item.getProvinceStr());
- String provinceStr = item.getProvinceStr();
- if (provinceStr.contains("(") && provinceStr.contains(")")) {
- String substring = provinceStr.substring(provinceStr.indexOf("(") + 1, provinceStr.indexOf(")"));
- patentColumnDTO.setAppProvince(substring);
- }
- //装载ipc(主)分类号
- PatentClassify mipcClassify = new PatentClassify();
- mipcClassify.setLevel5(item.getMainIpc());
- patentColumnDTO.setMipc(mipcClassify);
- //装载ipc分类号
- List<PatentClassify> classifies = new ArrayList<>();
- String[] split = item.getIpcListStr().split(";");
- for (String ipc : split) {
- PatentClassify ipcClassify = new PatentClassify();
- ipcClassify.setLevel5(ipc);
- }
- patentColumnDTO.setIpc(classifies);
- //获取摘要附图
- // String pictureApi = this.getPictureApi(item.getRowApplicationNo());
- // patentColumnDTO.setPictureGuid(pictureApi);
- //获取外部专利原始申请号
- patentColumnDTO.setRowApplicationNo(item.getRowApplicationNo());
- //获取法律状态
- // String cnLegalApi = this.getCnLegalApi(item.getRowApplicationNo());
- // patentColumnDTO.setLegalStatus(Arrays.asList(cnLegalApi));
- //获取被引用次数
- //装载公开日
- if (item.getPublicDate() != null && !item.getPublicDate().trim().equals("")) {
- patentColumnDTO.setPublicDate(DateUtils.strToDate(item.getPublicDate()));
- }
- //装载公开日
- if (item.getPublicAccreditDate() != null && !item.getPublicAccreditDate().trim().equals("")) {
- patentColumnDTO.setGrantDate(DateUtils.strToDate(item.getPublicAccreditDate()));
- }
- //装载申请人
- if (item.getApplicantStr() != null && !item.getApplicantStr().trim().equals("")) {
- List<String> names = Arrays.asList(item.getApplicantStr().split(";"));
- patentColumnDTO.setApplicant(names);
- } else {
- patentColumnDTO.setApplicant(new ArrayList<>());
- }
- //装载发明人
- if (item.getInventorStr() != null && !item.getInventorStr().trim().equals("")) {
- List<String> names = Arrays.asList(item.getInventorStr().split(";"));
- patentColumnDTO.setInventor(names);
- } else {
- patentColumnDTO.setInventor(new ArrayList<>());
- }
- //装载权利人
- if (item.getCurrentApplicantStr() != null && !item.getCurrentApplicantStr().trim().equals("")) {
- List<String> names = Arrays.asList(item.getCurrentApplicantStr().split(";"));
- patentColumnDTO.setRightHolder(names);
- } else {
- patentColumnDTO.setRightHolder(new ArrayList<>());
- }
- //装载代理人
- if (item.getAgentStr() != null && !item.getAgentStr().trim().equals("")) {
- List<String> names = Arrays.asList(item.getAgentStr().split(";"));
- patentColumnDTO.setAgent(names);
- } else {
- patentColumnDTO.setAgent(new ArrayList<>());
- }
- //装载代理机构
- if (item.getAgencyStr() != null && !item.getAgencyStr().trim().equals("")) {
- patentColumnDTO.setAgency(item.getAgencyStr());
- }
- //装载优先权
- patentColumnDTO.setPriorityNo(item.getPriorityNo());
- patentColumnDTO.setPriorityDate(item.getPriorityDate());
- patentColumnDTO.setAppCountry(item.getBureau());
- 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 (DocumentException 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 (DocumentException 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");
- pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
- pdfUrlArr[1] = "http" + pdfUrlArr[1];
- pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
- 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 { //若只有一个
- pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"));
- 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;
- }
- }
|