3 changed files with 102 additions and 0 deletions
-
55src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java
-
42src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStopCommand.java
-
5src/main/java/com/iflytop/handacid/app/common/enums/Direction.java
@ -0,0 +1,55 @@ |
|||
package com.iflytop.handacid.app.command.control; |
|||
|
|||
import com.iflytop.handacid.app.common.annotation.CommandMapping; |
|||
import com.iflytop.handacid.app.common.enums.ChannelCode; |
|||
import com.iflytop.handacid.app.common.enums.Direction; |
|||
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.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.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 蠕动泵旋转 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
@CommandMapping("pump_rotate_start") |
|||
public class PumpRotateStartCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
private final ChannelCtrlService channelCtrlService; |
|||
|
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
ChannelCode channelCode = commandDTO.getEnumParam("channelCode", ChannelCode.class); |
|||
if (channelCode == null) { |
|||
throw new IllegalArgumentException("参数 channelCode 不能为空"); |
|||
} |
|||
Direction direction = commandDTO.getEnumParam("direction", Direction.class); |
|||
if (direction == null) { |
|||
throw new IllegalArgumentException("参数 direction 不能为空"); |
|||
} |
|||
return runAsync(() -> { |
|||
if(Direction.FORWARD.equals(direction)) { |
|||
DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); |
|||
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|||
CommandUtil.wait(commandFuture); |
|||
}else{ |
|||
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); |
|||
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|||
CommandUtil.wait(commandFuture); |
|||
} |
|||
|
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,42 @@ |
|||
package com.iflytop.handacid.app.command.control; |
|||
|
|||
import com.iflytop.handacid.app.common.annotation.CommandMapping; |
|||
import com.iflytop.handacid.app.common.enums.ChannelCode; |
|||
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.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.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 蠕动泵停止旋转 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
@CommandMapping("pump_rotate_stop") |
|||
public class PumpRotateStopCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
private final ChannelCtrlService channelCtrlService; |
|||
|
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
ChannelCode channelCode = commandDTO.getEnumParam("channelCode", ChannelCode.class); |
|||
if (channelCode == null) { |
|||
throw new IllegalArgumentException("参数 channelCode 不能为空"); |
|||
} |
|||
return runAsync(() -> { |
|||
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelCode); |
|||
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|||
CommandUtil.wait(commandFuture); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,5 @@ |
|||
package com.iflytop.handacid.app.common.enums; |
|||
|
|||
public enum Direction { |
|||
FORWARD, BACKWARD; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue