From 0ee340a21c1061cb68eb124ab26b482552634dba Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期三, 23 十月 2024 20:23:22 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
/dev/null | 39 ---
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java | 174 +++++++++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/QueryVo.java | 32 ++
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/CodeLocal.java | 6
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java | 19 +
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java | 49 ++++
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java | 21 +
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineDeal.java | 14 +
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeMapper.java | 17 +
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/ToRtuMwCom.java | 85 +++++++
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/CommandInnerDeaLer.java | 31 ++
pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml | 131 ++++++++++-
12 files changed, 548 insertions(+), 70 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeMapper.java
index f67fb00..9789d67 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeMapper.java
@@ -127,6 +127,23 @@
//List<VoOnLineIntake> getOnLineIntakes(@Param("onLineMap") String onLineMap, @Param("isOnLine") Boolean isOnLine);
List<VoOnLineIntake> getOnLineIntakes(Map<?, ?> params);
+
+ /**
+ * 鑾峰彇鍙栨按鍙f暟閲忥紙鍦ㄧ嚎鎴栦笉鍦ㄧ嚎锛�
+ * @param params
+ * @return
+ */
+ Long selectIntakesCountForOnLine(Map<?, ?> params);
+
+ /**
+ * 鑾峰彇鍙栨按鍙e垪琛ㄥ湪绾挎垨涓嶅湪绾匡級
+ * @param params
+ * @return
+ */
+ List<VoOnLineIntake> selectIntakesForOnLine(Map<?, ?> params);
+
+
+
/**
* 鏍规嵁鍙栨按鍙g紪鍙疯幏鍙栧彇姘村彛瀵硅薄
* @param params
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
new file mode 100644
index 0000000..24f3a3c
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/CodeLocal.java
@@ -0,0 +1,21 @@
+package com.dy.pipIrrGlobal.rtuMw;
+
+public class CodeLocal {
+
+ public static final String clock = "LCD0000" ;//鏌ヨ鐩戞帶涓棿浠舵椂閽�
+
+ public static final String onLineAll = "LCD0001" ;//鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
+
+ public static final String onLinePart = "LCD0002" ;//鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+
+ public static final String onLineStatistics = "LCD0003" ;//鏌ヨ鎵�鏈塕TU鐘舵�佹儏鍐�
+
+ public static final String allProtocols = "LCD0100" ;//鏌ヨ鎵�鏈夊崗璁厤缃�
+
+ public static final String stopTcpSv = "LCD0110" ;//鍋滄TCP鏈嶅姟锛屼笉鍐嶆帴鍏ユ柊鐨凾CP杩炴帴锛屽凡缁廡CP杩炴帴鐨勫叏閮ㄦ柇杩炴帴
+
+ public static final String recoverTcpSv = "LCD0112" ;//閲嶅惎TCP鏈嶅姟锛屾帴鍏ユ柊鐨凾CP杩炴帴
+
+ public static final String mwState = "LCD0200" ;//寰楀埌閫氫俊涓棿浠惰繍琛屼俊鎭�
+
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/ToRtuMwCom.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/ToRtuMwCom.java
new file mode 100644
index 0000000..74099ea
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/ToRtuMwCom.java
@@ -0,0 +1,85 @@
+package com.dy.pipIrrGlobal.rtuMw;
+
+import com.dy.common.multiDataSource.DataSourceContext;
+import com.dy.common.mw.protocol.Command;
+import com.dy.common.mw.protocol.CommandType;
+import com.dy.common.webUtil.BaseResponse;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2024/10/23 11:45
+ * @Description
+ */
+public abstract class ToRtuMwCom {
+ /**
+ * pro_mw锛氬睘鎬�
+ * tag浠庢帶鍒跺櫒涓幏鍙�
+ * key_mw锛歶rl鐨刱ey
+ */
+ private static final String pro_mw = "mw";
+ private static final String key_mw = "comSendUrl";
+
+
+ /**
+ * 寰楀埌鍚戦�氫俊涓棿浠跺彂閫佹暟鎹殑URL
+ * @param env
+ * @return
+ */
+ protected String getToMwUrl(Environment env) {
+ return env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw);
+ }
+
+ /**
+ * 鍒涘缓澶栭儴鍛戒护锛堝彂缁欐帶鍒跺櫒锛�
+ * @param code 鍛戒护code
+ * @return
+ */
+ protected Command createOuterCommand(String comId, String code) {
+ Command com = new Command();
+ com.id = comId;
+ com.code = code ;
+ com.type = CommandType.outerCommand;
+ return com ;
+ }
+
+ /**
+ * 鍒涘缓鍐呴儴
+ * @param code 鍛戒护code
+ * @return
+ */
+ protected Command createInnerCommand(String code) {
+ Command com = new Command();
+ com.id = Command.defaultId;
+ com.code = code ;
+ com.type = CommandType.innerCommand;
+ return com ;
+ }
+
+ /**
+ * 鍙戦�佸懡浠�
+ *
+ * @return
+ */
+ protected BaseResponse sendCom2Mw(RestTemplate restTemplate, String comSendUrl, Command com) {
+ String url = UriComponentsBuilder.fromUriString(comSendUrl)
+ .build()
+ .toUriString();
+ HttpHeaders headers = new HttpHeaders();
+ HttpEntity<Command> httpEntity = new HttpEntity<>(com, headers);
+ ResponseEntity<BaseResponse> response = null;
+ try {
+ // 閫氳繃Post鏂瑰紡璋冪敤鎺ュ彛
+ response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return response.getBody();
+ }
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
index 5180618..8709694 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
@@ -421,27 +421,27 @@
LEFT JOIN pr_controller con ON con.intakeId = inta.id
LEFT JOIN rm_on_hour_report_last hou ON hou.intake_id = inta.id
LEFT JOIN(
- SELECT intake_id AS intakeId,
- CONCAT(
- IF(alarm_loss = 1, IF(alarm_water_meter_fault = 1, '娴侀噺璁℃晠闅�,', ''),
- IF(alarm_water_meter_fault = 1, '娴侀噺璁℃晠闅�', '')),
- IF(alarm_battery_volt = 1, IF(alarm_loss = 1, '婕忔崯(鍋锋按)鎶ヨ,', ''),
- IF(alarm_loss = 1, '婕忔崯(鍋锋按)鎶ヨ', '')),
- IF(alarm_valve = 1, IF(alarm_battery_volt = 1, '钃勭數姹犵數鍘嬫姤璀�,', ''),
- IF(alarm_battery_volt = 1, '钃勭數姹犵數鍘嬫姤璀�', '')),
- IF(alarm_valve = 1, '闃�闂ㄦ姤璀�', '')
- ) AS alarm
- FROM rm_alarm_state_last
- WHERE (alarm_water_meter_fault = 1 OR alarm_loss = 1 OR alarm_battery_volt = 1 OR alarm_valve = 1)
- AND dt >= DATE_SUB(NOW(), INTERVAL 12 HOUR)
- ) alarm ON alarm.intakeId = inta.id
+ SELECT intake_id AS intakeId,
+ CONCAT(
+ IF(alarm_loss = 1, IF(alarm_water_meter_fault = 1, '娴侀噺璁℃晠闅�,', ''),
+ IF(alarm_water_meter_fault = 1, '娴侀噺璁℃晠闅�', '')),
+ IF(alarm_battery_volt = 1, IF(alarm_loss = 1, '婕忔崯(鍋锋按)鎶ヨ,', ''),
+ IF(alarm_loss = 1, '婕忔崯(鍋锋按)鎶ヨ', '')),
+ IF(alarm_valve = 1, IF(alarm_battery_volt = 1, '钃勭數姹犵數鍘嬫姤璀�,', ''),
+ IF(alarm_battery_volt = 1, '钃勭數姹犵數鍘嬫姤璀�', '')),
+ IF(alarm_valve = 1, '闃�闂ㄦ姤璀�', '')
+ ) AS alarm
+ FROM rm_alarm_state_last
+ WHERE (alarm_water_meter_fault = 1 OR alarm_loss = 1 OR alarm_battery_volt = 1 OR alarm_valve = 1)
+ AND dt >= DATE_SUB(NOW(), INTERVAL 12 HOUR)
+ ) alarm ON alarm.intakeId = inta.id
LEFT JOIN JSON_TABLE(
- <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
- #{onLineMap},
- '$[*]' COLUMNS (
- rtuAddr VARCHAR(20) PATH '$.rtuAddr',
- isOnLine BOOLEAN PATH '$.isOnLine'
- )
+ <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
+ #{onLineMap},
+ '$[*]' COLUMNS (
+ rtuAddr VARCHAR(20) PATH '$.rtuAddr',
+ isOnLine BOOLEAN PATH '$.isOnLine'
+ )
) rtus ON con.rtuAddr = rtus.rtuAddr
<where>
<if test="isOnLine != null">
@@ -521,6 +521,97 @@
</trim>
</select>
+
+
+
+
+
+
+ <!--鑾峰彇鍙栨按鍙f暟閲忥紙鍦ㄧ嚎鎴栫绾挎垨涓嶈鐘舵�侊級-->
+ <select id="selectIntakesCountForOnLine" resultType="java.lang.Long">
+ SELECT COUNT(*) AS recordCount
+ FROM pr_intake inta
+ INNER JOIN pr_controller con ON con.intakeId = inta.id
+ <if test="onLineMap != null and onLineMap !='' and isOnLine != null">
+ LEFT JOIN JSON_TABLE(
+ <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
+ #{onLineMap},
+ '$[*]' COLUMNS (
+ rtuAddr VARCHAR(20) PATH '$.rtuAddr',
+ isOnLine BOOLEAN PATH '$.isOnLine'
+ )
+ ) rtus ON con.rtuAddr = rtus.rtuAddr
+ </if>
+ WHERE con.intakeId is not null
+ <if test="isOnLine != null">
+ AND rtus.isOnLine = #{isOnLine}
+ </if>
+ <if test="intakeNum != null and intakeNum != ''">
+ AND inta.name = #{intakeNum}
+ </if>
+ </select>
+
+
+ <!--鑾峰彇鍙栨按鍙e垪琛紙鍦ㄧ嚎鎴栫绾挎垨涓嶈鐘舵�侊級-->
+ <select id="selectIntakesForOnLine" resultType="com.dy.pipIrrGlobal.voPr.VoOnLineIntake">
+ SELECT
+ inta.id AS intakeId,
+ con.rtuAddr,
+ inta.name AS intakeNum,
+ inta.lng,
+ inta.lat,
+ IFNULL(hou.total_amount, 0) AS totalAmount,
+ alarm.alarm
+ FROM pr_intake inta
+ INNER JOIN pr_controller con ON con.intakeId = inta.id
+ LEFT JOIN rm_on_hour_report_last hou ON hou.intake_id = inta.id
+ LEFT JOIN(
+ SELECT intake_id AS intakeId,
+ CONCAT(
+ IF(alarm_loss = 1, '婕忔崯鎶ヨ锛�', ''),
+ IF(alarm_battery_volt = 1, '鐢垫睜鐢靛帇鎶ヨ锛�', ''),
+ IF(alarm_valve = 1, '闃�闂ㄦ姤璀︼紝', ''),
+ IF(alarm_water_meter_fault = 1, '娴侀噺璁℃晠闅滄姤璀︼紝', '')
+ ) AS alarm
+ FROM rm_alarm_state_last
+ WHERE (alarm_loss = 1 OR alarm_battery_volt = 1 OR alarm_valve = 1 OR alarm_water_meter_fault = 1)
+ AND dt >= DATE_SUB(NOW(), INTERVAL 12 HOUR)
+ ) alarm ON alarm.intakeId = inta.id
+ <if test="onLineMap != null and onLineMap !='' and isOnLine != null">
+ LEFT JOIN JSON_TABLE(
+ <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
+ #{onLineMap},
+ '$[*]' COLUMNS (
+ rtuAddr VARCHAR(20) PATH '$.rtuAddr',
+ isOnLine BOOLEAN PATH '$.isOnLine'
+ )
+ ) rtus ON con.rtuAddr = rtus.rtuAddr
+ </if>
+ WHERE con.intakeId is not null
+ <if test="isOnLine != null">
+ AND rtus.isOnLine = #{isOnLine}
+ </if>
+ <if test="intakeNum != null and intakeNum != ''">
+ AND inta.name = #{intakeNum}
+ </if>
+ order by inta.id ASC
+ <trim prefix="limit ">
+ <if test="start != null and count != null">
+ #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
+ </if>
+ </trim>
+ </select>
+
+
+
+
+
+
+
+
+
+
+
<!--鏍规嵁鍙栨按鍙g紪鍙疯幏鍙栧彇姘村彛瀵硅薄-->
<select id="getIntakeByName" resultType="com.dy.pipIrrGlobal.voPr.VoOnLineIntake">
SELECT con.intakeId,
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java
index 55869f8..fc34bbf 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java
@@ -162,6 +162,25 @@
return map ;
}
}
+
+
+ /**
+ * 寰楀埌閮ㄥ垎鍦ㄧ嚎鎯呭喌
+ * @return
+ */
+ public static HashMap<String, Boolean> partOnLine(String[] rtuAddrArrGrp){
+ synchronized (sessionTable){
+ HashMap<String, Boolean> map = new HashMap<String, Boolean>();
+ for(String rtuAddr : rtuAddrArrGrp){
+ TcpSession tcpSe = sessionTable.get(rtuAddr) ;
+ if(tcpSe != null){
+ map.put(rtuAddr, tcpSe.ioSession.isConnected()) ;
+ }
+ }
+ return map ;
+ }
+ }
+
/**
* 寰楀埌鎵�鏈塕TU杩炴帴鐘舵�佹儏鍐�
* @return
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/CommandInnerDeaLer.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/CommandInnerDeaLer.java
index 927c1b0..3148b1d 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/CommandInnerDeaLer.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/CommandInnerDeaLer.java
@@ -5,6 +5,8 @@
import com.dy.common.mw.protocol.Command;
import com.dy.rtuMw.server.local.localProtocol.*;
+import java.util.HashMap;
+
/**
* @Author liurunyu
* @Date 2023/12/21 15:56
@@ -21,8 +23,10 @@
String code = com.getCode() ;
if(code.equals(CodeLocal.clock)){
return this.clock(com) ;
- }else if(code.equals(CodeLocal.onLine)){
- return this.onLine(com) ;
+ }else if(code.equals(CodeLocal.onAllLine)){
+ return this.onAllLine(com) ;
+ }else if(code.equals(CodeLocal.onPartLine)){
+ return this.onPartLine(com) ;
}else if(code.equals(CodeLocal.onLineStatistics)){
return this.onLineStateStatistics(com) ;
}else if(code.equals(CodeLocal.allProtocols)){
@@ -50,9 +54,23 @@
* 鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
* @throws Exception
*/
- private Command onLine(Command command) throws Exception{
- RtuOnLineVo ol = new RtuOnLineDeal().deal() ;
- return ReturnCommand.successed("鏌ヨ鎵�鏈夋祴绔欏湪绾挎儏鍐电粨鏋�", command.getId(), command.getCode(), ol) ;
+ private Command onAllLine(Command command) throws Exception{
+ HashMap<String, Boolean> map = new RtuOnLineDeal().dealAll() ;
+ return ReturnCommand.successed("鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌缁撴灉", command.getId(), command.getCode(), map) ;
+ }
+
+ /**
+ * 鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+ * @throws Exception
+ */
+ private Command onPartLine(Command command) throws Exception{
+ if(command.param != null && command.param instanceof String && !command.param.equals("")){
+ String[] rtuAddrGrp = ((String)command.param).split(",");
+ HashMap<String, Boolean> map = new RtuOnLineDeal().dealPart(rtuAddrGrp) ;
+ return ReturnCommand.successed("鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌缁撴灉", command.getId(), command.getCode(), map) ;
+ }else{
+ return ReturnCommand.errored("鍑洪敊锛屽懡浠ゅ弬鏁板簲璇ユ槸鎵�鏌ヨRTU鐨勫湴鍧�涓�", command.getId(), command.getCode()) ;
+ }
}
/**
@@ -61,7 +79,7 @@
*/
private Command onLineStateStatistics(Command command) throws Exception{
RtuOnLineStateStatisticsVo vo = new RtuOnLineStateStatisticsDeal().deal() ;
- return ReturnCommand.successed("鏌ヨ鎵�鏈夋祴绔欏湪绾挎儏鍐电粨鏋�", command.getId(), command.getCode(), vo) ;
+ return ReturnCommand.successed("鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌缁撴灉", command.getId(), command.getCode(), vo) ;
}
/**
@@ -80,7 +98,6 @@
private Command stopTcpSv(Command command) throws Exception{
TcpUnit.getInstance().stop(new UnitCallbackInterface(){
public void call(Object obj) throws Exception {
-
}
});
return ReturnCommand.successed("宸茬粡鍚姩鍋滄TCP鏈嶅姟", command.getId(), command.getCode(), null) ;
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/CodeLocal.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/CodeLocal.java
index 8629628..479fa99 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/CodeLocal.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/CodeLocal.java
@@ -4,9 +4,11 @@
public static final String clock = "LCD0000" ;//鏌ヨ鐩戞帶涓棿浠舵椂閽�
- public static final String onLine = "LCD0001" ;//鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
+ public static final String onAllLine = "LCD0001" ;//鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
- public static final String onLineStatistics = "LCD0002" ;//鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
+ public static final String onPartLine = "LCD0002" ;//鏌ヨ鎵�鏈塕TU鍦ㄧ嚎鎯呭喌
+
+ public static final String onLineStatistics = "LCD0003" ;//鏌ヨ鎵�鏈塕TU鐘舵�佹儏鍐�
public static final String allProtocols = "LCD0100" ;//鏌ヨ鎵�鏈夊崗璁厤缃�
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineDeal.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineDeal.java
index 15fe543..7ddfe10 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineDeal.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineDeal.java
@@ -2,12 +2,22 @@
import com.dy.rtuMw.server.forTcp.TcpSessionCache;
+import java.util.HashMap;
+
public class RtuOnLineDeal {
/**
* 鏌ヨ鍦ㄧ嚎涓庝笉鍦ㄧ嚎鎯呭喌
*/
- public RtuOnLineVo deal(){
- return (new RtuOnLineVo()).setOnLine(TcpSessionCache.allOnLine());
+ public HashMap<String, Boolean> dealAll(){
+ return TcpSessionCache.allOnLine();
+ }
+
+
+ /**
+ * 鏌ヨ鍦ㄧ嚎涓庝笉鍦ㄧ嚎鎯呭喌
+ */
+ public HashMap<String, Boolean> dealPart(String[] rtuAddrGrp){
+ return TcpSessionCache.partOnLine(rtuAddrGrp) ;
}
}
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineVo.java
deleted file mode 100644
index b8ee880..0000000
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/RtuOnLineVo.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.dy.rtuMw.server.local.localProtocol;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map.Entry;
-
-public class RtuOnLineVo implements Serializable{
-
- private static final long serialVersionUID = 202312211559001L;
-
- private HashMap<String , Boolean> onLineMap ;
-
- public String toString(){
- String s = "" ;
- if(onLineMap != null){
- Iterator<Entry<String, Boolean>> it = onLineMap.entrySet().iterator() ;
- Entry<String, Boolean> entry = null ;
- while(it.hasNext()){
- entry = it.next() ;
- s += entry.getKey() + ": " + (entry.getValue().booleanValue()?"鍦ㄧ嚎":"绂荤嚎") + "\n";
- }
- }
- return s ;
- }
- /**
- * 瀛樺叆RTU鍦ㄧ嚎鎯呭喌
- * @param onLineMap 鍦ㄧ嚎闆嗗悎
- */
- public RtuOnLineVo setOnLine(HashMap<String , Boolean> onLineMap){
- this.onLineMap = onLineMap ;
- return this ;
- }
-
- public HashMap<String, Boolean> getOnLineMap() {
- return onLineMap;
- }
-
-}
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
new file mode 100644
index 0000000..36e30e9
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorCtrl.java
@@ -0,0 +1,49 @@
+package com.dy.pipIrrRemote.monitor;
+
+import com.dy.common.aop.SsoAop;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.common.webUtil.QueryResultVo;
+import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2024/10/23 11:32
+ * @Description
+ */
+
+@Slf4j
+@Tag(name = "鐩戞祴鎺у埗", description = "鐩戞祴鎺у埗")
+@RestController
+@RequestMapping(path = "monitor")
+@RequiredArgsConstructor
+public class MonitorCtrl {
+ private final MonitorSv monitorSv;
+
+ /**
+ * 鑾峰彇鍙栨按鍙e垪琛紙鍦ㄧ嚎鍜屼笉鍦ㄧ嚎锛�
+ *
+ * @param qo
+ * @return
+ */
+ @GetMapping(path = "all_intakes")
+ @SsoAop()
+ public BaseResponse<QueryResultVo<List<VoOnLineIntake>>> allIntakes(QueryVo qo) {
+ try {
+ QueryResultVo<List<VoOnLineIntake>> res = monitorSv.selectOnLineIntakes(qo);
+ return BaseResponseUtils.buildSuccess(res);
+ } catch (Exception e) {
+ log.error("鏌ヨ鍙栨按鍙e紓甯�", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ }
+
+}
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
new file mode 100644
index 0000000..a85672a
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java
@@ -0,0 +1,174 @@
+package com.dy.pipIrrRemote.monitor;
+
+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.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.voPr.VoOnLineIntake;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.common.utils.PojoUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2024/10/23 11:32
+ * @Description
+ */
+@Slf4j
+@Service
+public class MonitorSv extends ToRtuMwCom {
+
+ @Autowired
+ private PrIntakeMapper prIntakeMapper;
+
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ /**
+ * 鑾峰彇宸茬粡缁戝畾鎺у埗鍣ㄧ殑鍙栨按鍙e垪琛紙骞舵爣璁板湪绾夸笌涓嶅湪绾匡級
+ *
+ * @return
+ */
+ public QueryResultVo<List<VoOnLineIntake>> selectOnLineIntakes(QueryVo vo) {
+ if(vo.getIsOnLine() == null){
+ //涓嶅尯鍒嗗湪绾夸笌绂荤嚎
+ return selectIntakesIgnoreOnOffLine(vo) ;
+ }else{
+ //鍦ㄧ嚎 鎴� 绂荤嚎
+ return selectIntakesOnOrOffLine(vo) ;
+ }
+ }
+
+ /**
+ * 鏌ヨ鍙栨按鍙o紝涓嶉檺鍒跺湪绾夸笌绂荤嚎鐘舵��
+ * @param vo
+ * @return
+ */
+ private QueryResultVo<List<VoOnLineIntake>> selectIntakesIgnoreOnOffLine(QueryVo vo) {
+ QueryResultVo<List<VoOnLineIntake>> rsVo = this.queryDb(vo) ;
+ if(rsVo != null && rsVo.obj != null && (rsVo.obj.size() > 0)){
+ String rtuAddrs = "" ;
+ boolean first = true ;
+ for(VoOnLineIntake rVo : rsVo.obj){
+ if(first){
+ first = false ;
+ rtuAddrs += rVo.getRtuAddr() ;
+ }else{
+ rtuAddrs += "," + rVo.getRtuAddr() ;
+ }
+ }
+ //鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+ Command com = this.createInnerCommand(CodeLocal.onLinePart);
+ com.setParam(rtuAddrs) ;
+ String comSendUrl = this.getToMwUrl(this.env) ;
+ BaseResponse res = sendCom2Mw(restTemplate, comSendUrl, 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);
+ for(VoOnLineIntake rVo : rsVo.obj){
+ if(onLineMap.containsKey(rVo.getRtuAddr())) {
+ rVo.setIsOnLine(onLineMap.get(rVo.getRtuAddr()));
+ }
+ }
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀腑涓嶅寘鍚獵ommandBackParam绫诲瀷鍙傛暟");
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ゆ墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀负null");
+ }
+ }
+ return rsVo;
+ }
+
+
+ /**
+ * 鏌ヨ鍙栨按鍙o紝鍦ㄧ嚎鎴栫绾跨姸鎬�
+ * @param vo
+ * @return
+ */
+ private QueryResultVo<List<VoOnLineIntake>> selectIntakesOnOrOffLine(QueryVo vo) {
+ //鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+ Command com = this.createInnerCommand(CodeLocal.onLineAll);
+ String comSendUrl = this.getToMwUrl(this.env) ;
+ BaseResponse res = sendCom2Mw(restTemplate, comSendUrl, 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);
+ JSONArray jsonArray = new JSONArray();
+ for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("rtuAddr", entry.getKey());
+ jsonObject.put("isOnLine", entry.getValue());
+ jsonArray.add(jsonObject);
+ }
+ vo.setOnLineMap(jsonArray.toJSONString());
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀腑涓嶅寘鍚獵ommandBackParam绫诲瀷鍙傛暟");
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ゆ墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀负null");
+ }
+
+ return this.queryDb(vo) ;
+ }
+
+ /**
+ * 鏌ヨ鏁版嵁搴�
+ * @param vo
+ * @return
+ */
+ private QueryResultVo<List<VoOnLineIntake>> queryDb(QueryVo vo){
+ Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo);
+ Long itemTotal = prIntakeMapper.selectIntakesCountForOnLine(params);
+
+ QueryResultVo<List<VoOnLineIntake>> rsVo = new QueryResultVo<>();
+ rsVo.pageSize = vo.pageSize;
+ rsVo.pageCurr = vo.pageCurr;
+ rsVo.calculateAndSet(itemTotal, params);
+ List<VoOnLineIntake> records = prIntakeMapper.selectIntakesForOnLine(params) ;
+ 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)) ;
+ }
+ }
+ return rsVo ;
+ }
+
+
+
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/QueryVo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/QueryVo.java
new file mode 100644
index 0000000..8b846ef
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/QueryVo.java
@@ -0,0 +1,32 @@
+package com.dy.pipIrrRemote.monitor;
+
+import com.dy.common.webUtil.QueryConditionVo;
+import lombok.Data;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-05-27 20:32
+ * @LastEditTime 2024-05-27 20:32
+ * @Description
+ */
+
+@Data
+public class QueryVo extends QueryConditionVo {
+ /**
+ * 鍙栨按鍙g紪鍙�
+ */
+ private String intakeNum;
+
+ /**
+ * 鏄惁鍦ㄧ嚎
+ */
+
+ private Boolean isOnLine;
+
+
+ /**
+ * 闈炲墠绔缃殑鍙傛暟鎹紝涓棿浠惰繑鍥炵殑RTU鍦ㄧ嚎鎯呭喌瀵硅薄鏁扮粍
+ */
+ private String onLineMap;
+
+}
--
Gitblit v1.8.0