TRX 1 жил өмнө
parent
commit
965a7fe09e

+ 17 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainModel.java

@@ -1,5 +1,6 @@
 package com.zhongshu.iot.client.model.iot;
 
+import com.github.microservice.busInfoModel.device.DeviceInfoSimpleModel;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.models.baseParam.SuperModel;
 import com.zhongshu.iot.client.type.DataType;
@@ -10,6 +11,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -29,6 +31,21 @@ public class IotMainModel extends SuperModel {
     @Schema(description = "关联code,产品code")
     private String productCode;
 
+    @Schema(description = "关联的设备")
+    private String deviceId;
+
+    @Schema(description = "")
+    private String deviceName;
+
+    private DeviceInfoSimpleModel deviceInfo;
+
+    public String getDeviceName() {
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+            return deviceInfo.getDeviceName();
+        }
+        return "";
+    }
+
     @Schema(description = "功能名称")
     private String name;
 

+ 14 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java

@@ -2,6 +2,7 @@ package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.busInfoModel.device.DeviceInfoModel;
 import com.github.microservice.busInfoModel.device.DeviceInfoMoreModel;
+import com.github.microservice.busInfoModel.device.DeviceInfoSimpleModel;
 import com.github.microservice.busInfoModel.device.IotTemplateSimpleModel;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.net.ResultMessage;
@@ -468,6 +469,11 @@ public class DeviceInfoService {
         return toModel(deviceInfo);
     }
 
+    public DeviceInfoSimpleModel toSimpleModel(String deviceId) {
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        return toSimpleModel(deviceInfo);
+    }
+
     public DeviceInfoModel toModel(DeviceInfo deviceInfo) {
         DeviceInfoModel deviceInfoModel = new DeviceInfoModel();
         if (ObjectUtils.isNotEmpty(deviceInfo)) {
@@ -482,6 +488,14 @@ public class DeviceInfoService {
         return deviceInfoModel;
     }
 
+    public DeviceInfoSimpleModel toSimpleModel(DeviceInfo deviceInfo) {
+        DeviceInfoSimpleModel deviceInfoModel = new DeviceInfoSimpleModel();
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+            BeanUtils.copyProperties(deviceInfo, deviceInfoModel);
+        }
+        return deviceInfoModel;
+    }
+
     public DeviceInfoMoreModel toMoreModel(DeviceInfo deviceInfo) {
         DeviceInfoMoreModel deviceInfoModel = new DeviceInfoMoreModel();
         if (ObjectUtils.isNotEmpty(deviceInfo)) {

+ 7 - 8
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -422,17 +422,13 @@ public class IotServiceImpl extends SuperService {
             if (iotThing.getThingType() == ThingType.Auto) {
                 deviceInfo = deviceInfoDao.findTopByDeviceId(iotThing.getDeviceId());
             } else if (iotThing.getThingType() == ThingType.Manual) {
-                //手动创建 找出一个设备
-                if (StringUtils.isEmpty(param.getDeviceId())) {
-                    ResultContent<String> resultContent = iotThing2DeviceService.getIotFirstDevice(param.getIotThingId());
-                    if (resultContent.isFailed()) {
-                        return ResultContent.buildFail(resultContent.getMsg());
-                    }
-                    param.setDeviceId(resultContent.getContent());
-                }
                 if (StringUtils.isEmpty(param.getDeviceId())) {
                     return ResultContent.buildFail("手动创建的物模型deviceId不能为空");
                 }
+                ResultContent resultContent = iotThing2DeviceService.checkIotDeviceBind(param.getIotThingId(), param.getDeviceId());
+                if (resultContent.isFailed()) {
+                    return ResultContent.buildFail(resultContent.getMsg());
+                }
                 deviceInfo = deviceInfoDao.findTopByDeviceId(param.getDeviceId());
             }
             if (deviceInfo == null) {
@@ -695,6 +691,9 @@ public class IotServiceImpl extends SuperService {
             model = new IotMainAttributeModel();
             BeanUtils.copyProperties(entity, model);
 
+            // 设备信息
+            model.setDeviceInfo(deviceInfoService.toSimpleModel(entity.getDeviceId()));
+
             // 属性值
             if (entity.getFunctionType() == FunctionType.Attribute && entity.getIotDataType() == IotDataType.Device) {
                 model.setValue(iotDeviceDataService.getDevicePropertyModel(entity.getDeviceId(), entity.getIdentifier()));

+ 5 - 5
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotThing2DeviceService.java

@@ -186,12 +186,12 @@ public class IotThing2DeviceService extends SuperService {
         return iotThing2DeviceDao.findByIotThingId(iotThingId);
     }
 
-    public ResultContent<String> getIotFirstDevice(String iotThingId) {
-        List<IotThing2Device> list = iotThing2DeviceDao.findByIotThingIdOrderByCreateTimeDesc(iotThingId);
-        if (ObjectUtils.isEmpty(list)) {
-            return ResultContent.buildFail("物模型未绑定设备");
+    public ResultContent checkIotDeviceBind(String iotThingId, String deviceId) {
+        IotThing2Device iotThing2Device = iotThing2DeviceDao.findTopByIotThingIdAndDeviceId(iotThingId, deviceId);
+        if (ObjectUtils.isEmpty(iotThing2Device)) {
+            return ResultContent.buildFail(String.format("物模型未绑定设备"));
         }
-        return ResultContent.buildSuccess(list.get(0).getDeviceId());
+        return ResultContent.buildSuccess();
     }
 
     public IotThing2DeviceModel toModel(IotThing2Device entity) {