|
@@ -12,7 +12,10 @@ package cc.iotkit.comps.service;
|
|
import cc.iotkit.common.Constants;
|
|
import cc.iotkit.common.Constants;
|
|
import cc.iotkit.common.utils.JsonUtil;
|
|
import cc.iotkit.common.utils.JsonUtil;
|
|
import cc.iotkit.data.IDeviceInfoData;
|
|
import cc.iotkit.data.IDeviceInfoData;
|
|
|
|
+import cc.iotkit.data.IThingModelData;
|
|
|
|
+import cc.iotkit.model.device.DeviceInfo;
|
|
import cc.iotkit.model.device.message.ThingModelMessage;
|
|
import cc.iotkit.model.device.message.ThingModelMessage;
|
|
|
|
+import cc.iotkit.model.product.ThingModel;
|
|
import cc.iotkit.mq.ConsumerHandler;
|
|
import cc.iotkit.mq.ConsumerHandler;
|
|
import cc.iotkit.mq.MqConsumer;
|
|
import cc.iotkit.mq.MqConsumer;
|
|
import cc.iotkit.temporal.IDevicePropertyData;
|
|
import cc.iotkit.temporal.IDevicePropertyData;
|
|
@@ -22,7 +25,9 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 设备属性消息消费入库
|
|
* 设备属性消息消费入库
|
|
@@ -38,6 +43,9 @@ public class DevicePropertyConsumer implements ConsumerHandler<ThingModelMessage
|
|
@Autowired
|
|
@Autowired
|
|
@Qualifier("deviceInfoDataCache")
|
|
@Qualifier("deviceInfoDataCache")
|
|
private IDeviceInfoData deviceInfoData;
|
|
private IDeviceInfoData deviceInfoData;
|
|
|
|
+ @Autowired
|
|
|
|
+ @Qualifier("thingModelDataCache")
|
|
|
|
+ private IThingModelData thingModelData;
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
public void init() {
|
|
public void init() {
|
|
@@ -52,13 +60,36 @@ public class DevicePropertyConsumer implements ConsumerHandler<ThingModelMessage
|
|
|
|
|
|
Map<String, Object> properties = (Map<String, Object>) msg.getData();
|
|
Map<String, Object> properties = (Map<String, Object>) msg.getData();
|
|
String deviceId = msg.getDeviceId();
|
|
String deviceId = msg.getDeviceId();
|
|
|
|
+ DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId);
|
|
|
|
+ if (deviceInfo == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //物模型校验,过滤非物模型属性
|
|
|
|
+ ThingModel thingModel = thingModelData.findById(deviceInfo.getProductKey());
|
|
|
|
+ if (thingModel == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //物模型属性
|
|
|
|
+ Map<String, String> thingModelProperties = thingModel.getModel().
|
|
|
|
+ getProperties().stream().collect(Collectors.toMap(
|
|
|
|
+ ThingModel.Property::getIdentifier, ThingModel.Property::getName));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> addProperties = new HashMap<>();
|
|
|
|
+ //删除非属性字段
|
|
|
|
+ properties.forEach((key,val)->{
|
|
|
|
+ if (thingModelProperties.containsKey(key)) {
|
|
|
|
+ addProperties.put(key,val);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
//更新设备当前属性
|
|
//更新设备当前属性
|
|
- updateDeviceCurrentProperties(deviceId, properties);
|
|
|
|
|
|
+ updateDeviceCurrentProperties(deviceId, addProperties);
|
|
|
|
|
|
//保存属性记录
|
|
//保存属性记录
|
|
try {
|
|
try {
|
|
- devicePropertyData.addProperties(deviceId, properties, msg.getOccurred());
|
|
|
|
|
|
+ devicePropertyData.addProperties(deviceId, addProperties, msg.getOccurred());
|
|
} catch (Throwable e) {
|
|
} catch (Throwable e) {
|
|
log.warn("save property data error", e);
|
|
log.warn("save property data error", e);
|
|
}
|
|
}
|