Commit ad1e649b by Lin

refactor(reception): 优化接待记录处理逻辑和错误处理

- 更新 searchRecordingEndTime 函数以统一错误处理逻辑,确保 API 错误信息更具可读性
- 增强接待中心组件的调试信息输出,便于监控接待记录列表变化
- 重构 RecordSave 类中的 URL 列表处理逻辑,确保兼容不同数据结构
- 优化本地记录提交逻辑,确保状态判断一致性
- 清理冗余代码,提高代码可读性和维护性
1 parent 77feff42
......@@ -40,8 +40,8 @@ function logAndReturn(
errPayload[k] = meta[k];
}
logger.error(errPayload, "API");
// UTS 侧 throw 需要 Throwable,这里统一转 Error
throw new Error(`${err}`);
// UTS 侧 throw 需要 Throwable,这里统一转 Error(带上 name 便于与网关原始文案对照)
throw new Error(`[API:${name}] ${err}`);
}
})();
}
......@@ -107,15 +107,28 @@ function shukeRequestWithLog(
// }
export async function searchRecordingEndTime(params: UTSJSONObject): Promise<string> {
const data = withProjectName("boutique", params);
// returnAll=true:避免 ROP 在 code!=0 时直接 reject 被 logAndReturn 二次包装;在此统一解析业务码与 data
const res = await fetchWithLog(
"searchRecordingEndTime",
"dj.api.smartcarlife.recepiton.customer.searchRecordingEndTime",
data,
false,
true,
"dj"
);
// 这里按接口约定返回字符串;若后端返回结构变更,日志能帮助快速定位
return `${res}`;
) as UTSJSONObject;
const code = res["code"];
if (`${code}` != "0") {
const msg = res["message"] != null && `${res["message"]}` != "" ? `${res["message"]}` : "searchRecordingEndTime 调用失败";
throw new Error(msg);
}
const biz = res["data"];
if (biz == null) {
return "";
}
if (typeof biz === "string") {
return biz;
}
// 后端若将时间包在对象内,至少给出可观测字符串(调用方 RecordSave 会再 toStr / 日期归一化)
return `${biz}`;
}
export async function getMerchantPerformance(params: UTSJSONObject): Promise<any> {
......
......@@ -10,7 +10,7 @@
</template>
<script setup lang="uts">
import { state } from "@/store/index.uts";
import { computed, type ComputedRef } from "vue";
import { computed } from "vue";
import { useOrientation } from "@/services/adapter/hooks/useOrientation.uts";
const props = defineProps({
......@@ -24,7 +24,7 @@
// ✅ 横竖屏检测
const orientation = useOrientation();
const isPortrait = orientation.isPortrait as ComputedRef<boolean>;
const isPortrait = orientation.isPortrait;
// ✅ 根据横竖屏动态切换图片模式
// 横屏:aspectFill 铺满全屏(可能裁剪)
......
......@@ -70,7 +70,7 @@ import { getCustomerFileList, getMerchantPerformance, getList} from "@/api/recei
import TabBarShell from "@/components/HomeFrame/tabbar/TabBarShell.uvue";
import { updateOrientation, useOrientation, useScreenVars } from "@/services/adapter/hooks/index.uts";
// ✅ 数据库相关导入(用于本地未提交记录)
import { DBRecord, recordService, type RecordData } from "@/services/recorder/index.uts";
import { DBRecord, recordService, type RecordData, type RecordFile } from "@/services/recorder/index.uts";
import { storage } from "@/utils/storage.uts";
import { delay } from "@/utils/delay.uts"; // ✅ 导入延迟执行工具函数
import FormDetail from "./forms/FormDetail.uvue";
......@@ -176,6 +176,21 @@ const customerList = ref<UTSJSONObject[]>([]);
// 接待复盘列表(接待复盘 Tab,接口 dj.api.smartcarlife.reception.customer.page)
const receptionRecordList = ref<UTSJSONObject[]>([]);
/** 调试:接待复盘列表变化时打印(HBuilderX / 真机运行日志) */
watch(
(): UTSJSONObject[] => receptionRecordList.value,
(list: UTSJSONObject[]): void => {
if (list == null) {
console.log('[receptionCenter] receptionRecordList: null')
return
}
const n = list.length
console.log('[receptionCenter] receptionRecordList length=', n)
console.log('[receptionCenter] receptionRecordList JSON=', JSON.stringify(list))
},
{ immediate: true, deep: true }
);
// ⚠️ 临时保留:分页变量(待后续重构移到子组件)
/** 客户档案分页(customerInfoPage) */
const CUSTOMER_FILE_PAGE_SIZE = 10;
......@@ -202,18 +217,58 @@ let getCustomerListImpl: (append: boolean) => Promise<void> = async (_append: bo
let getReceptionRecordListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {};
/**
* 将 rec.urlList 扁平为路径字符串数组:对象项只取 filePath;纯字符串项原样保留(兼容库内历史混存)。
* 与 RecordSave._normalizeUrlListItems 的输入形态一致,避免把 String 当对象读属性导致 Android 端类型异常。
*/
function flattenRecordUrlListToPaths(urlList: RecordData["urlList"]): string[] {
if (urlList == null) {
return [];
}
const rawArr = urlList as any[];
const out: string[] = [];
for (let i = 0; i < rawArr.length; i++) {
const item = rawArr[i];
if (item == null) {
continue;
}
if (typeof item === "string") {
const s = `${item}`;
if (s !== "") {
out.push(s);
}
continue;
}
if (typeof item === "object") {
const fpVal = (item as UTSJSONObject)["filePath"];
if (fpVal != null && typeof fpVal === "string") {
const fp = fpVal as string;
if (fp !== "") {
out.push(fp);
}
}
}
}
return out;
}
/** ✅ 将本地数据库记录转换为列表行数据 */
function toReceptionListRowFromLocalRecord(rec: RecordData): UTSJSONObject {
console.log('[recrecrecrecrec] toReceptionListRowFromLocalRecord rec=', rec);
// 未提交列表不展示“战败/成交”,因此 orderFinishFlag 置空让角标隐藏。
return {
batchId: rec.id,
machineCode: rec.machineCode ?? "",
recordStatus: rec.recordStatus ?? 0,
customerName: rec.customerName ?? "",
carType: rec.carType ?? "",
phoneNumber: rec.customerPhone ?? "",
recordStatus: rec.recordStatus ?? 0,
result: rec.result ?? "",
receptionStartTime: rec.startTime ?? "",
receptionEndTime: rec.endTime ?? "",
reviewFlag: 1,
orderFinishFlag: null,
submitted: 0,
customerType: rec.customerType ?? "",
urlList: flattenRecordUrlListToPaths(rec.urlList)
} as UTSJSONObject;
}
......@@ -221,6 +276,10 @@ function toReceptionListRowFromLocalRecord(rec: RecordData): UTSJSONObject {
async function getLocalUnsubmittedReceptionRecords(): Promise<UTSJSONObject[]> {
// ✅ 返回所有未提交记录(已完成 + 临时),子组件根据 Tab 状态自行过滤
const recorder = recordService.getRecorder();
console.log('[receptionCenter] getLocalUnsubmittedReceptionRecords getRecorder=', recorder);
if (recorder != null) {
console.log('[receptionCenter] getLocalUnsubmittedReceptionRecords TempRecord.currentRecord=', recorder.currentRecord);
}
const db = recorder != null ? recorder.db : DBRecord.getInstance();
const rows: RecordData[] = unsubmittedPendingTabIndex.value == 0
? (await db.getCompletedRecords())
......
......@@ -118,7 +118,7 @@ class RecordSave {
}
_record.status = FileStatus.HasFile;
const urlList = this.urlListFilter(_record.urlList as UTSJSONObject[]);
const urlList = this.urlListFilter(this._normalizeUrlListItems(_record.urlList));
// find target file
let targetFile: null | UTSJSONObject = null;
for (const item of urlList) {
......@@ -178,13 +178,47 @@ class RecordSave {
return `${recordId}_${fileName}`;
}
async _handleCompletedRecord(record: UTSJSONObject, fileList: UTSJSONObject[]) {
/**
* urlList 在库里/合并提交时可能是「文件对象数组」,也可能混有或全部为「纯字符串 URL」。
* Android 上若把 String 当 UTSJSONObject 访问属性会 ClassCastException,此处统一为对象结构。
*/
_normalizeUrlListItems(raw: any | null): UTSJSONObject[] {
if (raw == null || !Array.isArray(raw)) {
return [];
}
const rawArr = raw as any[];
const out: UTSJSONObject[] = [];
for (let i = 0; i < rawArr.length; i++) {
const item = rawArr[i];
if (item == null) {
continue;
}
if (typeof item === "string") {
const s = `${item}`;
if (s !== "") {
const row: UTSJSONObject = {} as UTSJSONObject;
row["file"] = s;
row["filePathOnClient"] = "";
row["status"] = FileStatus.Completed;
out.push(row);
}
continue;
}
if (typeof item === "object") {
out.push(item as UTSJSONObject);
}
}
return out;
}
async _handleCompletedRecord(record: UTSJSONObject, fileList: any[] | UTSJSONObject[]) {
const list = this._normalizeUrlListItems(fileList);
// 1. 整理文件路径(与 _saveOrUpdate 判定一致:Uploaded / Completed 均视为已拿到可提交地址)
const uploadedFiles = fileList.filter(
file => file.status === FileStatus.Uploaded || file.status === FileStatus.Completed
const uploadedFiles = list.filter(
file => toNum(file.status) === FileStatus.Uploaded || toNum(file.status) === FileStatus.Completed
);
const serverPaths = uploadedFiles.map(i => i.file as string);
const localPaths = uploadedFiles.map(i => i.filePathOnClient as string);
const serverPaths = uploadedFiles.map(i => toStr(i.file));
const localPaths = uploadedFiles.map(i => toStr(i.filePathOnClient));
logger.warn(`【接待记录保存服务】 == 本条接待所有文件已经上传和处理完毕!!`, "RecordSave");
......@@ -354,16 +388,27 @@ class RecordSave {
logger.info(`【上传服务】 == 向服务器获取结束接待时间: urlList ->${serializeIfObject(urlList)} startTime: -> ${startTime}`, "RecordSave");
// mock api
// const endTime = await uni.$api.commonApi.searchRecordingEndTime({ urlList, startTime: startTime.replace(/\//g, '-') })
const startTimeStr = replaceAll(startTime, "/", "-");
const endTimeRaw = await searchRecordingEndTime({ urlList, startTime: startTimeStr });
const endTime = toStr(endTimeRaw);
logger.info(`【上传服务】 == 服务器返回结束接待时间: endTime ->${endTime}`, "RecordSave");
if (endTime.includes("-")) {
return replaceAll(endTime, "-", "/");
try {
const startTimeStr = replaceAll(startTime, "/", "-");
const endTimeRaw = await searchRecordingEndTime({ urlList, startTime: startTimeStr });
const endTime = toStr(endTimeRaw);
logger.info(`【上传服务】 == 服务器返回结束接待时间: endTime ->${endTime}`, "RecordSave");
if (endTime === "") {
logger.warn(`【上传服务】结束时间为空(常见原因:session 无效或未登录),回退为 startTime`, "RecordSave");
return startTime;
}
if (endTime.includes("-")) {
return replaceAll(endTime, "-", "/");
}
return endTime;
} catch (e: any) {
// 会话失效等导致 dj ROP 失败时,仍允许走 saveRecCustomer(数科 linkwe 侧 token);缺 endTime 用 startTime 兜底
logger.warn(
`【上传服务】获取结束接待时间失败,已用 startTime 兜底: ${serializeIfObject(e)}`,
"RecordSave"
);
return startTime;
}
return endTime;
}
/**
......@@ -372,8 +417,7 @@ class RecordSave {
*/
async submitLocalReceptionToServer(mergedRecord: UTSJSONObject): Promise<void> {
const record = toObj(deepClone<UTSJSONObject>(mergedRecord));
const urlListRaw = record.urlList;
const fileList: UTSJSONObject[] = Array.isArray(urlListRaw) ? (urlListRaw as UTSJSONObject[]) : [];
const fileList = this._normalizeUrlListItems(record.urlList);
await this._handleCompletedRecord(record, fileList);
}
......@@ -382,10 +426,12 @@ class RecordSave {
const status = data.status as number; // 没有文件的记录,status 为 NoFile 有文件的记录没有此状态
const record = toObj(deepClone<UTSJSONObject>(data));
const urlList = record.urlList as UTSJSONObject[];
const fileList = Array.isArray(urlList) ? urlList : [];
const fileList = this._normalizeUrlListItems(record.urlList);
const isAllCompleted = status === FileStatus.NoFile || fileList.every(i => [FileStatus.Completed, FileStatus.Uploaded].includes(i.status as number));
const isAllCompleted = status === FileStatus.NoFile || fileList.every(i => {
const st = toNum(i.status);
return st === FileStatus.Completed || st === FileStatus.Uploaded;
});
if (isAllCompleted) {
await this._handleCompletedRecord(record, fileList);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!