From d13f0cca2b5a07dc226cd9ae98a40a5cd242869f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Wed, 30 Jul 2025 17:45:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=90=8C=E6=AD=A5=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E4=BF=9D=E5=AD=98=E5=88=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handacid/app/controller/DeviceController.java | 13 ++----- .../handacid/app/service/DeviceService.java | 40 ++++++++++++++++++++++ .../common/service/SystemConfigService.java | 6 ++++ 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/iflytop/handacid/app/service/DeviceService.java diff --git a/src/main/java/com/iflytop/handacid/app/controller/DeviceController.java b/src/main/java/com/iflytop/handacid/app/controller/DeviceController.java index db14dd2..7240261 100644 --- a/src/main/java/com/iflytop/handacid/app/controller/DeviceController.java +++ b/src/main/java/com/iflytop/handacid/app/controller/DeviceController.java @@ -1,11 +1,9 @@ package com.iflytop.handacid.app.controller; -import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.DeviceState; -import com.iflytop.handacid.app.model.bo.SyncOperationsChannel; import com.iflytop.handacid.app.model.dto.SyncOperationsDTO; +import com.iflytop.handacid.app.service.DeviceService; import com.iflytop.handacid.common.result.Result; -import com.iflytop.handacid.common.service.SolutionService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -19,7 +17,7 @@ import org.springframework.web.bind.annotation.*; @Slf4j public class DeviceController { private final DeviceState deviceState; - private final SolutionService solutionService; + private final DeviceService deviceService; @Operation(summary = "获取当前设备状态") @GetMapping("/device-status") @@ -30,12 +28,7 @@ public class DeviceController { @Operation(summary = "同步用户操作") @PostMapping("/sync") public Result syncOperations(@RequestBody SyncOperationsDTO syncOperationsDTO) { - deviceState.setMode(syncOperationsDTO.getMode()); - for (SyncOperationsChannel syncOperationsChannel : syncOperationsDTO.getChannels()) { - ChannelState channelState = deviceState.getChannelStateMap().get(syncOperationsChannel.getChannelCode()); - channelState.setSelected(syncOperationsChannel.isSelected()); - channelState.setTargetVolume(syncOperationsChannel.getTargetVolume()); - } + deviceService.syncOperations(syncOperationsDTO); return Result.success(); } } diff --git a/src/main/java/com/iflytop/handacid/app/service/DeviceService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceService.java new file mode 100644 index 0000000..f5368ef --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceService.java @@ -0,0 +1,40 @@ +package com.iflytop.handacid.app.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.iflytop.handacid.app.common.enums.SystemConfigKey; +import com.iflytop.handacid.app.core.state.ChannelState; +import com.iflytop.handacid.app.core.state.DeviceState; +import com.iflytop.handacid.app.model.bo.SyncOperationsChannel; +import com.iflytop.handacid.app.model.dto.SyncOperationsDTO; +import com.iflytop.handacid.common.model.entity.Channel; +import com.iflytop.handacid.common.model.entity.SystemConfig; +import com.iflytop.handacid.common.service.ChannelService; +import com.iflytop.handacid.common.service.SystemConfigService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * 设备 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class DeviceService { + private final DeviceState deviceState; + private final SystemConfigService systemConfigService; + private final ChannelService channelService; + + public void syncOperations(SyncOperationsDTO syncOperationsDTO) { + deviceState.setMode(syncOperationsDTO.getMode()); + systemConfigService.updateValueByKey(SystemConfigKey.SOLUTION_ADD_MODE, syncOperationsDTO.getMode().toString()); + for (SyncOperationsChannel syncOperationsChannel : syncOperationsDTO.getChannels()) { + ChannelState channelState = deviceState.getChannelStateMap().get(syncOperationsChannel.getChannelCode()); + channelState.setSelected(syncOperationsChannel.isSelected()); + channelState.setTargetVolume(syncOperationsChannel.getTargetVolume()); + Channel channel = channelService.getOne(new LambdaQueryWrapper<>(Channel.class).eq(Channel::getCode, syncOperationsChannel.getChannelCode())); + channel.setTargetVolume(syncOperationsChannel.getTargetVolume()); + channelService.updateById(channel); + } + } +} diff --git a/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java b/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java index f7eb634..0b0db11 100644 --- a/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java +++ b/src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java @@ -21,4 +21,10 @@ public class SystemConfigService extends ServiceImpl(SystemConfig.class).eq(SystemConfig::getKey, key)); return systemConfig != null ? systemConfig.getValue() : null; } + + public boolean updateValueByKey(SystemConfigKey key, String value){ + SystemConfig systemConfig = this.getOne(new LambdaQueryWrapper<>(SystemConfig.class).eq(SystemConfig::getKey, key)); + systemConfig.setValue(value); + return this.updateById(systemConfig); + } } \ No newline at end of file