liurunyu
2025-01-21 5b89937212db0c507145187313eb5b326220f47b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.dy.pipIrrRemote.allRound;
 
import com.alibaba.fastjson2.JSON;
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.CommandBackParam;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.VoAllRound.VoArIntakeRemote;
import com.dy.pipIrrGlobal.daoAllRound.Ar4BaseMapper;
import com.dy.pipIrrGlobal.rtuMw.CodeLocal;
import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
import com.dy.pipIrrGlobal.voPr.VoOnLineIntake;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
 
import java.util.HashMap;
import java.util.List;
 
/**
 * @Author: liurunyu
 * @Date: 2025/1/14 16:59
 * @Description
 */
@Slf4j
@Service
public class Ar4RemoteSv extends Web2RtuMw {
 
    @Autowired
    private Ar4BaseMapper baseDao;
 
    @Autowired
    private Environment env;
 
    @Autowired
    private RestTemplate restTemplate;
 
    /**
     * 取水口基本信息
     * @return 取水口基本信息
     */
    public QueryResultVo<VoArIntakeRemote> intakeInfo(Long intakeId){
        VoArIntakeRemote rVo = new VoArIntakeRemote() ;
 
        String rtuAddr = null ;
        List<String> rtuAddrs = baseDao.intakeRtuAddr(intakeId) ;
        if(rtuAddrs != null && rtuAddrs.size() > 0){
            rtuAddr = rtuAddrs.get(0) ;
        }
        if(rtuAddr != null){
            //向通信中间件发关命令,查询部分RTU在线情况
            Command com = this.createInnerCommand(CodeLocal.onLinePart);
            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()){
                            //通信中间件成功返回命令结果
                            HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
                            if(onLineMap != null && onLineMap.size() > 0){
                                rVo.onLine = onLineMap.get(rtuAddr) ;
                            }
                        }
                    }else{
                        log.error("通信中间件返回内部命令结果中不包含CommandBackParam类型参数");
                    }
                }else{
                    log.error("通信中间件返回内部命令执行失败" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ;
                }
            }else{
                log.error("通信中间件返回内部命令结果为null");
            }
        }
 
        return null ;
    }
}