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 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 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 starPatentVOS = (List) 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 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 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 starPatentVOS = JSONArray.parseArray(Data.get("List").toString(), StarPatentVO.class); Map 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 loadPatentList(List columnDTOS, List list, String dbType) { if (CollectionUtils.isEmpty(list) || CollectionUtils.isEmpty(columnDTOS)) { return list.isEmpty() ? columnDTOS : createNewDTOs(list); } List result = new ArrayList<>(columnDTOS.size()); Set 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 createNewDTOs(List list) { List 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 getSplitedConditions(PatentStarListDTO patentStarListDTO, int patentNum) throws IOException { DateTime nowDate = new DateTime(); DateTime date = DateUtils2.formStrToDateTime("1900-01-01"); //超过1万的列表 List PatentStarListDTOs = new ArrayList<>(); //返回的列表 List 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 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 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 = (List) xpath.selectNodes(document); if (element.size() == 0) { xpath = document.createXPath("//business:ClaimText"); element = (List) xpath.selectNodes(document); } List 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 elements = (List) xpath.selectNodes(document); if (elements.size() == 0) { xpath = document.createXPath("//business:Description//base:Paragraphs"); elements = (List) xpath.selectNodes(document); } List reStrs = new ArrayList<>(); Integer count = 1; for (Element item : elements) { String claim = item.getText().replaceAll("
", ""); 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 splitPatentNoByType(List originalList, PatentStarListDTO patentStarListDTO, Integer type) { List patentStarListDTOS = new ArrayList<>(); List cnStrings = new ArrayList<>(); List wdStrings = new ArrayList<>(); List> 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 resultMap = this.patentStarSearchApi(patentStarListDTO); if (resultMap == null || (Integer) resultMap.get("total") == 0) { return starPatentVO; } List starPatents = (List) resultMap.get("records"); starPatentVO = starPatents.get(0); } catch (Exception e) { } return starPatentVO; } private List loadPatent(List starPatentVOS, String dbType) { List 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 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 names = Arrays.asList(item.getPA().split(";")); patentColumnDTO.setApplicant(names); } else { patentColumnDTO.setApplicant(new ArrayList<>()); } //装载发明人 if (item.getIN() != null && !item.getIN().trim().equals("")) { List names = Arrays.asList(item.getIN().split(";")); patentColumnDTO.setInventor(names); } else { patentColumnDTO.setInventor(new ArrayList<>()); } //装载权利人 if (item.getPE() != null && !item.getPE().trim().equals("")) { List 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 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 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 publicNos = new ArrayList<>(); if (StringUtils.isNotEmpty(familyInfos) && !familyInfos.equals("{}")) { publicNos = Arrays.asList(familyInfos.split(";")); } List 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) 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 getCnFullText(String appNo) { List 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 getExternalTextPdf(String appNo, String rowApplicationNo, String publicNo, String grantNo) throws IOException { List 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 getExternalFigure(String appNo) throws IOException { List 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 list = new ArrayList<>(); List legalEvents = new ArrayList<>(); String cnLegalApi = this.getCnLegalApi(appNo); if (StringUtils.isNotEmpty(cnLegalApi) && !cnLegalApi.equals("{}") && !cnLegalApi.contains("408")) { List statusDTOS = JSONArray.parseArray(cnLegalApi, ExternalLegalStatusDTO.class); if (!CollectionUtils.isEmpty(statusDTOS)) { List 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 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 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 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 pdfDTOS = new ArrayList<>(); for (InnerPatentPdfDTO innerPatentPdfDTO : pdfList) { if (StringUtils.isNotEmpty(innerPatentPdfDTO.getPdfGuid())) { File file = FileUtils.getFileByUrl(innerPatentPdfDTO.getPdfGuid()); List 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 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 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 list = fileManagerService.uploadFileGetGuid(Collections.singletonList(multipartFile)); if (!CollectionUtils.isEmpty(list)) { return list.get(0); } } return ""; } }