|
|
@@ -1,5 +1,6 @@
|
|
|
package com.coffee.aliyun;
|
|
|
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -137,23 +138,21 @@ public class AliyunConsumerGroupService {
|
|
|
|
|
|
private void processMessage(Message message) {
|
|
|
|
|
|
- Map<String, Object> platformData = new HashMap<>();
|
|
|
+
|
|
|
BusHospitalLogEntity hospitalLog = new BusHospitalLogEntity();
|
|
|
hospitalLog.setType(HospitalLogEnum.ALI);
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
+ String deviceName=null;
|
|
|
try {
|
|
|
// 获取主题,消息id和内容
|
|
|
String topic = message.getStringProperty(TOPIC);
|
|
|
String messageId = message.getStringProperty(MESSAGEID);
|
|
|
+ hospitalLog.setMsgId(messageId);
|
|
|
JSONObject content = JSON.parseObject(new String(message.getBody(byte[].class)));
|
|
|
- // 平台数据
|
|
|
- platformData.put(TOPIC,topic);
|
|
|
- platformData.put(MESSAGEID,messageId);
|
|
|
- platformData.put(CONTENT,content);
|
|
|
- log.info("阿里云物联网发送的数据:"+JSON.toJSONString(platformData));
|
|
|
+ log.info("阿里云物联网发送的数据:"+JSON.toJSONString(content));
|
|
|
|
|
|
// 设备名称
|
|
|
- String deviceName = content.getString(DEVICENAME);
|
|
|
+ deviceName = content.getString(DEVICENAME);
|
|
|
|
|
|
hospitalLog.setIdentityCode(deviceName);
|
|
|
hospitalLog.setInput(content.toJSONString());
|
|
|
@@ -216,9 +215,13 @@ public class AliyunConsumerGroupService {
|
|
|
hospitalLog.setMessage(e.toString());
|
|
|
log.error("阿里云数据【{}】数据处理失败 ", JSONUtil.toJsonStr(message), e);
|
|
|
}finally {
|
|
|
- long entTime = System.currentTimeMillis();
|
|
|
- hospitalLog.setUseTime(entTime-startTime);
|
|
|
- hospitalLogService.save(hospitalLog);
|
|
|
+ if(CharSequenceUtil.isNotBlank(deviceName)){
|
|
|
+ BusDeviceEntity device = deviceService.getByDeviceId(deviceName);
|
|
|
+ long entTime = System.currentTimeMillis();
|
|
|
+ hospitalLog.setTenantId(device.getTenantId());
|
|
|
+ hospitalLog.setUseTime(entTime-startTime);
|
|
|
+ hospitalLogService.save(hospitalLog);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|