TRX 1 anno fa
parent
commit
980db95f07

+ 18 - 6
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotTemplate2DeviceController.java

@@ -3,6 +3,8 @@ package com.zhongshu.iot.server.core.controller.iot;
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.base.IDParam;
+import com.zhongshu.card.client.model.base.IDsParam;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceModel;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceParam;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceSearch;
@@ -15,7 +17,10 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.web.PageableDefault;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * 模版绑定的 设备管理
@@ -33,7 +38,7 @@ public class IotTemplate2DeviceController {
     private IotTemplate2DeviceService iotTemplate2DeviceService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "模版绑定设备")
+    @Operation(summary = "模版绑定设备(多个)")
     @RequestMapping(value = "templateBindDevices", method = {RequestMethod.POST})
     public ResultContent templateBindDevices(@RequestBody IotTemplate2DeviceParam param) {
         return iotTemplate2DeviceService.templateBindDevices(param);
@@ -49,10 +54,17 @@ public class IotTemplate2DeviceController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "删除模版绑定设备")
-    @RequestMapping(value = "delete", method = {RequestMethod.GET})
-    public ResultContent delete(@RequestParam(name = "id") @Parameter(name = "id", description = "数据id") String id) {
-        return iotTemplate2DeviceService.delete(id);
+    @Operation(summary = "删除模版绑定设备(单个)")
+    @RequestMapping(value = "delete", method = {RequestMethod.POST})
+    public ResultContent delete(@RequestBody IDParam param) {
+        return iotTemplate2DeviceService.delete(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "删除模版绑定设备(多个)")
+    @RequestMapping(value = "deletes", method = {RequestMethod.POST})
+    public ResultContent deletes(@RequestBody IDsParam param) {
+        return iotTemplate2DeviceService.deletes(param);
     }
 
 }

+ 16 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotTemplate2DeviceService.java

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.service.iot;
 
 import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.base.IDsParam;
 import com.zhongshu.iot.client.model.iot.DeviceBindIotTemplate;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceModel;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceParam;
@@ -133,6 +134,21 @@ public class IotTemplate2DeviceService {
         return ResultContent.buildSuccess();
     }
 
+    public ResultContent deletes(IDsParam param) {
+        IotTemplate2Device iotTemplate2Device = iotTemplate2DeviceDao.findTopById(id);
+        if (ObjectUtils.isEmpty(iotTemplate2Device)) {
+            return ResultContent.buildFail("数据不存在");
+        }
+        iotTemplate2DeviceDao.delete(iotTemplate2Device);
+
+        IotTemplate iotTemplate = iotTemplate2Device.getIotTemplate();
+        // 删除物模型
+        if (ObjectUtils.isNotEmpty(iotTemplate)) {
+            iotService.deleteTemplate(iotTemplate.getId());
+        }
+        return ResultContent.buildSuccess();
+    }
+
     public IotTemplate2DeviceModel toModel(IotTemplate2Device entity) {
         IotTemplate2DeviceModel model = new IotTemplate2DeviceModel();
         if (ObjectUtils.isNotEmpty(entity)) {