Sfoglia il codice sorgente

refactor(visualization): 移除无用代码并添加新功能- 删除了 VisualizationController 类中的测试代码
- 在 LightingGatewayController 中添加了单个和批量设置面板开关的功能
- 在 FireFightingController 中添加了报警事件处理功能
- 新增了 AlarmRecord 和 DeviceSwitchRequest 类用于报警事件处理和设备开关控制

林仔 1 anno fa
parent
commit
bd4c2e4600

+ 0 - 11
screen-service/src/main/java/com/zksy/screen/controller/ScreenLampController.java

@@ -36,17 +36,6 @@ public class ScreenLampController {
     private final String BASE_URL = "http://172.16.102.52:8016/command/";
     @Autowired
     private ScreenControlService screenControlService;
-
-    @GetMapping("/a")
-    private Result<String> test() {
-        return Result.ok("爱与和平");
-    }
-
-    @PostMapping("/a")
-    private String test2() {
-        return "爱与和平";
-    }
-
     @ApiOperation(value = "清屏,清除顶层网页内容")
     @PostMapping("/clearTopWebPage")
     public Result clearTopWebPage(

+ 48 - 0
visualization-service/src/main/java/com/zksy/visualization/controller/FireFightingController.java

@@ -290,4 +290,52 @@ public class FireFightingController {
         }
         return Result.error("请求失败");
     }
+    @ApiOperation(value = "alarm事件处理")
+    @PostMapping("/getAlarmEventProcessing")
+    public Result getAlarmEventProcessing(AlarmRecord request){
+        ObjectMapper objectMapper = new ObjectMapper();
+        String jsonParams = null;
+        try {
+            jsonParams = objectMapper.writeValueAsString(request);
+        } catch (JsonProcessingException e) {
+            log.error("JSON序列化失败: {}", e);
+            return Result.error("请求失败");
+        }
+        String authorization = redisTemplate
+                .opsForValue()
+                .get("Authorization:" + iccConfigProperty.getUsername());
+        // 创建请求体
+        RequestBody body = RequestBody.create(jsonParams, JSON);
+        // 构建请求
+        Request requestHttp = new Request.Builder()
+                .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-event/"+iccConfigProperty.getVersion()+"/alarm-record/stat")
+                .addHeader("Authorization", authorization)
+                .put(body)
+                .build();
+        // 发送请求
+        try (Response response = httpClient.newCall(requestHttp).execute()) {
+            if (!response.isSuccessful()) {
+                return Result.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 Result.ok(dataNode);
+                    } else {
+                        return Result.ok(null);
+                    }
+                }else {
+                    return Result.error("事件处理失败");
+                }
+            }
+        } catch (IOException e) {
+            log.error("请求失败: {}", e);
+        }
+        return Result.error("请求失败");
+    }
 }

+ 0 - 63
visualization-service/src/main/java/com/zksy/visualization/controller/VisualizationController.java

@@ -1,63 +0,0 @@
-package com.zksy.visualization.controller;
-
-
-import com.zksy.common.core.domain.Result;
-import com.zksy.service.MinioFileStorageService;
-import com.zksy.visualization.config.IccConfigProperty;
-import lombok.extern.slf4j.Slf4j;
-import okhttp3.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-
-@RestController
-@RequestMapping("/visualization")
-@Slf4j
-public class VisualizationController {
-    @Autowired
-    private OkHttpClient httpClient;
-    @Autowired
-    private IccConfigProperty iccConfigProperty;
-    @Autowired
-    private RedisTemplate<String,String> redisTemplate;
-    @Autowired
-    private MinioFileStorageService minioFileStorageService;
-    @GetMapping("/test")
-    public Result test() {
-        String authorization = redisTemplate
-                .opsForValue()
-                .get("Authorization:" + iccConfigProperty.getUsername());
-        Request request = new Request.Builder()
-                .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-brm/" + iccConfigProperty.getVersion() + "/organization/001")
-                .addHeader("Authorization", authorization)
-                .build();
-        try {
-            Response response = httpClient.newCall(request).execute();
-            if(!response.isSuccessful()){
-                return Result.error("请求失败");
-            }
-            ResponseBody responseBody = response.body();
-            if (responseBody != null) {
-                return Result.ok(responseBody.string());
-            }
-        } catch (Exception e) {
-            log.error("error:{}", e);
-        }
-        return Result.error("请求失败");
-    }
-    @PostMapping
-    public Result upload(MultipartFile file){
-        try {
-            String s = minioFileStorageService.uploadFile(file, "test");
-            System.out.println(s);
-        } catch (Exception e) {
-            return Result.error("失败");
-        }
-        return Result.ok();
-    }
-}

+ 108 - 8
visualization-service/src/main/java/com/zksy/visualization/controller/smartElectricController/LightingGatewayController.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.zksy.common.core.domain.Result;
 import com.zksy.visualization.config.IccConfigProperty;
+import com.zksy.visualization.domain.request.DeviceSwitchRequest;
 import com.zksy.visualization.domain.request.IntelligenceSensorRequest;
 import com.zksy.visualization.domain.request.IntelligentPanelRequest;
 import com.zksy.visualization.domain.request.SmartSocketRequest;
@@ -76,18 +77,16 @@ public class LightingGatewayController {
                 String responseString = responseBody.string();
                 JsonNode rootNode = objectMapper.readTree(responseString);
                 JsonNode success = rootNode.path("success");
-                if(success.isBoolean() && success.asBoolean()) {
+                if("true".equals(success.asText())) {
                     JsonNode dataNode = rootNode.path("data");
-                    if (dataNode.isObject()) {
-                        IntelligentPanelResponse intelligentPanelResponse = objectMapper.treeToValue(dataNode, IntelligentPanelResponse.class);
-                        return Result.ok(intelligentPanelResponse);
+                    if (dataNode != null) {
+                        return Result.ok(dataNode);
                     } else {
                         return Result.ok(null);
                     }
                 }else {
-                    JsonNode errMsgNode = rootNode.path("errMsg");
-                    String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
-                    return Result.error(errMsg);
+                    JsonNode dataNode = rootNode.path("errMsg");
+                    return Result.error(dataNode.asText());
                 }
             }
         } catch (IOException e) {
@@ -95,6 +94,107 @@ public class LightingGatewayController {
         }
         return Result.error("请求失败");
     }
+
+    @ApiOperation(value = "单个设置面板开关")
+    @PostMapping("/getSinglePanelSwitch")
+    public Result getSinglePanelSwitch(DeviceSwitchRequest request) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        String jsonParams = null;
+        String authorization = redisTemplate
+                .opsForValue()
+                .get("Authorization:" + iccConfigProperty.getUsername());
+        try {
+            jsonParams = objectMapper.writeValueAsString(request);
+        } catch (JsonProcessingException e) {
+            log.error("JSON序列化失败: {}", e);
+            return Result.error("请求失败");
+        }
+        // 创建请求体
+        RequestBody body = RequestBody.create(jsonParams, JSON);
+        // 构建请求
+        Request requestHttp = new Request.Builder()
+                .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-electricity/"+ iccConfigProperty.getVersion() +"/lightingControl/singleSet/panel")
+                .addHeader("Authorization", authorization)
+                .post(body)
+                .build();
+        // 发送请求
+        try (Response response = httpClient.newCall(requestHttp).execute()) {
+            if (!response.isSuccessful()) {
+                return Result.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 Result.ok(dataNode);
+                    } else {
+                        return Result.ok(null);
+                    }
+                }else {
+                    JsonNode dataNode = rootNode.path("errMsg");
+                    return Result.error(dataNode.asText());
+                }
+            }
+        } catch (IOException e) {
+            log.error("请求失败: {}", e);
+        }
+        return Result.error("请求失败");
+    }
+
+    @ApiOperation(value = "批量设置面板开关")
+    @PostMapping("/getBatchPanelSwitch")
+    public Result getBatchPanelSwitch(DeviceSwitchRequest request) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        String jsonParams = null;
+        String authorization = redisTemplate
+                .opsForValue()
+                .get("Authorization:" + iccConfigProperty.getUsername());
+        try {
+            jsonParams = objectMapper.writeValueAsString(request);
+        } catch (JsonProcessingException e) {
+            log.error("JSON序列化失败: {}", e);
+            return Result.error("请求失败");
+        }
+        // 创建请求体
+        RequestBody body = RequestBody.create(jsonParams, JSON);
+        // 构建请求
+        Request requestHttp = new Request.Builder()
+                .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-electricity/"+ iccConfigProperty.getVersion() +"/lightingControl/batchSet/panel")
+                .addHeader("Authorization", authorization)
+                .post(body)
+                .build();
+        // 发送请求
+        try (Response response = httpClient.newCall(requestHttp).execute()) {
+            if (!response.isSuccessful()) {
+                return Result.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 Result.ok(dataNode);
+                    } else {
+                        return Result.ok(null);
+                    }
+                }else {
+                    JsonNode dataNode = rootNode.path("errMsg");
+                    return Result.error(dataNode.asText());
+                }
+            }
+        } catch (IOException e) {
+            log.error("请求失败: {}", e);
+        }
+        return Result.error("请求失败");
+    }
+/*
     @ApiOperation(value = "智能插座分页查询")
     @PostMapping("/getSmartSocketPage")
     public Result getSmartSocketPage(SmartSocketRequest request) {
@@ -196,6 +296,6 @@ public class LightingGatewayController {
             log.error("请求失败: {}", e);
         }
         return Result.error("请求失败");
-    }
+    }*/
 
 }

+ 25 - 0
visualization-service/src/main/java/com/zksy/visualization/domain/request/AlarmRecord.java

@@ -0,0 +1,25 @@
+package com.zksy.visualization.domain.request;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(description = "alarm事件处理")
+public class AlarmRecord {
+
+    @ApiModelProperty(value = "报警记录code", required = true)
+    private String alarmCode;
+
+    @ApiModelProperty(value = "处理状态:1处理中,2已处理,3误报,4忽略,0未处理", required = true)
+    private int handleStat;
+
+    @ApiModelProperty(value = "处理内容")
+    private String handleMessage;
+
+    @ApiModelProperty(value = "查询类型,0-本地库更新(默认),1-云数据库更新(含本地库更新),1.0.1版本新增")
+    private int dbType = 0;
+
+    @ApiModelProperty(value = "报警时间,分表功能所加,1.2.0版本新增,形式:yyyy-MM-dd HH:mm:ss", required = true)
+    private String alarmDate;
+}    

+ 16 - 0
visualization-service/src/main/java/com/zksy/visualization/domain/request/DeviceSwitchRequest.java

@@ -0,0 +1,16 @@
+package com.zksy.visualization.domain.request;
+
+import lombok.Data;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class DeviceSwitchRequest {
+
+    @ApiModelProperty(value = "设备编码集合", required = true)
+    private List<String> deviceCodes;
+
+    @ApiModelProperty(value = "开关状态(0:关 1:开),switch1 按键1 switch2 按键2 switch3 按键3,switch4 按键,onOff 控制四个键的开关", required = true)
+    private Map<String, Integer> switchsStatus;
+}