From 62fe672ec2946b42c2224227fba51371c6d48fd5 Mon Sep 17 00:00:00 2001 From: jay <75509151@qq.com> Date: Tue, 6 Jun 2023 11:52:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20=E6=8E=A5=E5=8F=A3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/controller/DeviceController.java | 29 ++++---- .../manager/controller/ProductController.java | 12 ++-- .../controller/ProtocolController.java | 29 ++++---- .../controller/RuleEngineController.java | 8 +-- .../controller/VirtualDeviceController.java | 72 +++++++++++++------ .../dto/bo/device/DeviceConsumerBo.java | 26 +++++++ .../dto/bo/device/DeviceQueryByPkDnBo.java | 29 ++++++++ .../dto/bo/device/DeviceSaveScriptBo.java | 26 +++++++ .../virtualdevice/VirtualSaveDevicesBo.java | 28 ++++++++ 9 files changed, 198 insertions(+), 61 deletions(-) create mode 100644 iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java create mode 100644 iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java create mode 100644 iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java create mode 100644 iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java index c24beb3a..489f622a 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java @@ -133,15 +133,14 @@ public class DeviceController { @ApiOperation("获取设备详情") @PostMapping(Constants.API_DEVICE.DETAIL) - public DeviceInfo getDetail(@PathVariable("deviceId") String deviceId) { - return deviceServiceImpl.getDetail(deviceId); + public DeviceInfo getDetail(@PathVariable("deviceId") Request deviceId) { + return deviceServiceImpl.getDetail(deviceId.getData()); } @ApiOperation("获取设备详情") - @PostMapping("/{pk}/{dn}") - public DeviceInfo getByPkDn(@PathVariable("pk") String pk, - @PathVariable("dn") String dn) { - return deviceServiceImpl.getByPkDn(pk, dn); + @PostMapping("/getByPkDn") + public DeviceInfo getByPkDn(@Validated @RequestBody Request query) { + return deviceServiceImpl.getByPkDn(query.getData().getPk(), query.getData().getDn()); } @ApiOperation("删除设备") @@ -178,7 +177,7 @@ public class DeviceController { @PostMapping("/getThingModel") public ThingModelVo getThingModel(@Validated @RequestBody Request request) { String deviceId = request.getData(); - DeviceInfo deviceInfo = getDetail(deviceId); + DeviceInfo deviceInfo = deviceServiceImpl.getDetail(deviceId); return productService.getThingModelByProductKey(deviceInfo.getProductKey()); } @@ -198,14 +197,12 @@ public class DeviceController { /** * 消费设备信息消息(实时推送设备信息) */ - @PostMapping("/{deviceId}/consumer/{clientId}") + @PostMapping("/consumer") public DeferredResult consumerDeviceInfo( - @PathVariable("deviceId") String deviceId, - @PathVariable("clientId") String clientId + @Validated @RequestBody Request bo ) { - - return deviceServiceImpl.addConsumer(deviceId, clientId); - + DeviceConsumerBo data = bo.getData(); + return deviceServiceImpl.addConsumer(data.getDeviceId(), data.getClientId()); } /** @@ -298,8 +295,10 @@ public class DeviceController { /** * 设备配置下发 */ - @PostMapping("/config/{deviceId}/send") - public InvokeResult sendConfig(@PathVariable("deviceId") String deviceId) { + @ApiOperation(value = "设备配置下发") + @PostMapping("/config/send") + public InvokeResult sendConfig(@Validated @RequestBody Request bo) { + String deviceId = bo.getData(); return new InvokeResult(deviceService.sendConfig(deviceId)); } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java index 40154380..13800a9e 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java @@ -110,9 +110,9 @@ public class ProductController { @SaCheckRole("iot_admin") @ApiOperation("品类编辑") @PostMapping("/category/edit") - public boolean saveCategory(@Validated @RequestBody CategoryBo req) { + public boolean saveCategory(@Validated @RequestBody Request req) { - return productService.editCategory(req); + return productService.editCategory(req.getData()); } @SaCheckRole("iot_admin") @@ -131,13 +131,13 @@ public class ProductController { @PostMapping("/getModelsByProductKey") @ApiModelProperty("获取产品型号") - public List getModels(String productKey) { - return productService.getModels(productKey); + public List getModels(@Validated @RequestBody Request bo) { + return productService.getModels(bo.getData()); } @PostMapping("/productModel/edit") @ApiOperation("编辑产品型号") - public boolean saveProductModel(ProductModelBo productModel) { - return productService.editProductModel(productModel); + public boolean saveProductModel(@Validated @RequestBody Request bo) { + return productService.editProductModel(bo.getData()); } } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java index a7b40cf4..5459b006 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java @@ -66,14 +66,14 @@ public class ProtocolController { @ApiOperation("添加组件") @PostMapping("/addComponent") - public boolean addComponent(@RequestBody @Validated ProtocolComponentBo component) { - return protocolService.addComponent(component); + public boolean addComponent(@RequestBody @Validated Request bo) { + return protocolService.addComponent(bo.getData()); } @ApiOperation("修改组件") @PostMapping("/editComponent") - public String saveComponent(@RequestBody @Validated ProtocolComponentBo component) { - return protocolService.saveComponent(component); + public String saveComponent(@RequestBody @Validated Request bo) { + return protocolService.saveComponent(bo.getData()); } @ApiOperation("获取组件详情") @@ -87,8 +87,8 @@ public class ProtocolController { @ApiOperation("保存组件脚本") @PostMapping("/saveComponentScript") public boolean saveComponentScript(@Validated - @RequestBody ProtocolComponentBo upReq) { - return protocolService.saveComponentScript(upReq); + @RequestBody Request upReq) { + return protocolService.saveComponentScript(upReq.getData()); } @@ -113,15 +113,14 @@ public class ProtocolController { @ApiOperation("新增转换脚本") @PostMapping("/converter/add") - public boolean addConverter(@Validated @RequestBody ProtocolConverterBo converter) { - return protocolService.addConverter(converter); - + public boolean addConverter(@Validated @RequestBody Request converter) { + return protocolService.addConverter(converter.getData()); } @ApiOperation("修改转换脚本") @PostMapping("/converter/edit") - public boolean editConverter(ProtocolConverterBo req) { - return protocolService.editConverter(req); + public boolean editConverter(Request req) { + return protocolService.editConverter(req.getData()); } @@ -138,9 +137,9 @@ public class ProtocolController { @PostMapping("/converterScript/edit") @ApiOperation("保存转换脚本") public boolean saveConverterScript( - @Validated @RequestBody ProtocolConverterBo req) { + @Validated @RequestBody Request req) { - return protocolService.saveConverterScript(req); + return protocolService.saveConverterScript(req.getData()); } @PostMapping("/converter/delete") @@ -152,8 +151,8 @@ public class ProtocolController { @PostMapping("/component/changeState}") @ApiOperation("组件启用/禁用") - public boolean changeComponentState(@RequestBody @Validated ChangeStateBo req) { - return protocolService.changeComponentState(req); + public boolean changeComponentState(@RequestBody @Validated Request req) { + return protocolService.changeComponentState(req.getData()); } } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java index 24fe31c2..bf7b00af 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java @@ -69,8 +69,8 @@ public class RuleEngineController { @ApiOperation("规则编辑") @PostMapping("/edit") - public boolean saveRule(@RequestBody @Validated RuleInfoBo ruleInfoBo) { - return ruleEngineService.saveRule(ruleInfoBo); + public boolean saveRule(@RequestBody @Validated Request ruleInfoBo) { + return ruleEngineService.saveRule(ruleInfoBo.getData()); } @@ -120,8 +120,8 @@ public class RuleEngineController { @ApiOperation("定时任务编辑") @PostMapping("/task/save") - public boolean saveTask(@Validated @RequestBody TaskInfoBo taskInfo) { - return ruleEngineService.saveTask(taskInfo); + public boolean saveTask(@Validated @RequestBody Request taskInfo) { + return ruleEngineService.saveTask(taskInfo.getData()); } @ApiOperation("停止定时任务") diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java index ab436692..7592f7e2 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java @@ -10,11 +10,16 @@ package cc.iotkit.manager.controller; import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Request; import cc.iotkit.common.enums.ErrCode; import cc.iotkit.common.exception.BizException; import cc.iotkit.common.satoken.utils.AuthUtil; import cc.iotkit.common.utils.ReflectUtil; import cc.iotkit.data.manager.IVirtualDeviceData; +import cc.iotkit.manager.dto.bo.ChangeStateBo; +import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceSaveScriptBo; +import cc.iotkit.manager.dto.bo.virtualdevice.VirtualSaveDevicesBo; import cc.iotkit.manager.service.DataOwnerService; import cc.iotkit.common.api.Paging; import cc.iotkit.model.device.VirtualDevice; @@ -23,8 +28,10 @@ import cc.iotkit.model.product.Product; import cc.iotkit.temporal.IVirtualDeviceLogData; import cc.iotkit.virtualdevice.VirtualManager; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -44,7 +51,9 @@ public class VirtualDeviceController { @Autowired private IVirtualDeviceLogData virtualDeviceLogData; - @PostMapping("/list/{size}/{page}") + + @ApiOperation("获取虚拟设备列表") + @PostMapping("/list") public Paging getDevices( PageRequest pageRequest) { String uid = AuthUtil.getUserId(); @@ -58,6 +67,7 @@ public class VirtualDeviceController { /** * 添加虚拟设备 */ + @ApiOperation("添加虚拟设备") @PostMapping("/add") public void add(VirtualDevice virtualDevice) { virtualDevice.setId(null); @@ -70,8 +80,10 @@ public class VirtualDeviceController { /** * 修改虚拟设备 */ + @ApiOperation("修改虚拟设备") @PostMapping("/modify") - public void modify(VirtualDevice virtualDevice) { + public void modify(Request bo) { + VirtualDevice virtualDevice = bo.getData(); VirtualDevice oldData = checkOwner(virtualDevice.getId()); ReflectUtil.copyNoNulls(virtualDevice, oldData, "name", "productKey", "type", "trigger", "triggerExpression"); @@ -82,16 +94,21 @@ public class VirtualDeviceController { /** * 获取虚拟设备详情 */ - @GetMapping("/{id}/detail") - public VirtualDevice detail(@PathVariable("id") String id) { - return checkOwner(id); + @ApiOperation("获取虚拟设备详情") + @GetMapping("/getDetail") + public VirtualDevice detail(@Validated @RequestBody Request bo) { + return checkOwner(bo.getData()); } /** * 设置虚拟设备状态 */ - @PostMapping("/{id}/setState") - public void setState(@PathVariable("id") String id, String state) { + @ApiOperation("设置虚拟设备状态") + @PostMapping("/setState") + public void setState(@Validated @RequestBody Request bo) { + ChangeStateBo data = bo.getData(); + String id = data.getId(); + String state = data.getState(); VirtualDevice oldData = checkOwner(id); if (!VirtualDevice.STATE_RUNNING.equals(state) && !VirtualDevice.STATE_STOPPED.equals(state)) { @@ -109,8 +126,10 @@ public class VirtualDeviceController { /** * 删除 */ - @DeleteMapping("/{id}/delete") - public void delete(@PathVariable("id") String id) { + @ApiOperation("删除虚拟设备") + @DeleteMapping("/delete") + public void delete(@Validated @RequestBody Request bo) { + String id = bo.getData(); checkOwner(id); virtualDeviceData.deleteById(id); } @@ -118,8 +137,12 @@ public class VirtualDeviceController { /** * 保存脚本 */ - @PostMapping("/{id}/saveScript") - public void saveScript(@PathVariable("id") String id, String script) { + @ApiOperation("保存脚本") + @PostMapping("/saveScript") + public void saveScript(@Validated @RequestBody Request bo) { + DeviceSaveScriptBo data = bo.getData(); + String id = data.getId(); + String script = data.getScript(); VirtualDevice old = checkOwner(id); old.setScript(script); virtualDeviceData.save(old); @@ -128,8 +151,12 @@ public class VirtualDeviceController { /** * 保存关联设备 */ - @PostMapping("/{id}/saveDevices") - public void saveDevices(@PathVariable("id") String id, @RequestBody List devices) { + @ApiOperation("保存关联设备") + @PostMapping("/saveDevices") + public void saveDevices(@Validated @RequestBody Request bo) { + VirtualSaveDevicesBo data = bo.getData(); + List devices = data.getDevices(); + String id = data.getId(); VirtualDevice old = checkOwner(id); old.setDevices(devices); virtualDeviceData.save(old); @@ -138,8 +165,10 @@ public class VirtualDeviceController { /** * 手动执行虚拟设备 */ - @PostMapping("/{id}/run") - public void run(@PathVariable("id") String id) { + @ApiOperation("手动执行虚拟设备") + @PostMapping("/run") + public void run(@Validated @RequestBody Request bo) { + String id = bo.getData(); VirtualDevice virtualDevice = checkOwner(id); virtualManager.run(virtualDevice); } @@ -147,15 +176,16 @@ public class VirtualDeviceController { /** * 取虚拟设备执行日志 */ - @PostMapping("/{id}/logs/{size}/{page}") + @ApiOperation("取虚拟设备执行日志") + @PostMapping("/logs/list") public Paging getLogs( - @PathVariable("id") String id, - @PathVariable("size") int size, - @PathVariable("page") int page - ) { - return virtualDeviceLogData.findByVirtualDeviceId(id, page, size); + @Validated @RequestBody PageRequest bo) { + DeviceLogQueryBo data = bo.getData(); + + return virtualDeviceLogData.findByVirtualDeviceId(data.getDeviceId(), bo.getPageNum(), bo.getPageSize()); } + private VirtualDevice checkOwner(String id) { VirtualDevice oldData = virtualDeviceData.findById(id); if (oldData == null) { diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java new file mode 100644 index 00000000..efce4a6f --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java @@ -0,0 +1,26 @@ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceConsumerBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceConsumerBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "deviceId不能为空") + @ApiModelProperty(value = "设备id") + private String deviceId; + + @NotBlank(message = "clientId不能为空") + @ApiModelProperty(value = "clientId") + private String clientId; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java new file mode 100644 index 00000000..3b3989fe --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java @@ -0,0 +1,29 @@ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceQueryByPkDnBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceQueryByPkDnBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "产品key不能为空") + @ApiModelProperty(value = "产品key") + private String pk; + + @NotBlank(message = "设备不能为空") + @ApiModelProperty(value = "设备") + private String dn; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java new file mode 100644 index 00000000..c10faf73 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java @@ -0,0 +1,26 @@ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceSaveScriptBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceSaveScriptBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "id") + private String id; + + + @ApiModelProperty(value = "脚本") + private String script; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java new file mode 100644 index 00000000..e1b3a3c6 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java @@ -0,0 +1,28 @@ +package cc.iotkit.manager.dto.bo.virtualdevice; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + + +@ApiModel(value = "VirtualSaveDevicesBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class VirtualSaveDevicesBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "id") + private String id; + + + @ApiModelProperty(value = "设备id列表") + private List devices; + +}