feat(credit): 添加附近企业批量导入功能
- 新增 ImportBatchCreditNearbyCompanyItem 和 ImportBatchCreditNearbyCompanyResult 接口定义 - 实现 importBatchCreditNearbyCompany 函数支持多文件循环导入 - 添加 stopOnError 选项控制遇到失败时是否停止导入 - 返回详细的导入结果统计(总数、成功数、失败数及明细) - 确保即使有失败也不 reject,便于上层展示部分成功/失败明细
This commit is contained in:
@@ -134,3 +134,61 @@ export async function importCreditNearbyCompany(
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
export interface ImportBatchCreditNearbyCompanyItem {
|
||||
fileName: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ImportBatchCreditNearbyCompanyResult {
|
||||
total: number;
|
||||
success: number;
|
||||
failure: number;
|
||||
items: ImportBatchCreditNearbyCompanyItem[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入附近企业(多文件)
|
||||
*
|
||||
* 说明:
|
||||
* - 目前复用单文件导入接口,前端循环调用实现“多文件导入”
|
||||
* - 不会在有失败时 reject(便于上层展示部分成功/失败明细)
|
||||
*/
|
||||
export async function importBatchCreditNearbyCompany(
|
||||
files: File[] | FileList,
|
||||
companyId?: number,
|
||||
options?: {
|
||||
/** 遇到失败是否立即停止,默认 false(继续导入后续文件) */
|
||||
stopOnError?: boolean;
|
||||
}
|
||||
): Promise<ImportBatchCreditNearbyCompanyResult> {
|
||||
const list = Array.isArray(files) ? files : Array.from(files);
|
||||
const items: ImportBatchCreditNearbyCompanyItem[] = [];
|
||||
const stopOnError = options?.stopOnError ?? false;
|
||||
|
||||
for (const file of list) {
|
||||
try {
|
||||
const msg = await importCreditNearbyCompany(file, companyId);
|
||||
items.push({ fileName: file.name, success: true, message: msg });
|
||||
} catch (e: unknown) {
|
||||
items.push({
|
||||
fileName: file.name,
|
||||
success: false,
|
||||
message: e instanceof Error ? e.message : String(e)
|
||||
});
|
||||
if (stopOnError) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const success = items.filter((d) => d.success).length;
|
||||
const failure = items.length - success;
|
||||
return {
|
||||
total: list.length,
|
||||
success,
|
||||
failure,
|
||||
items
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user