6 changed files with 121 additions and 1 deletions
-
48src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStartCommand.java
-
48src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStopCommand.java
-
1src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java
-
4src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
-
9src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
-
12src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
@ -0,0 +1,48 @@ |
|||
package com.iflytop.handacid.app.command.control; |
|||
|
|||
import com.iflytop.handacid.app.common.annotation.CommandMapping; |
|||
import com.iflytop.handacid.app.common.enums.ChannelStateCode; |
|||
import com.iflytop.handacid.app.common.utils.CommandUtil; |
|||
import com.iflytop.handacid.app.core.command.BaseCommandHandler; |
|||
import com.iflytop.handacid.app.core.command.CommandFuture; |
|||
import com.iflytop.handacid.app.core.command.DeviceCommand; |
|||
import com.iflytop.handacid.app.core.state.ChannelState; |
|||
import com.iflytop.handacid.app.core.state.DeviceState; |
|||
import com.iflytop.handacid.app.model.dto.CommandDTO; |
|||
import com.iflytop.handacid.app.service.ChannelCtrlService; |
|||
import com.iflytop.handacid.app.service.DeviceCommandService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 开始排空 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
@CommandMapping("solution_drain_start") |
|||
public class SolutionDrainStartCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
private final ChannelCtrlService channelCtrlService; |
|||
private final DeviceState deviceState; |
|||
|
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
List<ChannelState> channelCodeList = deviceState.filterChannelStatesIsPre(); |
|||
return runAsync(() -> { |
|||
List<CommandFuture> commandFutureList = new ArrayList<>(); |
|||
for (ChannelState channelState : channelCodeList) { |
|||
channelState.setStateCode(ChannelStateCode.DRAIN); |
|||
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelState.getChannelCode()); |
|||
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); |
|||
} |
|||
CommandUtil.wait(commandFutureList); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,48 @@ |
|||
package com.iflytop.handacid.app.command.control; |
|||
|
|||
import com.iflytop.handacid.app.common.annotation.CommandMapping; |
|||
import com.iflytop.handacid.app.common.enums.ChannelStateCode; |
|||
import com.iflytop.handacid.app.common.utils.CommandUtil; |
|||
import com.iflytop.handacid.app.core.command.BaseCommandHandler; |
|||
import com.iflytop.handacid.app.core.command.CommandFuture; |
|||
import com.iflytop.handacid.app.core.command.DeviceCommand; |
|||
import com.iflytop.handacid.app.core.state.ChannelState; |
|||
import com.iflytop.handacid.app.core.state.DeviceState; |
|||
import com.iflytop.handacid.app.model.dto.CommandDTO; |
|||
import com.iflytop.handacid.app.service.ChannelCtrlService; |
|||
import com.iflytop.handacid.app.service.DeviceCommandService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 停止排空 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
@CommandMapping("solution_drain_stop") |
|||
public class SolutionDrainStopCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
private final ChannelCtrlService channelCtrlService; |
|||
private final DeviceState deviceState; |
|||
|
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.DRAIN); |
|||
return runAsync(() -> { |
|||
List<CommandFuture> commandFutureList = new ArrayList<>(); |
|||
for (ChannelState channelState : channelCodeList) { |
|||
channelState.setStateCode(ChannelStateCode.DRAIN); |
|||
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelState.getChannelCode()); |
|||
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); |
|||
} |
|||
CommandUtil.wait(commandFutureList); |
|||
}); |
|||
} |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue