From 1950b0635a0db2c5286f8330e064879e020a7303 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期五, 22 十一月 2024 14:02:11 +0800 Subject: [PATCH] 1、通信中间件核心模块线程工作由Thread实现改为Timer实现; 2、完善通信中间件远程升级模块及webRemote模块; 3、优化代码。 --- pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 157 insertions(+), 7 deletions(-) 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 c8436a0..0e99c5e 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 @@ -2,13 +2,17 @@ import com.dy.common.aop.SsoAop; import com.dy.common.multiDataSource.DataSourceContext; +import com.dy.common.softUpgrade.state.UpgradeRtu; import com.dy.common.softUpgrade.state.UpgradeTaskVo; +import com.dy.common.springUtil.SpringContextUtil; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; import com.dy.common.webUtil.ResultCodeMsg; -import com.dy.pipIrrGlobal.pojoRm.UgRtuProgram; -import com.dy.pipIrrGlobal.pojoRm.UgRtuTask; +import com.dy.pipIrrGlobal.pojoUg.UgRtuProgram; +import com.dy.pipIrrGlobal.pojoUg.UgRtuTask; import com.dy.pipIrrGlobal.rtuMw.ToRtuMwCom; +import com.dy.pipIrrGlobal.voUg.VoWatch; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -23,6 +27,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.Base64; import java.util.List; /** @@ -61,7 +68,7 @@ @GetMapping(path = "/issuedTask") @SsoAop() public BaseResponse<Boolean> issuedTask(String id){ - if(id == null || !id.trim().equals("")){ + if(id == null || id.trim().equals("")){ return BaseResponseUtils.buildError("浠诲姟id涓嶈兘涓虹┖") ; } UgRtuTask tpo = this.sv.selectTaskById(id) ; @@ -81,7 +88,7 @@ return BaseResponseUtils.buildError("浠诲姟鎵�娑夊強鐨勬帶鍒跺櫒杩樻湭璁剧疆") ; } - String ugCallbackUrl_rm = env.getProperty("mw." + DataSourceContext.get() + ".ugCallbackUrl_rm" ); + String ugCallbackUrl_rm = env.getProperty("mw.ugCallbackUrl_rm" ); if(ugCallbackUrl_rm == null || ugCallbackUrl_rm.trim().equals("")){ return BaseResponseUtils.buildError("鏈厤缃崌绾т换鍔″洖璋冪綉鍧�") ; } @@ -95,10 +102,15 @@ BaseResponse res = sendUpgradeTask2Mw(restTemplate, ugSendUrl, vo) ; if(res != null){ if(res.isSuccess()){ + this.sv.setUpgradeTaskExecuted(id); return BaseResponseUtils.buildSuccess(true) ; }else{ - log.error("閫氫俊涓棿浠舵墽琛屼笅鍙戝崌绾т换鍔″け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ; - return BaseResponseUtils.buildFail("閫氫俊涓棿浠舵墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ; + String msg = res.getContent()==null?null:(String)res.getContent() ; + if(msg == null){ + msg = res.getMsg() ; + } + log.error("閫氫俊涓棿浠舵墽琛屼笅鍙戝崌绾т换鍔″け璐�" + msg) ; + return BaseResponseUtils.buildFail("閫氫俊涓棿浠舵墽琛屽け璐�" + msg) ; } }else{ log.error("閫氫俊涓棿浠惰繑鍥炵粨鏋滀负null") ; @@ -111,9 +123,147 @@ vo.softFileName = ppo.hexFileName ; vo.softStoreAddr = ppo.storeRamAddr ; vo.softStartAddr = ppo.startRamAddr ; - vo.softFileData = ppo.programBytes ; + vo.softFileData64 = Base64.getEncoder().encodeToString(ppo.programBytes) ; + //vo.softFileData = ppo.programBytes ; 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) ; + } + /** + * 鐩戣锛� + * 褰撳墠rtu杩滅▼鍗囩骇浠诲姟鎵ц鐘舵�� + * @return 鎿嶄綔缁撴灉 + */ + @Operation(summary = "褰撳墠rtu杩滅▼鍗囩骇浠诲姟鎵ц鐘舵��", description = "褰撳墠rtu杩滅▼鍗囩骇浠诲姟鎵ц鐘舵��") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖鎿嶄綔鎴愬姛涓庡惁鏁版嵁锛圔aseResponse.content:Boolean锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = VoWatch.class))} + ) + }) + @GetMapping(path = "/curUpgradeState") + @SsoAop() + public BaseResponse<QueryResultVo<VoWatch> > curUpgradeState(QueryVo qvo){ + if(qvo == null){ + qvo = new QueryVo(); + qvo.pageCurr = 1 ; + qvo.pageSize = 50 ; + } + if(RtuUpgradeStateReceiverCtrl.cache == null){ + //return BaseResponseUtils.buildError("褰撳墠娌℃湁鍗囩骇浠诲姟") ; + //姝e紡杩愯鏃讹紝涓嬮潰涓よ鍘绘帀锛屼笂闈竴琛屾墦寮� + RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class); + ctrl.demo(); + } + + QueryResultVo<VoWatch> rsVo = new QueryResultVo(); + VoWatch vo = new VoWatch() ; + List<UpgradeRtu> listFiltered = null ; + if(RtuUpgradeStateReceiverCtrl.cache != null && RtuUpgradeStateReceiverCtrl.cache.ugTaskId != null){ + 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) { + listFiltered = filterByQuery(qvo) ; + if (listFiltered.size() > 0) { + if(qvo.pageCurr < 1){ + qvo.pageCurr = 1 ; + } + int start = (qvo.pageCurr - 1) * qvo.pageSize ; + 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 < listFiltered.size(); i++){ + UpgradeRtu ugRtu = listFiltered.get(i) ; + VoWatch.VoWatchRtu rtu = new VoWatch.VoWatchRtu() ; + rtu.fromCache(ugRtu) ; + vo.rtus.add(rtu) ; + } + } + } + } + + rsVo.obj = vo ; + rsVo.pageSize = qvo.pageSize ; + rsVo.pageCurr = qvo.pageCurr ; + 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 ; + } + } } -- Gitblit v1.8.0