Browse Source

feat:新增通道开始加液、预充方法

master
白凤吉 4 days ago
parent
commit
13cfb74758
  1. 2
      src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java
  2. 2
      src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java
  3. 13
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  4. 3
      src/main/java/com/iflytop/handacid/app/model/dto/SyncOperationsDTO.java
  5. 77
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

2
src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java

@ -25,7 +25,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 开始加液
* 开始加液(废弃)
*/
@Slf4j
@Component

2
src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStartCommand.java

@ -22,7 +22,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 开始预充
* 开始预充(废弃)
*/
@Slf4j
@Component

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

@ -28,6 +28,9 @@ public class DeviceState {
@Schema(description = "加液模式")
private volatile SolutionAddMode mode;
@Schema(description = "加液间隔")
private volatile int delay = 0;
@Schema(description = "虚拟模式,true为虚拟")
private volatile boolean virtual = false;
@ -41,6 +44,7 @@ public class DeviceState {
JSONObject json = new JSONObject();
json.putOnce("channelState", new ArrayList<>(channelStateMap.values()));
json.putOnce("mode", mode);
json.putOnce("delay", delay);
json.putOnce("virtual", virtual);
json.putOnce("emergencyStop", emergencyStop);
json.putOnce("currentUser", currentUser);
@ -64,4 +68,13 @@ public class DeviceState {
.filter(ChannelState::isPre)
.collect(Collectors.toList());
}
/**
* 获取选中的通道
*/
public List<ChannelState> filterChannelStatesIsSelected() {
return channelStateMap.values().stream()
.filter(ChannelState::isSelected)
.collect(Collectors.toList());
}
}

3
src/main/java/com/iflytop/handacid/app/model/dto/SyncOperationsDTO.java

@ -18,6 +18,9 @@ public class SyncOperationsDTO {
@Schema(description = "加液模式")
private SolutionAddMode mode;
@Schema(description = "加液间隔")
private Integer delay;
@Schema(description = "通道")
private List<SyncOperationsChannel> channels;

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

@ -1,14 +1,26 @@
package com.iflytop.handacid.app.service;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.iflytop.handacid.app.common.enums.ChannelCode;
import com.iflytop.handacid.app.common.enums.ChannelStateCode;
import com.iflytop.handacid.app.common.enums.SolutionAddMode;
import com.iflytop.handacid.app.common.utils.CommandUtil;
import com.iflytop.handacid.app.core.command.CommandFuture;
import com.iflytop.handacid.app.core.command.DeviceCommand;
import com.iflytop.handacid.app.core.command.DeviceCommandGenerator;
import com.iflytop.handacid.app.core.state.ChannelState;
import com.iflytop.handacid.app.core.state.DeviceState;
import com.iflytop.handacid.common.model.entity.Formulation;
import com.iflytop.handacid.common.service.FormulationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 通道控制
*/
@ -16,9 +28,73 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ChannelCtrlService {
private final FormulationService formulationService;
private final ChannelCtrlService channelCtrlService;
private final DeviceCommandService deviceCommandService;
private final DeviceState deviceState;
/**
* 开始加液
*/
public void solutionAddStart() {
CompletableFuture.runAsync(() -> {
List<ChannelState> channelStateList = deviceState.filterChannelStatesIsSelected();
try {
for (ChannelState channelState : channelStateList) {
channelState.setStateCode(ChannelStateCode.ADD);
}
if (SolutionAddMode.AUTO.equals(deviceState.getMode())) {//自动模式
while (!deviceState.isSolutionAddStop()) {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelStateList) {
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId()));
DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
Thread.sleep(deviceState.getDelay() * 1000L);
}
} else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelStateList) {
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId()));
DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
for (ChannelState channelState : channelStateList) {
channelState.setStateCode(ChannelStateCode.IDLE);
}
deviceState.setSolutionAddStop(false);
}
});
}
/**
* 开始预充
*/
public void solutionPreFillStart() {
CompletableFuture.runAsync(() -> {
List<ChannelState> channelStateList = deviceState.filterChannelStatesIsSelected();
try {
for (ChannelState channelState : channelStateList) {
channelState.setStateCode(ChannelStateCode.PRE);
}
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelStateList) {
DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelState.getChannelCode());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
/**
* 根据通道code获取泵相对移动指令
@ -80,6 +156,7 @@ public class ChannelCtrlService {
/**
* 停止加液
*
* @param channelCode 通道code
*/
public void solutionAddStop(ChannelCode channelCode) {

Loading…
Cancel
Save