|
|
@@ -7,12 +7,14 @@ import com.coffee.aliyun.utils.Constants;
|
|
|
import com.coffee.aliyun.utils.Items;
|
|
|
import com.coffee.bus.bean.AliIotConfig;
|
|
|
import com.coffee.bus.entity.BusDeviceEntity;
|
|
|
+import com.coffee.bus.entity.BusDeviceHistoryEntity;
|
|
|
import com.coffee.bus.entity.BusDeviceRunningEntity;
|
|
|
import com.coffee.bus.entity.BusInfusionHistoryEntity;
|
|
|
-import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
|
|
|
+import com.coffee.bus.service.LocalBusDeviceHistoryService;
|
|
|
import com.coffee.bus.service.LocalBusDeviceService;
|
|
|
import com.coffee.bus.service.LocalBusInfusionHistoryService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
@@ -48,7 +50,9 @@ public class AliyunConsumerGroupService {
|
|
|
@Lazy
|
|
|
private LocalBusInfusionHistoryService infusionHistoryService;
|
|
|
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private LocalBusDeviceHistoryService deviceHistoryService;
|
|
|
|
|
|
@Value("${aliyun.server-subscription.enable:false}")
|
|
|
private boolean isEnable;
|
|
|
@@ -127,48 +131,33 @@ public class AliyunConsumerGroupService {
|
|
|
Date now = new Date();
|
|
|
// 根据topic判断数据类型
|
|
|
if (topic.matches("^/as/mqtt/status/[\\w\\/]*")){//设备上下线状态
|
|
|
+ BusDeviceEntity device = new BusDeviceEntity();
|
|
|
+ device.setDeviceId(deviceName);
|
|
|
String status = content.getString(STATUS);
|
|
|
if (status.equals("online")){
|
|
|
log.info(deviceName+"设备上线");
|
|
|
+ device.setStatus(1);
|
|
|
}else if (status.equals("offline")){
|
|
|
log.info(deviceName+"设备下线");
|
|
|
+ device.setStatus(2);
|
|
|
}else {
|
|
|
log.info(deviceName+"设备未激活");
|
|
|
+ device.setStatus(0);
|
|
|
}
|
|
|
+ // 更新设备状态
|
|
|
+ deviceService.updateByDeviceId(device);
|
|
|
}else if (topic.matches("[\\w\\/]*event/property/post$")){//设备属性上报
|
|
|
- /**
|
|
|
- * platformData:
|
|
|
- * {
|
|
|
- * "topic":"/a1M7k1TAECc/ceshi001/thing/event/property/post",
|
|
|
- * "messageId":"1496410088574460416",
|
|
|
- * "content":"{\"deviceType\":\"CustomCategory\",
|
|
|
- * \"iotId\":\"0syOzMqwkGebZBGKa08d000000\",
|
|
|
- * \"requestId\":\"254\",\"checkFailedData\":{},
|
|
|
- * \"productKey\":\"a1M7k1TAECc\",\"gmtCreate\":1645606941721,
|
|
|
- * \"deviceName\":\"ceshi001\",
|
|
|
- * \"items\":{
|
|
|
- * \"total\":{\"value\":100,\"time\":1645606941717},
|
|
|
- * \"pumpCode\":{\"value\":\"5719512336330299\",\"time\":1645606941717},
|
|
|
- * \"dataNumber\":{\"value\":254,\"time\":1645606941717},
|
|
|
- * \"PCAInvalid\":{\"value\":0,\"time\":1645606941717},
|
|
|
- * \"alarm\":{\"value\":0,\"time\":1645606941717},
|
|
|
- * \"flowRate\":{\"value\":2,\"time\":1645606941717},
|
|
|
- * \"PCAValid\":{\"value\":0,\"time\":1645606941717},
|
|
|
- * \"forecast\":{\"value\":0,\"time\":1645606941717},
|
|
|
- * \"finished\":{\"value\":17,\"time\":1645606941717},
|
|
|
- * \"battery\":{\"value\":65,\"time\":1645606941717},
|
|
|
- * \"runStatus\":{\"value\":2,\"time\":1645606941717},
|
|
|
- * \"patientCode\":{\"value\":111110000,\"time\":1645606941717}}}"
|
|
|
- * }
|
|
|
- */
|
|
|
// 设备属性集合
|
|
|
Items items = new Items(content.getJSONObject("items"));
|
|
|
BusInfusionHistoryEntity infusionHistory = infusionHistoryService.saveInfusion(deviceName,items);
|
|
|
-
|
|
|
-
|
|
|
- // 发布设备信息事件。处理完毕,传向下一步处理
|
|
|
- DeviceInfoEvent deviceInfoEvent = new DeviceInfoEvent(this,new BusDeviceRunningEntity(),"123456");
|
|
|
- SpringUtil.publishEvent(deviceInfoEvent);
|
|
|
+ // 保存到device_history表中
|
|
|
+ BusDeviceHistoryEntity deviceHistory = new BusDeviceHistoryEntity();
|
|
|
+ // 将infusionHistory对象的值,复制到deviceHistory对象
|
|
|
+ BeanUtils.copyProperties(infusionHistory,deviceHistory);
|
|
|
+ deviceHistory.setId(null);
|
|
|
+ deviceHistory.setInfusionId(infusionHistory.getId());
|
|
|
+ // 保存设备的历史数据
|
|
|
+ deviceHistoryService.save(deviceHistory);
|
|
|
|
|
|
}else if(topic.matches("[\\w\\/]+thing/lifecycle$")){// 设备生命周期
|
|
|
// 获取生命周期类型
|
|
|
@@ -197,8 +186,6 @@ public class AliyunConsumerGroupService {
|
|
|
deviceService.removeByDeviceId(deviceName);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}else {
|
|
|
log.error("未知的topic:"+topic);
|
|
|
}
|