فهرست منبع

修改返回值以及添加抛异常

nahida 1 سال پیش
والد
کامیت
4def75f4b5

+ 9 - 8
lamp-service/src/main/java/com/zksy/lamp/controller/ExecutionController.java

@@ -1,5 +1,6 @@
 package com.zksy.lamp.controller;
 
+import com.zksy.common.core.domain.Result;
 import com.zksy.lamp.server.ExecutionServer;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -23,35 +24,35 @@ public class ExecutionController {
     private ExecutionServer server;
     @GetMapping("/firstRelay")
     @ApiOperation(value = "第一路继电器闭合、断开", notes = "第一路继电器闭合、断开")
-    public String firstRelay(@ApiParam(value = "第一路继电器(0-断开,1-闭合)",required = true)
+    public Result<?> firstRelay(@ApiParam(value = "第一路继电器(0-断开,1-闭合)",required = true)
                        @RequestParam(value = "value") Integer value){
         String data = "AT+STACH1="+value+"\r\n";
         String msg = server.ExecutionData(data);
-        return msg;
+        return Result.ok(msg);
     }
     @GetMapping("/secondRelay")
     @ApiOperation(value = "第二路继电器闭合、断开", notes = "第二路继电器闭合、断开")
-    public String secondRelay(@ApiParam(value = "第二路继电器(0-断开,1-闭合)",required = true)
+    public Result<?> secondRelay(@ApiParam(value = "第二路继电器(0-断开,1-闭合)",required = true)
                                   @RequestParam(value = "value") Integer value){
         String data = "AT+STACH2="+value+"\r\n";
         String msg = server.ExecutionData(data);
-        return msg;
+        return Result.ok(msg);
     }
 
     @GetMapping("/timingOn")
     @ApiOperation(value = "定时开启", notes = "定时开启")
-    public String timingOn(@ApiParam(value = "定时开启时间,时:分:秒,示例:17:00:00",required = true)
+    public Result<?> timingOn(@ApiParam(value = "定时开启时间,时:分:秒,示例:17:00:00",required = true)
                               @RequestParam(value = "value") String value){
         String data = "AT+AUTOCONT=2,task1,[CYC:1],[T:3,0|1|2|3|4|5|6,"+value+"],[DO:0,1,1,100000,100000,1000000],[N:1,0]\r\n";
         String msg = server.ExecutionData(data);
-        return msg;
+        return Result.ok(msg);
     }
     @GetMapping("/timedShutdown")
     @ApiOperation(value = "定时关闭", notes = "定时关闭")
-    public String timedShutdown(@ApiParam(value = "定时关闭时间,时:分:秒,示例:06:00:00",required = true)
+    public Result<?> timedShutdown(@ApiParam(value = "定时关闭时间,时:分:秒,示例:06:00:00",required = true)
                            @RequestParam(value = "value") String value){
         String data = "AT+AUTOCONT=2,task2,[CYC:1],[T:3,0|1|2|3|4|5|6,"+value+"],[DO:0,1,0,100000,100000,1000000],[N:1,0]\r\n";
         String msg = server.ExecutionData(data);
-        return msg;
+        return Result.ok(msg);
     }
 }

+ 5 - 2
lamp-service/src/main/java/com/zksy/lamp/server/ExecutionServer.java

@@ -1,5 +1,7 @@
 package com.zksy.lamp.server;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -18,6 +20,7 @@ import java.net.Socket;
  */
 @Component
 public class ExecutionServer {
+    private static final Logger log = LoggerFactory.getLogger(ExecutionServer.class);
     private BufferedReader reader;
     private BufferedWriter writer;
     private ServerSocket server;
@@ -97,8 +100,8 @@ public class ExecutionServer {
             Thread.sleep(100);
             return msg;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.info(e.toString());
+            throw new RuntimeException("指令执行失败");
         }
-        return "发送指令:"+msg+"失败";
     }
 }

+ 1 - 9
lamp-service/src/main/resources/application-prod.yaml

@@ -8,12 +8,4 @@ zksy:
 spring:
   redis:
     host: 172.16.102.52
-    port: 6379
-minio:
-  endpoint: http://172.16.102.52:9000
-  accessKey: minio
-  secretKey: minio123
-  bucket: test
-  readPath: http://172.16.102.52:9000
-redisson:
-  host: redis://172.16.102.52:6379
+    port: 6379