|
|
@@ -4,6 +4,8 @@ import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.nb.aliyun.service.bean.AliIotMessagePojo;
|
|
|
import com.nb.aliyun.service.process.DeviceMsgHandler;
|
|
|
+import com.nb.web.api.entity.BusDeviceEntity;
|
|
|
+import com.nb.web.api.feign.IDeviceClient;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
@@ -27,10 +29,12 @@ public class AliyunConsumerGroupService implements CommandLineRunner {
|
|
|
|
|
|
private final DeviceMsgHandler deviceMsgHandler;
|
|
|
|
|
|
+ private final IDeviceClient deviceService;
|
|
|
|
|
|
- public AliyunConsumerGroupService(AliyunIotSubscribeClient client, DeviceMsgHandler deviceMsgHandler) {
|
|
|
+ public AliyunConsumerGroupService(AliyunIotSubscribeClient client, DeviceMsgHandler deviceMsgHandler,IDeviceClient deviceService) {
|
|
|
this.client = client;
|
|
|
this.deviceMsgHandler = deviceMsgHandler;
|
|
|
+ this.deviceService=deviceService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -101,7 +105,9 @@ public class AliyunConsumerGroupService implements CommandLineRunner {
|
|
|
String messageId = message.getStringProperty(AliIotConstant.MESSAGE_ID);
|
|
|
JSONObject content = JSONUtil.parseObj(new String(message.getBody(byte[].class)));
|
|
|
log.info("阿里云物联网发送的数据:"+content.toString());
|
|
|
- AliIotMessagePojo msg = AliIotMessagePojo.of(topic, messageId, content);
|
|
|
+ String deviceName = content.getStr(AliIotConstant.DEVICE_NAME);
|
|
|
+ BusDeviceEntity device = deviceService.getByDeviceId(deviceName);
|
|
|
+ AliIotMessagePojo msg = AliIotMessagePojo.of(topic, messageId, content,device);
|
|
|
deviceMsgHandler.handleMessage(msg,true);
|
|
|
} catch (Exception e) {
|
|
|
log.error("阿里云数据【{}】处理失败 ", JSONUtil.toJsonStr(message), e);
|