Browse Source

fix:停止指令全部停止

master
白凤吉 4 days ago
parent
commit
983adf7cf2
  1. 17
      src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStopCommand.java

17
src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStopCommand.java

@ -6,6 +6,7 @@ import com.iflytop.handacid.app.common.utils.CommandUtil;
import com.iflytop.handacid.app.core.command.BaseCommandHandler; import com.iflytop.handacid.app.core.command.BaseCommandHandler;
import com.iflytop.handacid.app.core.command.CommandFuture; import com.iflytop.handacid.app.core.command.CommandFuture;
import com.iflytop.handacid.app.core.command.DeviceCommand; import com.iflytop.handacid.app.core.command.DeviceCommand;
import com.iflytop.handacid.app.core.command.DeviceCommandGenerator;
import com.iflytop.handacid.app.model.dto.CommandDTO; import com.iflytop.handacid.app.model.dto.CommandDTO;
import com.iflytop.handacid.app.service.ChannelCtrlService; import com.iflytop.handacid.app.service.ChannelCtrlService;
import com.iflytop.handacid.app.service.DeviceCommandService; import com.iflytop.handacid.app.service.DeviceCommandService;
@ -13,6 +14,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
@ -28,14 +31,14 @@ public class PumpRotateStopCommand extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
ChannelCode channelCode = commandDTO.getEnumParam("channelCode", ChannelCode.class);
if (channelCode == null) {
throw new IllegalArgumentException("参数 channelCode 不能为空");
}
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelCode);
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand);
CommandUtil.wait(commandFuture);
List<CommandFuture> commandFutureList = new ArrayList<>();
for(ChannelCode channelCode : ChannelCode.values()) {
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelCode);
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand);
commandFutureList.add(commandFuture);
}
CommandUtil.wait(commandFutureList);
}); });
} }
} }

Loading…
Cancel
Save