Browse Source

feat:同步状态的时候保存到数据库

master
白凤吉 4 days ago
parent
commit
d13f0cca2b
  1. 13
      src/main/java/com/iflytop/handacid/app/controller/DeviceController.java
  2. 40
      src/main/java/com/iflytop/handacid/app/service/DeviceService.java
  3. 6
      src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java

13
src/main/java/com/iflytop/handacid/app/controller/DeviceController.java

@ -1,11 +1,9 @@
package com.iflytop.handacid.app.controller; 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.core.state.DeviceState;
import com.iflytop.handacid.app.model.bo.SyncOperationsChannel;
import com.iflytop.handacid.app.model.dto.SyncOperationsDTO; 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.result.Result;
import com.iflytop.handacid.common.service.SolutionService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -19,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
@Slf4j @Slf4j
public class DeviceController { public class DeviceController {
private final DeviceState deviceState; private final DeviceState deviceState;
private final SolutionService solutionService;
private final DeviceService deviceService;
@Operation(summary = "获取当前设备状态") @Operation(summary = "获取当前设备状态")
@GetMapping("/device-status") @GetMapping("/device-status")
@ -30,12 +28,7 @@ public class DeviceController {
@Operation(summary = "同步用户操作") @Operation(summary = "同步用户操作")
@PostMapping("/sync") @PostMapping("/sync")
public Result<?> syncOperations(@RequestBody SyncOperationsDTO syncOperationsDTO) { 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(); return Result.success();
} }
} }

40
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);
}
}
}

6
src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java

@ -21,4 +21,10 @@ public class SystemConfigService extends ServiceImpl<SystemConfigMapper, SystemC
SystemConfig systemConfig = this.getOne(new LambdaQueryWrapper<>(SystemConfig.class).eq(SystemConfig::getKey, key)); SystemConfig systemConfig = this.getOne(new LambdaQueryWrapper<>(SystemConfig.class).eq(SystemConfig::getKey, key));
return systemConfig != null ? systemConfig.getValue() : null; 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);
}
} }
Loading…
Cancel
Save