|
@@ -1,6 +1,8 @@
|
|
|
package cn.cslg.report.service;
|
|
|
|
|
|
import cn.cslg.report.common.model.vo.LoginVO;
|
|
|
+import cn.cslg.report.common.utils.JsonUtils;
|
|
|
+import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import okhttp3.MediaType;
|
|
@@ -12,20 +14,20 @@ import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author 沈永艺
|
|
|
- * @description 调用外部接口的Service类
|
|
|
+ * @description 调用外部接口的Service类 PCS:权限系统 PAS:专利分析系统
|
|
|
* @date 2022-10-31
|
|
|
*/
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class OutInterfaceService {
|
|
|
- @Value("${authorUrl}")
|
|
|
- private String url;
|
|
|
+ @Value("${PCSUrl}")
|
|
|
+ private String PCSUrl;
|
|
|
+ @Value("${PASUrl}")
|
|
|
+ private String PASUrl;
|
|
|
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
|
/**
|
|
@@ -35,7 +37,7 @@ public class OutInterfaceService {
|
|
|
public String getVerifyCodeFromPCS() throws IOException {
|
|
|
OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
Request request = new Request.Builder()
|
|
|
- .url(url + "/permission/api/admin/verifyCode")
|
|
|
+ .url(PCSUrl + "/permission/api/admin/verifyCode")
|
|
|
.get()
|
|
|
.build();
|
|
|
return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
@@ -45,19 +47,61 @@ public class OutInterfaceService {
|
|
|
* @title 登录接口
|
|
|
* @description 接口来源:PCS
|
|
|
*/
|
|
|
- public String LoginFromPCS(LoginVO loginVO) throws IOException {
|
|
|
+ public String loginFromPCS(LoginVO loginVO) throws IOException {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("code", loginVO.getCode());
|
|
|
map.put("uuid", loginVO.getUuid());
|
|
|
map.put("username", loginVO.getUsername());
|
|
|
map.put("password", loginVO.getPassword());
|
|
|
JSONObject json = new JSONObject(map);
|
|
|
- RequestBody a = RequestBody.create(JSON, String.valueOf(json));
|
|
|
+ RequestBody requestBody = RequestBody.create(JSON, String.valueOf(json));
|
|
|
OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
Request request = new Request.Builder()
|
|
|
- .url(url + "/permission/api/admin/login")
|
|
|
- .post(a)
|
|
|
+ .url(PCSUrl + "/permission/api/admin/login")
|
|
|
+ .post(requestBody)
|
|
|
.build();
|
|
|
return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @title 登录人信息
|
|
|
+ * @description 接口来源:PCS
|
|
|
+ */
|
|
|
+ public String userInfoFromPCS() throws IOException {
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(PCSUrl + "/permission/api/system/userinfo")
|
|
|
+ .get()
|
|
|
+ .addHeader("Cookie", LoginUtils.getToken())
|
|
|
+ .build();
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @title 获取字典项
|
|
|
+ * @description 接口来源:PCS PAS
|
|
|
+ */
|
|
|
+ public Map<String, Object> dictMessageFromPCS() throws IOException {
|
|
|
+ //从PCS取字典项
|
|
|
+ OkHttpClient okHttpClient1 = new OkHttpClient();
|
|
|
+ Request request1 = new Request.Builder()
|
|
|
+ .url(PCSUrl + "/permission/api/system/getDict")
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ String pcsDictMessage = Objects.requireNonNull(okHttpClient1.newCall(request1).execute().body()).string();
|
|
|
+ //从PAS取字典项
|
|
|
+ OkHttpClient okHttpClient2 = new OkHttpClient();
|
|
|
+ Request request2 = new Request.Builder()
|
|
|
+ .url(PASUrl + "/api/v2/common/getDictMessage")
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ String pasDictMessage = Objects.requireNonNull(okHttpClient2.newCall(request2).execute().body()).string();
|
|
|
+
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(pcsDictMessage);
|
|
|
+ JSONObject jsonObject2 = JSONObject.parseObject(pasDictMessage);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.putAll(JsonUtils.jsonToMap(String.valueOf(jsonObject1.get("data"))));
|
|
|
+ map.putAll(JsonUtils.jsonToMap(String.valueOf(jsonObject2.get("data"))));
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|