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) { if(syncOperationsDTO.getMode() != null){ deviceState.setMode(syncOperationsDTO.getMode()); systemConfigService.updateValueByKey(SystemConfigKey.SOLUTION_ADD_MODE, syncOperationsDTO.getMode().toString()); } if(syncOperationsDTO.getChannels() != null){ for (SyncOperationsChannel syncOperationsChannel : syncOperationsDTO.getChannels()) { ChannelState channelState = deviceState.getChannelStateMap().get(syncOperationsChannel.getChannelCode()); if(syncOperationsChannel.getSelected() != null){ channelState.setSelected(syncOperationsChannel.getSelected()); } if(syncOperationsChannel.getTargetVolume() != null){ channelState.setTargetVolume(syncOperationsChannel.getTargetVolume()); Channel channel = channelService.getOne(new LambdaQueryWrapper<>(Channel.class).eq(Channel::getCode, syncOperationsChannel.getChannelCode())); channel.setTargetVolume(syncOperationsChannel.getTargetVolume()); channelService.updateById(channel); } } } } }