Commit 58b49ba9 by liimin

refactor(recorder): 重构录音服务业务数据处理逻辑

- 移除 BusiType 类型定义,简化业务数据处理接口
- 修改 getBusinessData 方法,移除 type 参数,改为直接获取完整记录数据
- 更新 onAudioStop 方法参数命名,使用下划线前缀表示未使用参数
- 简化 updateBusinessData 方法,移除 type 参数,自动根据字段判断缓存或持久化
- 重构 DefaultRecorderStrategy,移除复杂的策略配置映射
- 实现统一的 processBusinessData 方法处理数据缓存和持久化逻辑
- 更新 IBusinessDataHandler 接口定义,使用新的方法签名
- 优化数据合并逻辑,使用深拷贝避免引用问题
- 添加错误处理和空值检查,提高代码健壮性
1 parent 4faff569
......@@ -10,7 +10,7 @@ import DBRecord from "./DBRecord.uts";
import { RecorderStrategyFactory } from "./strategies/RecorderStrategyFactory.uts";
import TempRecord from "./TempRecord.uts";
import TimeoutService from "./TimeoutService.uts";
import { BusiType, RecordData, RecordFile } from "./types";
import { RecordData, RecordFile } from "./types";
import { IRecorderStrategy } from "./types/strategy.uts";
export class RecordService {
......@@ -48,10 +48,22 @@ export class RecordService {
* @param type 业务数据类型标识 (如 'customer', 'book', 'status', 'material')
* @returns 业务数据,如果不存在则返回 null
*/
async getBusinessData(type: BusiType): Promise<any> {
async getBusinessData(): Promise<any> {
const recordId = this.record?.currentRecord?.id ?? "";
const currentRecord = this.record?.currentRecord as any | null;
return await this.businessHandler.getBusinessData(recordId, currentRecord, type);
if (recordId === "") {
console.warn("[getBusinessData] recordId is empty, return null");
return null;
}
try {
const fullRecord = await this.record?.getRecord(recordId) as UTSJSONObject;
const businessData = await this.businessHandler.getBusinessData(recordId, fullRecord as any) as UTSJSONObject;
return businessData;
} catch (error) {
handleError(error, "RecordService", "[getBusinessData] Error fetching record from database:");
return null;
}
}
......@@ -135,7 +147,7 @@ export class RecordService {
}
}
async onAudioStop(res: any) {
async onAudioStop(_res: any) {
if (this.audioManager?.isRecording === true) {
logger.info("【录音服务RecordService】 == 接待中,再次开启录音! ", "RecordService");
this.audioManager?.start();
......@@ -246,13 +258,12 @@ export class RecordService {
/**
* 通用业务数据更新入口
* @param type 业务数据类型标识 (如 'customer', 'book', 'status', 'material')
* @param data 数据载荷
* @param data 数据载荷,会自动根据字段判断是缓存还是直接持久化
*/
updateBusinessData(type: string, data: any | null) {
updateBusinessData(data: any | null) {
// if (!this.isReceptioning()) return;
// 委托给 Handler 处理,传入 recordId 以便策略自行决定缓存还是持久化
const result = this.businessHandler.handle(type, data, this.record?.currentRecord?.id ?? "");
const result = this.businessHandler.processBusinessData(data, this.record?.currentRecord?.id ?? "");
console.log("🚀 ~ RecordService ~ updateBusinessData ~ result:", result, this.record);
// 如果策略返回 null,说明已经由策略自行处理(如缓存)或无需处理
if (result === null) return;
......
......@@ -30,5 +30,5 @@ export interface IBusinessDataHandler {
* 返回 null 表示无需处理或忽略
* 返回带有 _isCache: true 的对象表示缓存操作
*/
handle(type: string, data: any | null, recordId: string): null | UTSJSONObject
processBusinessData(data: any | null, recordId: string): null | UTSJSONObject
}
import { BusiType, IBusinessDataHandler } from "./handler";
import { IBusinessDataHandler } from "./handler";
/**
* 录音业务策略接口
......@@ -53,7 +53,7 @@ export interface IRecorderStrategy extends IBusinessDataHandler {
* @param type 业务数据类型标识,默认为 "all" 获取所有数据
* @returns 业务数据,如果 type 为具体类型则返回该类型数据,否则返回所有数据
*/
getBusinessData(recordId: string, currentRecord: any | null, type: BusiType): Promise<any>
getBusinessData(recordId: string, currentRecord: any | null): Promise<any|null>
/**
* 保存前数据处理:将业务数据与核心记录数据合并(可选实现)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!