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 | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 152 insertions(+), 15 deletions(-)
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 6684947..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
@@ -1,15 +1,18 @@
package com.dy.pipIrrRemote.monitor;
+import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.CommandBackParam;
+import com.dy.common.mw.protocol.rtuState.RtuStatus;
+import com.dy.common.util.DateTime;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper;
import com.dy.pipIrrGlobal.rtuMw.CodeLocal;
-import com.dy.pipIrrGlobal.rtuMw.ToRtuMwCom;
+import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
@@ -18,6 +21,8 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
+import java.text.DateFormat;
+import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -29,7 +34,7 @@
*/
@Slf4j
@Service
-public class MonitorSv extends ToRtuMwCom {
+public class MonitorSv extends Web2RtuMw {
@Autowired
private PrIntakeMapper prIntakeMapper;
@@ -40,6 +45,23 @@
@Autowired
private RestTemplate restTemplate;
+ /**
+ * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+ *
+ * @return
+ */
+ public Boolean isOnLine4Rtu(String devId) {
+ return selectOnOrOffLine4Rtu(devId) ;
+ }
+
+ /**
+ * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+ *
+ * @return
+ */
+ public Boolean isOnLine4Mqtt(String devId) {
+ return selectOnOrOffLine4Mqtt(devId) ;
+ }
/**
* 鑾峰彇宸茬粡缁戝畾鎺у埗鍣ㄧ殑鍙栨按鍙e垪琛紙骞舵爣璁板湪绾夸笌涓嶅湪绾匡級
*
@@ -53,6 +75,46 @@
//鍦ㄧ嚎 鎴� 绂荤嚎
return selectIntakesOnOrOffLine(vo) ;
}
+ }
+
+ /**
+ * 鏌ヨRTU鍦ㄩ�氫俊涓棿浠朵腑鐨勭姸鎬�
+ * @param rtuAddr
+ * @return
+ */
+ public RtuStatus rtuStatus(String rtuAddr) throws Exception{
+ //鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+ RtuStatus rtuStatus = null ;
+ Command com = this.createInnerCommand(CodeLocal.oneRtuStates);
+ 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()){
+ //閫氫俊涓棿浠舵垚鍔熻繑鍥炲懡浠ょ粨鏋�
+ if(reCom.getAttachment() != null){
+ rtuStatus = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), RtuStatus.class);
+ }else{
+ throw new Exception("閫氫俊涓棿浠舵湭鎺屾彙璇TU鐨勭姸鎬侊紝鍙兘璇TU鏈笂绾�") ;
+ }
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀腑涓嶅寘鍚獵ommandBackParam绫诲瀷鍙傛暟");
+ throw new Exception("閫氫俊涓棿浠舵墽琛屽懡浠ゅ嚭閿�") ;
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ゆ墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+ throw new Exception("閫氫俊涓棿浠舵墽琛屽懡浠ゅ嚭閿�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀负null");
+ throw new Exception("閫氫俊涓棿浠舵墽琛屽懡浠ゅ嚭閿欙紝杩斿洖鍐呴儴鍛戒护缁撴灉涓簄ull") ;
+ }
+ return rtuStatus ;
}
/**
@@ -76,16 +138,16 @@
//鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
Command com = this.createInnerCommand(CodeLocal.onLinePart);
com.setParam(rtuAddrs) ;
- String comSendUrl = this.getToMwUrl(this.env) ;
- BaseResponse<Command> res = sendCom2Mw(restTemplate, comSendUrl, com) ;
+ String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
+ BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
if(res != null){
if(res.isSuccess()){
- Command reCom = res.getContent() ;
- CommandBackParam bakParam = JSON.parseObject(((JSONObject)reCom.param).toJSONString(), CommandBackParam.class) ;
+ 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(((JSONObject)reCom.getAttachment()).toJSONString(), HashMap.class);
+ HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
for(VoOnLineIntake rVo : rsVo.obj){
if(onLineMap.containsKey(rVo.getRtuAddr())) {
rVo.setIsOnLine(onLineMap.get(rVo.getRtuAddr()));
@@ -107,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
@@ -114,16 +249,16 @@
private QueryResultVo<List<VoOnLineIntake>> selectIntakesOnOrOffLine(QueryVo vo) {
//鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
Command com = this.createInnerCommand(CodeLocal.onLineAll);
- String comSendUrl = this.getToMwUrl(this.env) ;
- BaseResponse<Command> res = sendCom2Mw(restTemplate, comSendUrl, com) ;
+ String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
+ BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
if(res != null){
if(res.isSuccess()){
- Command reCom = res.getContent() ;
- CommandBackParam bakParam = JSON.parseObject(((JSONObject)reCom.param).toJSONString(), CommandBackParam.class) ;
+ 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(((JSONObject)reCom.getAttachment()).toJSONString(), HashMap.class);
+ HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
JSONArray jsonArray = new JSONArray();
for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
JSONObject jsonObject = new JSONObject();
@@ -163,12 +298,14 @@
rsVo.obj = records ;
for(VoOnLineIntake rVo : records){
if(rVo.getAlarm() != null && !rVo.getAlarm().trim().equals("") && rVo.getAlarm().endsWith("锛�")){
- rVo.setAlarm(rVo.getAlarm().substring(0, rVo.getAlarm().length() - 1)) ;
+ if(rVo.getAlarmDt() != null){
+ rVo.setAlarm(rVo.getAlarm().substring(0, rVo.getAlarm().length() - 1) + "\n" + DateTime.yyyy_MM_dd_HH_mm_ss(rVo.getAlarmDt()) ) ;
+ }else{
+ rVo.setAlarm(rVo.getAlarm().substring(0, rVo.getAlarm().length() - 1)) ;
+ }
}
}
return rsVo ;
}
-
-
}
--
Gitblit v1.8.0