|
@ -1,14 +1,26 @@ |
|
|
package com.iflytop.handacid.app.service; |
|
|
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.ChannelCode; |
|
|
import com.iflytop.handacid.app.common.enums.ChannelStateCode; |
|
|
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.DeviceCommand; |
|
|
import com.iflytop.handacid.app.core.command.DeviceCommandGenerator; |
|
|
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.app.core.state.DeviceState; |
|
|
|
|
|
import com.iflytop.handacid.common.model.entity.Formulation; |
|
|
|
|
|
import com.iflytop.handacid.common.service.FormulationService; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.stereotype.Service; |
|
|
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 |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
|
public class ChannelCtrlService { |
|
|
public class ChannelCtrlService { |
|
|
|
|
|
private final FormulationService formulationService; |
|
|
|
|
|
private final ChannelCtrlService channelCtrlService; |
|
|
private final DeviceCommandService deviceCommandService; |
|
|
private final DeviceCommandService deviceCommandService; |
|
|
private final DeviceState deviceState; |
|
|
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获取泵相对移动指令 |
|
|
* 根据通道code获取泵相对移动指令 |
|
@ -80,6 +156,7 @@ public class ChannelCtrlService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 停止加液 |
|
|
* 停止加液 |
|
|
|
|
|
* |
|
|
* @param channelCode 通道code |
|
|
* @param channelCode 通道code |
|
|
*/ |
|
|
*/ |
|
|
public void solutionAddStop(ChannelCode channelCode) { |
|
|
public void solutionAddStop(ChannelCode channelCode) { |
|
|