f2ff4ae123
- 将 FLOW_USE_CUSTOM_PROCESS 从 true 改为 false,禁用自定义流程 - 在 BlockTest 测试用例中改用 setBlockMode 方法设置阻断模式 - 设置统一的错误处理,将错误转为异常抛出 - 重命名 BlockTest 测试文件路径,优化测试组织结构 - 更新 IDE php include paths,调整依赖包引用顺序 - 删除无用的 tests/flow/Test.php 测试文件 - 微调 start.php、webman、windows.php 配置或代码模块
372 lines
9.4 KiB
PHP
372 lines
9.4 KiB
PHP
<?php
|
|
|
|
namespace app\flow\context;
|
|
|
|
use app\flow\config\ProcessConfig;
|
|
use app\flow\context\bean\EndoscopeInfo;
|
|
use app\flow\context\bean\ExecutionResult;
|
|
use app\flow\context\bean\MorningWashStatus;
|
|
use app\flow\context\bean\OperatorInfo;
|
|
use app\flow\context\bean\ProcessStatus;
|
|
use app\flow\context\bean\ReaderInfo;
|
|
use app\flow\context\bean\ReminderStatus;
|
|
use app\flow\context\bean\StorageStatus;
|
|
use app\flow\context\bean\VoiceState;
|
|
use app\model\EctActions;
|
|
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;
|
|
}
|
|
|
|
// ==================== 便捷查询方法(带数据来源标注) ====================
|
|
|
|
/**
|
|
* 获取当前步骤
|
|
* @return string 当前步骤名称 (来源: ProcessStatus)
|
|
*/
|
|
public function getCurrentStep(): string
|
|
{
|
|
return $this->processStatus->currentStep;
|
|
}
|
|
|
|
/**
|
|
* 获取流程类型
|
|
* @return string 流程类型 (来源: ProcessStatus)
|
|
*/
|
|
public function getProcessType(): string
|
|
{
|
|
return $this->processStatus->processType;
|
|
}
|
|
|
|
/**
|
|
* 获取批次号
|
|
* @return string 批次号 (来源: ProcessStatus)
|
|
*/
|
|
public function getBatchNo(): string
|
|
{
|
|
return $this->processStatus->batchNo;
|
|
}
|
|
|
|
/**
|
|
* 获取操作开始时间
|
|
* @return string 操作开始时间 (来源: ProcessStatus)
|
|
*/
|
|
public function getActionStartTime(): string
|
|
{
|
|
return $this->processStatus->actionStartTime;
|
|
}
|
|
|
|
/**
|
|
* 获取操作时长
|
|
* @return int|null 操作时长(秒)(来源: ProcessStatus)
|
|
*/
|
|
public function getDuration(): ?int
|
|
{
|
|
return $this->processStatus->duration;
|
|
}
|
|
|
|
/**
|
|
* 获取上一个操作记录
|
|
* @return EctActions|null 上一个操作记录 (来源: ProcessStatus)
|
|
*/
|
|
public function getPreviousAction(): ?EctActions
|
|
{
|
|
return $this->processStatus->previousAction;
|
|
}
|
|
|
|
/**
|
|
* 获取完整语音
|
|
* @return string 完整语音内容 (来源: VoiceState)
|
|
*/
|
|
public function getFullVoice(): string
|
|
{
|
|
return $this->voice->getFullVoice();
|
|
}
|
|
|
|
/**
|
|
* 流程是否成功
|
|
* @return bool 是否成功 (来源: ExecutionResult)
|
|
*/
|
|
public function isSuccess(): bool
|
|
{
|
|
return $this->result->success;
|
|
}
|
|
|
|
/**
|
|
* 是否需要操作数据库
|
|
* @return bool 是否需要数据库操作 (来源: ExecutionResult)
|
|
*/
|
|
public function isDatabaseOperationNeeded(): bool
|
|
{
|
|
return $this->result->needDatabaseOperation;
|
|
}
|
|
|
|
/**
|
|
* 是否需要WebSocket通知
|
|
* @return bool 是否需要通知 (来源: ExecutionResult)
|
|
*/
|
|
public function isWebSocketNotifyNeeded(): bool
|
|
{
|
|
return $this->result->needWebSocketNotify;
|
|
}
|
|
|
|
/**
|
|
* 获取数据库操作列表
|
|
* @return array 数据库操作列表 (来源: ExecutionResult)
|
|
*/
|
|
public function getDbOperations(): array
|
|
{
|
|
return $this->result->dbOperations;
|
|
}
|
|
|
|
/**
|
|
* 检查是否可以开始新流程
|
|
* @return bool 是否可以开始新流程 (来源: ProcessStatus)
|
|
*/
|
|
public function canStartNewProcess(): bool
|
|
{
|
|
return $this->processStatus->canStartNewProcess();
|
|
}
|
|
|
|
/**
|
|
* 检查是否已完成清洗流程
|
|
* @return bool 是否已完成 (来源: ProcessStatus)
|
|
*/
|
|
public function isWashProcessCompleted(): bool
|
|
{
|
|
return $this->processStatus->isWashProcessCompleted();
|
|
}
|
|
|
|
/**
|
|
* 是否有操作员
|
|
* @return bool 是否有有效操作员 (来源: OperatorInfo)
|
|
*/
|
|
public function hasOperator(): bool
|
|
{
|
|
return $this->operator->isValid();
|
|
}
|
|
|
|
/**
|
|
* 获取步骤时长(从缓存或返回0)
|
|
*/
|
|
public function getStepDuration(string $stepCode): int
|
|
{
|
|
return $this->stepDurations[$stepCode] ?? 0;
|
|
}
|
|
|
|
/**
|
|
* 是否需要增强洗
|
|
* @return bool 是否需要增强洗 (来源: ReminderStatus)
|
|
*/
|
|
public function isEnhanceWashNeeded(): bool
|
|
{
|
|
return $this->reminder->needEnhanceWash;
|
|
}
|
|
|
|
/**
|
|
* 是否需要测漏提醒
|
|
* @return bool 是否需要测漏提醒 (来源: ReminderStatus)
|
|
*/
|
|
public function isLeakTestRemindNeeded(): bool
|
|
{
|
|
return $this->reminder->needLeakTestRemind;
|
|
}
|
|
|
|
/**
|
|
* 是否需要存储提醒
|
|
* @return bool 是否需要存储提醒 (来源: ReminderStatus)
|
|
*/
|
|
public function isStorageRemindNeeded(): bool
|
|
{
|
|
return $this->reminder->needStorageRemind;
|
|
}
|
|
|
|
/**
|
|
* 是否已测漏
|
|
* @return bool 是否已测漏 (来源: ReminderStatus)
|
|
*/
|
|
public function isLeakTestDoneByReminder(): bool
|
|
{
|
|
return $this->reminder->leakTestDone;
|
|
}
|
|
|
|
/**
|
|
* 获取测漏结果
|
|
* @return string 测漏结果 (来源: ReminderStatus)
|
|
*/
|
|
public function getLeakTestResultByReminder(): 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);
|
|
}
|
|
}
|