diff --git a/src/api/credit/creditNearbyCompany/index.ts b/src/api/credit/creditNearbyCompany/index.ts index 5588608..3e1c9d8 100644 --- a/src/api/credit/creditNearbyCompany/index.ts +++ b/src/api/credit/creditNearbyCompany/index.ts @@ -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 { + 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 + }; +}