|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final UpgradeManager INSTANCE = new UpgradeManager(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Boolean openNoUpgrade ;//阀开(泵开)不执行升级 | 
|---|
|  |  |  | private Integer lastOpenMaxGoOn ;//阀开(泵开)状态设置以来持续最长时间(秒钟),超过这个时间认为状态无效(这个时长取决于工作报间隔) | 
|---|
|  |  |  | private Integer failTryTimes ;//升级失败后,重新偿试升级次数,0表示不重新偿试升级 | 
|---|
|  |  |  | private Integer ugMaxRtuSameTime ;//同时升级RTU最大个数 | 
|---|
|  |  |  | private Integer notifyTimesAfterOver; //升级结束后,再向web服务系统通知状态的次数 | 
|---|
|  |  |  | private int nowNotifyTimesAfterOver; //升级结束后,再向web服务系统通知状态的次数 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private UpgradeTask task ;//升级任务 | 
|---|
|  |  |  | private boolean monitorFirst = true ;//是否是第一次监视 | 
|---|
|  |  |  | private boolean monitorFirst ;//是否是第一次监视 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private UpgradeManager(){ | 
|---|
|  |  |  | monitorFirst = true ; | 
|---|
|  |  |  | 
|---|
|  |  |  | *  初始化配置信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void initOption(UpgradeUnitConfigVo configVo) { | 
|---|
|  |  |  | this.openNoUpgrade = configVo.openNoUpgrade; | 
|---|
|  |  |  | this.lastOpenMaxGoOn = configVo.lastOpenMaxGoOn; | 
|---|
|  |  |  | this.failTryTimes = configVo.failTryTimes; | 
|---|
|  |  |  | this.ugMaxRtuSameTime = configVo.ugMaxRtuAtOnce; | 
|---|
|  |  |  | this.notifyTimesAfterOver = configVo.notifyTimesAfterOver; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | this.task.forceOver(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.task = new UpgradeTask(); | 
|---|
|  |  |  | this.task.initOption(this.failTryTimes, this.ugMaxRtuSameTime); | 
|---|
|  |  |  | this.task.initOption(this.openNoUpgrade, this.lastOpenMaxGoOn, this.failTryTimes, this.ugMaxRtuSameTime); | 
|---|
|  |  |  | this.task.setTask(vo); | 
|---|
|  |  |  | this.nowNotifyTimesAfterOver = 0 ; | 
|---|
|  |  |  | this.monitorFirst = true ; | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("=设置了升级任务,涉及RTU" + vo.rtuAddrList.size() + "台                            =") ; | 
|---|
|  |  |  | 
|---|
|  |  |  | if(this.task != null){ | 
|---|
|  |  |  | this.task.countRunningRtuCount(); | 
|---|
|  |  |  | if(this.task.curUgRunningRtuTotal > 0){ | 
|---|
|  |  |  | return "当前存在升级中的设备,不能停止升级任务" ; | 
|---|
|  |  |  | return "当前存在升级中的设备,不能结束升级任务" ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | this.stop(); | 
|---|
|  |  |  | this.task.forceOver(); | 
|---|
|  |  |  | this.task = null ; | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param protocolVersion 上行数据对应的协议版本号 | 
|---|
|  |  |  | * @param callbackCom 回调函数,处理下行命令 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void trigger(String rtuAddr, String code, String protocolName, Short protocolVersion, Callback callbackCom){ | 
|---|
|  |  |  | public void trigger(String rtuAddr, String code, String protocolName, Short protocolVersion, Callback callbackCom, Object ...objects){ | 
|---|
|  |  |  | if(task != null && !task.taskIsOver){ | 
|---|
|  |  |  | this.task.trigger(rtuAddr, code, protocolName, protocolVersion, callbackCom); | 
|---|
|  |  |  | this.task.trigger(rtuAddr, code, protocolName, protocolVersion, callbackCom, objects); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | this.stop() ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(!this.task.taskIsOver){ | 
|---|
|  |  |  | if(this.openNoUpgrade != null | 
|---|
|  |  |  | && this.openNoUpgrade.booleanValue() | 
|---|
|  |  |  | && this.monitorFirst){ | 
|---|
|  |  |  | //第一次进入,进行阀开不升级处理 | 
|---|
|  |  |  | this.task.openNoUpgrade() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.nowNotifyTimesAfterOver = 0 ; | 
|---|
|  |  |  | //升级任务未完成 | 
|---|
|  |  |  | //工作1:判断是否无任何一个RTU进行过升级,并且达到时限,则认为当前升级任务完成 | 
|---|
|  |  |  | //-1:无一RTU升级且超时,0:无RTU升级但未超时等待,1有RTU升级正常执行 | 
|---|
|  |  |  | 
|---|
|  |  |  | }else if(temp == 1){ | 
|---|
|  |  |  | //当前有RTU进行过升级 | 
|---|
|  |  |  | //工作2:统计当前正在升级的RTU数量,为同时升级数量限制做准备 | 
|---|
|  |  |  | this.task.countRunningRtuCount() ; | 
|---|
|  |  |  | temp = this.task.countRunningRtuCount() ; | 
|---|
|  |  |  | if(temp > 0){ | 
|---|
|  |  |  | //说前当前还有升级中的RTU | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //工作3:统计需要升级但当前离线RTU的情况,超过时限的设置为升级完成 | 
|---|
|  |  |  | int tmp = this.task.countOffRtuAndSetIfOver() ; | 
|---|
|  |  |  | if(tmp >= 1){ | 
|---|
|  |  |  | //超时,强制设置一些RTU升级失败并且升级完成) | 
|---|
|  |  |  | //超时,强制设置一些RTU升级失败并且升级完成 | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("=因离线超时,强制设置" + tmp + "台RTU升级失败并且升级完成            =") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | }else if(tmp == 0){ | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("=离线超时,但无一台RTU因离线而被设置成升级失败并且升级完成     =") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | }else{//tmp = -1 | 
|---|
|  |  |  | //无任务逻辑 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //工作4:统计是否全部升级完成 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //工作4:统计进行升级过程而后又停止升级,发呆一定时长的设备 | 
|---|
|  |  |  | tmp = this.task.countRunningIdleRtuAndSetIfOver() ; | 
|---|
|  |  |  | if(tmp >= 1){ | 
|---|
|  |  |  | //升级发呆超时,强制设置一些RTU升级失败并且升级完成 | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("=因升级发呆超时,强制设置" + tmp + "台RTU升级失败并且升级完成          =") ; | 
|---|
|  |  |  | log.info("=                                                    =") ; | 
|---|
|  |  |  | log.info("======================================================") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //工作5:统计是否全部升级完成 | 
|---|
|  |  |  | this.task.taskIsOver = this.task.countIsAllOver() ; | 
|---|
|  |  |  | if(this.task.taskIsOver){ | 
|---|
|  |  |  | log.info("==================================================") ; | 
|---|
|  |  |  | 
|---|
|  |  |  | this.task.taskOverDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;//任务完成时间(yyyy-mm-dd HH:MM:SS) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //任务完成,执行最后一次升级状态通知 | 
|---|
|  |  |  | //工作5:升级状态通知 | 
|---|
|  |  |  | //工作6:升级状态通知 | 
|---|
|  |  |  | //if(!first){ | 
|---|
|  |  |  | //    this.notifyUpgradeStatus() ; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //任务未完成,继续执行升级状态通知 | 
|---|
|  |  |  | //工作5: 升级状态通知 | 
|---|
|  |  |  | //工作6: 升级状态通知 | 
|---|
|  |  |  | //if(!first){ | 
|---|
|  |  |  | //    this.notifyUpgradeStatus() ; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //工作5:升级状态通知 | 
|---|
|  |  |  | //工作6:升级状态通知 | 
|---|
|  |  |  | if(!this.monitorFirst){ | 
|---|
|  |  |  | this.notifyUpgradeStatus() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //任务已经完成 | 
|---|
|  |  |  | this.stop(); | 
|---|
|  |  |  | //工作6:任务结束后,最后发升级状态通知 | 
|---|
|  |  |  | if(this.nowNotifyTimesAfterOver == 0){ | 
|---|
|  |  |  | this.nowNotifyTimesAfterOver++ ; | 
|---|
|  |  |  | this.notifyUpgradeStatus() ;//必须通知一次 | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //然后重复通知 | 
|---|
|  |  |  | if(this.nowNotifyTimesAfterOver <= this.notifyTimesAfterOver){ | 
|---|
|  |  |  | //保证上面必须通知一次,那此处上面if中就得用<= | 
|---|
|  |  |  | this.nowNotifyTimesAfterOver++ ; | 
|---|
|  |  |  | this.notifyUpgradeStatus() ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | this.stop(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(this.monitorFirst){ | 
|---|
|  |  |  | 
|---|
|  |  |  | return true ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 升级状态通知 | 
|---|
|  |  |  | */ | 
|---|