liurunyu
2024-12-06 0c5ce0576e24041177eb1eba1761e661ddf2e135
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/MonitorSv.java
@@ -5,11 +5,12 @@
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.CommandBackParam;
import com.dy.common.mw.protocol.rtuState.RtuStatus;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper;
import com.dy.pipIrrGlobal.rtuMw.CodeLocal;
import com.dy.pipIrrGlobal.rtuMw.ToRtuMwCom;
import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
@@ -29,7 +30,7 @@
 */
@Slf4j
@Service
public class MonitorSv extends ToRtuMwCom {
public class MonitorSv extends Web2RtuMw {
    @Autowired
    private PrIntakeMapper prIntakeMapper;
@@ -56,6 +57,46 @@
    }
    /**
     * 查询RTU在通信中间件中的支行状态
     * @param rtuAddr
     * @return
     */
    public RtuStatus rtuStatus(String rtuAddr) throws Exception{
        //向通信中间件发关命令,查询部分RTU在线情况
        RtuStatus rtuStatus = null ;
        Command com = this.createInnerCommand(CodeLocal.oneRtuStates);
        com.setParam(rtuAddr) ;
        String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
        BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
        if(res != null){
            if(res.isSuccess()){
                Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ;
                CommandBackParam bakParam = JSON.parseObject((reCom== null || reCom.param == null) ? null : JSON.toJSONString(reCom.param), CommandBackParam.class) ;
                if(bakParam != null){
                    if(bakParam.getSuccess().booleanValue()){
                        //通信中间件成功返回命令结果
                        if(reCom.getAttachment() != null){
                            rtuStatus = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), RtuStatus.class);
                        }else{
                            throw new Exception("通信中间件未掌握该RTU的状态,可能该RTU未上线") ;
                        }
                    }
                }else{
                    log.error("通信中间件返回内部命令结果中不包含CommandBackParam类型参数");
                    throw new Exception("通信中间件执行命令出错") ;
                }
            }else{
                log.error("通信中间件返回内部命令执行失败" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ;
                throw new Exception("通信中间件执行命令出错" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ;
            }
        }else{
            log.error("通信中间件返回内部命令结果为null");
            throw new Exception("通信中间件执行命令出错,返回内部命令结果为null") ;
        }
        return rtuStatus ;
    }
    /**
     * 查询取水口,不限制在线与离线状态
     * @param vo
     * @return
@@ -76,8 +117,8 @@
            //向通信中间件发关命令,查询部分RTU在线情况
            Command com = this.createInnerCommand(CodeLocal.onLinePart);
            com.setParam(rtuAddrs) ;
            String comSendUrl = this.getToMwUrl(this.env) ;
            BaseResponse res = sendCom2Mw(restTemplate, comSendUrl, com) ;
            String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
            BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
            if(res != null){
                if(res.isSuccess()){
                    Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ;
@@ -85,7 +126,7 @@
                    if(bakParam != null){
                        if(bakParam.getSuccess().booleanValue()){
                            //通信中间件成功返回命令结果
                            HashMap<String, Boolean> onLineMap = JSON.parseObject(((JSONObject)reCom.getAttachment()).toJSONString(), HashMap.class);
                            HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
                            for(VoOnLineIntake rVo : rsVo.obj){
                                if(onLineMap.containsKey(rVo.getRtuAddr())) {
                                    rVo.setIsOnLine(onLineMap.get(rVo.getRtuAddr()));
@@ -114,8 +155,8 @@
    private QueryResultVo<List<VoOnLineIntake>> selectIntakesOnOrOffLine(QueryVo vo) {
        //向通信中间件发关命令,查询部分RTU在线情况
        Command com = this.createInnerCommand(CodeLocal.onLineAll);
        String comSendUrl = this.getToMwUrl(this.env) ;
        BaseResponse res = sendCom2Mw(restTemplate, comSendUrl, com) ;
        String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
        BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
        if(res != null){
            if(res.isSuccess()){
                Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ;
@@ -123,7 +164,7 @@
                if(bakParam != null){
                    if(bakParam.getSuccess().booleanValue()){
                        //通信中间件成功返回命令结果
                        HashMap<String, Boolean> onLineMap = JSON.parseObject(((JSONObject)reCom.getAttachment()).toJSONString(), HashMap.class);
                        HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
                        JSONArray jsonArray = new JSONArray();
                        for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
                            JSONObject jsonObject = new JSONObject();