Commit 96cba921 by liimin

refactor(recorder): 优化临时记录服务的数据处理逻辑

- 修改 updatePreRecords 方法参数类型支持 null 值
- 修复超时服务中的时间配置错误,将 TIMEOUT 值从 1 改为 40
- 更新默认录音策略中的数据类型定义,统一使用 UTSJSONObject 类型
- 重构 fetcher、processor 和 merger 的调用方式,通过方法名动态获取执行
- 优化数据获取和处理方法,增强类型安全性和数据转换逻辑
- 添加数据获取过程中的空值判断和日志输出功能
- 统一返回值处理,确保所有方法返回正确的 UTSJSONObject 类型
1 parent 9f8ff746
......@@ -409,7 +409,7 @@ class TempRecord {
* @param {object} items - 需要更新的键值对
* @returns {Promise<object>} 返回更新后的记录对象
*/
async updatePreRecords(items: UTSJSONObject): Promise<null | RecordData> {
async updatePreRecords(items: null|UTSJSONObject): Promise<null | RecordData> {
await this.__update(items);
return this.record;
}
......
......@@ -13,7 +13,7 @@ export class TimeoutService {
readonly INTERVAL: number = 1;// 1 分钟检查一次
readonly MINIUTE: number = 60 * 1000;
onStop: (() => Promise<void>) | null = null;
readonly TIMEOUT: number = 1; // 40 分钟
readonly TIMEOUT: number = 40; // 40 分钟
readonly TIMER_DURATION: number;
constructor(onStop: () => Promise<void>) {
......
......@@ -24,16 +24,16 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
]);
// 统一策略配置:包含数据获取和数据处理
private strategyConfig: Map<BusiType, StrategyConfig> = new Map([
private strategyConfig: Map<BusiType, UTSJSONObject> = new Map([
["book", {
fetcher: (_: string, currentRecord: any | null): any => this.fetchBookData(currentRecord),
fetcher: (_: string, currentRecord: any | null): UTSJSONObject => this.fetchBookData(currentRecord === null ? null : JSON.parse(JSON.stringify(currentRecord)) as UTSJSONObject),
processor: (data: any | null, _: string): null | UTSJSONObject => this.processBookList(data as UTSJSONObject[]),
merger: (merged: UTSJSONObject, data: any): void => {
merged.receptionCustomerPaySourceList = data;
}
}],
["customer", {
fetcher: (_: string, currentRecord: any | null): any => this.fetchCustomerData(currentRecord),
fetcher: (_: string, currentRecord: any | null): UTSJSONObject => this.fetchCustomerData(currentRecord === null ? null : JSON.parse(JSON.stringify(currentRecord)) as UTSJSONObject),
processor: (data: any | null, _: string): null | UTSJSONObject => this.processCustomerInfo(data as null | UTSJSONObject),
merger: (merged: UTSJSONObject, data: any): void => {
const customerData = data as UTSJSONObject;
......@@ -49,7 +49,7 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
}],
["status", {
fetcher: (_: string, currentRecord: any | null): any => this.fetchStatusData(currentRecord),
fetcher: (_: string, currentRecord: any | null): UTSJSONObject => this.fetchStatusData(currentRecord === null ? null : JSON.parse(JSON.stringify(currentRecord)) as UTSJSONObject),
processor: (data: any | null, _: string): null | UTSJSONObject => this.processReceptionStatus(data as string),
merger: (merged: UTSJSONObject, data: any): void => {
merged.receptionStatus = data;
......@@ -145,7 +145,7 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
handle(type: BusiType, data: any | null, recordId: string): null | UTSJSONObject {
const config = this.strategyConfig.get(type);
const config: null | UTSJSONObject = this.strategyConfig.get(type);
if (config === null) {
console.warn(`[DefaultRecorderStrategy] Unknown data type: ${type}`);
......@@ -153,7 +153,8 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
try {
return config.processor.invoke(data, recordId);
const processor = config.get("processor") as ((data: any | null, recordId: string) => null | UTSJSONObject);
return processor.invoke(data, recordId);
} catch (error) {
console.error(`[DefaultRecorderStrategy] Process ${type} data failed:`, error);
return null;
......@@ -180,43 +181,46 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
/**
* 获取预订单数据
*/
private fetchBookData(currentRecord: any | null): any {
private fetchBookData(currentRecord: null | UTSJSONObject): UTSJSONObject {
if (currentRecord === null) {
return null as any;
return {} as UTSJSONObject;
}
const obj = currentRecord as UTSJSONObject;
const result = obj.receptionCustomerPaySourceList;
return result === null ? null as any : result;
const result = currentRecord.get("receptionCustomerPaySourceList");
return result === null ? {} as UTSJSONObject : result as UTSJSONObject;
}
/**
* 获取客户信息数据
*/
private fetchCustomerData(currentRecord: any | null): any {
private fetchCustomerData(currentRecord: null | UTSJSONObject): UTSJSONObject {
console.log(`[fetchCustomerData] currentRecord: ${JSON.stringify(currentRecord)}`);
if (currentRecord === null) {
return null as any;
console.warn("[fetchCustomerData] currentRecord is null");
return {} as UTSJSONObject;
}
const record = currentRecord as UTSJSONObject;
const result: any = {
customerName: record.customerName,
phoneNumber: record.phoneNumber,
carModel: record.carModel,
salesUuid: record.salesUuid,
salesName: record.staffName,
carBrand: record.carBrand,
carBrandId: record.carBrandId,
oneCarBrand: record.oneCarBrand,
oneCarBrandId: record.oneCarBrandId
};
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;
console.log(`[fetchCustomerData] result: ${JSON.stringify(result)}`);
return result;
}
/**
* 获取物料轨迹点数据(从缓存)
*/
private async fetchMaterialData(recordId: string): Promise<any> {
if (recordId === "") return null;
private async fetchMaterialData(recordId: string): Promise<UTSJSONObject> {
if (recordId === "") return {} as UTSJSONObject;
const storageKey = `MATERIAL_POINTS_${recordId}`;
const materialList = await StrategyUtils.loadFromStorage(storageKey);
......@@ -224,21 +228,20 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
if (materialList !== null && materialList !== "") {
return {
receptionCustomerMaterialPointList: materialList
};
} as UTSJSONObject;
}
return null;
return {} as UTSJSONObject;
}
/**
* 获取接待状态数据
*/
private fetchStatusData(currentRecord: any | null): any {
private fetchStatusData(currentRecord: null | UTSJSONObject): UTSJSONObject {
if (currentRecord === null) {
return null as any;
return {} as UTSJSONObject;
}
const record = currentRecord as UTSJSONObject;
const result = record.receptionStatus;
return result === null ? null as any : result;
const result = currentRecord.get("receptionStatus");
return result === null ? {} as UTSJSONObject : { receptionStatus: result } as UTSJSONObject;
}
/**
......@@ -263,7 +266,7 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
* 获取指定类型的业务数据(内部实现)
*/
private async getBusinessDataByTypeInternal(recordId: string, currentRecord: any | null, type: BusiType): Promise<any> {
const config = this.strategyConfig.get(type);
const config: null | UTSJSONObject = this.strategyConfig.get(type);
if (config === null) {
console.warn(`[DefaultRecorderStrategy] Unknown business data type: ${type}`);
......@@ -271,7 +274,13 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
}
try {
return config.fetcher.invoke(recordId, currentRecord);
// 将 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);
} catch (error) {
console.error(`[DefaultRecorderStrategy] Fetch ${type} data failed:`, error);
return null;
......@@ -326,9 +335,10 @@ export class DefaultRecorderStrategy implements IRecorderStrategy {
const data = results[index];
if (data === null) return;
const config = this.strategyConfig.get(type);
const config: null | UTSJSONObject = this.strategyConfig.get(type);
if (config !== null) {
config.merger.invoke(merged, data);
const merger = config.get("merger") as ((merged: UTSJSONObject, data: any) => void);
merger.invoke(merged, data);
}
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!