ai-refactor(flow): 调整抽象流程节点实现和依赖路径
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\config\StepConfig;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\strategies\ProcessStrategyInterface;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -67,26 +68,33 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
$context = $this->executeBeforeStrategies($context);
|
||||
|
||||
// 如果前置策略返回错误,不再继续
|
||||
if (!$context->success) {
|
||||
if (!$context->isSuccess()) {
|
||||
Logger::debug('[{}-Node] 前置策略拦截 error={}', [
|
||||
$this->getCode(),
|
||||
$context->errorMessage,
|
||||
$context->getVoice()->errorMessage,
|
||||
]);
|
||||
return $context;
|
||||
}
|
||||
|
||||
|
||||
// 如果不能处理当前步骤,传递给下一个节点
|
||||
if (!$this->canHandle($context)) {
|
||||
$canHandleResult = $this->canHandle($context);
|
||||
if (!$canHandleResult->canHandle) {
|
||||
Logger::debug('[{}-Node] 不能处理当前步骤,跳过', [$this->getCode()]);
|
||||
// 如果有期望下一步提示,设置到上下文
|
||||
if ($canHandleResult->hasExpectedNextStep()) {
|
||||
$context = $context->builder()
|
||||
->expectedNextStep($canHandleResult->expectedNextStep)
|
||||
->build();
|
||||
}
|
||||
return $this->passToNext($context);
|
||||
}
|
||||
|
||||
// 输出当前节点
|
||||
Logger::debug('[{}-Node] 开始处理 step={} batch={}', [
|
||||
$this->getCode(),
|
||||
$context->currentStep,
|
||||
$context->batchNo ?: '-',
|
||||
$context->getCurrentStep(),
|
||||
$context->getBatchNo() ?: '-',
|
||||
]);
|
||||
|
||||
|
||||
@@ -95,25 +103,25 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
|
||||
Logger::debug('[{}-Node] 处理完成 step={} batch={} success={}', [
|
||||
$this->getCode(),
|
||||
$context->currentStep,
|
||||
$context->batchNo ?: '-',
|
||||
$context->success,
|
||||
$context->getCurrentStep(),
|
||||
$context->getBatchNo() ?: '-',
|
||||
$context->isSuccess(),
|
||||
]);
|
||||
|
||||
// 执行后置策略
|
||||
$context = $this->executeAfterStrategies($context);
|
||||
// 后置策略拦截
|
||||
if (!$context->success) {
|
||||
if (!$context->isSuccess()) {
|
||||
Logger::debug('[{}-Node] 后置策略拦截 error={}', [
|
||||
$this->getCode(),
|
||||
$context->errorMessage,
|
||||
$context->getVoice()->errorMessage,
|
||||
]);
|
||||
return $context;
|
||||
}
|
||||
|
||||
$nextNode = $this->getNext();
|
||||
// 跳过节点逻辑
|
||||
for ($i = 0; $i < $context->skipNodeCount; $i++) {
|
||||
for ($i = 0; $i < $context->getResult()->skipNodeCount; $i++) {
|
||||
Logger::debug('[{}-Node] 跳过节点 code={}', [$this->getCode(), $nextNode->getCode()]);
|
||||
$nextNode = $nextNode->getNext();
|
||||
}
|
||||
@@ -146,7 +154,7 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
*/
|
||||
public function isMatchReaderType(ProcessContext $context): bool
|
||||
{
|
||||
return $this->getCode() === $context->readerType;
|
||||
return $this->getCode() === $context->getReader()->type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,8 +173,9 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
*/
|
||||
protected function stopNext(ProcessContext $context): ProcessContext
|
||||
{
|
||||
$context->skipNodeCount = count($this->getRemainingNodes());
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->skipNodeCount(count($this->getRemainingNodes()))
|
||||
->build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +223,7 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
foreach ($this->strategies as $strategy) {
|
||||
if ($strategy->getPhase() === 'before') {
|
||||
$context = $strategy->execute($context, $this);
|
||||
if (!$context->success) {
|
||||
if (!$context->isSuccess()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -287,10 +296,15 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
* 默认实现:检查当前步骤是否匹配节点编码
|
||||
*
|
||||
* @return CanHandleResult 包含是否能处理以及期望下一步的结果对象
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
return $context->currentStep === $this->getCode();
|
||||
if ($context->getCurrentStep() === $this->getCode()) {
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\repository\EctActionsRepository;
|
||||
use app\utils\Logger;
|
||||
|
||||
@@ -35,12 +36,12 @@ class CloseNode extends AbstractProcessNode
|
||||
*
|
||||
* 所有需要数据库记录的场景都需要经过本节点检查
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
if (!$context->success || $context->needDatabaseOperation || !empty($context->voiceMessage)) {
|
||||
return false;
|
||||
if (!$context->isSuccess() || $context->needDatabaseOperation() || !empty($context->getVoice()->message)) {
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,21 +49,22 @@ class CloseNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
if (!$context->success || $context->needDatabaseOperation || !empty($context->voiceMessage)) return $context;
|
||||
if (!$context->isSuccess() || $context->needDatabaseOperation() || !empty($context->getVoice()->message)) {
|
||||
return $context;
|
||||
}
|
||||
// 无节点命中
|
||||
Logger::debug('当前刷卡无节点命中 currentStep={} readerType={} expectedNextStep={}', [
|
||||
$context->currentStep ?: '(空)',
|
||||
$context->readerType,
|
||||
$context->expectedNextStep
|
||||
$context->getCurrentStep() ?: '(空)',
|
||||
$context->getReader()->type,
|
||||
$context->getVoice()->expectedNextStep
|
||||
]);
|
||||
// 如果有预期的下一步,则返回错误
|
||||
if (!empty($context->expectedNextStep) && $context->expectedNextStep != VoiceMessage::NONE) {
|
||||
Logger::debug("节点期望: {$context->expectedNextStep->value}");
|
||||
return $context->setError($context->expectedNextStep);
|
||||
if ($context->getVoice()->hasExpectedNextStep()) {
|
||||
Logger::debug("节点期望: {$context->getVoice()->expectedNextStep->value}");
|
||||
return $context->builder()->error($context->getVoice()->expectedNextStep)->build();
|
||||
}
|
||||
// 异常流程
|
||||
Logger::error("异常流程,所有节点处理完成,无匹配节点并且无预期的下一步");
|
||||
$context->setError(VoiceMessage::UNKNOWN_ERROR);
|
||||
return $context;
|
||||
return $context->builder()->error(VoiceMessage::UNKNOWN_ERROR)->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
|
||||
/**
|
||||
* 消毒节点
|
||||
@@ -31,27 +32,26 @@ class DisinfectNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
if ($context->currentStep === RinseNode::getName()) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_DISINFECT;
|
||||
if ($context->getCurrentStep() === RinseNode::getName()) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_DISINFECT);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 上一个步骤必须是漂洗 或者 晨洗
|
||||
if (!$this->isRequiredNode($context->currentStep, [RinseNode::getName(), MorningWashNode::getName()])) {
|
||||
return false;
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), [RinseNode::getName(), MorningWashNode::getName()])) {
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,14 +59,11 @@ class DisinfectNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 更新步骤
|
||||
$context->currentStep = '消毒';
|
||||
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withCurrentStep('消毒')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-23
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -35,29 +36,27 @@ class DryNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
if ($context->currentStep === FinalRinseNode::getName()) {
|
||||
if (!$context->success) Logger::debug("[DryNode] 刷卡错误,当前步骤是终末漂洗,但是刷的读卡器类型不是终末漂洗,对用户进行语音提示刷终末漂洗读卡器");
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_DRY;
|
||||
if ($context->getCurrentStep() === FinalRinseNode::getName()) {
|
||||
if (!$context->isSuccess()) Logger::debug("[DryNode] 刷卡错误,当前步骤是终末漂洗,但是刷的读卡器类型不是终末漂洗,对用户进行语音提示刷终末漂洗读卡器");
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_DRY);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 上一个步骤必须是终末漂洗
|
||||
if (!$this->isRequiredNode($context->currentStep, [FinalRinseNode::getName()])) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_DISINFECT;
|
||||
return false;
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), [FinalRinseNode::getName()])) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_DISINFECT);
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,13 +64,11 @@ class DryNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 更新步骤
|
||||
$context->currentStep = '干燥';
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withCurrentStep('干燥')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\repository\EctActionsRepository;
|
||||
use app\utils\Logger;
|
||||
|
||||
@@ -36,9 +37,12 @@ class DuplicateCheckNode extends AbstractProcessNode
|
||||
*
|
||||
* 所有需要数据库记录的场景都需要经过本节点检查
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
return $context->previousAction->process_name === $context->readerType;
|
||||
if ($context->getPreviousAction()?->process_name === $context->getReader()->type) {
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +50,6 @@ class DuplicateCheckNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
$context->setError(VoiceMessage::DUPLICATE_SWIPING);
|
||||
return $context;
|
||||
return $context->builder()->error(VoiceMessage::DUPLICATE_SWIPING)->build();
|
||||
}
|
||||
}
|
||||
|
||||
+21
-23
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
|
||||
/**
|
||||
* 结束节点
|
||||
@@ -31,31 +32,30 @@ class EndNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
if ($context->currentStep === DryNode::getName() && $context->currentStep === FinalRinseNode::getName()) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_END;
|
||||
if ($context->getCurrentStep() === DryNode::getName() && $context->getCurrentStep() === FinalRinseNode::getName()) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_END);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 上一个步骤必须是干燥、终末漂洗或机洗
|
||||
$validSteps = ['干燥', '终末漂洗', '机洗'];
|
||||
if ($this->isRequiredNode($context->currentStep, ['干燥', '终末漂洗', '机洗'])) {
|
||||
if ($context->currentStep === FinalRinseNode::getName()) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_WASH;
|
||||
if ($this->isRequiredNode($context->getCurrentStep(), ['干燥', '终末漂洗', '机洗'])) {
|
||||
if ($context->getCurrentStep() === FinalRinseNode::getName()) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_WASH);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,13 +63,11 @@ class EndNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 更新步骤
|
||||
$context->currentStep = '结束';
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withCurrentStep('结束')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -34,24 +35,26 @@ class FinalRinseNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
if ($context->currentStep === DisinfectNode::getName()) {
|
||||
if (!$context->success) Logger::debug("[FinalRinseNode] 刷卡错误,当前步骤是消毒,但是刷的读卡器类型不是消毒,对用户进行语音提示刷消毒读卡器");
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_FINAL_RINSE;
|
||||
if ($context->getCurrentStep() === DisinfectNode::getName()) {
|
||||
if (!$context->isSuccess()) Logger::debug("[FinalRinseNode] 刷卡错误,当前步骤是消毒,但是刷的读卡器类型不是消毒,对用户进行语音提示刷消毒读卡器");
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_FINAL_RINSE);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 上一个步骤必须是消毒或机洗
|
||||
return $this->isRequiredNode($context->currentStep, ['消毒', '机洗']);
|
||||
if ($this->isRequiredNode($context->getCurrentStep(), ['消毒', '机洗'])) {
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,14 +62,11 @@ class FinalRinseNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 更新步骤
|
||||
$context->currentStep = '终末漂洗';
|
||||
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withCurrentStep('终末漂洗')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
|
||||
/**
|
||||
* 机洗节点
|
||||
@@ -31,35 +32,34 @@ class MachineWashNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
if ($context->currentStep === WashNode::getName()) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_MACHINE_WASH;
|
||||
if ($context->getCurrentStep() === WashNode::getName()) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_MACHINE_WASH);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 需要晨洗但未完成:提示先进行晨洗
|
||||
if ($context->needMorningWash && !$context->morningWashed) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_MORNING_WASH;
|
||||
return false;
|
||||
if ($context->getMorningWash()->needMorningWash && !$context->getMorningWash()->morningWashed) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_MORNING_WASH);
|
||||
}
|
||||
|
||||
// 机洗可以在多个步骤后执行:空步骤(新流程)、结束、内镜取出、清洗,晨洗
|
||||
if (!$this->isRequiredNode($context->currentStep, ['', '结束', '内镜取出', '清洗', MachineWashNode::getName()])) {
|
||||
if ($context->currentStep === EndNode::getName()) $context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_MACHINE_WASH;
|
||||
else $context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_END;
|
||||
return false;
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), ['', '结束', '内镜取出', '清洗', MachineWashNode::getName()])) {
|
||||
if ($context->getCurrentStep() === EndNode::getName()) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_MACHINE_WASH);
|
||||
}
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_END);
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,21 +67,13 @@ class MachineWashNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 设置流程类型为机洗
|
||||
$context->processType = '机洗';
|
||||
|
||||
// 更新步骤
|
||||
$context->currentStep = '机洗';
|
||||
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
// 更新批次为机洗,
|
||||
$context->processType = '机洗';
|
||||
$context->dbOperation = DbOperationType::UPDATE;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withProcessType('机洗')
|
||||
->withCurrentStep('机洗')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->dbOperation(DbOperationType::UPDATE)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\flow\vo\MorningWashStatus;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -32,25 +34,23 @@ class MorningWashNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
// 只有需要晨洗且未完成晨洗时才处理
|
||||
if (!$context->needMorningWash || $context->morningWashed) {
|
||||
return false;
|
||||
if (!$context->getMorningWash()->needMorningWash || $context->getMorningWash()->morningWashed) {
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 检查当前读卡器类型是否匹配
|
||||
if (!$this->isRequiredNode($context->readerType, ['漂洗', '机洗'])){
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_MORNING_WASH;
|
||||
return false;
|
||||
if (!$this->isRequiredNode($context->getReader()->type, ['漂洗', '机洗'])){
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_MORNING_WASH);
|
||||
}
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,23 +59,25 @@ class MorningWashNode extends AbstractProcessNode
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
Logger::debug("处理晨洗节点");
|
||||
|
||||
// 标记晨洗已开始
|
||||
$context->morningWashed = true;
|
||||
$morningWash = new MorningWashStatus(
|
||||
needMorningWash: $context->getMorningWash()->needMorningWash,
|
||||
morningWashed: true,
|
||||
startTime: $context->getMorningWash()->startTime,
|
||||
todayWashRecords: $context->getMorningWash()->todayWashRecords
|
||||
);
|
||||
|
||||
// 设置流程类型
|
||||
if ($context->readerType === '机洗') {
|
||||
$context->processType = '机洗(晨洗)';
|
||||
} else {
|
||||
$context->processType = '手工洗(晨洗)';
|
||||
}
|
||||
$processType = $context->getReader()->type === '机洗' ? '机洗(晨洗)' : '手工洗(晨洗)';
|
||||
|
||||
// 更新当前步骤
|
||||
$context->currentStep = self::getName();
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withMorningWash($morningWash)
|
||||
->withProcessType($processType)
|
||||
->withCurrentStep(self::getName())
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
|
||||
/**
|
||||
* 流程节点接口
|
||||
@@ -45,9 +46,9 @@ interface ProcessNodeInterface
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
* @param ProcessContext $context
|
||||
* @return bool
|
||||
* @return CanHandleResult 包含是否能处理以及期望下一步的结果
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool;
|
||||
public function canHandle(ProcessContext $context): CanHandleResult;
|
||||
|
||||
/**
|
||||
* 是否启用该节点
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
|
||||
/**
|
||||
* 漂洗节点
|
||||
@@ -33,30 +34,28 @@ class RinseNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
// 期望当前读卡器为漂洗
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
// 当前步骤是清洗且读卡器不符:说明清洗完了应该刷漂洗
|
||||
if ($context->currentStep === WashNode::getName()) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_RINSE;
|
||||
if ($context->getCurrentStep() === WashNode::getName()) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_RINSE);
|
||||
}
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 上一个步骤必须是清洗
|
||||
if (!$this->isRequiredNode($context->currentStep, [WashNode::getName()])) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_WASH;
|
||||
return false;
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), [WashNode::getName()])) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_WASH);
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,14 +63,11 @@ class RinseNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 更新步骤
|
||||
$context->currentStep = '漂洗';
|
||||
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withCurrentStep('漂洗')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\config\Config;
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\flow\vo\StorageStatus;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -35,38 +37,38 @@ class StorageInNode extends AbstractProcessNode
|
||||
* 判断当前节点是否能处理该步骤
|
||||
* 双读卡器模式:只在非单读卡器模式下生效
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$singleReaderMode = $config->storageSingleReader;
|
||||
|
||||
// 单读卡器模式不处理,由 StorageNode 统一处理
|
||||
if ($singleReaderMode) {
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 读卡器不是内镜放入类型,不处理
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 获取内镜当前存储状态
|
||||
$isInStorage = $context->isInStorage ?? false;
|
||||
$isInStorage = $context->getStorage()->isInStorage;
|
||||
|
||||
// 如果内镜已在库中,则当前应该是出库操作,不处理
|
||||
if ($isInStorage) {
|
||||
Logger::debug('[StorageInNode] 内镜已在库中,转由出库节点处理');
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 检查前置步骤要求
|
||||
$validSteps = ['', '结束', '内镜取出', '测漏正常', '测漏异常'];
|
||||
if (!in_array($context->currentStep, $validSteps)) {
|
||||
Logger::debug('[StorageInNode] 当前步骤 {} 不符合入库条件', [$context->currentStep]);
|
||||
return false;
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageInNode] 当前步骤 {} 不符合入库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,23 +76,15 @@ class StorageInNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 设置流程类型为存储
|
||||
$context->processType = '存储';
|
||||
Logger::debug('[StorageInNode] 内镜入库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
|
||||
// 更新步骤
|
||||
$context->currentStep = self::getName();
|
||||
|
||||
// 标记入库状态
|
||||
$context->isInStorage = true;
|
||||
$context->storageInTime = date('Y-m-d H:i:s');
|
||||
|
||||
// 设置数据库操作
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
Logger::debug('[StorageInNode] 内镜入库成功 endoscope={}', [$context->endoscopeName]);
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withProcessType('存储')
|
||||
->withCurrentStep(self::getName())
|
||||
->withStorage(StorageStatus::inStorage(date('Y-m-d H:i:s')))
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\config\Config;
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\flow\vo\StorageStatus;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -38,40 +40,40 @@ class StorageNode extends AbstractProcessNode
|
||||
*
|
||||
* 单读卡器模式:读卡器类型是'内镜放入'或'内镜取出',根据 isInStorage 状态判断执行入库还是出库
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$singleReaderMode = $config->storageSingleReader;
|
||||
|
||||
// 非单读卡器模式不处理
|
||||
if (!$singleReaderMode) {
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 读卡器类型必须是'内镜放入'或'内镜取出'
|
||||
if (!in_array($context->readerType, ['内镜放入', '内镜取出'])) {
|
||||
return false;
|
||||
if (!in_array($context->getReader()->type, ['内镜放入', '内镜取出'])) {
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
$isInStorage = $context->isInStorage ?? false;
|
||||
$isInStorage = $context->getStorage()->isInStorage;
|
||||
|
||||
if ($isInStorage) {
|
||||
// 内镜已在库中,执行出库
|
||||
$validSteps = ['内镜放入', '结束'];
|
||||
if (!in_array($context->currentStep, $validSteps)) {
|
||||
Logger::debug('[StorageNode] 当前步骤 {} 不符合出库条件', [$context->currentStep]);
|
||||
return false;
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageNode] 当前步骤 {} 不符合出库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
} else {
|
||||
// 内镜不在库中,执行入库
|
||||
$validSteps = ['', '结束', '内镜取出', '测漏正常', '测漏异常'];
|
||||
if (!in_array($context->currentStep, $validSteps)) {
|
||||
Logger::debug('[StorageNode] 当前步骤 {} 不符合入库条件', [$context->currentStep]);
|
||||
return false;
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageNode] 当前步骤 {} 不符合入库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,28 +82,25 @@ class StorageNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 设置流程类型为存储
|
||||
$context->processType = '存储';
|
||||
$builder = $context->builder()->withProcessType('存储');
|
||||
|
||||
// 根据当前状态判断执行入库还是出库(canHandle 已经验证过状态)
|
||||
if (!$context->isInStorage) {
|
||||
if (!$context->getStorage()->isInStorage) {
|
||||
// 入库操作
|
||||
$context->currentStep = '内镜放入';
|
||||
$context->isInStorage = true;
|
||||
$context->storageInTime = date('Y-m-d H:i:s');
|
||||
Logger::debug('[StorageNode] 内镜入库成功 endoscope={}', [$context->endoscopeName]);
|
||||
Logger::debug('[StorageNode] 内镜入库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
$builder->withCurrentStep('内镜放入')
|
||||
->withStorage(StorageStatus::inStorage(date('Y-m-d H:i:s')));
|
||||
} else {
|
||||
// 出库操作
|
||||
$context->currentStep = '内镜取出';
|
||||
$context->isInStorage = false;
|
||||
Logger::debug('[StorageNode] 内镜出库成功 endoscope={}', [$context->endoscopeName]);
|
||||
Logger::debug('[StorageNode] 内镜出库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
$builder->withCurrentStep('内镜取出')
|
||||
->withStorage(StorageStatus::outOfStorage());
|
||||
}
|
||||
|
||||
// 设置数据库操作
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $builder
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\config\Config;
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\flow\vo\StorageStatus;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -35,38 +37,38 @@ class StorageOutNode extends AbstractProcessNode
|
||||
* 判断当前节点是否能处理该步骤
|
||||
* 双读卡器模式:只在非单读卡器模式下生效
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$singleReaderMode = $config->storageSingleReader;
|
||||
|
||||
// 单读卡器模式不处理,由 StorageNode 统一处理
|
||||
if ($singleReaderMode) {
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 读卡器不是内镜取出类型,不处理
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 获取内镜当前存储状态
|
||||
$isInStorage = $context->isInStorage ?? false;
|
||||
$isInStorage = $context->getStorage()->isInStorage;
|
||||
|
||||
// 如果内镜不在库中,则当前应该是入库操作,不处理
|
||||
if (!$isInStorage) {
|
||||
Logger::debug('[StorageOutNode] 内镜不在库中,转由入库节点处理');
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 检查前置步骤要求:必须在库中才能出库
|
||||
$validSteps = ['内镜放入', '结束'];
|
||||
if (!in_array($context->currentStep, $validSteps)) {
|
||||
Logger::debug('[StorageOutNode] 当前步骤 {} 不符合出库条件', [$context->currentStep]);
|
||||
return false;
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageOutNode] 当前步骤 {} 不符合出库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,22 +76,15 @@ class StorageOutNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
// 设置流程类型为存储
|
||||
$context->processType = '存储';
|
||||
Logger::debug('[StorageOutNode] 内镜出库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
|
||||
// 更新步骤
|
||||
$context->currentStep = self::getName();
|
||||
|
||||
// 标记出库状态
|
||||
$context->isInStorage = false;
|
||||
|
||||
// 设置数据库操作
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
Logger::debug('[StorageOutNode] 内镜出库成功 endoscope={}', [$context->endoscopeName]);
|
||||
|
||||
return $context;
|
||||
return $context->builder()
|
||||
->withProcessType('存储')
|
||||
->withCurrentStep(self::getName())
|
||||
->withStorage(StorageStatus::outOfStorage())
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\config\Config;
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
|
||||
/**
|
||||
* 虚拟清洗机节点
|
||||
@@ -32,20 +33,22 @@ class VirtualWashMachineNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
// 如果不是机洗
|
||||
if ($context->readerType !== MachineWashNode::getName()) {
|
||||
return false;
|
||||
if ($context->getReader()->type !== MachineWashNode::getName()) {
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
return Config::getInstance()->enableVirtualCleanerParser;
|
||||
if (Config::getInstance()->enableVirtualCleanerParser) {
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+23
-26
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace app\flow\nodes;
|
||||
|
||||
use app\flow\DbOperationType;
|
||||
use app\flow\ProcessContext;
|
||||
use app\flow\VoiceMessage;
|
||||
use app\flow\enum\DbOperationType;
|
||||
use app\flow\context\ProcessContext;
|
||||
use app\flow\enum\VoiceMessage;
|
||||
use app\flow\vo\CanHandleResult;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
@@ -33,34 +34,31 @@ class WashNode extends AbstractProcessNode
|
||||
/**
|
||||
* 判断当前节点是否能处理该步骤
|
||||
*/
|
||||
public function canHandle(ProcessContext $context): bool
|
||||
public function canHandle(ProcessContext $context): CanHandleResult
|
||||
{
|
||||
|
||||
// 如果内镜未取出
|
||||
if ($context->isInStorage) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_STORAGE_OUT;
|
||||
return false;
|
||||
if ($context->getStorage()->isInStorage) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_STORAGE_OUT);
|
||||
}
|
||||
|
||||
// 读卡器不是本节点,不处理
|
||||
if (!$this->isMatchReaderType($context)) {
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
// 需要晨洗但未完成:提示先进行晨洗
|
||||
if ($context->needMorningWash && !$context->morningWashed) {
|
||||
$context->expectedNextStep = VoiceMessage::PLEASE_SWIPE_MORNING_WASH;
|
||||
return false;
|
||||
if ($context->getMorningWash()->needMorningWash && !$context->getMorningWash()->morningWashed) {
|
||||
return CanHandleResult::no(VoiceMessage::PLEASE_SWIPE_MORNING_WASH);
|
||||
}
|
||||
|
||||
$validCurrentSteps = ['', '结束', '内镜取出', '内镜放入', '测漏正常', '晨洗'];
|
||||
if (!in_array($context->currentStep, $validCurrentSteps)) {
|
||||
if (!in_array($context->getCurrentStep(), $validCurrentSteps)) {
|
||||
// 读卡器是清洗但步骤不对(如终末漂洗时刷清洗),提示应该先刷结束
|
||||
// $context->expectedNextStep = "清洗应在流程开始时刷,当前步骤为{$context->currentStep},请先刷结束卡重新开始";
|
||||
return false;
|
||||
return CanHandleResult::no();
|
||||
}
|
||||
|
||||
return true;
|
||||
return CanHandleResult::yes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,19 +66,18 @@ class WashNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
$builder = $context->builder();
|
||||
|
||||
// 设置流程类型
|
||||
if (empty($context->processType) || $context->processType === '晨洗') {
|
||||
$context->processType = '手工洗';
|
||||
if (empty($context->getProcessType()) || $context->getProcessType() === '晨洗') {
|
||||
$builder->withProcessType('手工洗');
|
||||
}
|
||||
|
||||
// 更新步骤
|
||||
$context->currentStep = self::getName();
|
||||
|
||||
|
||||
$context->needDatabaseOperation = true;
|
||||
$context->dbOperation = DbOperationType::INSERT;
|
||||
$context->needWebSocketNotify = true;
|
||||
|
||||
return $context;
|
||||
return $builder
|
||||
->withCurrentStep(self::getName())
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user