Browse Source

feat:开始排空、停止排空指令

master
白凤吉 5 days ago
parent
commit
65fdfb666f
  1. 48
      src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStartCommand.java
  2. 48
      src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStopCommand.java
  3. 1
      src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java
  4. 4
      src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
  5. 9
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  6. 12
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

48
src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStartCommand.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);
});
}
}

48
src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStopCommand.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_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);
});
}
}

1
src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java

@ -46,6 +46,7 @@ public class SolutionPreFillStopCommand extends BaseCommandHandler {
CommandUtil.wait(commandFutureList); CommandUtil.wait(commandFutureList);
} finally { } finally {
for (ChannelState channelCode : channelCodeList) { for (ChannelState channelCode : channelCodeList) {
channelCode.setPre(true);
channelCode.setStateCode(ChannelStateCode.IDLE); channelCode.setStateCode(ChannelStateCode.IDLE);
} }
} }

4
src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java

@ -3,7 +3,6 @@ package com.iflytop.handacid.app.core.state;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.iflytop.handacid.app.common.enums.ChannelCode; import com.iflytop.handacid.app.common.enums.ChannelCode;
import com.iflytop.handacid.app.common.enums.ChannelStateCode; import com.iflytop.handacid.app.common.enums.ChannelStateCode;
import com.iflytop.handacid.app.model.bo.ChannelSolution;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -23,6 +22,9 @@ public class ChannelState {
@Schema(description = "当前通道状态") @Schema(description = "当前通道状态")
private ChannelStateCode stateCode = ChannelStateCode.IDLE; private ChannelStateCode stateCode = ChannelStateCode.IDLE;
@Schema(description = "是否已预充")
private volatile boolean pre = false;
@Schema(description = "剩余容量(单位:mL)") @Schema(description = "剩余容量(单位:mL)")
private Double remainingVolume; private Double remainingVolume;

9
src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java

@ -50,4 +50,13 @@ public class DeviceState {
.filter(cs -> cs.getStateCode() == stateCode) .filter(cs -> cs.getStateCode() == stateCode)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 获取已经预充过的通道
*/
public List<ChannelState> filterChannelStatesIsPre() {
return channelStateMap.values().stream()
.filter(ChannelState::isPre)
.collect(Collectors.toList());
}
} }

12
src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

@ -45,6 +45,18 @@ public class ChannelCtrlService {
} }
/** /**
* 根据通道code获取泵反转指令
*/
public DeviceCommand getPumpBackwardRotateCommandByChannel(ChannelCode channelCode) {
return switch (channelCode) {
case CHANNEL_1 -> DeviceCommandGenerator.pump1BackwardRotate();
case CHANNEL_2 -> DeviceCommandGenerator.pump2BackwardRotate();
case CHANNEL_3 -> DeviceCommandGenerator.pump3BackwardRotate();
case CHANNEL_4 -> DeviceCommandGenerator.pump4BackwardRotate();
};
}
/**
* 根据通道code获取停止泵指令 * 根据通道code获取停止泵指令
*/ */
public DeviceCommand getPumpStopCommandByChannel(ChannelCode channelCode) { public DeviceCommand getPumpStopCommandByChannel(ChannelCode channelCode) {

Loading…
Cancel
Save