|
|
@@ -0,0 +1,78 @@
|
|
|
+package com.zksy.controller.common;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.zksy.common.domain.dto.UserPermissions;
|
|
|
+import com.zksy.utils.AjaxResult;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Administrator
|
|
|
+ * @version 1.0
|
|
|
+ * @project enterprise-assets-service
|
|
|
+ * @description 用户权限
|
|
|
+ * @date 2025/8/11 10:26:24
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Api(tags = "用户权限", description = "用户权限")
|
|
|
+@RequestMapping("/userPermissions")
|
|
|
+@Slf4j
|
|
|
+public class UserPermissionsController {
|
|
|
+ private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
+ @Autowired
|
|
|
+ private OkHttpClient httpClient;
|
|
|
+ @ApiOperation(value = "用户权限查询")
|
|
|
+ @PostMapping("/queryUserPermissions")
|
|
|
+ public AjaxResult queryUserPermissions(UserPermissions request){
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String jsonParams = null;
|
|
|
+ try {
|
|
|
+ jsonParams = objectMapper.writeValueAsString(request);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error("JSON序列化失败: {}", e);
|
|
|
+ return AjaxResult.error("请求失败");
|
|
|
+ }
|
|
|
+ // 创建请求体
|
|
|
+ RequestBody body = RequestBody.create(jsonParams, JSON);
|
|
|
+ // 构建请求
|
|
|
+ Request requestHttp = new Request.Builder()
|
|
|
+ .url("http://172.168.80.14:8082/minto/extTask/findUsers")
|
|
|
+ .post(body)
|
|
|
+ .build();
|
|
|
+ // 发送请求
|
|
|
+ try (Response response = httpClient.newCall(requestHttp).execute()) {
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
+ return AjaxResult.error("请求失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if("true".equals(success.asText())) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode != null) {
|
|
|
+ return AjaxResult.success(dataNode);
|
|
|
+ } else {
|
|
|
+ return AjaxResult.success(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return AjaxResult.error("用户权限查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("请求失败: {}", e);
|
|
|
+ }
|
|
|
+ return AjaxResult.error("请求失败");
|
|
|
+ }
|
|
|
+}
|