TRX 1 gadu atpakaļ
vecāks
revīzija
3432b54a33

+ 2 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/OperationMessageController.java

@@ -52,7 +52,8 @@ public class OperationMessageController {
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "指令列表-分页查询")
     @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
-    public ResultContent<Page<OperationMessageModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) OperationMessageSearchParam param) {
+    public ResultContent<Page<OperationMessageModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) OperationMessageSearchParam param) {
         return operationMessageService.page(pageable, param);
     }
 

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/IotThing2DeviceDao.java

@@ -24,4 +24,5 @@ public interface IotThing2DeviceDao extends IotThing2DeviceDaoExtend, MongoRepos
 
     IotThing2Device findTopByIotThingIdAndDeviceId(String iotThingId, String deviceId);
 
+    List<IotThing2Device> findByIotThingIdOrderByCreateTimeDesc(String iotThingId);
 }

+ 12 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -85,6 +85,9 @@ public class IotServiceImpl extends SuperService {
     @Autowired
     private IotDeviceDataService iotDeviceDataService;
 
+    @Autowired
+    private IotThing2DeviceService iotThing2DeviceService;
+
     //----------------------------- 产品 start----------------------------
 
     /**
@@ -414,10 +417,19 @@ public class IotServiceImpl extends SuperService {
             if (iotThing == null) {
                 return ResultContent.buildFail(String.format("物模型不存在:%s", param.getIotThingId()));
             }
+
             aboutDataId = param.getIotThingId();
             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不能为空");
                 }

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

@@ -186,6 +186,14 @@ 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("物模型未绑定设备");
+        }
+        return ResultContent.buildSuccess(list.get(0).getDeviceId());
+    }
+
     public IotThing2DeviceModel toModel(IotThing2Device entity) {
         IotThing2DeviceModel model = null;
         if (entity != null) {