From c90bfbc68527ab60a1f20cc6b21289419695e7fe Mon Sep 17 00:00:00 2001 From: xiwa Date: Fri, 22 Apr 2022 05:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=A7=E5=88=B6=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotkit/manager/service/DeviceService.java | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/manager/src/main/java/cc/iotkit/manager/service/DeviceService.java b/manager/src/main/java/cc/iotkit/manager/service/DeviceService.java index 67d01177..356950fb 100755 --- a/manager/src/main/java/cc/iotkit/manager/service/DeviceService.java +++ b/manager/src/main/java/cc/iotkit/manager/service/DeviceService.java @@ -1,12 +1,12 @@ package cc.iotkit.manager.service; -import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.NotFoundException; import cc.iotkit.common.exception.OfflineException; import cc.iotkit.common.utils.UniqueIdUtil; import cc.iotkit.comps.ComponentManager; import cc.iotkit.converter.ThingService; import cc.iotkit.dao.DeviceRepository; +import cc.iotkit.dao.ThingModelMessageRepository; import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.message.ThingModelMessage; import lombok.extern.slf4j.Slf4j; @@ -27,6 +27,8 @@ public class DeviceService { private ComponentManager componentManager; @Autowired private ThingModelService thingModelService; + @Autowired + private ThingModelMessageRepository thingModelMessageRepository; public String invokeService(String deviceId, String service, Map args) { @@ -56,7 +58,23 @@ public class DeviceService { thingModelService.parseParams(thingService); componentManager.send(thingService); - return thingService.getMid(); + String mid = thingService.getMid(); + + //保存设备日志 + ThingModelMessage thingModelMessage = ThingModelMessage.builder() + .mid(mid) + .deviceId(deviceId) + .productKey(device.getProductKey()) + .deviceName(device.getDeviceName()) + .type(ThingModelMessage.TYPE_SERVICE) + .identifier(service) + .data(args) + .occurred(System.currentTimeMillis()) + .time(System.currentTimeMillis()) + .build(); + thingModelMessageRepository.save(thingModelMessage); + + return mid; } public String setProperty(String deviceId, Map properties) { @@ -86,7 +104,23 @@ public class DeviceService { thingModelService.parseParams(thingService); componentManager.send(thingService); - return thingService.getMid(); + String mid = thingService.getMid(); + + //保存设备日志 + ThingModelMessage thingModelMessage = ThingModelMessage.builder() + .mid(mid) + .deviceId(deviceId) + .productKey(device.getProductKey()) + .deviceName(device.getDeviceName()) + .type(ThingModelMessage.TYPE_PROPERTY) + .identifier("set") + .data(properties) + .occurred(System.currentTimeMillis()) + .time(System.currentTimeMillis()) + .build(); + thingModelMessageRepository.save(thingModelMessage); + + return mid; } }