From a0e0f51ebbfdb6b3d6371eaa1b3b3fc8560dc9d7 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 14 十一月 2024 14:04:25 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java              |  101 ++++++++++++++++++++++++++++-----
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/QueryVo.java                     |    6 ++
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java |   39 +++++++-----
 3 files changed, 114 insertions(+), 32 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/QueryVo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/QueryVo.java
index aac5f50..3f2f7cb 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/QueryVo.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/QueryVo.java
@@ -17,5 +17,11 @@
     @Schema(description = "鎺у埗鍣ㄥ湴鍧�")
     public String rtuAddr ;
 
+    @Schema(description = "鐘舵��")
+    public Integer status ;//杩涜涓� 锛� 1    宸茬粨鏉� 锛� 0
+
+    @Schema(description = "缁撴灉")
+    public Integer result ;//鎴愬姛  :  1    澶辫触  锛� 0
+
 }
 
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
index 0fdd253..3646149 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
@@ -122,6 +122,23 @@
         vo.softBytesCalculate = ppo.programCalculateBytes ;
         vo.softByteSrc16 = ppo.programCrc16 ;
     }
+    /**
+     *  鐩戣锛�
+     * 閲嶇疆锛屾紨绀虹殑閲嶇疆
+     * @return 鎿嶄綔缁撴灉
+     */
+    @GetMapping(path = "/demoReset")
+    @SsoAop()
+    public BaseResponse<Boolean> demoReset(){
+        if(RtuUpgradeStateReceiverCtrl.cache == null){
+            //return BaseResponseUtils.buildError("褰撳墠娌℃湁鍗囩骇浠诲姟") ;
+            //姝e紡杩愯鏃讹紝涓嬮潰涓よ鍘绘帀锛屼笂闈竴琛屾墦寮�
+            RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class);
+            ctrl.resetDemo();
+            ctrl.demo();
+        }
+        return BaseResponseUtils.buildSuccess(true) ;
+    }
 
     /**
      *  鐩戣锛�
@@ -134,7 +151,7 @@
                     responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                     description = "杩斿洖鎿嶄綔鎴愬姛涓庡惁鏁版嵁锛圔aseResponse.content:Boolean锛�",
                     content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
-                            schema = @Schema(implementation = Boolean.class))}
+                            schema = @Schema(implementation = VoWatch.class))}
             )
     })
     @GetMapping(path = "/curUpgradeState")
@@ -155,25 +172,23 @@
         vo.upgrade = this.sv.selectTaskDetail(RtuUpgradeStateReceiverCtrl.cache.ugTaskId);
         vo.overall = RtuUpgradeStateReceiverCtrl.cache.ugOverallState ;
         vo.rtus = new ArrayList<>() ;
-        if(RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList != null && RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size() > 0){
-            if(qvo.rtuAddr != null && !qvo.rtuAddr.trim().equals("")){
-                qvo.pageCurr = 1 ;
-                final String queryAddr = qvo.rtuAddr ;
-                RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.stream().filter(rtu -> rtu.rtuAddr.equals(queryAddr)).forEach(ugRtu -> {
-                    VoWatch.VoWatchRtu rtu = new VoWatch.VoWatchRtu() ;
-                    rtu.fromCache(ugRtu) ;
-                    vo.rtus.add(rtu) ;
-                }); ;
-            }else{
+        List<UpgradeRtu> listFiltered = null ;
+        if(RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList != null && RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size() > 0) {
+            listFiltered = filterByQuery(qvo) ;
+            if (listFiltered.size() > 0) {
                 if(qvo.pageCurr < 1){
                     qvo.pageCurr = 1 ;
                 }
                 int start = (qvo.pageCurr - 1) * qvo.pageSize ;
-                if(start >= RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size()){
-                    start = RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size() - 1 ;
+                if(start >= listFiltered.size()){
+                    if(listFiltered.size()%qvo.pageSize > 0){
+                        start = listFiltered.size() - listFiltered.size()%qvo.pageSize ;
+                    }else{
+                        start = listFiltered.size() - qvo.pageSize ;
+                    }
                 }
-                for(int i = start; i < (start + qvo.pageSize) && i < RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.size(); i++){
-                    UpgradeRtu ugRtu = RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.get(i) ;
+                for(int i = start; i < (start + qvo.pageSize) && i < listFiltered.size(); i++){
+                    UpgradeRtu ugRtu = listFiltered.get(i) ;
                     VoWatch.VoWatchRtu rtu = new VoWatch.VoWatchRtu() ;
                     rtu.fromCache(ugRtu) ;
                     vo.rtus.add(rtu) ;
@@ -183,7 +198,61 @@
         rsVo.obj = vo ;
         rsVo.pageSize = qvo.pageSize ;
         rsVo.pageCurr = qvo.pageCurr ;
-        rsVo.calculateAndSet(0L + vo.rtus.size(), null);
+        rsVo.calculateAndSet(0L + (listFiltered==null?0:listFiltered.size()), null);
         return BaseResponseUtils.buildSuccess(rsVo) ;
     }
+
+    private List<UpgradeRtu> filterByQuery(QueryVo qvo){
+        if (qvo.status != null || qvo.result != null) {
+            final Integer qvoStatus = qvo.status ;
+            final Integer qvoResult = qvo.result ;
+            final String qvoRtuAddr = qvo.rtuAddr ;
+            return RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList.stream().filter(rtu -> {
+                boolean ok = false;
+                if (qvoStatus != null) {
+                    if (qvoStatus.intValue() == 1) {
+                        if (rtu.state == UpgradeRtu.STATE_RUNNING) {
+                            ok = true;
+                        }else{
+                            ok = false ;
+                        }
+                    } else if (qvoStatus.intValue() == 0) {
+                        if (rtu.isOver) {
+                            ok = true;
+                        }else{
+                            ok = false ;
+                        }
+                    }
+                }
+                if (qvoResult != null) {
+                    if (qvoResult.intValue() == 1) {
+                        if (rtu.state == UpgradeRtu.STATE_SUCCESS) {
+                            ok = true;
+                        }else{
+                            ok = false ;
+                        }
+                    } else if (qvoResult.intValue() == 0) {
+                        if (rtu.state == UpgradeRtu.STATE_OFFLINE
+                                || rtu.state == UpgradeRtu.STATE_FAILONE
+                                || rtu.state == UpgradeRtu.STATE_FAIL
+                                || rtu.state == UpgradeRtu.STATE_FAILOFFLINE) {
+                            ok = true;
+                        }else{
+                            ok = false ;
+                        }
+                    }
+                }
+                if(qvoRtuAddr != null && !qvoRtuAddr.trim().equals("")){
+                    if(rtu.rtuAddr.equals(qvoRtuAddr)){
+                        ok = true;
+                    }else{
+                        ok = false ;
+                    }
+                }
+                return ok;
+            }).toList() ;
+        }else{
+            return RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList ;
+        }
+    }
 }
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java
index abf7883..c32acaa 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java
@@ -112,6 +112,14 @@
 
     private static ThreadJob threadJob ;
 
+    protected void resetDemo(){
+        if(threadJob != null){
+            threadJob.stop() ;
+            threadJob = null ;
+        }
+        cache = null ;
+    }
+
     protected void demo(){
         if(cache == null){
             UgRtuTask tpo = this.sv.selectLastTask() ;
@@ -137,7 +145,17 @@
                             threadJob = new ThreadJob() {
                                 @Override
                                 public Object execute() throws Exception {
-                                    runDemo() ;
+                                    while(!this.stop){
+                                        if(!runDemo()){
+                                            this.stop = true ;
+                                        }else{
+                                            try {
+                                                Thread.sleep(500);
+                                            } catch (InterruptedException e) {
+                                                e.printStackTrace();
+                                            }
+                                        }
+                                    }
                                     return null;
                                 }
                             };
@@ -162,22 +180,11 @@
             }
         }
     }
-    private void runDemo(){
-        boolean hasRunning = true ;
-        while (true){
-            for(UpgradeRtu rtu : cache.ugRtuStateList){
-                this.rtuUpgrade(rtu) ;
-            }
-            hasRunning = this.statisticsNowUpgradeState() ;
-            if(!hasRunning){
-                break ;
-            }
-            try {
-                Thread.sleep(500);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
+    private boolean runDemo(){
+        for(UpgradeRtu rtu : cache.ugRtuStateList){
+            this.rtuUpgrade(rtu) ;
         }
+        return this.statisticsNowUpgradeState() ;
     }
     private void rtuUpgrade(UpgradeRtu rtu){
         if(rtu.lastDownDt == null){

--
Gitblit v1.8.0