fix(process): 修复自定义配置 required 不生效
This commit is contained in:
@@ -82,7 +82,7 @@ class ProcessEngine
|
||||
protected function buildChain(): void
|
||||
{
|
||||
Logger::debug("[ProcessEngine] 构建流程链...");
|
||||
$steps = $this->config->getSteps();
|
||||
$steps = $this->config->getSteps();
|
||||
$prevNode = null;
|
||||
|
||||
foreach ($steps as $step) {
|
||||
@@ -119,7 +119,7 @@ class ProcessEngine
|
||||
$prevNode = $node;
|
||||
Logger::debug("[{}] 节点创建完成", [$node->getName()]);
|
||||
}
|
||||
Logger::debug("[ProcessEngine] 流程链构建完成");
|
||||
Logger::debug("[ProcessEngine] 流程链构建完成 node:{},steps:{}", [$this->chainHead->getChildNodeCount() + 1, count($steps)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,13 +178,13 @@ class ProcessEngine
|
||||
if ($this->chainHead === null) {
|
||||
return $context->builder()->error(VoiceMessage::PROCESS_CHAIN_NOT_INITIALIZED)->build();
|
||||
}
|
||||
|
||||
|
||||
Logger::debug('[ProcessEngine] 开始执行流程链 readerType={} currentStep={} endoscope={}', [
|
||||
$context->getReader()->type,
|
||||
$context->getCurrentStep() ?: '(空)',
|
||||
$context->getEndoscope()->name ?: $context->getEndoscope()->id ?: '-',
|
||||
]);
|
||||
|
||||
|
||||
$result = $this->chainHead->handle($context);
|
||||
|
||||
Logger::debug('[ProcessEngine] 流程执行完成 endoscope={} step={} success={} error={}', [
|
||||
@@ -193,7 +193,7 @@ class ProcessEngine
|
||||
$result->isSuccess() ? 'true' : 'false',
|
||||
$result->getVoice()->errorMessage->value ?: '-',
|
||||
]);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,20 @@ class StepsConfig extends AbstractConfig
|
||||
} elseif ($override) {
|
||||
$this->steps = $parsed;
|
||||
} else {
|
||||
$this->steps = array_merge(self::defaultSteps(), $parsed);
|
||||
// 核心逻辑:合并默认步骤 + 自定义步骤,重复 code 以自定义步骤为准
|
||||
// 1. 将默认步骤转为「code => StepConfig」的关联数组(方便快速查找/覆盖)
|
||||
$defaultStepsMap = [];
|
||||
foreach (self::defaultSteps() as $defaultStep) {
|
||||
$defaultStepsMap[$defaultStep->code] = $defaultStep;
|
||||
}
|
||||
|
||||
// 2. 遍历自定义步骤,覆盖默认步骤中相同 code 的元素
|
||||
foreach ($parsed as $customStep) {
|
||||
$defaultStepsMap[$customStep->code] = $customStep;
|
||||
}
|
||||
|
||||
// 3. 转回索引数组(重置键名从0开始),赋值给 $this->steps
|
||||
$this->steps = array_values($defaultStepsMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,12 +165,13 @@ class StepsConfig extends AbstractConfig
|
||||
*/
|
||||
private static function createStep(array $step): StepConfig
|
||||
{
|
||||
$known = ['code', 'class', 'enabled'];
|
||||
$known = ['code', 'class', 'enabled', 'required'];
|
||||
$expand = array_diff_key($step, array_flip($known));
|
||||
return new StepConfig(
|
||||
$step['code'],
|
||||
$step['class'],
|
||||
$step['enabled'] ?? true,
|
||||
$step['required'] ?? [],
|
||||
$expand
|
||||
);
|
||||
}
|
||||
|
||||
@@ -138,6 +138,14 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
return (!empty($this->getConfig()->required)) ? $this->getConfig()->required : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子节点数量
|
||||
*/
|
||||
public function getChildNodeCount(): int
|
||||
{
|
||||
return count($this->getChildNodes());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是需要的前置节点
|
||||
* @param string $currentStep
|
||||
@@ -174,14 +182,14 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
protected function stopNext(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->skipNodeCount(count($this->getRemainingNodes()))
|
||||
->skipNodeCount(count($this->getChildNodes()))
|
||||
->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取剩余节点
|
||||
*/
|
||||
protected function getRemainingNodes(): array
|
||||
public function getChildNodes(): array
|
||||
{
|
||||
$remainingNodes = [];
|
||||
$node = $this->next;
|
||||
|
||||
@@ -31,6 +31,10 @@ interface ProcessNodeInterface
|
||||
*/
|
||||
public function handle(ProcessContext $context): ProcessContext;
|
||||
|
||||
|
||||
public function getChildNodes(): array;
|
||||
public function getChildNodeCount(): int;
|
||||
|
||||
/**
|
||||
* 获取节点名称
|
||||
* @return string
|
||||
|
||||
@@ -63,7 +63,7 @@ class StorageInNode extends AbstractProcessNode
|
||||
|
||||
// 检查前置步骤要求
|
||||
$validSteps = ['', '结束', '内镜取出', '测漏正常', '测漏异常'];
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageInNode] 当前步骤 {} 不符合入库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::cannotHandle();
|
||||
}
|
||||
|
||||
@@ -60,14 +60,14 @@ class StorageNode extends AbstractProcessNode
|
||||
if ($isInStorage) {
|
||||
// 内镜已在库中,执行出库
|
||||
$validSteps = ['内镜放入', '结束'];
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageNode] 当前步骤 {} 不符合出库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::cannotHandle();
|
||||
}
|
||||
} else {
|
||||
// 内镜不在库中,执行入库
|
||||
$validSteps = ['', '结束', '内镜取出', '测漏正常', '测漏异常'];
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageNode] 当前步骤 {} 不符合入库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::cannotHandle();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class StorageOutNode extends AbstractProcessNode
|
||||
|
||||
// 检查前置步骤要求:必须在库中才能出库
|
||||
$validSteps = ['内镜放入', '结束'];
|
||||
if (!in_array($context->getCurrentStep(), $validSteps)) {
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), $validSteps)) {
|
||||
Logger::debug('[StorageOutNode] 当前步骤 {} 不符合出库条件', [$context->getCurrentStep()]);
|
||||
return CanHandleResult::cannotHandle();
|
||||
}
|
||||
|
||||
@@ -49,8 +49,10 @@ class WashNode extends AbstractProcessNode
|
||||
return CanHandleResult::cannotHandle(VoiceMessage::PLEASE_SWIPE_MORNING_WASH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$validCurrentSteps = ['', '结束', '内镜取出', '内镜放入', '测漏正常', '晨洗'];
|
||||
if (!in_array($context->getCurrentStep(), $validCurrentSteps)) {
|
||||
if (!$this->isRequiredNode($context->getCurrentStep(), $validCurrentSteps)) {
|
||||
// 读卡器是清洗但步骤不对(如终末漂洗时刷清洗),提示应该先刷结束
|
||||
return CanHandleResult::cannotHandle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user