refactor(context): 重命名上下文构建器及更新相关方法命名
- 将 ProcessContext 中的 builder() 重命名为 createModifyBuilder() 并添加调用栈日志 - ProcessContextBuilder 中所有 with* 方法统一改为 set* 命名风格 - Flow 各节点及流程处理器中调用 builder() 替换为 createModifyBuilder() - 虚拟测试环境相关 ContextBuilder 中方法同步改名保持一致 - 优化流程节点中上下文修改代码调用,提升代码规范性 - 添加Config中加载自定义流程配置的占位注释及代码 - 无功能改动,纯代码风格及命名规范调整
This commit is contained in:
@@ -83,8 +83,8 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
Logger::debug('[{}-Node] 不能处理当前步骤,跳过', [$this->getCode()]);
|
||||
// 如果有期望下一步提示,设置到上下文
|
||||
if ($canHandleResult->hasExpectedNextStep()) {
|
||||
$context = $context->builder()
|
||||
->expectedNextStep($canHandleResult->expectedNextStep)
|
||||
$context = $context->createModifyBuilder()
|
||||
->setExpectedNextStep($canHandleResult->expectedNextStep)
|
||||
->build();
|
||||
}
|
||||
return $this->passToNext($context);
|
||||
@@ -181,7 +181,7 @@ abstract class AbstractProcessNode implements ProcessNodeInterface
|
||||
*/
|
||||
protected function stopNext(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
return $context->createModifyBuilder()
|
||||
->skipNodeCount(count($this->getChildNodes()))
|
||||
->build();
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ class CloseNode extends AbstractProcessNode
|
||||
// 如果有预期的下一步,则返回错误
|
||||
if ($context->getVoice()->hasExpectedNextStep()) {
|
||||
Logger::debug("节点期望: {$context->getVoice()->expectedNextStep->value}");
|
||||
return $context->builder()->error($context->getVoice()->expectedNextStep)->build();
|
||||
return $context->createModifyBuilder()->error($context->getVoice()->expectedNextStep)->build();
|
||||
}
|
||||
// 异常流程
|
||||
Logger::error("异常流程,所有节点处理完成,无匹配节点并且无预期的下一步");
|
||||
return $context->builder()->error(VoiceMessage::UNKNOWN_ERROR)->build();
|
||||
return $context->createModifyBuilder()->error(VoiceMessage::UNKNOWN_ERROR)->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,11 @@ class DisinfectNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->withCurrentStep('消毒')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setCurrentStep('消毒')
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ class DryNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->withCurrentStep('干燥')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setCurrentStep('干燥')
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,6 @@ class DuplicateCheckNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()->error(VoiceMessage::DUPLICATE_SWIPING)->build();
|
||||
return $context->createModifyBuilder()->error(VoiceMessage::DUPLICATE_SWIPING)->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ class EndNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->withCurrentStep('结束')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setCurrentStep('结束')
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ class FinalRinseNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->withCurrentStep('终末漂洗')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setCurrentStep('终末漂洗')
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ class MachineWashNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->withProcessType('机洗')
|
||||
->withCurrentStep('机洗')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->dbOperation(DbOperationType::UPDATE)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setProcessType('机洗')
|
||||
->setCurrentStep('机洗')
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setDbOperation(DbOperationType::UPDATE)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ class MorningWashNode extends AbstractProcessNode
|
||||
// 设置流程类型
|
||||
$processType = $context->getReader()->type === '机洗' ? '机洗(晨洗)' : '手工洗(晨洗)';
|
||||
|
||||
return $context->builder()
|
||||
->withMorningWash($morningWash)
|
||||
->withProcessType($processType)
|
||||
->withCurrentStep(self::getName())
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setMorningWash($morningWash)
|
||||
->setProcessType($processType)
|
||||
->setCurrentStep(self::getName())
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ class RinseNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
return $context->builder()
|
||||
->withCurrentStep('漂洗')
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setCurrentStep('漂洗')
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ class StorageInNode extends AbstractProcessNode
|
||||
{
|
||||
Logger::debug('[StorageInNode] 内镜入库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
|
||||
return $context->builder()
|
||||
->withProcessType('存储')
|
||||
->withCurrentStep(self::getName())
|
||||
->withStorage(StorageStatus::inStorage(date('Y-m-d H:i:s')))
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setProcessType('存储')
|
||||
->setCurrentStep(self::getName())
|
||||
->setStorage(StorageStatus::inStorage(date('Y-m-d H:i:s')))
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,25 +82,25 @@ class StorageNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
$builder = $context->builder()->withProcessType('存储');
|
||||
$builder = $context->createModifyBuilder()->setProcessType('存储');
|
||||
|
||||
// 根据当前状态判断执行入库还是出库(canHandle 已经验证过状态)
|
||||
if (!$context->getStorage()->isInStorage) {
|
||||
// 入库操作
|
||||
Logger::debug('[StorageNode] 内镜入库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
$builder->withCurrentStep('内镜放入')
|
||||
->withStorage(StorageStatus::inStorage(date('Y-m-d H:i:s')));
|
||||
$builder->setCurrentStep('内镜放入')
|
||||
->setStorage(StorageStatus::inStorage(date('Y-m-d H:i:s')));
|
||||
} else {
|
||||
// 出库操作
|
||||
Logger::debug('[StorageNode] 内镜出库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
$builder->withCurrentStep('内镜取出')
|
||||
->withStorage(StorageStatus::outOfStorage());
|
||||
$builder->setCurrentStep('内镜取出')
|
||||
->setStorage(StorageStatus::outOfStorage());
|
||||
}
|
||||
|
||||
return $builder
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ class StorageOutNode extends AbstractProcessNode
|
||||
{
|
||||
Logger::debug('[StorageOutNode] 内镜出库成功 endoscope={}', [$context->getEndoscope()->name]);
|
||||
|
||||
return $context->builder()
|
||||
->withProcessType('存储')
|
||||
->withCurrentStep(self::getName())
|
||||
->withStorage(StorageStatus::outOfStorage())
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
return $context->createModifyBuilder()
|
||||
->setProcessType('存储')
|
||||
->setCurrentStep(self::getName())
|
||||
->setStorage(StorageStatus::outOfStorage())
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,18 +70,18 @@ class WashNode extends AbstractProcessNode
|
||||
*/
|
||||
protected function doHandle(ProcessContext $context): ProcessContext
|
||||
{
|
||||
$builder = $context->builder();
|
||||
$builder = $context->createModifyBuilder();
|
||||
|
||||
// 设置流程类型
|
||||
if (empty($context->getProcessType()) || $context->getProcessType() === '晨洗') {
|
||||
$builder->withProcessType('手工洗');
|
||||
$builder->setProcessType('手工洗');
|
||||
}
|
||||
|
||||
return $builder
|
||||
->withCurrentStep(self::getName())
|
||||
->needDatabaseOperation()
|
||||
->dbOperation(DbOperationType::INSERT)
|
||||
->needWebSocketNotify()
|
||||
->setCurrentStep(self::getName())
|
||||
->setNeedDatabaseOperation()
|
||||
->setDbOperation(DbOperationType::INSERT)
|
||||
->setNeedWebSocketNotify()
|
||||
->build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user