ai-refactor(flow): 调整抽象流程节点实现和依赖路径

- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext
- 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示
- 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法
- 增加日志记录细节,便于调试策略执行中断时的错误信息
- 优化代码注释,提升代码可读性和维护性
This commit is contained in:
zimoyin
2026-03-11 00:48:10 +08:00
parent d303f3501f
commit e040fccba6
45 changed files with 819 additions and 2718 deletions
+10 -10
View File
@@ -4,9 +4,9 @@ namespace app\flow\strategies;
use app\config\Config;
use app\flow\config\TimeValidationConfig;
use app\flow\ProcessContext;
use app\flow\context\ProcessContext;
use app\flow\nodes\ProcessNodeInterface;
use app\flow\VoiceMessage;
use app\flow\enum\VoiceMessage;
use app\repository\ProcessDurationRepository;
use app\utils\Logger;
@@ -63,8 +63,8 @@ class TimeValidationStrategy extends AbstractStrategy
protected function doExecute(ProcessContext $context, ProcessNodeInterface $node): ProcessContext
{
$stepCode = $node->getCode();
$currentStep = $context->currentStep;
$processType = $context->processType;
$currentStep = $context->getCurrentStep();
$processType = $context->getProcessType();
Logger::debug("开始执行时间验证策略,步骤:{$stepCode},流程类型:{$processType}");
$configDuration = $this->timeValidationConfig->getDuration($stepCode,$processType);
@@ -76,9 +76,9 @@ class TimeValidationStrategy extends AbstractStrategy
} else {
Logger::debug("步骤:{$stepCode},流程类型:{$processType},无配置时长,从数据库查询");
// 从数据库按流程类型精确查询
$requiredDuration = $this->getDurationFromDb($stepCode, $context->processType);
$requiredDuration = $this->getDurationFromDb($stepCode, $context->getProcessType());
if ($requiredDuration > 0) {
$context->setStepDuration($stepCode, $requiredDuration);
$context = $context->builder()->withStepDuration($stepCode, $requiredDuration)->build();
} else {
// 最后使用上下文已缓存值
$requiredDuration = $context->getStepDuration($stepCode);
@@ -91,7 +91,7 @@ class TimeValidationStrategy extends AbstractStrategy
}
// 获取上次该步骤的操作时间
$duration = $context->duration;
$duration = $context->getDuration();
// 没有上次记录(第一次操作),允许通过
if (empty($duration)) {
@@ -105,7 +105,7 @@ class TimeValidationStrategy extends AbstractStrategy
$voice = VoiceMessage::NOT_ENOUGH_TIME->value;
$voice = str_replace('{step}', $stepCode, $voice);
$voice = str_replace('{time}', $requiredDuration - $duration, $voice);
$context->setCustomError($voice);
$context = $context->builder()->customError($voice)->build();
}
return $context;
}
@@ -119,8 +119,8 @@ class TimeValidationStrategy extends AbstractStrategy
*/
public function isApplicable(ProcessContext $context, ProcessNodeInterface $node): bool
{
if ($context->currentStep != $context->previousAction->process_name) return false;
if (!$this->timeValidationConfig->hasStep($node->getCode(), $context->processType)) return false;
if ($context->getCurrentStep() != $context->getPreviousAction()?->process_name) return false;
if (!$this->timeValidationConfig->hasStep($node->getCode(), $context->getProcessType())) return false;
return true;
}