69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace app\flow\nodes;
|
|
|
|
use app\flow\DbOperationType;
|
|
use app\flow\ProcessContext;
|
|
use app\flow\VoiceMessage;
|
|
use app\repository\EctActionsRepository;
|
|
use app\utils\Logger;
|
|
|
|
/**
|
|
* 最后节点,用于扫尾
|
|
*
|
|
*/
|
|
class CloseNode extends AbstractProcessNode
|
|
{
|
|
/**
|
|
* 获取节点名称
|
|
*/
|
|
public static function getName(): string
|
|
{
|
|
return "Close";
|
|
}
|
|
|
|
/**
|
|
* 获取节点编码
|
|
*/
|
|
public function getCode(): string
|
|
{
|
|
return self::getName();
|
|
}
|
|
|
|
/**
|
|
* 判断当前节点是否能处理该步骤
|
|
*
|
|
* 所有需要数据库记录的场景都需要经过本节点检查
|
|
*/
|
|
public function canHandle(ProcessContext $context): bool
|
|
{
|
|
if (!$context->success || $context->needDatabaseOperation || !empty($context->voiceMessage)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 具体处理逻辑:最后节点处理
|
|
*/
|
|
protected function doHandle(ProcessContext $context): ProcessContext
|
|
{
|
|
if (!$context->success || $context->needDatabaseOperation || !empty($context->voiceMessage)) return $context;
|
|
// 无节点命中
|
|
Logger::debug('当前刷卡无节点命中 currentStep={} readerType={} expectedNextStep={}', [
|
|
$context->currentStep ?: '(空)',
|
|
$context->readerType,
|
|
$context->expectedNextStep
|
|
]);
|
|
// 如果有预期的下一步,则返回错误
|
|
if (!empty($context->expectedNextStep) && $context->expectedNextStep != VoiceMessage::NONE) {
|
|
Logger::debug("节点期望: {$context->expectedNextStep->value}");
|
|
return $context->setError($context->expectedNextStep);
|
|
}
|
|
// 异常流程
|
|
Logger::error("异常流程,所有节点处理完成,无匹配节点并且无预期的下一步");
|
|
$context->setError(VoiceMessage::UNKNOWN_ERROR);
|
|
return $context;
|
|
}
|
|
}
|