|
@@ -10,11 +10,10 @@ import com.yunfeiyun.agmp.iot.common.model.mq.IotDeviceEditMqModel;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.DeviceconnCacheService;
|
|
import com.yunfeiyun.agmp.iot.common.service.DeviceconnCacheService;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.TypeCacheService;
|
|
import com.yunfeiyun.agmp.iot.common.service.TypeCacheService;
|
|
|
import com.yunfeiyun.agmp.iots.common.modal.IotDeviceconnResVo;
|
|
import com.yunfeiyun.agmp.iots.common.modal.IotDeviceconnResVo;
|
|
|
-import com.yunfeiyun.agmp.iots.common.modal.TosDevicetypeResVo;
|
|
|
|
|
import com.yunfeiyun.agmp.iots.core.mqtt.DeviceTopicService;
|
|
import com.yunfeiyun.agmp.iots.core.mqtt.DeviceTopicService;
|
|
|
import com.yunfeiyun.agmp.iots.core.mqtt.modal.MqttTopicValue;
|
|
import com.yunfeiyun.agmp.iots.core.mqtt.modal.MqttTopicValue;
|
|
|
-import com.yunfeiyun.agmp.iots.device.common.Device;
|
|
|
|
|
import com.yunfeiyun.agmp.iots.service.BusinessCoreService;
|
|
import com.yunfeiyun.agmp.iots.service.BusinessCoreService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iots.task.IotStatusService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.util.TextUtils;
|
|
import org.apache.http.util.TextUtils;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
@@ -46,6 +45,8 @@ public class ConnectionManager {
|
|
|
private DeviceTopicService deviceTopicService;
|
|
private DeviceTopicService deviceTopicService;
|
|
|
@Resource
|
|
@Resource
|
|
|
private DeviceconnCacheService deviceconnCacheService;
|
|
private DeviceconnCacheService deviceconnCacheService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotStatusService iotStatusService;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -60,7 +61,7 @@ public class ConnectionManager {
|
|
|
log.info("【初始化】设备型号 构建链接 协议: {}个", iotDeviceConnResVoList.size());
|
|
log.info("【初始化】设备型号 构建链接 协议: {}个", iotDeviceConnResVoList.size());
|
|
|
for (IotDeviceconnResVo iotDeviceconnResVo : iotDeviceConnResVoList) {
|
|
for (IotDeviceconnResVo iotDeviceconnResVo : iotDeviceConnResVoList) {
|
|
|
deviceconnCacheService.setCache(iotDeviceconnResVo);
|
|
deviceconnCacheService.setCache(iotDeviceconnResVo);
|
|
|
- log.info("【初始化】【开始】协议加载,连接名称:{},厂家:{},类型:{} ,配置:{}", iotDeviceconnResVo.getDevconnName(),iotDeviceconnResVo.getFirmName(), iotDeviceconnResVo.getDevtypeBid(), iotDeviceconnResVo.getDevconnConfig());
|
|
|
|
|
|
|
+ log.info("【初始化】【开始】协议加载,连接名称:{},厂家:{},类型:{} ,配置:{}", iotDeviceconnResVo.getDevconnName(), iotDeviceconnResVo.getFirmName(), iotDeviceconnResVo.getDevtypeBid(), iotDeviceconnResVo.getDevconnConfig());
|
|
|
//将配置信息转换成jsonObject,这是个数组
|
|
//将配置信息转换成jsonObject,这是个数组
|
|
|
JSONArray jsonConfig = parseConfigJson(iotDeviceconnResVo.getDevconnConfig());
|
|
JSONArray jsonConfig = parseConfigJson(iotDeviceconnResVo.getDevconnConfig());
|
|
|
|
|
|
|
@@ -133,10 +134,11 @@ public class ConnectionManager {
|
|
|
}
|
|
}
|
|
|
return jsonConfig;
|
|
return jsonConfig;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设备创建时,初始化设备连接
|
|
* 设备创建时,初始化设备连接
|
|
|
- * */
|
|
|
|
|
- public void createDeviceHandle(IotDevice iotDevice) throws Exception {
|
|
|
|
|
|
|
+ */
|
|
|
|
|
+ public void createDeviceHandle(IotDevice iotDevice) {
|
|
|
IotDeviceconn iotDeviceconn = deviceconnCacheService.getIotDeviceConnByDevconnBid(iotDevice.getDevconnBid());
|
|
IotDeviceconn iotDeviceconn = deviceconnCacheService.getIotDeviceConnByDevconnBid(iotDevice.getDevconnBid());
|
|
|
JSONArray connItemArray = JSONArray.parseArray(iotDeviceconn.getDevconnConfig());
|
|
JSONArray connItemArray = JSONArray.parseArray(iotDeviceconn.getDevconnConfig());
|
|
|
for (Object connItemObject : connItemArray) {
|
|
for (Object connItemObject : connItemArray) {
|
|
@@ -169,9 +171,10 @@ public class ConnectionManager {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设备删除时,删除设备连接
|
|
* 设备删除时,删除设备连接
|
|
|
- * */
|
|
|
|
|
|
|
+ */
|
|
|
public void deleteDeviceHandle(IotDevice iotDevice) {
|
|
public void deleteDeviceHandle(IotDevice iotDevice) {
|
|
|
IotDeviceconn iotDeviceconn = deviceconnCacheService.getIotDeviceConnByDevconnBid(iotDevice.getDevconnBid());
|
|
IotDeviceconn iotDeviceconn = deviceconnCacheService.getIotDeviceConnByDevconnBid(iotDevice.getDevconnBid());
|
|
|
JSONArray connItemArray = JSONArray.parseArray(iotDeviceconn.getDevconnConfig());
|
|
JSONArray connItemArray = JSONArray.parseArray(iotDeviceconn.getDevconnConfig());
|
|
@@ -205,17 +208,19 @@ public class ConnectionManager {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设备更新时,先删除旧设备连接,再创建新设备连接
|
|
* 设备更新时,先删除旧设备连接,再创建新设备连接
|
|
|
- * */
|
|
|
|
|
|
|
+ */
|
|
|
public void editDeviceHandle(IotDeviceEditMqModel iotDeviceEditMqModel) throws Exception {
|
|
public void editDeviceHandle(IotDeviceEditMqModel iotDeviceEditMqModel) throws Exception {
|
|
|
deleteDeviceHandle(iotDeviceEditMqModel.getOldIotDevice());
|
|
deleteDeviceHandle(iotDeviceEditMqModel.getOldIotDevice());
|
|
|
createDeviceHandle(iotDeviceEditMqModel.getNewIotDevice());
|
|
createDeviceHandle(iotDeviceEditMqModel.getNewIotDevice());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 连接信息创建,初始化连接信息
|
|
* 连接信息创建,初始化连接信息
|
|
|
- * */
|
|
|
|
|
- public void createIotDeviceconnHandle(IotDeviceconn iotDeviceconn){
|
|
|
|
|
|
|
+ */
|
|
|
|
|
+ public void createIotDeviceconnHandle(IotDeviceconn iotDeviceconn) {
|
|
|
log.info("【初始化】【开始】协议加载,连接名称:{},类型:{} ,配置:{}", iotDeviceconn.getDevconnName(), iotDeviceconn.getDevtypeBid(), iotDeviceconn.getDevconnConfig());
|
|
log.info("【初始化】【开始】协议加载,连接名称:{},类型:{} ,配置:{}", iotDeviceconn.getDevconnName(), iotDeviceconn.getDevtypeBid(), iotDeviceconn.getDevconnConfig());
|
|
|
//将配置信息转换成jsonObject,这是个数组
|
|
//将配置信息转换成jsonObject,这是个数组
|
|
|
JSONArray jsonConfig = parseConfigJson(iotDeviceconn.getDevconnConfig());
|
|
JSONArray jsonConfig = parseConfigJson(iotDeviceconn.getDevconnConfig());
|
|
@@ -225,16 +230,17 @@ public class ConnectionManager {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
IotDeviceconnResVo iotDeviceconnResVo = new IotDeviceconnResVo();
|
|
IotDeviceconnResVo iotDeviceconnResVo = new IotDeviceconnResVo();
|
|
|
- BeanUtils.copyProperties(iotDeviceconn,iotDeviceconnResVo);
|
|
|
|
|
|
|
+ BeanUtils.copyProperties(iotDeviceconn, iotDeviceconnResVo);
|
|
|
// 遍历多个配置
|
|
// 遍历多个配置
|
|
|
for (int j = 0; j < jsonConfig.size(); j++) {
|
|
for (int j = 0; j < jsonConfig.size(); j++) {
|
|
|
buildSingleMqttCoreByConfig(iotDeviceconnResVo, jsonConfig.getJSONObject(j));
|
|
buildSingleMqttCoreByConfig(iotDeviceconnResVo, jsonConfig.getJSONObject(j));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 连接信息删除,删除连接信息
|
|
* 连接信息删除,删除连接信息
|
|
|
- * */
|
|
|
|
|
- public void deleteIotDeviceconnHandle(IotDeviceconn iotDeviceconn){
|
|
|
|
|
|
|
+ */
|
|
|
|
|
+ public void deleteIotDeviceconnHandle(IotDeviceconn iotDeviceconn) {
|
|
|
log.info("【连接信息删除】连接名称:{},类型:{} ,配置:{}", iotDeviceconn.getDevconnName(), iotDeviceconn.getDevtypeBid(), iotDeviceconn.getDevconnConfig());
|
|
log.info("【连接信息删除】连接名称:{},类型:{} ,配置:{}", iotDeviceconn.getDevconnName(), iotDeviceconn.getDevtypeBid(), iotDeviceconn.getDevconnConfig());
|
|
|
deviceconnCacheService.deleteCache(iotDeviceconn);
|
|
deviceconnCacheService.deleteCache(iotDeviceconn);
|
|
|
//将配置信息转换成jsonObject,这是个数组
|
|
//将配置信息转换成jsonObject,这是个数组
|
|
@@ -244,7 +250,7 @@ public class ConnectionManager {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
IotDeviceconnResVo iotDeviceconnResVo = new IotDeviceconnResVo();
|
|
IotDeviceconnResVo iotDeviceconnResVo = new IotDeviceconnResVo();
|
|
|
- BeanUtils.copyProperties(iotDeviceconn,iotDeviceconnResVo);
|
|
|
|
|
|
|
+ BeanUtils.copyProperties(iotDeviceconn, iotDeviceconnResVo);
|
|
|
// 遍历多个配置
|
|
// 遍历多个配置
|
|
|
for (int j = 0; j < jsonConfig.size(); j++) {
|
|
for (int j = 0; j < jsonConfig.size(); j++) {
|
|
|
JSONObject config = jsonConfig.getJSONObject(j);
|
|
JSONObject config = jsonConfig.getJSONObject(j);
|
|
@@ -278,14 +284,21 @@ public class ConnectionManager {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 连接信息编辑,先删除连接信息,再初始化连接信息
|
|
* 连接信息编辑,先删除连接信息,再初始化连接信息
|
|
|
- * */
|
|
|
|
|
- public void editIotDeviceconnHandle(IotDeviceconn iotDeviceconn){
|
|
|
|
|
|
|
+ */
|
|
|
|
|
+ public void editIotDeviceconnHandle(IotDeviceconn iotDeviceconn) {
|
|
|
deleteIotDeviceconnHandle(iotDeviceconn);
|
|
deleteIotDeviceconnHandle(iotDeviceconn);
|
|
|
createIotDeviceconnHandle(iotDeviceconn);
|
|
createIotDeviceconnHandle(iotDeviceconn);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 对该设备进行订阅
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param iotDevice
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
private void mqttDeviceCreateHandle(IotDevice iotDevice) throws Exception {
|
|
private void mqttDeviceCreateHandle(IotDevice iotDevice) throws Exception {
|
|
|
String serviceName = typeCacheService.getServiceNameByDevTypeBid(iotDevice.getDevtypeBid());
|
|
String serviceName = typeCacheService.getServiceNameByDevTypeBid(iotDevice.getDevtypeBid());
|
|
|
String[] topics = deviceTopicService.getTopic(serviceName, iotDevice.getDevCode());
|
|
String[] topics = deviceTopicService.getTopic(serviceName, iotDevice.getDevCode());
|
|
@@ -305,6 +318,12 @@ public class ConnectionManager {
|
|
|
httpManager.deviceCreateHandle(iotDevice);
|
|
httpManager.deviceCreateHandle(iotDevice);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除该设备的订阅
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param iotDevice
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
private void mqttDeleteDeviceHandle(IotDevice iotDevice) throws Exception {
|
|
private void mqttDeleteDeviceHandle(IotDevice iotDevice) throws Exception {
|
|
|
String serviceName = typeCacheService.getServiceNameByDevTypeBid(iotDevice.getDevtypeBid());
|
|
String serviceName = typeCacheService.getServiceNameByDevTypeBid(iotDevice.getDevtypeBid());
|
|
|
String[] topics = deviceTopicService.getTopic(serviceName, iotDevice.getDevCode());
|
|
String[] topics = deviceTopicService.getTopic(serviceName, iotDevice.getDevCode());
|
|
@@ -323,5 +342,6 @@ public class ConnectionManager {
|
|
|
private void httpDeleteDeviceHandle(IotDevice iotDevice) {
|
|
private void httpDeleteDeviceHandle(IotDevice iotDevice) {
|
|
|
httpManager.deviceCreateHandle(iotDevice);
|
|
httpManager.deviceCreateHandle(iotDevice);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|