| | |
| | | |
| | | 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; |
| | |
| | | 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.List; |
| | | |
| | | /** |
| | |
| | | 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()))) ; |
| | |
| | | vo.softBytesCalculate = ppo.programCalculateBytes ; |
| | | vo.softByteSrc16 = ppo.programCrc16 ; |
| | | } |
| | | /** |
| | | * 监视: |
| | | * 重置,演示的重置 |
| | | * @return 操作结果 |
| | | */ |
| | | @GetMapping(path = "/demoReset") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> demoReset(){ |
| | | if(RtuUpgradeStateReceiverCtrl.cache == null){ |
| | | //return BaseResponseUtils.buildError("当前没有升级任务") ; |
| | | //正式运行时,下面两行去掉,上面一行打开 |
| | | 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 = "返回操作成功与否数据(BaseResponse.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(); |
| | | } |
| | | if(RtuUpgradeStateReceiverCtrl.cache == null){ |
| | | //return BaseResponseUtils.buildError("当前没有升级任务") ; |
| | | //正式运行时,下面两行去掉,上面一行打开 |
| | | RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class); |
| | | ctrl.demo(); |
| | | } |
| | | |
| | | QueryResultVo<VoWatch> rsVo = new QueryResultVo(); |
| | | VoWatch vo = new VoWatch() ; |
| | | vo.upgrade = this.sv.selectTaskDetail(RtuUpgradeStateReceiverCtrl.cache.ugTaskId); |
| | | vo.overall = RtuUpgradeStateReceiverCtrl.cache.ugOverallState ; |
| | | vo.rtus = new ArrayList<>() ; |
| | | 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 >= 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 ; |
| | | } |
| | | } |
| | | } |