From 9a79ab2ed27dd7b6ad03cac61962a5844b8828de Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Fri, 25 Apr 2025 17:45:44 +0800 Subject: [PATCH] =?UTF-8?q?update:=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE=E6=9F=90=E4=B8=AA=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=98=AF=E5=90=A6=E8=87=AA=E5=8A=A8=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/controller/DeviceController.java | 13 ++++++ .../modules/device/service/DeviceService.java | 8 +--- .../service/impl/DeviceServiceImpl.java | 10 +---- main/manager-web/src/apis/module/device.js | 16 +++++++ .../src/views/DeviceManagement.vue | 42 ++++++++++--------- 5 files changed, 55 insertions(+), 34 deletions(-) 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 1c68a7565..5b0bf4bcf 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 @@ -7,6 +7,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -79,4 +80,16 @@ public class DeviceController { return new Result(); } + @PutMapping("/enableOta/{id}/{status}") + @Operation(summary = "启用/关闭OTA自动升级") + @RequiresPermissions("sys:role:normal") + public Result enableOtaUpgrade(@PathVariable String id, @PathVariable Integer status) { + DeviceEntity entity = deviceService.selectById(id); + if (entity == null) { + return new Result().error("设备不存在"); + } + entity.setAutoUpdate(status); + deviceService.updateById(entity); + return new Result(); + } } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java index 8bb203cc4..aff31bff3 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java @@ -3,18 +3,14 @@ package xiaozhi.modules.device.service; import java.util.List; import xiaozhi.common.page.PageData; +import xiaozhi.common.service.BaseService; import xiaozhi.modules.device.dto.DevicePageUserDTO; import xiaozhi.modules.device.dto.DeviceReportReqDTO; import xiaozhi.modules.device.dto.DeviceReportRespDTO; import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.vo.UserShowDeviceListVO; -public interface DeviceService { - - /** - * 根据Mac地址获取设备信息 - */ - DeviceEntity getDeviceById(String macAddress); +public interface DeviceService extends BaseService { /** * 检查设备是否激活 diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java index 95a5dc181..a31cbdd80 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java @@ -13,7 +13,6 @@ import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -55,13 +54,6 @@ public class DeviceServiceImpl extends BaseServiceImpl private final RedisUtils redisUtils; private final OtaService otaService; - @Override - public DeviceEntity getDeviceById(String deviceId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(DeviceEntity::getId, deviceId); - return deviceDao.selectOne(queryWrapper); - } - @Override public Boolean deviceActivation(String agentId, String activationCode) { if (StringUtils.isBlank(activationCode)) { @@ -149,7 +141,7 @@ public class DeviceServiceImpl extends BaseServiceImpl response.setWebsocket(websocket); - DeviceEntity deviceById = getDeviceById(macAddress); + DeviceEntity deviceById = getDeviceByMacAddress(macAddress); if (deviceById != null) { // 如果设备存在,则更新上次连接时间 deviceById.setLastConnectedAt(new Date()); deviceDao.updateById(deviceById); diff --git a/main/manager-web/src/apis/module/device.js b/main/manager-web/src/apis/module/device.js index a62db3b0b..53738bc66 100644 --- a/main/manager-web/src/apis/module/device.js +++ b/main/manager-web/src/apis/module/device.js @@ -51,4 +51,20 @@ export default { }); }).send(); }, + enableOtaUpgrade(id, status, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/device/enableOta/${id}/${status}`) + .method('PUT') + .success((res) => { + RequestService.clearRequestTime() + callback(res) + }) + .fail((err) => { + console.error('更新OTA状态失败:', err) + this.$message.error(err.msg || '更新OTA状态失败') + RequestService.reAjaxFun(() => { + this.enableOtaUpgrade(id, status, callback) + }) + }).send() + }, } \ No newline at end of file diff --git a/main/manager-web/src/views/DeviceManagement.vue b/main/manager-web/src/views/DeviceManagement.vue index 662287a39..578469bc1 100644 --- a/main/manager-web/src/views/DeviceManagement.vue +++ b/main/manager-web/src/views/DeviceManagement.vue @@ -15,15 +15,9 @@
- + - + @@ -53,8 +47,8 @@ @@ -326,6 +320,16 @@ export default { const firmwareType = FIRMWARE_TYPES.find(item => item.key === type); return firmwareType ? firmwareType.name : type; }, + handleOtaSwitchChange(row) { + Api.device.enableOtaUpgrade(row.device_id, row.otaSwitch ? 1 : 0, ({ data }) => { + if (data.code === 0) { + this.$message.success(row.otaSwitch ? '已设置成自动升级' : '已关闭自动升级') + } else { + row.otaSwitch = !row.otaSwitch + this.$message.error(data.msg || '操作失败') + } + }) + }, } }; @@ -472,12 +476,13 @@ export default { flex: 1; overflow: hidden; } - ::v-deep .el-card__body { - padding: 15px; - display: flex; - flex-direction: column; - flex: 1; - overflow: hidden; + +::v-deep .el-card__body { + padding: 15px; + display: flex; + flex-direction: column; + flex: 1; + overflow: hidden; } .table_bottom { @@ -691,5 +696,4 @@ export default { ::v-deep .el-table::before { display: none !important; } -