From 9885d4758bd27a97daa6ff5d48c82968ec8f765f Mon Sep 17 00:00:00 2001 From: caixypromise Date: Mon, 16 Jun 2025 03:27:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=97=A0=E6=B3=95=E6=8F=90=E4=BA=A4=E5=A4=87?= =?UTF-8?q?=E6=B3=A8=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= =?UTF-8?q?=20chore:=20=E5=B0=86=E8=AE=BE=E5=A4=87=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=8A=B6=E6=80=81=E6=8E=A5=E5=8F=A3=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E4=B8=BA=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BB=A5=E6=AD=A4=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=A4=87=E6=B3=A8=E3=80=81=E8=87=AA=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=90=88=E5=B9=B6=E5=9C=A8=E4=B8=80=E4=B8=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/controller/DeviceController.java | 12 +- .../modules/device/dto/DeviceUpdateDTO.java | 29 ++++ main/manager-web/src/apis/module/device.js | 7 +- .../src/views/DeviceManagement.vue | 153 +++++++++++------- 4 files changed, 138 insertions(+), 63 deletions(-) create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceUpdateDTO.java diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java b/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java index 5b0bf4bc..dc0b7498 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java @@ -2,8 +2,11 @@ package xiaozhi.modules.device.controller; import java.util.List; +import jakarta.validation.Valid; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.BeanUtils; +import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -22,6 +25,7 @@ import xiaozhi.common.user.UserDetail; import xiaozhi.common.utils.Result; import xiaozhi.modules.device.dto.DeviceRegisterDTO; import xiaozhi.modules.device.dto.DeviceUnBindDTO; +import xiaozhi.modules.device.dto.DeviceUpdateDTO; import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.service.DeviceService; import xiaozhi.modules.security.user.SecurityUser; @@ -80,15 +84,15 @@ public class DeviceController { return new Result(); } - @PutMapping("/enableOta/{id}/{status}") - @Operation(summary = "启用/关闭OTA自动升级") + @PutMapping("/update/{id}") + @Operation(summary = "更新设备信息") @RequiresPermissions("sys:role:normal") - public Result enableOtaUpgrade(@PathVariable String id, @PathVariable Integer status) { + public Result updateDeviceInfo(@PathVariable String id, @Valid @RequestBody DeviceUpdateDTO deviceUpdateDTO) { DeviceEntity entity = deviceService.selectById(id); if (entity == null) { return new Result().error("设备不存在"); } - entity.setAutoUpdate(status); + BeanUtils.copyProperties(deviceUpdateDTO, entity); deviceService.updateById(entity); return new Result(); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceUpdateDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceUpdateDTO.java new file mode 100644 index 00000000..2e9a4793 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceUpdateDTO.java @@ -0,0 +1,29 @@ +package xiaozhi.modules.device.dto; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.io.Serializable; + +/** + * 设备更新DTO + */ +@Data +public class DeviceUpdateDTO implements Serializable { + /** + * 自动更新状态 + */ + @Max(1) + @Min(0) + private Integer autoUpdate; + + /** + * 设备别名 + */ + @Size(max = 64) + private String alias; + + private static final long serialVersionUID = 1L; +} diff --git a/main/manager-web/src/apis/module/device.js b/main/manager-web/src/apis/module/device.js index 2f20425d..e6d61353 100644 --- a/main/manager-web/src/apis/module/device.js +++ b/main/manager-web/src/apis/module/device.js @@ -51,10 +51,11 @@ export default { }); }).send(); }, - enableOtaUpgrade(id, status, callback) { + updateDeviceInfo(id, payload, callback) { RequestService.sendRequest() - .url(`${getServiceUrl()}/device/enableOta/${id}/${status}`) + .url(`${getServiceUrl()}/device/update/${id}`) .method('PUT') + .data(payload) .success((res) => { RequestService.clearRequestTime() callback(res) @@ -63,7 +64,7 @@ export default { console.error('更新OTA状态失败:', err) this.$message.error(err.msg || '更新OTA状态失败') RequestService.reAjaxFun(() => { - this.enableOtaUpgrade(id, status, callback) + this.updateDeviceInfo(id, payload, callback) }) }).send() }, diff --git a/main/manager-web/src/views/DeviceManagement.vue b/main/manager-web/src/views/DeviceManagement.vue index 14138bd8..25cd5a68 100644 --- a/main/manager-web/src/views/DeviceManagement.vue +++ b/main/manager-web/src/views/DeviceManagement.vue @@ -1,12 +1,12 @@