From 988442b22b0a4999e27bd61580e3d852a4ae0714 Mon Sep 17 00:00:00 2001 From: xiwa Date: Wed, 23 Mar 2022 05:34:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E7=8C=AB=E6=8E=A5=E5=85=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/iotkit/dao/AligenieProductRepository.java | 2 ++ .../controller/aligenie/AligenieDeviceController.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dao/src/main/java/cc/iotkit/dao/AligenieProductRepository.java b/dao/src/main/java/cc/iotkit/dao/AligenieProductRepository.java index af13b620..00965923 100755 --- a/dao/src/main/java/cc/iotkit/dao/AligenieProductRepository.java +++ b/dao/src/main/java/cc/iotkit/dao/AligenieProductRepository.java @@ -10,4 +10,6 @@ import java.util.List; public interface AligenieProductRepository extends MongoRepository { List findByUid(String uid); + + AligenieProduct findByProductKey(String productKey); } diff --git a/manager/src/main/java/cc/iotkit/manager/controller/aligenie/AligenieDeviceController.java b/manager/src/main/java/cc/iotkit/manager/controller/aligenie/AligenieDeviceController.java index 12d3fb34..2492c6a2 100755 --- a/manager/src/main/java/cc/iotkit/manager/controller/aligenie/AligenieDeviceController.java +++ b/manager/src/main/java/cc/iotkit/manager/controller/aligenie/AligenieDeviceController.java @@ -1,12 +1,12 @@ package cc.iotkit.manager.controller.aligenie; import cc.iotkit.common.exception.BizException; -import cc.iotkit.dao.AligenieDeviceRepository; -import cc.iotkit.dao.DeviceRepository; -import cc.iotkit.dao.UserInfoRepository; +import cc.iotkit.dao.*; import cc.iotkit.manager.service.DataOwnerService; import cc.iotkit.model.UserInfo; import cc.iotkit.model.aligenie.AligenieDevice; +import cc.iotkit.model.aligenie.AligenieProduct; +import cc.iotkit.model.device.DeviceInfo; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -26,6 +26,8 @@ public class AligenieDeviceController { private DataOwnerService ownerService; @Autowired private DeviceRepository deviceRepository; + @Autowired + private AligenieProductRepository aligenieProductRepository; @GetMapping("/list/{uid}") public List getDevices(@PathVariable("uid") String uid) { @@ -46,9 +48,12 @@ public class AligenieDeviceController { aligenieDeviceRepository.deleteByUid(uid); for (Device device : devices) { + DeviceInfo deviceInfo = deviceRepository.findById(device.getDeviceId()).get(); + AligenieProduct product = aligenieProductRepository.findByProductKey(deviceInfo.getProductKey()); aligenieDeviceRepository.save(AligenieDevice.builder() .uid(uid) .deviceId(device.getDeviceId()) + .productId(product.getProductId()) .spaceName("客厅") .name(device.getName()) .build());