加酸仪(java版本)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.2 KiB

  1. package com.iflytop.handacid.app.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.iflytop.handacid.app.common.enums.SystemConfigKey;
  4. import com.iflytop.handacid.app.core.state.ChannelState;
  5. import com.iflytop.handacid.app.core.state.DeviceState;
  6. import com.iflytop.handacid.app.model.bo.SyncOperationsChannel;
  7. import com.iflytop.handacid.app.model.dto.SyncOperationsDTO;
  8. import com.iflytop.handacid.common.model.entity.Channel;
  9. import com.iflytop.handacid.common.model.entity.SystemConfig;
  10. import com.iflytop.handacid.common.service.ChannelService;
  11. import com.iflytop.handacid.common.service.SystemConfigService;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.stereotype.Service;
  15. /**
  16. * 设备
  17. */
  18. @Slf4j
  19. @Service
  20. @RequiredArgsConstructor
  21. public class DeviceService {
  22. private final DeviceState deviceState;
  23. private final SystemConfigService systemConfigService;
  24. private final ChannelService channelService;
  25. public void syncOperations(SyncOperationsDTO syncOperationsDTO) {
  26. if(syncOperationsDTO.getMode() != null){
  27. deviceState.setMode(syncOperationsDTO.getMode());
  28. systemConfigService.updateValueByKey(SystemConfigKey.SOLUTION_ADD_MODE, syncOperationsDTO.getMode().toString());
  29. }
  30. if(syncOperationsDTO.getChannels() != null){
  31. for (SyncOperationsChannel syncOperationsChannel : syncOperationsDTO.getChannels()) {
  32. ChannelState channelState = deviceState.getChannelStateMap().get(syncOperationsChannel.getChannelCode());
  33. if(syncOperationsChannel.getSelected() != null){
  34. channelState.setSelected(syncOperationsChannel.getSelected());
  35. }
  36. if(syncOperationsChannel.getTargetVolume() != null){
  37. channelState.setTargetVolume(syncOperationsChannel.getTargetVolume());
  38. Channel channel = channelService.getOne(new LambdaQueryWrapper<>(Channel.class).eq(Channel::getCode, syncOperationsChannel.getChannelCode()));
  39. channel.setTargetVolume(syncOperationsChannel.getTargetVolume());
  40. channelService.updateById(channel);
  41. }
  42. }
  43. }
  44. }
  45. }