From dbb4ac17ff70578662af99c6b1772b5c0641d005 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 20 十一月 2024 18:48:23 +0800 Subject: [PATCH] 1、基于Timer实现定时执行的任务,并在满足条件下结束定时任务,为此实现抽象类TimerTaskJob类,并在UpgradeManager类中应用; 2、TreadJob类由TimerTaskJob替换,弃用TreadJob类。 --- pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java | 93 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 68 insertions(+), 25 deletions(-) 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..7d5409d 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 @@ -1,5 +1,7 @@ package com.dy.pipIrrRemote.rtuUpgrage; +import com.dy.common.contant.Constant; +import com.dy.common.multiDataSource.DataSourceContext; import com.dy.common.softUpgrade.state.UpgradeInfo; import com.dy.common.softUpgrade.state.UpgradeRtu; import com.dy.common.softUpgrade.state.UpgradeState; @@ -12,6 +14,8 @@ import com.dy.pipIrrGlobal.pojoUg.UgRtuTask; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -43,11 +47,15 @@ */ @Hidden //涓嶅叕寮�鎺ュ彛锛屽叾鍙湁閫氫俊涓棿浠惰皟鐢� @PostMapping(path = "/receive") - public BaseResponse<Boolean> receive(@RequestBody UpgradeInfo info){ - log.info("鎺ユ敹鍒扮殑RTU杩滅▼鍗囩骇鐘舵�佹暟鎹负锛歿}", info.toString()); + public BaseResponse<Boolean> receive(@RequestBody UpgradeInfo info, HttpServletRequest req, HttpServletResponse rep){ + log.info("鎺ユ敹鍒扮殑RTU杩滅▼鍗囩骇鐘舵�佹暟鎹负锛歿}", info.toString("532328000214")); //杩涜鎺掑簭 //Comparator<UpgradeRtu> comparator = Comparator.comparing(UpgradeRtu::getRtuAddr, Comparator.naturalOrder()); //info.ugRtuStateList = info.ugRtuStateList.stream().sorted(comparator).collect(Collectors.toList()); + + //閫氫俊涓棿浠朵紶杩囨潵鐨勬満鏋則ag锛屼互鐢ㄤ簬鏌ユ壘鏁版嵁婧� + String token = req.getHeader(Constant.UserTokenKeyInHeader); + DataSourceContext.set(token); if(info.ugRtuStateList != null && info.ugRtuStateList.size() > 0){ if(info.ugRtuStateList.size() < 10){ @@ -112,6 +120,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 +153,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 +188,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){ @@ -212,13 +227,36 @@ return ; } int n = Integer.parseInt(new CreateRandom().create(2)) ; - if(n == 44 || n == 45 || n == 54){ + if(n == 4 + || n == 14 + || n == 24 + || n == 34 + || n == 44 + || n == 54 + || n == 64 + || n == 74 + || n == 84 + || n == 95 + || n == 45 + || n == 46 + || n == 47 + || n == 48 + || n == 49){ if(rtu.currentPackage == 1){ //1鍖呮 rtu.state = UpgradeRtu.STATE_FAILONE ; return ; } } + + if(n == 45){ + if(rtu.currentPackage != 1){ + //鍗囨 + rtu.state = UpgradeRtu.STATE_FAIL ; + return ; + } + } + if(rtu.currentPackage == rtu.totalPackage){ //鍗囩骇缁撴潫 rtu.state = UpgradeRtu.STATE_SUCCESS ; @@ -226,12 +264,16 @@ return ; } - rtu.state = UpgradeRtu.STATE_RUNNING ; - rtu.currentPackage += 1 ; - rtu.currentRamAddr = 0x00 + UpgradeRtu.RAMADDRADD ; - rtu.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; - rtu.reTryTimes = 0 ; - rtu.isOver = false ; + if(rtu.state != UpgradeRtu.STATE_FAILONE && + rtu.state != UpgradeRtu.STATE_FAIL){ + rtu.state = UpgradeRtu.STATE_RUNNING ; + rtu.currentPackage += 1 ; + rtu.currentRamAddr = 0x00 + UpgradeRtu.RAMADDRADD ; + rtu.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; + rtu.reTryTimes = 0 ; + rtu.isOver = false ; + } + } /** @@ -242,6 +284,7 @@ boolean hasRunning = false ; if(cache.ugRtuStateList != null && cache.ugRtuStateList.size() > 0){ cache.ugOverallState.init(); + cache.ugOverallState.rtuTotal = cache.ugRtuStateList.size() ; for(UpgradeRtu rtu : cache.ugRtuStateList){ if(rtu.state == UpgradeRtu.STATE_OFFLINE){ cache.ugOverallState.offLineTotal ++ ; -- Gitblit v1.8.0