package com.dy.pipIrrWechat.mqtt;
|
|
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.pipIrrGlobal.rtuMw.CodeLocal;
|
import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
|
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;
|
|
/**
|
* @Author: liurunyu
|
* @Date: 2025/8/14 8:44
|
* @Description
|
*/
|
@Slf4j
|
@Service
|
public class MqttMonitorSv extends Web2RtuMw {
|
|
@Autowired
|
private Environment env;
|
|
@Autowired
|
private RestTemplate restTemplate;
|
|
|
/**
|
* 查询设备是否在线
|
*
|
* @return
|
*/
|
public Boolean isOnLine4Mqtt(String fboxId) {
|
return selectOnOrOffLine4Mqtt(fboxId) ;
|
}
|
|
/**
|
* 查询MQTT在线或离线状态
|
* @param fboxId
|
* @return
|
*/
|
private Boolean selectOnOrOffLine4Mqtt(String fboxId) {
|
//向通信中间件发关命令,查询部分RTU在线情况
|
Command com = this.createInnerCommand(CodeLocal.onPartLineMqtt);
|
com.setParam(fboxId) ;
|
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);
|
Boolean flag = onLineMap.get(fboxId);
|
if(flag != null){
|
return flag ;
|
}
|
}
|
}else{
|
log.error("通信中间件返回内部命令结果中不包含CommandBackParam类型参数");
|
}
|
}else{
|
log.error("通信中间件返回内部命令执行失败" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ;
|
}
|
}else{
|
log.error("通信中间件返回内部命令结果为null");
|
}
|
return null ;
|
}
|
}
|