|
@@ -6,9 +6,11 @@ import com.fjhx.params.IotData.MessageBody;
|
|
|
import com.fjhx.utils.amqp.AmqpClient;
|
|
|
import com.fjhx.utils.amqp.AmqpClientOptions;
|
|
|
import com.fjhx.utils.amqp.AmqpConstants;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.jms.JMSException;
|
|
|
import javax.jms.Message;
|
|
|
import javax.jms.MessageConsumer;
|
|
@@ -22,6 +24,12 @@ import java.util.List;
|
|
|
@Component
|
|
|
public class IotDataListener {
|
|
|
|
|
|
+ // 设备前缀
|
|
|
+ private static final String DEVICE_PREFIX = "prefix:";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BladeRedis redisCache;
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void listener() throws Exception {
|
|
|
AmqpClientOptions options = AmqpClientOptions.builder()
|
|
@@ -73,18 +81,36 @@ public class IotDataListener {
|
|
|
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;
|
|
|
}
|
|
|
System.err.println(JSONObject.toJSONString(messageBody));
|
|
|
+
|
|
|
+ } catch (JMSException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if (oldServices == null || newServices.getEventTime().compareTo(oldServices.getEventTime()) > 0) {
|
|
|
+ redisCache.set(DEVICE_PREFIX + deviceId, newServices);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
message.acknowledge();
|
|
|
} catch (JMSException e) {
|
|
|
e.printStackTrace();
|