From d15cae9e8d2cabf8d0f3ed41f2f88b04131f8c76 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 31 七月 2025 14:18:58 +0800
Subject: [PATCH] 增加查询单个设备(RTU或FBox)是否在线的功能接口

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java   |   90 ++++++++++++++++++++++++++++++
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java |   37 ++++++++++++
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java                    |   29 +++++++++
 3 files changed, 155 insertions(+), 1 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java
index 0602ff8..ea48390 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java
@@ -3,7 +3,13 @@
 public class CodeLocal {
 
 	public static final String clock = "LCD0000" ;//鏌ヨ鐩戞帶涓棿浠舵椂閽�
+	public static final String mwState = "LCD0200" ;//寰楀埌閫氫俊涓棿浠惰繍琛屼俊鎭�
 
+	////////////////////////////////////////////
+	//
+	// 浠ヤ笅鏄浉鍏冲熀浜嶵CP杩炴帴鐨凴TU璁惧鐨勫唴閮ㄥ懡浠�
+	//
+	////////////////////////////////////////////
 	public static final String onLineAll = "LCD0001" ;//鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
 
 	public static final String onLinePart = "LCD0002" ;//鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
@@ -22,6 +28,27 @@
 
 	public static final String recoverTcpSv = "LCD0112" ;//閲嶅惎TCP鏈嶅姟锛屾帴鍏ユ柊鐨凾CP杩炴帴
 
-	public static final String mwState = "LCD0200" ;//寰楀埌閫氫俊涓棿浠惰繍琛屼俊鎭�
+
+	////////////////////////////////////////////
+	//
+	// 浠ヤ笅鏄浉鍏冲熀浜嶮QTT杩炴帴鐨勮澶囩殑鍐呴儴鍛戒护
+	//
+	////////////////////////////////////////////
+	public static final String onAllLineMqtt = "LMCD0001" ;//鏌ヨ鎵�鏈塎QTT璁惧鍦ㄧ嚎鎯呭喌
+
+	public static final String onPartLineMqtt = "LMCD0002" ;//鏌ヨ閮ㄥ垎MQTT璁惧鍦ㄧ嚎鎯呭喌
+
+	public static final String onLineStatisticsMqtt = "LMCD0003" ;//鏌ヨ鎵�鏈塎QTT璁惧鍦ㄧ嚎鐘舵�佺粺璁℃儏鍐�
+
+	public static final String allRtuStatesMqtt = "LMCD0010" ;//鏌ヨ鎵�鏈塎QTT璁惧鐘舵��
+
+	public static final String partRtuStatesMqtt = "LMCD0011" ;//鏌ヨ閮ㄥ垎MQTT璁惧鐘舵��
+
+	public static final String oneRtuStatesMqtt = "LMCD0012" ;//鏌ヨ涓�涓狹QTT璁惧鐘舵��
+
+	public static final String stopMqttSv = "LMCD0110" ;//鍋滄Mqtt鏈嶅姟
+
+	public static final String recoverMqttSv = "LMCD0112" ;//閲嶅惎MQTT鏈嶅姟锛屾帴鍏ユ柊鐨凪QTT杩炴帴
+
 
 }
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java
index 46cfc3d..a82b724 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java
@@ -30,6 +30,43 @@
     private final MonitorSv monitorSv;
 
     /**
+     * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+     *
+     * @param rtuAddr
+     * @return
+     */
+    @GetMapping(path = "isOnLine4Rtu")
+    @SsoAop()
+    public BaseResponse<Boolean> isOnLine4Rtu(String rtuAddr) {
+        try {
+            Boolean res = monitorSv.isOnLine4Rtu(rtuAddr);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鍛戒护鎵ц寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+
+    /**
+     * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+     *
+     * @param rtuAddr
+     * @return
+     */
+    @GetMapping(path = "isOnLine4Mqtt")
+    @SsoAop()
+    public BaseResponse<Boolean> isOnLine4Mqtt(String rtuAddr) {
+        try {
+            Boolean res = monitorSv.isOnLine4Mqtt(rtuAddr);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鍛戒护鎵ц寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+
+
+    /**
      * 鑾峰彇鍙栨按鍙e垪琛紙鍦ㄧ嚎鍜屼笉鍦ㄧ嚎锛�
      *
      * @param qo
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java
index fc76796..8d2d2c5 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java
@@ -46,6 +46,23 @@
     private RestTemplate restTemplate;
 
     /**
+     * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+     *
+     * @return
+     */
+    public Boolean isOnLine4Rtu(String devId) {
+        return selectOnOrOffLine4Rtu(devId) ;
+    }
+
+    /**
+     * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+     *
+     * @return
+     */
+    public Boolean isOnLine4Mqtt(String devId) {
+        return selectOnOrOffLine4Mqtt(devId) ;
+    }
+    /**
      * 鑾峰彇宸茬粡缁戝畾鎺у埗鍣ㄧ殑鍙栨按鍙e垪琛紙骞舵爣璁板湪绾夸笌涓嶅湪绾匡級
      *
      * @return
@@ -152,6 +169,79 @@
 
 
     /**
+     * 鏌ヨRTU鍦ㄧ嚎鎴栫绾跨姸鎬�
+     * @param rtuAddr
+     * @return
+     */
+    private Boolean selectOnOrOffLine4Rtu(String rtuAddr) {
+        //鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+        Command com = this.createInnerCommand(CodeLocal.onPartLineMqtt);
+        com.setParam(rtuAddr) ;
+        String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
+        BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
+        if(res != null){
+            if(res.isSuccess()){
+                Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ;
+                CommandBackParam bakParam = JSON.parseObject((reCom== null || reCom.param == null) ? null : JSON.toJSONString(reCom.param), CommandBackParam.class) ;
+                if(bakParam != null){
+                    if(bakParam.getSuccess().booleanValue()){
+                        //閫氫俊涓棿浠舵垚鍔熻繑鍥炲懡浠ょ粨鏋�
+                        HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
+                        Boolean flag = onLineMap.get(rtuAddr);
+                        if(flag != null){
+                            return flag ;
+                        }
+                    }
+                }else{
+                    log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀腑涓嶅寘鍚獵ommandBackParam绫诲瀷鍙傛暟");
+                }
+            }else{
+                log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ゆ墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+            }
+        }else{
+            log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀负null");
+        }
+        return null ;
+    }
+
+
+    /**
+     * 鏌ヨMQTT鍦ㄧ嚎鎴栫绾跨姸鎬�
+     * @param devId
+     * @return
+     */
+    private Boolean selectOnOrOffLine4Mqtt(String devId) {
+        //鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+        Command com = this.createInnerCommand(CodeLocal.onPartLineMqtt);
+        com.setParam(devId) ;
+        String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
+        BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
+        if(res != null){
+            if(res.isSuccess()){
+                Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ;
+                CommandBackParam bakParam = JSON.parseObject((reCom== null || reCom.param == null) ? null : JSON.toJSONString(reCom.param), CommandBackParam.class) ;
+                if(bakParam != null){
+                    if(bakParam.getSuccess().booleanValue()){
+                        //閫氫俊涓棿浠舵垚鍔熻繑鍥炲懡浠ょ粨鏋�
+                        HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
+                        Boolean flag = onLineMap.get(devId);
+                        if(flag != null){
+                            return flag ;
+                        }
+                    }
+                }else{
+                    log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀腑涓嶅寘鍚獵ommandBackParam绫诲瀷鍙傛暟");
+                }
+            }else{
+                log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ゆ墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+            }
+        }else{
+            log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀负null");
+        }
+        return null ;
+    }
+
+    /**
      * 鏌ヨ鍙栨按鍙o紝鍦ㄧ嚎鎴栫绾跨姸鎬�
      * @param vo
      * @return

--
Gitblit v1.8.0