123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- package com.example.xiaoshiweixinback.service.importPatent;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.example.xiaoshiweixinback.business.config.XDns;
- import com.example.xiaoshiweixinback.business.utils.DateUtils2;
- import com.example.xiaoshiweixinback.business.utils.FormatUtil;
- import com.example.xiaoshiweixinback.business.utils.StringUtils;
- import com.example.xiaoshiweixinback.entity.dto.patent.PatentStarDTO;
- import com.example.xiaoshiweixinback.entity.dto.patent.PatentStarListDTO;
- import com.example.xiaoshiweixinback.entity.dto.patent.StarPatentVO;
- import lombok.RequiredArgsConstructor;
- 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.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.stream.Collectors;
- /**
- * 调用外部接口的Service类 PCS:权限系统
- *
- * @Author chenyu
- * @Date 2023/4/25
- */
- @RequiredArgsConstructor
- @Slf4j
- @Service
- public class PatentStarApiService {
- private ApplicationContext applicationContext;
- @Autowired
- private FormatQueryService formatQueryService;
- 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) {
- 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;
- }
- return null;
- }
- 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();
- }
- } 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();
- }
- } 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 "{}";
- }
- /**
- * @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();
- }
- } 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) {
- String config ="";
- if(webId==4&&webGroup==1){
- config="{\"appId\":\"K8FFB741E163BE6536\",\"appKey\":\"FNYJD7902206FFB741E163BE6536C3689D55\"}";
- }
- else {
- config="{\"appId\":\"1000046\",\"appKey\":\"6AE6D4DC6AF94F26862501EDEE9E27A2\"}";
- }
- 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;
- }
- /**
- * 获取附图
- *
- * @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);
- }
- }
|