From 24f53bb77f9ac80feb2e62e8ee670be4aa5f3c6e Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 13 二月 2025 11:56:42 +0800
Subject: [PATCH] 1、远程模块remote模块实现: (1、系统启动时向通信中间件注册消息接收者; (2、消息接收者ctr实现(测试阶段); 2、在配置文件增加配置Springboot RestTemplate网络请求超时时长; 3、其他一些测试与优化。

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java |   94 ++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 76 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 0dcd9cc..f50db60 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
@@ -1,16 +1,20 @@
 package com.dy.rtuMw.web.com;
 
+import com.dy.common.softUpgrade.state.UpgradeTaskVo;
+import com.dy.common.webUtil.ResultCodeMsg;
 import com.dy.rtuMw.resource.ResourceUnit;
 import com.dy.rtuMw.server.ServerProperties;
 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.tasks.RtuDownTask;
+import com.dy.rtuMw.server.msCenter.MsCenterUnit;
+import com.dy.rtuMw.server.tasks.WebDownComTask;
 import com.dy.common.mw.core.CoreUnit;
 import com.dy.common.mw.protocol.Command;
 import com.dy.common.mw.protocol.CommandType;
 import com.dy.common.webUtil.BaseResponse;
 import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.rtuMw.server.upgrade.UpgradeUnit;
 import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
@@ -20,7 +24,10 @@
 
 import java.io.*;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 
 /**
@@ -102,18 +109,26 @@
      */
     @GetMapping("/rtuLogText")
     public BaseResponse<List<String>> rtuLogText(String rtuAddr){
-        List<String> list = new ArrayList() ;
+        List<String> list ;
         File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".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) ;
                 }
+                */
                 return BaseResponseUtils.buildSuccess(list);
             } catch (Exception e) {
+                list = new ArrayList() ;
                 list.add("璇诲彇鎺у埗鍣紙" + rtuAddr + "锛夌殑鏃ュ織鏂囦欢寮傚父锛�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))) ;
                 return BaseResponseUtils.buildSuccess(list);
             }finally{
@@ -125,10 +140,67 @@
                 }
             }
         }else{
+            list = new ArrayList() ;
             list.add("鏈緱鍒版帶鍒跺櫒锛�" + rtuAddr + "锛夌殑鏃ュ織鏂囦欢") ;
             return BaseResponseUtils.buildSuccess(list);
         }
     }
+
+
+    /**
+     * 娉ㄥ唽娑堟伅鎺ユ敹鑰�
+     * @param msReceiverWebUrl 娑堟伅鎺ユ敹鑰厀eb http post url
+     * @return
+     */
+    @GetMapping("/registerMsReceiverWebUrl")
+    public BaseResponse<Boolean> registerMsReceiverWebUrl(String msReceiverWebUrl){
+        try{
+            MsCenterUnit.getInstance().registerMsReceiver(msReceiverWebUrl);
+        }catch (Exception e){
+            log.error("娉ㄥ唽娑堟伅鎺ユ敹鑰呮椂鍙戠敓寮傚父", e);
+            return BaseResponseUtils.buildError("娉ㄥ唽娑堟伅鎺ユ敹鑰呮椂鍙戠敓寮傚父" + (e.getMessage() == null?"":("锛�" + e.getMessage())));
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鎺ユ敹web绯荤粺鍙戞潵鍗囩骇浠诲姟
+     * @param vo
+     * @return
+     */
+    @PostMapping(path = "upgradeRtu", consumes = MediaType.APPLICATION_JSON_VALUE)
+    public BaseResponse<Boolean> upgradeRtu(@RequestBody UpgradeTaskVo vo) {
+        log.info("鏀跺埌RTU鍗囩骇浠诲姟锛歕n" + vo.toString()) ;
+        try{
+            UpgradeUnit.getInstance().setUpgradeTask(vo);
+        }catch (Exception e){
+            log.error("璁剧疆RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�", e);
+            return BaseResponseUtils.buildError("璁剧疆RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�" + (e.getMessage() == null?"":("锛�" + e.getMessage())));
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鎺ユ敹web绯荤粺鍙戞潵寮哄埗缁撴潫鍗囩骇浠诲姟
+     * @return
+     */
+    @GetMapping(path = "ugForceOver")
+    public BaseResponse<String> ugForceOver() {
+        log.info("鏀跺埌鍋滄RTU鍗囩骇浠诲姟鍛戒护") ;
+        try{
+            String mes = UpgradeUnit.getInstance().forceOverUpgradeTask();
+            if(mes == null){
+                mes = "鍋滄鍗囩骇浠诲姟鎴愬姛" ;
+                return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, mes, mes);
+            }else{
+                return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.FAIL_CODE, mes, mes);
+            }
+        }catch (Exception e){
+            log.error("鍋滄RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�", e);
+            return BaseResponseUtils.buildError("鍋滄RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�" + (e.getMessage() == null?"":("锛�" + e.getMessage())));
+        }
+    }
+
     /**
      * 鎺ユ敹web绯荤粺鍙戞潵鐨勫懡浠�
      * @param com
@@ -156,24 +228,10 @@
             //閫氫俊涓棿浠跺唴閮ㄥ懡浠わ紝渚嬪鏌ヨ鐩戞帶涓棿浠舵椂閽燂紝鏌ヨRTU鍦ㄧ嚎鎯呭喌绛�
             try{
                 Command reCom = new CommandInnerDeaLer().deal(com) ;
-                /*
-                boolean error = false ;
-                if(reCom.param != null && reCom.param != null){
-                    CommandBackParam cbp = (CommandBackParam)reCom.param ;
-                    if(cbp.getSuccess() != null && !cbp.getSuccess().booleanValue()){
-                        error = true ;
-                        return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null));
-                    }
-                }
-                if(!error){
-                    return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null));
-                }
-                */
                 return BaseResponseUtils.buildSuccess(reCom);
             }catch(Exception e){
                 return BaseResponseUtils.buildError(ReturnCommand.errored("澶勭悊鍐呴儴鍛戒护鍑洪敊" + (e.getMessage() == null?"":("锛�" + e.getMessage())), com.getId(), com.getCode()) );
             }
-
         }else if(commandType.equals(CommandType.outerCommand)){
             //鍙戝悜RTU鐨勫閮ㄥ懡浠わ紝寮傛澶勭悊锛寃eb绔痡roups鎴愬憳鍚屾寰楀埌鍛戒护澶勭悊缁撴灉锛屼絾鏋勯�犲懡浠ゅ強涓嬪彂鍛戒护鍜屽懡浠ょ粨鏋滄帴鏀惰寮傛寰楀埌
             try{
@@ -189,7 +247,7 @@
     }
 
     /**
-     * 鏈湴璋冪敤锛屼緥濡傞噸浠诲姟鏍戜腑鏌愪釜浠诲姟涓嬪彂鐨勫懡浠わ紙濡傛竻绌哄懡浠わ級
+     * 鏈湴璋冪敤锛屼緥濡備换鍔℃爲涓煇涓换鍔′笅鍙戠殑鍛戒护锛堝娓呯┖鍛戒护锛�
      * @param com
      * @return
      */
@@ -222,7 +280,7 @@
         }
 
         //鐢熸垚寮傛浠诲姟
-        RtuDownTask task = new RtuDownTask() ;
+        WebDownComTask task = new WebDownComTask() ;
         task.data = command ;
         try{
             log.info("鏋勯�犱笅鍙戣繙绋嬪懡浠�" + command.getCode() + "鐨勬牳蹇冧换鍔★紝骞舵斁鍏ヤ换鍔¢槦鍒椾腑");

--
Gitblit v1.8.0