refactor(context): 重命名上下文构建器及更新相关方法命名
- 将 ProcessContext 中的 builder() 重命名为 createModifyBuilder() 并添加调用栈日志 - ProcessContextBuilder 中所有 with* 方法统一改为 set* 命名风格 - Flow 各节点及流程处理器中调用 builder() 替换为 createModifyBuilder() - 虚拟测试环境相关 ContextBuilder 中方法同步改名保持一致 - 优化流程节点中上下文修改代码调用,提升代码规范性 - 添加Config中加载自定义流程配置的占位注释及代码 - 无功能改动,纯代码风格及命名规范调整
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -116,6 +116,8 @@ class Config
|
||||
{
|
||||
$this->detectCircularDependency();
|
||||
$this->database = new DatabaseConfig();
|
||||
// TODO 加载自定义流程配置
|
||||
// 加载根目录的
|
||||
$this->customProcess = require __DIR__ . '/custom_process_config.php';
|
||||
$this->machineId = self::getStringEnv("MACHINE_ID", "0");
|
||||
if (empty($this->machineId) || $this->machineId == '0') {
|
||||
|
||||
@@ -9,3 +9,5 @@
|
||||
动态提示请刷XXX
|
||||
|
||||
配置文件 required 无法生效
|
||||
|
||||
干燥
|
||||
@@ -64,8 +64,7 @@ class FlowMain
|
||||
$processConfig = null;
|
||||
if ($useCustomProcess && !empty($processConfigKey)) {
|
||||
// 从全局配置加载自定义流程
|
||||
$globalConfig = Config::getInstance();
|
||||
$customProcess = $globalConfig->customProcess;
|
||||
$customProcess = Config::getInstance()->customProcess;
|
||||
$processConfigArray = $customProcess[$processConfigKey] ?? null;
|
||||
|
||||
if ($processConfigArray !== null) {
|
||||
|
||||
@@ -62,7 +62,7 @@ class FlowProcessor
|
||||
// 读卡器未绑定
|
||||
if (empty($context->getReader()->id)) {
|
||||
Logger::error('读卡器未绑定,放弃处理 card={}', [$context->isOperatorCard() ? $context->getOperator()->rfid : $context->getEndoscope()->cardNo]);
|
||||
$context = $context->builder()->error(VoiceMessage::READER_NOT_BOUND)->build();
|
||||
$context = $context->createModifyBuilder()->error(VoiceMessage::READER_NOT_BOUND)->build();
|
||||
$this->sendVoice($context);
|
||||
return $context;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class FlowProcessor
|
||||
$context->getOperator()->name,
|
||||
$context->getOperator()->rfid
|
||||
);
|
||||
$context = $context->builder()->error(VoiceMessage::PLEASE_SWIPE_ENDOSCOPE)->build();
|
||||
$context = $context->createModifyBuilder()->error(VoiceMessage::PLEASE_SWIPE_ENDOSCOPE)->build();
|
||||
$this->sendVoice($context);
|
||||
return $context;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class FlowProcessor
|
||||
// 如果内镜未绑定,返回错误
|
||||
if ($context->getEndoscope()->isEmpty()) {
|
||||
Logger::error('内镜未绑定,放弃处理 card={}', [$context->getEndoscope()->cardNo]);
|
||||
$context = $context->builder()->error(VoiceMessage::CARD_NOT_BOUND)->build();
|
||||
$context = $context->createModifyBuilder()->error(VoiceMessage::CARD_NOT_BOUND)->build();
|
||||
$this->sendVoice($context);
|
||||
return $context;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class FlowProcessor
|
||||
if ($mgr->hasOperator($context->getReader()->id) || $context->hasOperator()) {
|
||||
if ($mgr->hasOperator($context->getReader()->id)) {
|
||||
$op = $mgr->getOperator($context->getReader()->id, $context->getReader()->type);
|
||||
$context = $context->builder()->withOperator(new \app\flow\context\bean\OperatorInfo(
|
||||
$context = $context->createModifyBuilder()->setOperator(new \app\flow\context\bean\OperatorInfo(
|
||||
id: $op['id'],
|
||||
name: $op['name'],
|
||||
rfid: $op['rfid']
|
||||
@@ -107,7 +107,7 @@ class FlowProcessor
|
||||
$context->getEndoscope()->cardNo,
|
||||
]);
|
||||
// 处理这个错误
|
||||
$context = $context->builder()->error(VoiceMessage::PLEASE_SWIPE_OPERATOR)->build();
|
||||
$context = $context->createModifyBuilder()->error(VoiceMessage::PLEASE_SWIPE_OPERATOR)->build();
|
||||
$this->handleResult($context);
|
||||
return $context;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ class ProcessEngine
|
||||
public function execute(ProcessContext $context): ProcessContext
|
||||
{
|
||||
if ($this->chainHead === null) {
|
||||
return $context->builder()->error(VoiceMessage::PROCESS_CHAIN_NOT_INITIALIZED)->build();
|
||||
return $context->createModifyBuilder()->error(VoiceMessage::PROCESS_CHAIN_NOT_INITIALIZED)->build();
|
||||
}
|
||||
|
||||
Logger::debug('[ProcessEngine] 开始执行流程链 readerType={} currentStep={} endoscope={}', [
|
||||
|
||||
@@ -14,6 +14,7 @@ use app\flow\context\bean\StorageStatus;
|
||||
use app\flow\context\bean\VoiceState;
|
||||
use app\model\EctActions;
|
||||
use app\net\PacketContext;
|
||||
use app\utils\Logger;
|
||||
|
||||
/**
|
||||
* 流程上下文类(不可变)
|
||||
@@ -81,8 +82,13 @@ readonly class ProcessContext
|
||||
* 创建一个基于当前上下文的 Builder
|
||||
* 用于创建修改后的新上下文实例
|
||||
*/
|
||||
public function builder(): ProcessContextBuilder
|
||||
public function createModifyBuilder(): ProcessContextBuilder
|
||||
{
|
||||
$caller = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1];
|
||||
$callerClass = $caller['class'];
|
||||
$callerMethod = $caller['function'];
|
||||
$callerLine = $caller['line'];
|
||||
Logger::debug("上下文请求修改构建器: class={}, method={}, line={}", [$callerClass, $callerMethod, $callerLine]);
|
||||
return ProcessContextBuilder::from($this);
|
||||
}
|
||||
|
||||
|
||||
@@ -328,55 +328,55 @@ class ProcessContextBuilder
|
||||
|
||||
// ==================== 值对象设置方法 ====================
|
||||
|
||||
public function withEndoscope(EndoscopeInfo $endoscope): self
|
||||
public function setEndoscope(EndoscopeInfo $endoscope): self
|
||||
{
|
||||
$this->endoscope = $endoscope;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withReader(ReaderInfo $reader): self
|
||||
public function setReader(ReaderInfo $reader): self
|
||||
{
|
||||
$this->reader = $reader;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withOperator(OperatorInfo $operator): self
|
||||
public function setOperator(OperatorInfo $operator): self
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStorage(StorageStatus $storage): self
|
||||
public function setStorage(StorageStatus $storage): self
|
||||
{
|
||||
$this->storage = $storage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withMorningWash(MorningWashStatus $morningWash): self
|
||||
public function setMorningWash(MorningWashStatus $morningWash): self
|
||||
{
|
||||
$this->morningWash = $morningWash;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withVoice(VoiceState $voice): self
|
||||
public function setVoiceState(VoiceState $voice): self
|
||||
{
|
||||
$this->voice = $voice;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withResult(ExecutionResult $result): self
|
||||
public function setResult(ExecutionResult $result): self
|
||||
{
|
||||
$this->result = $result;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withProcessStatus(ProcessStatus $processStatus): self
|
||||
public function setProcessStatus(ProcessStatus $processStatus): self
|
||||
{
|
||||
$this->processStatus = $processStatus;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withReminder(ReminderStatus $reminder): self
|
||||
public function setReminder(ReminderStatus $reminder): self
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
return $this;
|
||||
@@ -384,7 +384,7 @@ class ProcessContextBuilder
|
||||
|
||||
// ==================== 流程状态便捷设置方法 ====================
|
||||
|
||||
public function withCurrentStep(string $currentStep): self
|
||||
public function setCurrentStep(string $currentStep): self
|
||||
{
|
||||
$this->processStatus = new ProcessStatus(
|
||||
currentStep: $currentStep,
|
||||
@@ -397,7 +397,7 @@ class ProcessContextBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withProcessType(string $processType): self
|
||||
public function setProcessType(string $processType): self
|
||||
{
|
||||
$this->processStatus = new ProcessStatus(
|
||||
currentStep: $this->processStatus->currentStep,
|
||||
@@ -410,7 +410,7 @@ class ProcessContextBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withBatchNo(string $batchNo): self
|
||||
public function setBatchNo(string $batchNo): self
|
||||
{
|
||||
$this->processStatus = new ProcessStatus(
|
||||
currentStep: $this->processStatus->currentStep,
|
||||
@@ -423,8 +423,10 @@ class ProcessContextBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDuration(?int $duration): self
|
||||
public function setDuration(?int $duration = null): self
|
||||
{
|
||||
if (empty($duration)) $duration = time() - strtotime($this->processStatus->actionStartTime);
|
||||
|
||||
$this->processStatus = new ProcessStatus(
|
||||
currentStep: $this->processStatus->currentStep,
|
||||
processType: $this->processStatus->processType,
|
||||
@@ -436,7 +438,7 @@ class ProcessContextBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPreviousAction(?EctActions $action): self
|
||||
public function setPreviousAction(?EctActions $action): self
|
||||
{
|
||||
$this->processStatus = new ProcessStatus(
|
||||
currentStep: $this->processStatus->currentStep,
|
||||
@@ -473,7 +475,7 @@ class ProcessContextBuilder
|
||||
/**
|
||||
* 设置自定义错误
|
||||
*/
|
||||
public function customError(string $message): self
|
||||
public function setCustomError(string $message): self
|
||||
{
|
||||
$this->voice = $this->voice->withMessage($message)->withError(VoiceMessage::CUSTOM);
|
||||
$this->result = $this->result->fail();
|
||||
@@ -483,7 +485,7 @@ class ProcessContextBuilder
|
||||
/**
|
||||
* 设置语音消息
|
||||
*/
|
||||
public function voiceMessage(string|VoiceMessage $message): self
|
||||
public function setVoiceMessage(string|VoiceMessage $message): self
|
||||
{
|
||||
$this->voice = $this->voice->withMessage($message);
|
||||
return $this;
|
||||
@@ -492,7 +494,7 @@ class ProcessContextBuilder
|
||||
/**
|
||||
* 设置期望下一步
|
||||
*/
|
||||
public function expectedNextStep(VoiceMessage $expected): self
|
||||
public function setExpectedNextStep(VoiceMessage $expected): self
|
||||
{
|
||||
$this->voice = $this->voice->withExpectedNextStep($expected);
|
||||
return $this;
|
||||
@@ -501,7 +503,7 @@ class ProcessContextBuilder
|
||||
/**
|
||||
* 添加数据库操作
|
||||
*/
|
||||
public function dbOperation(DbOperationType $operation): self
|
||||
public function setDbOperation(DbOperationType $operation): self
|
||||
{
|
||||
$this->result = $this->result->addDbOperation($operation);
|
||||
return $this;
|
||||
@@ -510,7 +512,7 @@ class ProcessContextBuilder
|
||||
/**
|
||||
* 设置需要数据库操作
|
||||
*/
|
||||
public function needDatabaseOperation(bool $need = true): self
|
||||
public function setNeedDatabaseOperation(bool $need = true): self
|
||||
{
|
||||
$this->result = new ExecutionResult(
|
||||
success: $this->result->success,
|
||||
@@ -525,7 +527,7 @@ class ProcessContextBuilder
|
||||
/**
|
||||
* 设置需要WebSocket通知
|
||||
*/
|
||||
public function needWebSocketNotify(bool $need = true): self
|
||||
public function setNeedWebSocketNotify(bool $need = true): self
|
||||
{
|
||||
$this->result = $this->result->withWebSocketNotify($need);
|
||||
return $this;
|
||||
@@ -542,25 +544,25 @@ class ProcessContextBuilder
|
||||
|
||||
// ==================== 提醒状态便捷设置方法 ====================
|
||||
|
||||
public function withNeedEnhanceWash(bool $need): self
|
||||
public function setNeedEnhanceWash(bool $need): self
|
||||
{
|
||||
$this->reminder = $this->reminder->withEnhanceWash($need);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNeedLeakTestRemind(bool $need): self
|
||||
public function setNeedLeakTestRemind(bool $need): self
|
||||
{
|
||||
$this->reminder = $this->reminder->withLeakTestRemind($need);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNeedStorageRemind(bool $need): self
|
||||
public function setNeedStorageRemind(bool $need): self
|
||||
{
|
||||
$this->reminder = $this->reminder->withStorageRemind($need);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withLeakTestDone(bool $done, string $result = ''): self
|
||||
public function setLeakTestDone(bool $done, string $result = ''): self
|
||||
{
|
||||
$this->reminder = $this->reminder->withLeakTestDone($result);
|
||||
return $this;
|
||||
@@ -568,13 +570,13 @@ class ProcessContextBuilder
|
||||
|
||||
// ==================== 标记设置方法 ====================
|
||||
|
||||
public function withIsOperatorCard(bool $isOperatorCard): self
|
||||
public function setIsOperatorCard(bool $isOperatorCard): self
|
||||
{
|
||||
$this->isOperatorCard = $isOperatorCard;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStepDuration(string $stepCode, int $duration): self
|
||||
public function setStepDuration(string $stepCode, int $duration): self
|
||||
{
|
||||
$this->stepDurations[$stepCode] = $duration;
|
||||
return $this;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class MorningWashStrategy extends AbstractStrategy
|
||||
todayWashRecords: $context->getMorningWash()->todayWashRecords
|
||||
);
|
||||
|
||||
return $context->builder()->withMorningWash($morningWash)->build();
|
||||
return $context->createModifyBuilder()->setMorningWash($morningWash)->build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,7 +79,7 @@ class TimeValidationStrategy extends AbstractStrategy
|
||||
// 从数据库按流程类型精确查询
|
||||
$requiredDuration = $this->getDurationFromDb($stepCode, $processType);
|
||||
if ($requiredDuration > 0) {
|
||||
$context = $context->builder()->withStepDuration($stepCode, $requiredDuration)->build();
|
||||
$context = $context->createModifyBuilder()->setStepDuration($stepCode, $requiredDuration)->build();
|
||||
} else {
|
||||
// 最后使用上下文已缓存值
|
||||
$requiredDuration = $context->getStepDuration($stepCode);
|
||||
@@ -106,7 +106,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 = $context->builder()->customError($voice)->build();
|
||||
$context = $context->createModifyBuilder()->setCustomError($voice)->build();
|
||||
}
|
||||
return $context;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class VoiceGenerationStrategy extends AbstractStrategy
|
||||
"流程中存在自定义语音或存在多次设置语音,语音应该在 VoiceGenerationStrategy 策略中配置,否则不能拦截与自定义配置",
|
||||
new IllegalUsageException("In the existing process, there is custom voice, which should be configured in the VoiceGenerationStrategy strategy; otherwise, it cannot be intercepted and customized")
|
||||
);
|
||||
return $context->builder()->voiceMessage($context->getVoice()->message)->build();
|
||||
return $context->createModifyBuilder()->setVoiceMessage($context->getVoice()->message)->build();
|
||||
}
|
||||
|
||||
// 如果已经有错误,生成错误语音
|
||||
@@ -56,7 +56,7 @@ class VoiceGenerationStrategy extends AbstractStrategy
|
||||
}
|
||||
Logger::debug("应用语音模板后的内容: {$voice}");
|
||||
|
||||
return $context->builder()->voiceMessage($voice)->build();
|
||||
return $context->createModifyBuilder()->setVoiceMessage($voice)->build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -245,7 +245,7 @@ class VirtualContextBuilder
|
||||
/**
|
||||
* 设置操作时长(秒)
|
||||
*/
|
||||
public function duration(int $seconds): self
|
||||
public function setDuration(int $seconds): self
|
||||
{
|
||||
$this->processStatus = new ProcessStatus(
|
||||
currentStep: $this->processStatus->currentStep,
|
||||
@@ -277,7 +277,7 @@ class VirtualContextBuilder
|
||||
/**
|
||||
* 设置上一条操作记录(虚拟)
|
||||
*/
|
||||
public function previousAction(string $processName, string $batchNo = '', ?string $opEndtime = null): self
|
||||
public function setPreviousAction(string $processName, string $batchNo = '', ?string $opEndtime = null): self
|
||||
{
|
||||
$action = new EctActions();
|
||||
$action->process_name = $processName;
|
||||
|
||||
@@ -124,8 +124,8 @@ class VirtualityFlowProcessor
|
||||
->build();
|
||||
|
||||
// 人员卡不走流程链,直接返回
|
||||
$result = $context->builder()
|
||||
->voiceMessage('请刷内镜卡')
|
||||
$result = $context->createModifyBuilder()
|
||||
->setVoiceMessage('请刷内镜卡')
|
||||
->build();
|
||||
|
||||
$this->history[] = $result;
|
||||
@@ -147,6 +147,7 @@ class VirtualityFlowProcessor
|
||||
?? throw new \InvalidArgumentException("未找到内镜: {$endoscopeName}");
|
||||
|
||||
// 获取内镜当前状态
|
||||
/** @var ProcessContext $currentState */
|
||||
$currentState = $this->endoscopeStates[$endoscopeData['id']] ?? null;
|
||||
|
||||
// 构建上下文
|
||||
@@ -164,12 +165,13 @@ class VirtualityFlowProcessor
|
||||
// 继承之前的流程状态
|
||||
if ($currentState !== null) {
|
||||
$builder->currentStep($currentState->getCurrentStep())
|
||||
->batchNo($currentState->getBatchNo())
|
||||
->processType($currentState->getProcessType());
|
||||
->batchNo($currentState->getBatchNo())
|
||||
->setDuration(time() - strtotime($currentState->getActionStartTime()))
|
||||
->processType($currentState->getProcessType());
|
||||
|
||||
// 设置 previousAction:上一步骤名称就是当前状态的 currentStep
|
||||
if (!empty($currentState->getCurrentStep())) {
|
||||
$builder->previousAction($currentState->getCurrentStep(), $currentState->getBatchNo());
|
||||
$builder->setPreviousAction($currentState->getCurrentStep(), $currentState->getBatchNo());
|
||||
}
|
||||
} else {
|
||||
// 新流程
|
||||
@@ -180,7 +182,7 @@ class VirtualityFlowProcessor
|
||||
|
||||
// 未刷人员卡检查
|
||||
if (!$context->hasOperator() && !isset($this->operatorSessions[$readerData['id']])) {
|
||||
$result = $context->builder()
|
||||
$result = $context->createModifyBuilder()
|
||||
->error(\app\flow\enum\VoiceMessage::PLEASE_SWIPE_OPERATOR)
|
||||
->build();
|
||||
$this->history[] = $result;
|
||||
@@ -193,8 +195,8 @@ class VirtualityFlowProcessor
|
||||
// 确保 previousAction 在结果中正确设置
|
||||
// 如果执行成功且有上一步骤信息,确保 previousAction 被保留
|
||||
if ($result->isSuccess() && $context->getPreviousAction() !== null && $result->getPreviousAction() === null) {
|
||||
$result = $result->builder()
|
||||
->withPreviousAction($context->getPreviousAction())
|
||||
$result = $result->createModifyBuilder()
|
||||
->setPreviousAction($context->getPreviousAction())
|
||||
->build();
|
||||
}
|
||||
|
||||
@@ -223,13 +225,13 @@ class VirtualityFlowProcessor
|
||||
|
||||
// 刷内镜卡
|
||||
Logger::info("测试刷卡:{$endoscopeName}, {$readerType}");
|
||||
$result = $this->swipeEndoscopeCard($endoscopeName, $readerType);
|
||||
$result = $this->swipeEndoscopeCard($endoscopeName, $readerType);
|
||||
Logger::info("当前流程:{}", [$result->getProcessType()]);
|
||||
Logger::info("当前批次号:{}", [$result->getBatchNo()]);
|
||||
Logger::info("当前步骤:{}", [$result->getCurrentStep()]);
|
||||
Logger::info("上一个步骤类型:{}", [$result->getPreviousAction()->action_type_name?? "null"]);
|
||||
Logger::info("上一个步骤:{}", [$result->getPreviousAction()->process_name??"null"]);
|
||||
Logger::info("时长:{}", [$result->getDuration()?? "null"]);
|
||||
Logger::info("上一个步骤类型:{}", [$result->getPreviousAction()->action_type_name ?? "null"]);
|
||||
Logger::info("上一个步骤:{}", [$result->getPreviousAction()->process_name ?? "null"]);
|
||||
Logger::info("时长:{}", [$result->getDuration() ?? "null"]);
|
||||
Logger::info("当前语音:{$result->getFullVoice()}\n");
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user