瀏覽代碼

水压传感器指令上报

limeng 2 年之前
父節點
當前提交
30a358f7dc

+ 9 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/controller/WaterPressureController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.monitorInterface.chenganshengbang.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.monitorInterface.chenganshengbang.service.WaterPressureService;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -24,6 +25,14 @@ public class WaterPressureController {
         return responseData();
     }
 
+    /**
+     * 水压传感器指令下发
+     * */
+    @PostMapping("/command")
+    public String command(@RequestBody String data){
+        return waterPressureService.command(data);
+    }
+
     public static byte[] responseData(){
         int xiangyingma = 200;
         byte[] xiangyingbytes = new byte[4];

+ 4 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/WaterPressureService.java

@@ -1,7 +1,11 @@
 package com.ruoyi.monitorInterface.chenganshengbang.service;
 
 
+import com.alibaba.fastjson.JSONObject;
+
 public interface WaterPressureService {
 
     void waterPressureMessageReceiver(String data);
+
+    String command(String data);
 }

+ 19 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/impl/WaterPressureServiceImpl.java

@@ -36,4 +36,23 @@ public class WaterPressureServiceImpl implements WaterPressureService {
             log.error("数据推送失败! data ===> {} , result ===> {}",data, e.getMessage());
         }
     }
+
+    public String command(String data){
+        log.info("WaterPressure-command 接到指令 ==>{}",data);
+        JSONObject object;
+        String res = null;
+        try {
+            object = JSONObject.parseObject(data);
+            res = HttpRequest.post(configService.getKey("commandURL"))
+                    .header("Content-Type", "application/json")
+                    .body(object.toJSONString())
+                    .execute().body();
+            log.info("指令下发成功! data ===> {} , result ===> {}",data, res);
+            return res;
+        }catch(Exception e){
+            e.printStackTrace();
+            log.error("指令下发失败! data ===> {} , result ===> {}",data, e.getMessage());
+            return res;
+        }
+    }
 }