|  |  | 
 |  |  |  | 
 |  |  | import com.dy.common.aop.SsoAop; | 
 |  |  | 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.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.voRm.VoUpgradeDetail; | 
 |  |  | 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.Base64; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |     @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) ; | 
 |  |  | 
 |  |  |             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("未配置升级任务回调网址") ; | 
 |  |  |         } | 
 |  |  | 
 |  |  |                 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") ; | 
 |  |  | 
 |  |  |         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("当前没有升级任务") ; | 
 |  |  |             //正式运行时,下面两行去掉,上面一行打开 | 
 |  |  |             RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class); | 
 |  |  |             ctrl.resetDemo(); | 
 |  |  |             ctrl.demo(); | 
 |  |  |         } | 
 |  |  |         return BaseResponseUtils.buildSuccess(true) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      *  监视: | 
 |  |  |      * 当前rtu远程升级任务执行状态 | 
 |  |  |      * @return 操作结果 | 
 |  |  |      */ | 
 |  |  | 
 |  |  |                     responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
 |  |  |                     description = "返回操作成功与否数据(BaseResponse.content:Boolean)", | 
 |  |  |                     content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
 |  |  |                             schema = @Schema(implementation = Boolean.class))} | 
 |  |  |                             schema = @Schema(implementation = VoWatch.class))} | 
 |  |  |             ) | 
 |  |  |     }) | 
 |  |  |     @GetMapping(path = "/curUpgradeState") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<UpgradeInfo> curUpgradeState(){ | 
 |  |  |     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("当前没有升级任务") ; | 
 |  |  |             //正式运行时,下面两行去掉,上面一行打开 | 
 |  |  |             RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class); | 
 |  |  |             ctrl.demo(); | 
 |  |  |         } | 
 |  |  |         CurUpgradeStateVo vo = new CurUpgradeStateVo() ; | 
 |  |  |         List<VoUpgradeDetail> list = this.sv.selectTaskDetail(RtuUpgradeStateReceiverCtrl.cache.ugTaskId); | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             vo.upgrade = list.get(0) ; | 
 |  |  |  | 
 |  |  |         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) ; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         vo.ugOverallState = RtuUpgradeStateReceiverCtrl.cache.ugOverallState ; | 
 |  |  |         vo.ugRtuStateList = RtuUpgradeStateReceiverCtrl.cache.ugRtuStateList ; | 
 |  |  |         return BaseResponseUtils.buildSuccess(vo) ; | 
 |  |  |  | 
 |  |  |         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 ; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |