|
@@ -3,6 +3,7 @@ package com.fjhx.listener;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fjhx.enums.ProductEnum;
|
|
|
import com.fjhx.params.IotData.MessageBody;
|
|
|
+import com.fjhx.params.IotData.UpperComputerData;
|
|
|
import com.fjhx.utils.amqp.AmqpClient;
|
|
|
import com.fjhx.utils.amqp.AmqpClientOptions;
|
|
|
import com.fjhx.utils.amqp.AmqpConstants;
|
|
@@ -25,7 +26,7 @@ import java.util.List;
|
|
|
public class IotDataListener {
|
|
|
|
|
|
// 设备前缀
|
|
|
- private static final String DEVICE_PREFIX = "prefix:";
|
|
|
+ public static final String DEVICE_PREFIX = "device:";
|
|
|
|
|
|
@Resource
|
|
|
private BladeRedis redisCache;
|
|
@@ -76,24 +77,18 @@ public class IotDataListener {
|
|
|
if (body == null) {
|
|
|
return;
|
|
|
}
|
|
|
- List<MessageBody.Services> services = body.getServices();
|
|
|
+ List<MessageBody.Service> services = body.getServices();
|
|
|
if (services == null || services.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 设备id
|
|
|
- String deviceId = header.getDeviceId();
|
|
|
-
|
|
|
- switch (ProductEnum.getEnumByProductId(productId)) {
|
|
|
- case JBJ:
|
|
|
- defaultHandle(message, deviceId, services);
|
|
|
- break;
|
|
|
- case YBJ:
|
|
|
- defaultHandle(message, deviceId, services);
|
|
|
- break;
|
|
|
- default:
|
|
|
- return;
|
|
|
+ ProductEnum productEnum = ProductEnum.getEnumByProductId(productId);
|
|
|
+ if (productEnum != null) {
|
|
|
+ appointProductHandle(productEnum, message, services);
|
|
|
+ } else {
|
|
|
+ upperComputerHandle(message, services);
|
|
|
}
|
|
|
+
|
|
|
System.err.println(JSONObject.toJSONString(messageBody));
|
|
|
|
|
|
} catch (JMSException e) {
|
|
@@ -102,12 +97,45 @@ public class IotDataListener {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void defaultHandle(Message message, String deviceId, List<MessageBody.Services> services) {
|
|
|
- MessageBody.Services oldServices = redisCache.get(DEVICE_PREFIX + deviceId);
|
|
|
- MessageBody.Services newServices = services.get(0);
|
|
|
+ /**
|
|
|
+ * 指定设备处理方式
|
|
|
+ *
|
|
|
+ * @param productEnum 产品枚举
|
|
|
+ * @param message message
|
|
|
+ * @param services 设备消息列表
|
|
|
+ */
|
|
|
+ private void appointProductHandle(ProductEnum productEnum, Message message, List<MessageBody.Service> services) {
|
|
|
+ // 获取设备编号
|
|
|
+ String equipmentNo = productEnum.getEquipmentNo();
|
|
|
+ String redisKey = DEVICE_PREFIX + equipmentNo;
|
|
|
+
|
|
|
+ MessageBody.Service oldService = redisCache.get(redisKey);
|
|
|
+ MessageBody.Service newService = services.get(0);
|
|
|
+
|
|
|
+ if (oldService == null || newService.getEventTime().compareTo(oldService.getEventTime()) > 0) {
|
|
|
+ redisCache.set(redisKey, newService);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ message.acknowledge();
|
|
|
+ } catch (JMSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认处理
|
|
|
+ */
|
|
|
+ private void upperComputerHandle(Message message, List<MessageBody.Service> services) {
|
|
|
+ MessageBody.Service service = services.get(0);
|
|
|
+
|
|
|
+ UpperComputerData newData = service.getProperties().toJavaObject(UpperComputerData.class);
|
|
|
|
|
|
- if (oldServices == null || newServices.getEventTime().compareTo(oldServices.getEventTime()) > 0) {
|
|
|
- redisCache.set(DEVICE_PREFIX + deviceId, newServices);
|
|
|
+ String redisKey = DEVICE_PREFIX + newData.getEquipmentNo();
|
|
|
+ UpperComputerData oldData = redisCache.get(redisKey);
|
|
|
+
|
|
|
+ if (oldData == null || newData.getCreateTime().compareTo(oldData.getCreateTime()) > 0) {
|
|
|
+ redisCache.set(redisKey, newData);
|
|
|
}
|
|
|
|
|
|
try {
|
|
@@ -115,6 +143,7 @@ public class IotDataListener {
|
|
|
} catch (JMSException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|