ai-refactor(flow): 调整抽象流程节点实现和依赖路径
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user