|
@@ -1,6 +1,7 @@
|
|
package com.fjhx.listener;
|
|
package com.fjhx.listener;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fjhx.constants.RedisConstant;
|
|
import com.fjhx.enums.ProductEnum;
|
|
import com.fjhx.enums.ProductEnum;
|
|
import com.fjhx.params.IotData.MessageBody;
|
|
import com.fjhx.params.IotData.MessageBody;
|
|
import com.fjhx.params.IotData.UpperComputerData;
|
|
import com.fjhx.params.IotData.UpperComputerData;
|
|
@@ -25,9 +26,6 @@ import java.util.List;
|
|
@Component
|
|
@Component
|
|
public class IotDataListener {
|
|
public class IotDataListener {
|
|
|
|
|
|
- // 设备前缀
|
|
|
|
- public static final String DEVICE_PREFIX = "device:";
|
|
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private BladeRedis redisCache;
|
|
private BladeRedis redisCache;
|
|
|
|
|
|
@@ -107,7 +105,7 @@ public class IotDataListener {
|
|
private void appointProductHandle(ProductEnum productEnum, Message message, List<MessageBody.Service> services) {
|
|
private void appointProductHandle(ProductEnum productEnum, Message message, List<MessageBody.Service> services) {
|
|
// 获取设备编号
|
|
// 获取设备编号
|
|
String equipmentNo = productEnum.getEquipmentNo();
|
|
String equipmentNo = productEnum.getEquipmentNo();
|
|
- String redisKey = DEVICE_PREFIX + equipmentNo;
|
|
|
|
|
|
+ String redisKey = RedisConstant.DEVICE_PREFIX + equipmentNo;
|
|
|
|
|
|
MessageBody.Service oldService = redisCache.get(redisKey);
|
|
MessageBody.Service oldService = redisCache.get(redisKey);
|
|
MessageBody.Service newService = services.get(0);
|
|
MessageBody.Service newService = services.get(0);
|
|
@@ -124,14 +122,14 @@ public class IotDataListener {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 默认处理
|
|
|
|
|
|
+ * 上位机连接设备处理
|
|
*/
|
|
*/
|
|
private void upperComputerHandle(Message message, List<MessageBody.Service> services) {
|
|
private void upperComputerHandle(Message message, List<MessageBody.Service> services) {
|
|
MessageBody.Service service = services.get(0);
|
|
MessageBody.Service service = services.get(0);
|
|
|
|
|
|
UpperComputerData newData = service.getProperties().toJavaObject(UpperComputerData.class);
|
|
UpperComputerData newData = service.getProperties().toJavaObject(UpperComputerData.class);
|
|
|
|
|
|
- String redisKey = DEVICE_PREFIX + newData.getEquipmentNo();
|
|
|
|
|
|
+ String redisKey = RedisConstant.DEVICE_PREFIX + newData.getEquipmentNo();
|
|
UpperComputerData oldData = redisCache.get(redisKey);
|
|
UpperComputerData oldData = redisCache.get(redisKey);
|
|
|
|
|
|
if (oldData == null || newData.getCreateTime().compareTo(oldData.getCreateTime()) > 0) {
|
|
if (oldData == null || newData.getCreateTime().compareTo(oldData.getCreateTime()) > 0) {
|