fix: 优先校验批量输入行标识

This commit is contained in:
2026-08-17 21:34:09 +08:00
parent 934cde0034
commit 357ef89d3e
2 changed files with 20 additions and 4 deletions

View File

@@ -217,6 +217,22 @@ describe('batch-form-model', () => {
);
});
it('keeps every row when input client keys are duplicated and failures are empty', () => {
const rows = [createBatchRow(), createBatchRow()];
rows[1]!.clientKey = rows[0]!.clientKey;
const result = applyBatchResult(rows, {
successCount: 2,
failureCount: 0,
failures: [],
});
const generalError = '批量保存结果无法匹配,请核对后重试';
expect(result.rows).toEqual(rows);
expect(result.rowErrors).toEqual(
new Map(rows.map((row) => [row.clientKey, generalError])),
);
});
it('returns no rows or errors when every row succeeds', () => {
const result = applyBatchResult([createBatchRow()], {
successCount: 1,

View File

@@ -80,10 +80,6 @@ export function applyBatchResult(
rows: BatchFormRow[],
result: LmsSubPackageRelationApi.BatchCreateResult,
): { rows: BatchFormRow[]; rowErrors: Map<string, string> } {
if (result.failures.length === 0) {
return { rows: [], rowErrors: new Map() };
}
const generalError = '批量保存结果无法匹配,请核对后重试';
const rowByClientKey = new Map<string, BatchFormRow>();
for (const row of rows) {
@@ -96,6 +92,10 @@ export function applyBatchResult(
rowByClientKey.set(row.clientKey, row);
}
if (result.failures.length === 0) {
return { rows: [], rowErrors: new Map() };
}
const failedClientKeys = new Set<string>();
const rowErrors = new Map<string, string>();
for (const failure of result.failures) {