Commit 4faff569 by liimin

feat(recorder): 集成录音服务并优化业务数据处理

- 在App启动时集成录音服务模拟接待流程
- 实现业务数据的深度克隆和合并逻辑
- 重构默认录音策略的数据获取和处理方法
- 添加客户信息和物料轨迹点数据类型定义
- 优化缓存处理逻辑和错误处理机制
- 更新业务数据类型注释和接口定义
1 parent 96cba921
......@@ -131,7 +131,6 @@ export class RecordService {
await this.record.addAudio(recordFile);
}
} catch (error) {
console.log("🚀 ~ RecordService ~ onAudioStart ~ error:", error);
handleError(error, "RecordService", "〖RecordService〗 == onAudioStart error:");
}
}
......@@ -251,10 +250,10 @@ export class RecordService {
* @param data 数据载荷
*/
updateBusinessData(type: string, data: any | null) {
if (!this.isReceptioning()) return;
// if (!this.isReceptioning()) return;
// 委托给 Handler 处理,传入 recordId 以便策略自行决定缓存还是持久化
const result = this.businessHandler.handle(type, data, this.record?.currentRecord?.id ?? "");
console.log("🚀 ~ RecordService ~ updateBusinessData ~ result:", result, this.record);
// 如果策略返回 null,说明已经由策略自行处理(如缓存)或无需处理
if (result === null) return;
......
......@@ -125,11 +125,13 @@ class TempRecord {
* @returns {Promise<void>|undefined} 值未变化时返回 undefined
*/
async __update(items: null | UTSJSONObject): Promise<void> {
const record = this.record;
if (record === null || items === null) return;
// 直接应用所有更新
Object.assign(record, items);
this.record = record;
// 使用深拷贝合并数据,确保新对象引用
const merged = Object.assign({}, record, items);
this.record = deepClone<RecordData>(merged);
// 持久化到数据库
const id = record.id;
await this.updateRecord(items, { id });
......
import type { MaterialPointData, RecordData } from "../types/record.uts";
import { storage } from "../../../utils/storage.uts";
import { BusiType } from "../types/handler.uts";
import { IRecorderStrategy } from "../types/strategy.uts";
......@@ -33,11 +35,10 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
}],
["customer", {
fetcher: (_: string, currentRecord: any | null): UTSJSONObject => this.fetchCustomerData(currentRecord === null ? null : JSON.parse(JSON.stringify(currentRecord)) as UTSJSONObject),
fetcher: (_: string, currentRecord: any | null): UTSJSONObject => this.fetchCustomerData(currentRecord as null | RecordData),
processor: (data: any | null, _: string): null | UTSJSONObject => this.processCustomerInfo(data as null | UTSJSONObject),
merger: (merged: UTSJSONObject, data: any): void => {
const customerData = data as UTSJSONObject;
Object.assign(merged, customerData);
Object.assign(merged, data as IUTSObject);
}
}],
["material", {
......@@ -192,7 +193,7 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
/**
* 获取客户信息数据
*/
private fetchCustomerData(currentRecord: null | UTSJSONObject): UTSJSONObject {
private fetchCustomerData(currentRecord: null | RecordData): UTSJSONObject {
console.log(`[fetchCustomerData] currentRecord: ${JSON.stringify(currentRecord)}`);
if (currentRecord === null) {
......@@ -200,17 +201,17 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
return {} as UTSJSONObject;
}
const result = {
customerName: currentRecord.get("customerName"),
phoneNumber: currentRecord.get("phoneNumber"),
carModel: currentRecord.get("carModel"),
salesUuid: currentRecord.get("salesUuid"),
salesName: currentRecord.get("staffName"),
carBrand: currentRecord.get("carBrand"),
carBrandId: currentRecord.get("carBrandId"),
oneCarBrand: currentRecord.get("oneCarBrand"),
oneCarBrandId: currentRecord.get("oneCarBrandId")
} as UTSJSONObject;
const result: UTSJSONObject = {
customerName: currentRecord.customerName,
phoneNumber: currentRecord.phoneNumber,
carModel: currentRecord.carModel,
salesUuid: currentRecord.salesUuid,
salesName: currentRecord.staffName,
carBrand: currentRecord.carBrand,
carBrandId: currentRecord.carBrandId,
oneCarBrand: currentRecord.oneCarBrand,
oneCarBrandId: currentRecord.oneCarBrandId
};
console.log(`[fetchCustomerData] result: ${JSON.stringify(result)}`);
return result;
......@@ -219,18 +220,18 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
/**
* 获取物料轨迹点数据(从缓存)
*/
private async fetchMaterialData(recordId: string): Promise<UTSJSONObject> {
if (recordId === "") return {} as UTSJSONObject;
private async fetchMaterialData(recordId: string): Promise<MaterialPointData> {
if (recordId === "") return {} as MaterialPointData;
const storageKey = `MATERIAL_POINTS_${recordId}`;
const materialList = await StrategyUtils.loadFromStorage(storageKey);
const materialList: any | null = await StrategyUtils.loadFromStorage(storageKey);
if (materialList !== null && materialList !== "") {
return {
receptionCustomerMaterialPointList: materialList
} as UTSJSONObject;
receptionCustomerMaterialPointList: materialList as any[]
} as MaterialPointData;
}
return {} as UTSJSONObject;
return {} as MaterialPointData;
}
/**
......@@ -274,13 +275,8 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
try {
// 将 currentRecord 转换为 UTSJSONObject
let recordObj: null | UTSJSONObject = null;
if (currentRecord !== null) {
recordObj = JSON.parse(JSON.stringify(currentRecord)) as UTSJSONObject;
}
const fetcher = config.get("fetcher") as ((recordId: string, currentRecord: null | UTSJSONObject) => UTSJSONObject);
return fetcher.invoke(recordId, recordObj);
const fetcher = config.get("fetcher") as ((recordId: string, currentRecord: any | null) => UTSJSONObject);
return fetcher.invoke(recordId, currentRecord);
} catch (error) {
console.error(`[DefaultRecorderStrategy] Fetch ${type} data failed:`, error);
return null;
......@@ -359,19 +355,23 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
private processCustomerInfo(info: null | UTSJSONObject): UTSJSONObject {
if (info === null) return {};
const customerName = info.customerName;
const phoneNumber = info.phoneNumber;
const salesUuid = info.salesUuid;
const carModel = info.carModel;
const salesName = info.staffName;
const carBrand = info.carBrand;
const carBrandId = info.carBrandId;
const oneCarBrand = info.oneCarBrand;
const oneCarBrandId = info.oneCarBrandId;
return {
if (info === null) {
console.warn("[processCustomerInfo] info is null");
return {} as UTSJSONObject;
}
const customerName = info.get("customerName");
const phoneNumber = info.get("phoneNumber");
const carModel = info.get("carModel");
const salesUuid = info.get("salesUuid");
const salesName = info.get("staffName");
const carBrand = info.get("carBrand");
const carBrandId = info.get("carBrandId");
const oneCarBrand = info.get("oneCarBrand");
const oneCarBrandId = info.get("oneCarBrandId");
const result: UTSJSONObject = {
customerName,
phoneNumber,
carModel,
......@@ -382,6 +382,8 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
oneCarBrand,
oneCarBrandId
};
return result;
}
private processMaterialPoints(list: UTSJSONObject[]): UTSJSONObject {
......@@ -421,7 +423,6 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
});
return {
_isCache: true,
key: "MATERIAL_POINTS",
value: receptionCustomerMaterialPointList
};
......@@ -429,13 +430,10 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
private processMaterialPointsWithCache(list: UTSJSONObject[], recordId: string): null | UTSJSONObject {
const result = this.processMaterialPoints(list);
if (result.getBoolean("_isCache") === true) {
const key = result.getString("key");
const val = result.get("value");
if (key !== null && val !== null) {
this.cacheBusinessData(recordId, key, val);
}
return null;
const key = result.getString("key");
const val = result.get("value");
if (key !== null && val !== null) {
this.cacheBusinessData(recordId, key, val);
}
return result;
}
......
......@@ -30,6 +30,28 @@ export type RecordData = {
staffUuid?: null | string
}
/**
* 客户信息数据类型
*/
export type CustomerInfoData = {
carBrand?: null | string
carBrandId?: null | number
carModel?: null | string
customerName?: null | string
oneCarBrand?: null | string
oneCarBrandId?: null | number
phoneNumber?: null | string
salesName?: null | string
salesUuid?: null | string
}
/**
* 物料轨迹点数据类型
*/
export type MaterialPointData = {
receptionCustomerMaterialPointList?: any[] | null
}
export type FileInfo = {
clientPath: string
error?: string
......@@ -58,7 +80,7 @@ export type UploadResultPayload = {
filePath?: null | string
message?: null | string
recordId?: null | string
status?: number | null
status?: null | number
}
export type UploadResultDetail = {
......@@ -70,5 +92,5 @@ export type UploadResult = {
fileName?: null | string
filePath?: null | string
recordId?: null | string
status?: number | null
status?: null | number
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!