refactor(context): 重命名上下文构建器及更新相关方法命名
- 将 ProcessContext 中的 builder() 重命名为 createModifyBuilder() 并添加调用栈日志 - ProcessContextBuilder 中所有 with* 方法统一改为 set* 命名风格 - Flow 各节点及流程处理器中调用 builder() 替换为 createModifyBuilder() - 虚拟测试环境相关 ContextBuilder 中方法同步改名保持一致 - 优化流程节点中上下文修改代码调用,提升代码规范性 - 添加Config中加载自定义流程配置的占位注释及代码 - 无功能改动,纯代码风格及命名规范调整
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user