From 62afcbeaa5cc328bff01ae1facb18a6b8c03c5bc Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期二, 24 六月 2025 16:57:18 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java |   65 +++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java
index 5c13be1..196b13c 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java
@@ -7,6 +7,7 @@
 import com.dy.rtuMw.server.forTcp.TcpSessionCache;
 import com.dy.rtuMw.server.local.CommandInnerDeaLer;
 import com.dy.rtuMw.server.local.ReturnCommand;
+import com.dy.rtuMw.server.mqtt.DevStatusDealer;
 import com.dy.rtuMw.server.mqtt.MqttManager;
 import com.dy.rtuMw.server.msCenter.MsCenterUnit;
 import com.dy.rtuMw.server.tasks.WebDownCom4MqttTask;
@@ -58,7 +59,21 @@
      */
     @GetMapping("/rtuLogFile")
     public void rtuLogFile(String rtuAddr, HttpServletRequest req, HttpServletResponse rep){
-        File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".log") ;
+        logFile(rtuAddr, req, rep) ;
+    }
+
+    /**
+     * 涓嬭浇鎺у埗鍣紙RTU锛変笂涓嬭鏁版嵁鐨刲og鏃ュ織鏂囦欢
+     * @param devId
+     * @param req
+     * @param rep
+     */
+    @GetMapping("/mqttDevLogFile")
+    public void mqttDevLogFile(String devId, HttpServletRequest req, HttpServletResponse rep){
+        logFile(devId, req, rep) ;
+    }
+    private void logFile(String fileName, HttpServletRequest req, HttpServletResponse rep){
+        File logFile = ResourceUnit.getInstance().getLogFile(fileName + ".log") ;
         if(logFile != null && logFile.exists()){
             //鍦⊿pring Boot涓紝application/octet-stream;charset=UTF-8閫氬父琛ㄧず鍝嶅簲鐨勫唴瀹规槸瀛楄妭娴侊紝
             //骞朵笖瀛楃闆嗘槸UTF-8銆傚浜庤繖绉嶇被鍨嬬殑鍝嶅簲锛孲pring Boot榛樿浣跨敤ByteArrayHttpMessageConverter鏉ュ鐞嗭紝
@@ -67,7 +82,7 @@
             //瀛楃闆嗛�氬父鐢ㄤ簬鏂囨湰鍐呭锛岃�宎pplication/octet-stream閫氬父鐢ㄤ簬浜岃繘鍒跺唴瀹癸紝鍥犳鍦ㄨ繖绉嶆儏鍐典笅鎸囧畾瀛楃闆嗗彲鑳芥槸涓嶅悎閫傜殑銆�
             //涓嶈繃锛屽鏋滀綘纭疄闇�瑕佸鐞嗗甫鏈夌壒瀹氬瓧绗﹂泦鐨刟pplication/octet-stream鍝嶅簲锛屼綘鍙兘闇�瑕佽嚜瀹氫箟HttpMessageConverter銆�
             rep.addHeader("content-type", "application/octet-stream;charset=UTF-8");
-            rep.addHeader("Content-Disposition", "attachment;fileName=" + (rtuAddr + ".log")) ;
+            rep.addHeader("Content-Disposition", "attachment;fileName=" + (fileName + ".log")) ;
             ServletOutputStream out = null;
             FileInputStream in = null ;
             try {
@@ -112,27 +127,38 @@
      */
     @GetMapping("/rtuLogText")
     public BaseResponse<List<String>> rtuLogText(String rtuAddr){
+        return logText(rtuAddr, true) ;
+    }
+    /**
+     * 涓嬭浇鎺у埗鍣紙RTU锛変笂涓嬭鏁版嵁鐨刲og鏃ュ織鏂囦欢
+     * @param devId
+     */
+    @GetMapping("/mqttDevLogText")
+    public BaseResponse<List<String>> mqttDevLogText(String devId){
+        return logText(devId, false) ;
+    }
+    /**
+     * 涓嬭浇鎺у埗鍣紙RTU锛変笂涓嬭鏁版嵁鐨刲og鏃ュ織鏂囦欢
+     * @param fileName
+     * @param reverseOrder
+     */
+    private BaseResponse<List<String>> logText(String fileName, boolean reverseOrder){
         List<String> list ;
-        File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".log") ;
+        File logFile = ResourceUnit.getInstance().getLogFile(fileName + ".log") ;
         if(logFile != null && logFile.exists()){
             BufferedReader reader = null ;
             try {
                 reader = new BufferedReader(new FileReader(logFile)) ;
-                //鏂扮殑瀹炵幇鏂规硶
                 Stream<String> linesStream = reader.lines() ;
-                //list = linesStream.toList() ; //鎸夊師鏉ラ『搴�
-                list = linesStream.sorted(Comparator.reverseOrder()).collect(Collectors.toList()) ;//鍊掑簭
-                /* 鍘熸潵鐨勫疄鐜版柟娉�
-                list = new ArrayList() ;
-                String line ;
-                while((line = reader.readLine()) != null){
-                    list.add(line) ;
+                if(reverseOrder){
+                    list = linesStream.sorted(Comparator.reverseOrder()).collect(Collectors.toList()) ;//鍊掑簭
+                }else{
+                    list = linesStream.toList() ; //鎸夊師鏉ラ『搴�
                 }
-                */
                 return BaseResponseUtils.buildSuccess(list);
             } catch (Exception e) {
                 list = new ArrayList() ;
-                list.add("璇诲彇鎺у埗鍣紙" + rtuAddr + "锛夌殑鏃ュ織鏂囦欢寮傚父锛�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))) ;
+                list.add("璇诲彇鎺у埗鍣紙" + fileName + "锛夌殑鏃ュ織鏂囦欢寮傚父锛�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))) ;
                 return BaseResponseUtils.buildSuccess(list);
             }finally{
                 if(reader != null){
@@ -144,7 +170,7 @@
             }
         }else{
             list = new ArrayList() ;
-            list.add("鏈緱鍒版帶鍒跺櫒锛�" + rtuAddr + "锛夌殑鏃ュ織鏂囦欢") ;
+            list.add("鏈緱鍒版帶鍒跺櫒锛�" + fileName + "锛夌殑鏃ュ織鏂囦欢") ;
             return BaseResponseUtils.buildSuccess(list);
         }
     }
@@ -350,15 +376,18 @@
      * @return 缁撴灉
      */
     private BaseResponse<Command> dealMqttCommand(Command command){
-        String rtuAddr = command.getRtuAddr() ;
-        if(rtuAddr == null || rtuAddr.trim().equals("")){
-            return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛岃澶嘔D涓虹┖锛�", command.getId(), command.getCode())) ;
+        String mqttDevId = command.getRtuAddr() ;//FBox璁惧鍙�
+        if(mqttDevId == null || mqttDevId.trim().equals("")){
+            return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孎Box璁惧ID涓虹┖锛�", command.getId(), command.getCode())) ;
         }
         if(!ServerProperties.mqttUnitEnable.booleanValue()){
             return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孧QTT杩炴帴妯″潡閰嶇疆鏈惎鍔紒", command.getId(), command.getCode())) ;
         }
         if(MqttManager.getInstance().poolIsClose()){
-            return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孧QTT杩炴帴姹犳按鍒涘缓鎴愬姛锛�", command.getId(), command.getCode())) ;
+            return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孧QTT杩炴帴姹犳湭鍒涘缓鎴愬姛锛�", command.getId(), command.getCode())) ;
+        }
+        if(!DevStatusDealer.oneOnLine(mqttDevId)){
+            return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孎Box璁惧鏈湪绾匡紒", command.getId(), command.getCode())) ;
         }
 
         //鐢熸垚寮傛浠诲姟

--
Gitblit v1.8.0