ai-refactor(flow): 调整抽象流程节点实现和依赖路径
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
This commit is contained in:
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
|
||||
namespace app\flow\context;
|
||||
|
||||
use app\flow\config\ProcessConfig;
|
||||
use app\flow\vo\EndoscopeInfo;
|
||||
use app\flow\vo\ExecutionResult;
|
||||
use app\flow\vo\MorningWashStatus;
|
||||
use app\flow\vo\OperatorInfo;
|
||||
use app\flow\vo\ProcessStatus;
|
||||
use app\flow\vo\ReaderInfo;
|
||||
use app\flow\vo\ReminderStatus;
|
||||
use app\flow\vo\StorageStatus;
|
||||
use app\flow\vo\VoiceState;
|
||||
use app\net\PacketContext;
|
||||
|
||||
/**
|
||||
* 流程上下文类(不可变)
|
||||
*
|
||||
* 所有属性均为只读,修改上下文必须通过 builder() 方法创建新实例。
|
||||
* 用于在责任链节点之间传递数据。
|
||||
*/
|
||||
readonly class ProcessContext
|
||||
{
|
||||
public function __construct(
|
||||
// ==================== 值对象 ====================
|
||||
/** 内镜信息 */
|
||||
private EndoscopeInfo $endoscope,
|
||||
/** 读卡器信息 */
|
||||
private ReaderInfo $reader,
|
||||
/** 操作员信息 */
|
||||
private OperatorInfo $operator,
|
||||
/** 存储状态 */
|
||||
private StorageStatus $storage,
|
||||
/** 晨洗状态 */
|
||||
private MorningWashStatus $morningWash,
|
||||
/** 语音状态 */
|
||||
private VoiceState $voice,
|
||||
/** 执行结果状态 */
|
||||
private ExecutionResult $result,
|
||||
/** 流程状态 */
|
||||
private ProcessStatus $processStatus,
|
||||
/** 提醒状态 */
|
||||
private ReminderStatus $reminder,
|
||||
|
||||
// ==================== 原始数据 ====================
|
||||
/** 原始刷卡数据 */
|
||||
private ?PacketContext $packetContext = null,
|
||||
/** 流程引擎配置 */
|
||||
private ?ProcessConfig $engineConfig = null,
|
||||
/** 原始数据数组 */
|
||||
private array $rawData = [],
|
||||
|
||||
// ==================== 标记 ====================
|
||||
/** 是否是人员卡 */
|
||||
private bool $isOperatorCard = false,
|
||||
/** 各步骤时长缓存 */
|
||||
private array $stepDurations = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 创建空的上下文实例
|
||||
*/
|
||||
public static function empty(): self
|
||||
{
|
||||
return new self(
|
||||
endoscope: EndoscopeInfo::empty(),
|
||||
reader: ReaderInfo::empty(),
|
||||
operator: OperatorInfo::empty(),
|
||||
storage: StorageStatus::notInStorage(),
|
||||
morningWash: MorningWashStatus::notRequired(),
|
||||
voice: VoiceState::empty(),
|
||||
result: ExecutionResult::success(),
|
||||
processStatus: ProcessStatus::empty(),
|
||||
reminder: ReminderStatus::none(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个基于当前上下文的 Builder
|
||||
* 用于创建修改后的新上下文实例
|
||||
*/
|
||||
public function builder(): ProcessContextBuilder
|
||||
{
|
||||
return ProcessContextBuilder::from($this);
|
||||
}
|
||||
|
||||
// ==================== Getter 方法 ====================
|
||||
|
||||
public function getEndoscope(): EndoscopeInfo
|
||||
{
|
||||
return $this->endoscope;
|
||||
}
|
||||
|
||||
public function getReader(): ReaderInfo
|
||||
{
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
public function getOperator(): OperatorInfo
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
public function getStorage(): StorageStatus
|
||||
{
|
||||
return $this->storage;
|
||||
}
|
||||
|
||||
public function getMorningWash(): MorningWashStatus
|
||||
{
|
||||
return $this->morningWash;
|
||||
}
|
||||
|
||||
public function getVoice(): VoiceState
|
||||
{
|
||||
return $this->voice;
|
||||
}
|
||||
|
||||
public function getResult(): ExecutionResult
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function getProcessStatus(): ProcessStatus
|
||||
{
|
||||
return $this->processStatus;
|
||||
}
|
||||
|
||||
public function getReminder(): ReminderStatus
|
||||
{
|
||||
return $this->reminder;
|
||||
}
|
||||
|
||||
public function getPacketContext(): ?PacketContext
|
||||
{
|
||||
return $this->packetContext;
|
||||
}
|
||||
|
||||
public function getEngineConfig(): ?ProcessConfig
|
||||
{
|
||||
return $this->engineConfig;
|
||||
}
|
||||
|
||||
public function getRawData(): array
|
||||
{
|
||||
return $this->rawData;
|
||||
}
|
||||
|
||||
public function isOperatorCard(): bool
|
||||
{
|
||||
return $this->isOperatorCard;
|
||||
}
|
||||
|
||||
public function getStepDurations(): array
|
||||
{
|
||||
return $this->stepDurations;
|
||||
}
|
||||
|
||||
// ==================== 便捷查询方法 ====================
|
||||
|
||||
/**
|
||||
* 获取当前步骤
|
||||
*/
|
||||
public function getCurrentStep(): string
|
||||
{
|
||||
return $this->processStatus->currentStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程类型
|
||||
*/
|
||||
public function getProcessType(): string
|
||||
{
|
||||
return $this->processStatus->processType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取批次号
|
||||
*/
|
||||
public function getBatchNo(): string
|
||||
{
|
||||
return $this->processStatus->batchNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作开始时间
|
||||
*/
|
||||
public function getActionStartTime(): string
|
||||
{
|
||||
return $this->processStatus->actionStartTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作时长
|
||||
*/
|
||||
public function getDuration(): ?int
|
||||
{
|
||||
return $this->processStatus->duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上一个操作记录
|
||||
*/
|
||||
public function getPreviousAction(): ?\app\model\EctActions
|
||||
{
|
||||
return $this->processStatus->previousAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整语音
|
||||
*/
|
||||
public function getFullVoice(): string
|
||||
{
|
||||
return $this->voice->getFullVoice();
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程是否成功
|
||||
*/
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
return $this->result->success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要操作数据库
|
||||
*/
|
||||
public function needDatabaseOperation(): bool
|
||||
{
|
||||
return $this->result->needDatabaseOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要WebSocket通知
|
||||
*/
|
||||
public function needWebSocketNotify(): bool
|
||||
{
|
||||
return $this->result->needWebSocketNotify;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库操作列表
|
||||
*/
|
||||
public function getDbOperations(): array
|
||||
{
|
||||
return $this->result->dbOperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否可以开始新流程
|
||||
*/
|
||||
public function canStartNewProcess(): bool
|
||||
{
|
||||
return $this->processStatus->canStartNewProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已完成清洗流程
|
||||
*/
|
||||
public function isWashProcessCompleted(): bool
|
||||
{
|
||||
return $this->processStatus->isWashProcessCompleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有操作员
|
||||
*/
|
||||
public function hasOperator(): bool
|
||||
{
|
||||
return $this->operator->isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取步骤时长(从缓存或返回0)
|
||||
*/
|
||||
public function getStepDuration(string $stepCode): int
|
||||
{
|
||||
return $this->stepDurations[$stepCode] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要增强洗
|
||||
*/
|
||||
public function needEnhanceWash(): bool
|
||||
{
|
||||
return $this->reminder->needEnhanceWash;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要测漏提醒
|
||||
*/
|
||||
public function needLeakTestRemind(): bool
|
||||
{
|
||||
return $this->reminder->needLeakTestRemind;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要存储提醒
|
||||
*/
|
||||
public function needStorageRemind(): bool
|
||||
{
|
||||
return $this->reminder->needStorageRemind;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否已测漏
|
||||
*/
|
||||
public function isLeakTestDone(): bool
|
||||
{
|
||||
return $this->reminder->leakTestDone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取测漏结果
|
||||
*/
|
||||
public function getLeakTestResult(): string
|
||||
{
|
||||
return $this->reminder->leakTestResult;
|
||||
}
|
||||
|
||||
// ==================== 序列化方法 ====================
|
||||
|
||||
/**
|
||||
* 转换为数组
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'endoscope' => $this->endoscope->toArray(),
|
||||
'reader' => $this->reader->toArray(),
|
||||
'operator' => $this->operator->toArray(),
|
||||
'storage' => $this->storage->toArray(),
|
||||
'morningWash' => $this->morningWash->toArray(),
|
||||
'voice' => $this->voice->toArray(),
|
||||
'result' => $this->result->toArray(),
|
||||
'processStatus' => $this->processStatus->toArray(),
|
||||
'reminder' => $this->reminder->toArray(),
|
||||
'isOperatorCard' => $this->isOperatorCard,
|
||||
'stepDurations' => $this->stepDurations,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 JSON 字符串
|
||||
*/
|
||||
public function toJson(int $flags = JSON_UNESCAPED_UNICODE): string
|
||||
{
|
||||
return json_encode($this->toArray(), $flags);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user