pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java
@@ -7,12 +7,14 @@
import com.dy.rtuMw.server.forTcp.TcpSessionCache;
import com.dy.rtuMw.server.local.CommandInnerDeaLer;
import com.dy.rtuMw.server.local.ReturnCommand;
import com.dy.rtuMw.server.msCenter.MsCenterUnit;
import com.dy.rtuMw.server.tasks.WebDownComTask;
import com.dy.common.mw.core.CoreUnit;
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.CommandType;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.rtuMw.server.tasks.WebDownTransparentComTask;
import com.dy.rtuMw.server.upgrade.UpgradeUnit;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
@@ -144,6 +146,24 @@
            return BaseResponseUtils.buildSuccess(list);
        }
    }
    /**
     * 注册消息接收者
     * @param msReceiverWebUrl 消息接收者web http post url
     * @return
     */
    @GetMapping("/registerMsReceiverWebUrl")
    public BaseResponse<Boolean> registerMsReceiverWebUrl(String msReceiverWebUrl){
        try{
            MsCenterUnit.getInstance().registerMsReceiver(msReceiverWebUrl);
        }catch (Exception e){
            log.error("注册消息接收者时发生异常", e);
            return BaseResponseUtils.buildError("注册消息接收者时发生异常" + (e.getMessage() == null?"":(":" + e.getMessage())));
        }
        return BaseResponseUtils.buildSuccess(true);
    }
    /**
     * 接收web系统发来升级任务
     * @param vo
@@ -165,15 +185,17 @@
     * 接收web系统发来强制结束升级任务
     * @return
     */
    @GetMapping(path = "ugForceOver", consumes = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(path = "ugForceOver")
    public BaseResponse<String> ugForceOver() {
        log.info("收到停止RTU升级任务命令") ;
        try{
            String mes = UpgradeUnit.getInstance().forceOverUpgradeTask();
            if(mes == null){
                mes = "停止升级任务成功" ;
                return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, mes, mes);
            }else{
                return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.FAIL_CODE, mes, mes);
            }
            return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, mes, mes);
        }catch (Exception e){
            log.error("停止RTU升级任务时发生异常", e);
            return BaseResponseUtils.buildError("停止RTU升级任务时发生异常" + (e.getMessage() == null?"":(":" + e.getMessage())));
@@ -207,30 +229,23 @@
            //通信中间件内部命令,例如查询监控中间件时钟,查询RTU在线情况等
            try{
                Command reCom = new CommandInnerDeaLer().deal(com) ;
                /*
                boolean error = false ;
                if(reCom.param != null && reCom.param != null){
                    CommandBackParam cbp = (CommandBackParam)reCom.param ;
                    if(cbp.getSuccess() != null && !cbp.getSuccess().booleanValue()){
                        error = true ;
                        return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null));
                    }
                }
                if(!error){
                    return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null));
                }
                */
                return BaseResponseUtils.buildSuccess(reCom);
            }catch(Exception e){
                return BaseResponseUtils.buildError(ReturnCommand.errored("处理内部命令出错" + (e.getMessage() == null?"":("," + e.getMessage())), com.getId(), com.getCode()) );
            }
        }else if(commandType.equals(CommandType.outerCommand)){
            //发向RTU的外部命令,异步处理,web端jroups成员同步得到命令处理结果,但构造命令及下发命令和命令结果接收要异步得到
            //发向RTU的外部命令
            try{
                return this.dealOuterCommand(com) ;
            }catch(Exception e){
                return BaseResponseUtils.buildError(ReturnCommand.errored("处理发向RTU的外部命令出错" + (e.getMessage() == null?"":("," + e.getMessage())), com.getId(), com.getCode()) );
            }
        }else if(commandType.equals(CommandType.outerTransCommand)){
            //发向RTU的外部透传命令
            try{
                return this.dealOutTransparentCommand(com) ;
            }catch(Exception e){
                return BaseResponseUtils.buildError(ReturnCommand.errored("处理发向RTU的外部透传命令出错" + (e.getMessage() == null?"":("," + e.getMessage())), com.getId(), com.getCode()) );
            }
        }else if(commandType.equals(CommandType.resultCommand)){
            return BaseResponseUtils.buildError(ReturnCommand.errored("出错,通信中间件不接结果类型的命令!", com.getId(), com.getCode()));
@@ -286,4 +301,39 @@
        return BaseResponseUtils.buildSuccess(ReturnCommand.successed("命令已接受,即将构造并下发命令。", command.getId(), command.getCode()));
    }
    /**
     * 处理发向RTU的外部命令
     * @return 结果
     */
    private BaseResponse<Command> dealOutTransparentCommand(Command command){
        String rtuAddr = command.getRtuAddr() ;
        if(rtuAddr == null || rtuAddr.trim().equals("")){
            return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU地址为空!", command.getId(), command.getCode())) ;
        }
        rtuAddr = rtuAddr.trim() ;
        Boolean onLine = TcpSessionCache.isConnect(rtuAddr);
        if(onLine == null){
            return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")未上线!", command.getId(), command.getCode())) ;
        }else if(!onLine.booleanValue()){
            if(!ServerProperties.isLowPower){
                return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")离线!", command.getId(), command.getCode())) ;
            }
        }
        //生成异步任务
        WebDownTransparentComTask task = new WebDownTransparentComTask() ;
        task.data = command ;
        try{
            log.info("构造下发远程透传命令" + command.getCode() + "的核心任务,并放入任务队列中");
            CoreUnit.getInstance().pushCoreTask(task);
        }catch(Exception e){
            log.error(e.getMessage(), e);
            return BaseResponseUtils.buildError(ReturnCommand.errored("透传命令处理失败" + e.getMessage(), command.getId(), command.getCode())) ;
        }
        return BaseResponseUtils.buildSuccess(ReturnCommand.successed("透传命令已接受,即将构造并下发命令。", command.getId(), command.getCode()));
    }
}