|
@@ -0,0 +1,125 @@
|
|
|
|
+package cn.cslg.pas.service;
|
|
|
|
+
|
|
|
|
+import cn.cslg.pas.common.model.vo.UserVO;
|
|
|
|
+import cn.cslg.pas.common.utils.ApiUtils;
|
|
|
|
+import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
|
|
+import cn.cslg.pas.domain.Client;
|
|
|
|
+import cn.cslg.pas.domain.Project;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import okhttp3.*;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
|
+public class RequestService {
|
|
|
|
+ @Value("${authorUrl}")
|
|
|
|
+ private String url;
|
|
|
|
+ private final ApiUtils apiUtils;
|
|
|
|
+ public static final MediaType JSON1 = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
+ private final ProjectService projectService;
|
|
|
|
+ private final ClientService clientService;
|
|
|
|
+ //从权限系统查询专题库负责人信息
|
|
|
|
+ public String getDepartmentFromPCS(List<Project> dataList) throws IOException {
|
|
|
|
+ //获取专题库负责人对应信息
|
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
|
+ map1.put("departmentId", dataList.stream().map(Project::getDepartmentId).filter(Objects::nonNull).collect(Collectors.toList()));
|
|
|
|
+ return apiUtils.invokeApi(new JSONObject(map1), "/permission/api/system/getDepartmentById", "post", "data");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //从权限系统获取专题库负责人对应信息
|
|
|
|
+ public String getPersonnelFromPCS(List<Project> dataList) throws IOException {
|
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
|
+ map1.put("personnelId", dataList.stream().map(Project::getPersonnelId).collect(Collectors.toList()));
|
|
|
|
+ return apiUtils.invokeApi(new JSONObject(map1), "/permission/api/system/getPersonnelById", "post", "data");
|
|
|
|
+ }
|
|
|
|
+ //从权限系统获取验证码
|
|
|
|
+ public String getverifyCodeFromPCS() throws IOException {
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(url + "/permission/api/admin/verifyCode")
|
|
|
|
+ .get()
|
|
|
|
+ .build();
|
|
|
|
+ return okHttpClient.newCall(request).execute().body().string();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //从权限系统登录
|
|
|
|
+ public String LoginFromPCS(String username, String password, String code, String uuid) throws IOException {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("code", code);
|
|
|
|
+ map.put("uuid", uuid);
|
|
|
|
+ map.put("username", username);
|
|
|
|
+ map.put("password", password);
|
|
|
|
+ JSONObject json = new JSONObject(map);
|
|
|
|
+ RequestBody a = RequestBody.create(JSON1, String.valueOf(json));
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(url + "/permission/api/admin/login")
|
|
|
|
+ .post(a)
|
|
|
|
+ .build();
|
|
|
|
+ return okHttpClient.newCall(request).execute().body().string();
|
|
|
|
+ }
|
|
|
|
+ //从权限系统获得租户信息
|
|
|
|
+ public String getTenantMessageFromPCS(UserVO params) throws IOException {
|
|
|
|
+ //查询数据规则
|
|
|
|
+ //设定formdata类型参数
|
|
|
|
+ Project project = projectService.getProjectById(params.getProjectId());
|
|
|
|
+ int tentId = project.getTenantId();
|
|
|
|
+ List<Client> clients = clientService.getClientBytenant(tentId);
|
|
|
|
+ List<String> tenantNames = new ArrayList<>();
|
|
|
|
+ clients.forEach(item->{ tenantNames.add(item.getName());});
|
|
|
|
+ String names = JSON.toJSONString(tenantNames);
|
|
|
|
+ String name ="";
|
|
|
|
+ name = params.getName()==null? name:params.getName();
|
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
|
+ .add("tenantId", tentId+"" )
|
|
|
|
+ .add("tenantNames",names)
|
|
|
|
+ .add("tenantName",name)
|
|
|
|
+ .add("current",params.getCurrent().toString())
|
|
|
|
+ .add("size",params.getSize().toString())
|
|
|
|
+ .build();
|
|
|
|
+ //建立连接
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(url + "/permission/api/system/getTenantMessage")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .addHeader("Cookie", LoginUtils.getToken())
|
|
|
|
+ .build();
|
|
|
|
+ //获得请求返回
|
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ }
|
|
|
|
+ //从权限系统获得租户信息
|
|
|
|
+ public String getPersonnelMessageFromPCS(UserVO params) throws IOException {
|
|
|
|
+ //查询数据规则
|
|
|
|
+ //设定formdata类型参数
|
|
|
|
+ List<Client> clients = clientService.getClientBytenant(params.getTenantId());
|
|
|
|
+ List<String> tenantNames = new ArrayList<>();
|
|
|
|
+ clients.forEach(item->{ tenantNames.add(item.getName());});
|
|
|
|
+ String name ="";
|
|
|
|
+ name = params.getName()==null? name:params.getName();
|
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
|
+ .add("tenantId", params.getTenantId()+"" )
|
|
|
|
+ .add("personnelName",name)
|
|
|
|
+ .add("current",params.getCurrent().toString())
|
|
|
|
+ .add("size",params.getSize().toString())
|
|
|
|
+ .build();
|
|
|
|
+ //建立连接
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(url + "/permission/api/system/getPersonnelMessage")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .addHeader("Cookie", LoginUtils.getToken())
|
|
|
|
+ .build();
|
|
|
|
+ //获得请求返回
|
|
|
|
+ String resBody = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+
|
|
|
|
+ return resBody;
|
|
|
|
+ }
|
|
|
|
+}
|