Commit 4faff569 by liimin

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

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