|
@@ -0,0 +1,226 @@
|
|
|
+package cn.cslg.pas.service.outApi;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.model.PatentCell;
|
|
|
+import cn.cslg.pas.common.model.dto.GetClaimsInfoParamsDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.GetDescriptionInfoParamsDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.GetFuTuParamsDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.GetSearchBiblioParamsDTO;
|
|
|
+import cn.cslg.pas.common.model.outApi.PatentStarListDto;
|
|
|
+import cn.cslg.pas.domain.PubNo;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 调用外部接口的Service类 PCS:权限系统
|
|
|
+ *
|
|
|
+ * @Author chenyu
|
|
|
+ * @Date 2023/4/25
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PatentStarApiService {
|
|
|
+ @Value("${authorUrl}")
|
|
|
+ private String PCSUrl;
|
|
|
+ @Value("${OPSUrl}")
|
|
|
+ private String OPSUrl;
|
|
|
+ @Value("${PASUrl}")
|
|
|
+ private String PASUrl;
|
|
|
+
|
|
|
+
|
|
|
+ public String patentStarSearchApi(PatentStarListDto patentStarListDto) throws IOException {
|
|
|
+
|
|
|
+// // 创建一个OkHttpClient对象
|
|
|
+// OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+//
|
|
|
+// // 创建一个RequestBody(参数1:数据类型 参数2传递的json串)
|
|
|
+// FormBody.Builder builder = new FormBody.Builder();
|
|
|
+//
|
|
|
+// for (String key : param.keySet()) {
|
|
|
+// Object obj = param.get(key);
|
|
|
+// if (obj != null) {
|
|
|
+// builder.addEncoded(key, param.get(key).toString());
|
|
|
+// } else {
|
|
|
+// builder.addEncoded(key, "");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// FormBody requestBody = builder.build();
|
|
|
+//
|
|
|
+// // 创建一个请求对象
|
|
|
+// Request request = new Request.Builder().url(url).post(requestBody).build();
|
|
|
+// // 发送请求获取响应
|
|
|
+// try {
|
|
|
+// Response response = okHttpClient.newCall(request).execute();
|
|
|
+// // 判断请求是否成功
|
|
|
+// if (response.isSuccessful()) {
|
|
|
+// // 打印服务端返回结果
|
|
|
+// return response.body().string();
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// return "{}";
|
|
|
+// OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+// Request request = new Request.Builder()
|
|
|
+// .url(PCSUrl + "/permission/api/system/getPersonIdByName?personName=" + personName)
|
|
|
+// .get()
|
|
|
+// .build();
|
|
|
+// return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据人员ids查询人员列表
|
|
|
+ *
|
|
|
+ * @param ids 人员ids
|
|
|
+ * @return 返回装载着人员列表数据的data的String
|
|
|
+ */
|
|
|
+ public String getPersonnelByIdsFromPCS(List<Integer> ids) throws IOException {
|
|
|
+
|
|
|
+ String param = new Gson().toJson(ids);
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(PCSUrl + "/permission/api/system/getPersonnelByIds")
|
|
|
+ .post(requestBody)
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程调用获取一批专利著录的接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getSearchBiblio(GetSearchBiblioParamsDTO getSearchBiblioParamsDTO) throws IOException {
|
|
|
+ //String param = new Gson().toJson(getSearchBiblioParamsDTO);
|
|
|
+ //RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(OPSUrl + "/api/OPSQuery/SearchBiblio?query=" + getSearchBiblioParamsDTO.getQuery() + "&start=" + getSearchBiblioParamsDTO.getStart() + "&end=" + getSearchBiblioParamsDTO.getEnd())
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程调用获取权要信息的接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getClaimsInfo(GetClaimsInfoParamsDTO getClaimsInfoParamsDTO) throws IOException {
|
|
|
+ //String param = new Gson().toJson(getClaimsInfoParamsDTO);
|
|
|
+ //RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(OPSUrl + "/api/OPSQuery/GetClaimsInfo?cc=" + getClaimsInfoParamsDTO.getCc() + "&number=" + getClaimsInfoParamsDTO.getNumber() + "&kind=" + getClaimsInfoParamsDTO.getKind())
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程调用获取说明书的接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getDescriptionInfo(GetDescriptionInfoParamsDTO getDescriptionInfoParamsDTO) throws IOException {
|
|
|
+ //String param = new Gson().toJson(getDescriptionInfoParamsDTO);
|
|
|
+ //RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(OPSUrl + "/api/OPSQuery/GetDescriptionInfo?cc=" + getDescriptionInfoParamsDTO.getCc() + "&number=" + getDescriptionInfoParamsDTO.getNumber() + "&kind=" + getDescriptionInfoParamsDTO.getKind())
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程调用获取Image信息的接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getImagesInfo(PubNo pubNo) throws IOException {
|
|
|
+ String pn = pubNo.getCountry() + pubNo.getNumber() + "." + pubNo.getKind();
|
|
|
+ //String param = new Gson().toJson(pn);
|
|
|
+ //RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(OPSUrl + "/api/OPSQuery/GetImagesInfo?Pn=" + pn)
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程调用获取附件文件流的接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public byte[] getPatentFile(GetFuTuParamsDTO getFuTuParamsDTO) throws IOException {
|
|
|
+ //String param = new Gson().toJson(getFuTuParamsDTO);
|
|
|
+ //RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(OPSUrl + "/api/OPSQuery/GetPatentFile?link=" + getFuTuParamsDTO.getLink() + "&page=" + getFuTuParamsDTO.getPage() + "&type=" + getFuTuParamsDTO.getType())
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ byte[] buffer = okHttpClient.newCall(request).execute().body().bytes();
|
|
|
+ return buffer;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @params 传对象
|
|
|
+ * @title 导入专利
|
|
|
+ * @description 导入专利
|
|
|
+ * @author lrj
|
|
|
+ */
|
|
|
+ public String importPatents(PatentCell patentCell) throws IOException {
|
|
|
+ OkHttpClient httpClient = new OkHttpClient.Builder()
|
|
|
+ .pingInterval(400, TimeUnit.SECONDS) // 设置 PING 帧发送间隔
|
|
|
+ .connectTimeout(300, TimeUnit.SECONDS)//设置连接超时时间
|
|
|
+ .readTimeout(300, TimeUnit.SECONDS)//设置读取超时时间
|
|
|
+ .build();
|
|
|
+ String param = new Gson().toJson(patentCell);
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(PASUrl + "/api/v2/system/patentCellTODb")
|
|
|
+ .post(requestBody)
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(httpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|