e040fccba6
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
151 lines
4.2 KiB
PHP
151 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace app\flow\config;
|
|
|
|
use app\flow\enum\VoiceMessage;
|
|
|
|
/**
|
|
* 语音模板配置类
|
|
* 管理所有流程步骤的语音播报文本
|
|
*/
|
|
class VoiceTemplatesConfig extends AbstractConfig
|
|
{
|
|
/**
|
|
* 晨洗流程语音
|
|
*/
|
|
public array $morningWash {
|
|
get => $this->config['morning_wash'];
|
|
}
|
|
|
|
/**
|
|
* 标准手工洗流程语音
|
|
*/
|
|
public array $normalWash {
|
|
get => $this->config['normal_wash'];
|
|
}
|
|
|
|
/**
|
|
* 机洗流程语音
|
|
*/
|
|
public array $machineWash {
|
|
get => $this->config['machine_wash'];
|
|
}
|
|
|
|
/**
|
|
* 测漏流程语音
|
|
*/
|
|
public array $leakTest {
|
|
get => $this->config['leak_test'];
|
|
}
|
|
|
|
/**
|
|
* 存储流程语音
|
|
*/
|
|
public array $storage {
|
|
get => $this->config['storage'];
|
|
}
|
|
|
|
/**
|
|
* 错误/提示语音(VoiceMessage name => 文本)
|
|
*/
|
|
public array $voiceMessage {
|
|
get => $this->config['voice_message'];
|
|
}
|
|
|
|
protected array $config = [
|
|
'morning_wash' => [
|
|
'消毒' => '手工晨洗 流程开始',
|
|
'机洗' => '机洗晨洗 开始',
|
|
],
|
|
'normal_wash' => [
|
|
'start' => '清洗流程 开始',
|
|
'清洗' => '清洗',
|
|
'漂洗' => '漂洗',
|
|
'消毒' => '消毒',
|
|
'终末漂洗' => '终末漂洗',
|
|
'干燥' => '干燥',
|
|
'结束' => '流程结束',
|
|
],
|
|
'machine_wash' => [
|
|
'start' => '机洗流程 开始',
|
|
'机洗' => '机洗完成',
|
|
],
|
|
'leak_test' => [
|
|
'测漏正常' => '测漏正常',
|
|
'测漏异常' => '内镜测漏异常,请检查',
|
|
],
|
|
'storage' => [
|
|
'内镜放入' => '内镜放入',
|
|
'内镜取出' => '内镜取出',
|
|
],
|
|
'voice_message' => [
|
|
'wrong_step' => '刷错,请刷{expected}',
|
|
VoiceMessage::DUPLICATE_SWIPING->name => '刷错,重复刷卡',
|
|
'not_completed' => '刷错,清洗完成才能入柜',
|
|
],
|
|
];
|
|
|
|
public function __construct(array $config = [])
|
|
{
|
|
$this->config = array_merge($this->config, $config);
|
|
}
|
|
|
|
|
|
/**
|
|
* 按模板 key 获取整组模板
|
|
*/
|
|
public function getTemplates(string $key): array
|
|
{
|
|
return match ($key) {
|
|
'morning_wash' => $this->morningWash,
|
|
'normal_wash' => $this->normalWash,
|
|
'machine_wash' => $this->machineWash,
|
|
'leak_test' => $this->leakTest,
|
|
'storage' => $this->storage,
|
|
'voice_message' => $this->voiceMessage,
|
|
default => $this->expand[$key] ?? [],
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 设置指定步骤的自定义语音
|
|
* @deprecated
|
|
*/
|
|
public function setStepVoice(string $stepCode, string $voice): self
|
|
{
|
|
$this->config['custom'][$stepCode] = $voice;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 从数组创建
|
|
*
|
|
* @param array $config = [
|
|
* 'morning_wash' => ['start' => '手工晨洗 流程开始', 'machine_start' => '机洗晨洗 开始'],
|
|
* 'normal_wash' => ['start' => '清洗流程 开始', '清洗' => '清洗', '漂洗' => '漂洗', ...],
|
|
* 'machine_wash' => ['start' => '机洗流程 开始', '机洗' => '机洗完成'],
|
|
* 'leak_test' => ['测漏正常' => '测漏正常', '测漏异常' => '内镜测漏异常,请检查'],
|
|
* 'storage' => ['内镜放入' => '内镜放入', '内镜取出' => '内镜取出'],
|
|
* 'voice_message' => ['wrong_step' => '刷错,请刷{expected}', 'not_completed' => '...'],
|
|
* ]
|
|
*/
|
|
public static function create(array $config = []): self
|
|
{
|
|
$instance = new self($config);
|
|
$instance->log("加载[voice_templates]语音模板配置,来源: {}", [empty($config) ? "默认配置" : "自定义配置"]);
|
|
return $instance;
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'morning_wash' => $this->morningWash,
|
|
'normal_wash' => $this->normalWash,
|
|
'machine_wash' => $this->machineWash,
|
|
'leak_test' => $this->leakTest,
|
|
'storage' => $this->storage,
|
|
'voice_message' => $this->voiceMessage,
|
|
];
|
|
}
|
|
}
|