liurunyu
2024-11-29 053d5042846ae96c9c7ba031bae9d9221745cd7f
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeCtrl.java
@@ -3,7 +3,6 @@
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.dy.common.aop.SsoAop;
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;
@@ -12,8 +11,7 @@
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoUg.UgRtuProgram;
import com.dy.pipIrrGlobal.pojoUg.UgRtuTask;
import com.dy.pipIrrGlobal.rtuMw.ToRtuMwCom;
import com.dy.pipIrrGlobal.voPr.VoDivide;
import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
import com.dy.pipIrrGlobal.voUg.VoUgRtuResult;
import com.dy.pipIrrGlobal.voUg.VoWatch;
import io.swagger.v3.oas.annotations.Operation;
@@ -35,7 +33,6 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
@@ -48,7 +45,7 @@
@Tag(name = "rtu远程升级任务", description = "rtu远程升级任务相关操作")
@RestController
@RequestMapping(path = "rtuUpgrade")
public class RtuUpgradeCtrl extends ToRtuMwCom {
public class RtuUpgradeCtrl extends Web2RtuMw {
    @Autowired
    private RtuUpgradeSv sv ;
@@ -79,28 +76,28 @@
    @SsoAop()
    public BaseResponse<Boolean> issuedTask(String id){
        if(id == null || id.trim().equals("")){
            return BaseResponseUtils.buildError("任务id不能为空") ;
            return BaseResponseUtils.buildErrorMsg("任务id不能为空") ;
        }
        UgRtuTask tpo = this.sv.selectTaskById(id) ;
        if(tpo == null){
            return BaseResponseUtils.buildError("任务不存在") ;
            return BaseResponseUtils.buildErrorMsg("任务不存在") ;
        }
        if(tpo.isExecute == 1){
            return BaseResponseUtils.buildError("任务已下发,不能重复下发任务") ;
            return BaseResponseUtils.buildErrorMsg("任务已下发,不能重复下发任务") ;
        }
        UgRtuProgram ppo = this.sv.selectProgramById(tpo.programId) ;
        if(ppo == null){
            return BaseResponseUtils.buildError("任务对应的程序不存在") ;
            return BaseResponseUtils.buildErrorMsg("任务对应的程序不存在") ;
        }
        List<String> taskRtuAddrs = this.sv.selectAllRtuAddrByTask(id) ;
        if(taskRtuAddrs == null || taskRtuAddrs.size() == 0){
            return BaseResponseUtils.buildError("任务所涉及的控制器还未设置") ;
            return BaseResponseUtils.buildErrorMsg("任务所涉及的控制器还未设置") ;
        }
        String ugCallbackUrl_rm = env.getProperty("mw.ugCallbackUrl_rm" );
        if(ugCallbackUrl_rm == null || ugCallbackUrl_rm.trim().equals("")){
            return BaseResponseUtils.buildError("未配置升级任务回调网址") ;
            return BaseResponseUtils.buildErrorMsg("未配置升级任务回调网址") ;
        }
        UpgradeTaskVo vo = new UpgradeTaskVo() ;
@@ -108,8 +105,8 @@
        vo.rtuAddrList = taskRtuAddrs ;
        vo.callbackWebUrl = ugCallbackUrl_rm ;
        String ugSendUrl = this.getToMwUgUrl(this.env) ;
        BaseResponse res = sendUpgradeTask2Mw(restTemplate, ugSendUrl, vo) ;
        String rqUrl = this.get2MwRequestUrl(this.env, ContextUgTaskSend) ;
        BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, vo) ;
        if(res != null){
            if(res.isSuccess()){
                this.sv.setUpgradeTaskExecuted(id);
@@ -119,14 +116,49 @@
                if(msg == null){
                    msg = res.getMsg() ;
                }
                log.error("通信中间件执行下发升级任务失败" + msg) ;
                return BaseResponseUtils.buildFail("通信中间件执行失败" + msg) ;
                log.error("通信中间件执行下发升级任务失败," + msg) ;
                return BaseResponseUtils.buildErrorMsg("通信中间件执行失败," + msg) ;
            }
        }else{
            log.error("通信中间件返回结果为null") ;
            return BaseResponseUtils.buildFail("通信中间件返回结果为null") ;
            return BaseResponseUtils.buildErrorMsg("通信中间件返回结果为null") ;
        }
    }
    /**
     * 下发强制结束当前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 = String.class))}
            )
    })
    @GetMapping(path = "/forceOver")
    @SsoAop()
    public BaseResponse<String> forceOver() {
        String rqUrl = this.get2MwRequestUrl(this.env, ContextUgForceOver) ;
        BaseResponse res = sendGetRequest2Mw(restTemplate, rqUrl) ;
        if(res != null){
            if(res.isSuccess()){
                return BaseResponseUtils.buildSuccess(true) ;
            }else{
                String msg = res.getContent()==null?null:(String)res.getContent() ;
                if(msg == null){
                    msg = res.getMsg() ;
                }
                log.error("通信中间件执行下发强制结束当前rtu远程升级任务失败:" + msg) ;
                return BaseResponseUtils.buildErrorMsg("通信中间件执行强制结束当前rtu远程升级任务失败:" + msg) ;
            }
        }else{
            log.error("通信中间件返回结果为null") ;
            return BaseResponseUtils.buildErrorMsg("通信中间件返回结果为null") ;
        }
    }
    private void valueFromPo(UpgradeTaskVo vo, UgRtuTask tpo, UgRtuProgram ppo){
        vo.id = "" + tpo.id ;
@@ -180,10 +212,10 @@
            qvo.pageSize = 49 ;
        }
        if(RtuUpgradeStateReceiverCtrl.cache == null){
            //return BaseResponseUtils.buildError("当前没有升级任务") ;
            return BaseResponseUtils.buildErrorMsg("当前没有升级任务") ;
            //正式运行时,下面两行去掉,上面一行打开
            RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class);
            ctrl.demo();
            //RtuUpgradeStateReceiverCtrl ctrl = SpringContextUtil.getBean(RtuUpgradeStateReceiverCtrl.class);
            //ctrl.demo();
        }
        QueryResultVo<VoWatch> rsVo = this.resSv.curUpgradeState(qvo) ;
        return BaseResponseUtils.buildSuccess(rsVo) ;