|
@@ -0,0 +1,742 @@
|
|
|
+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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|