feat(cleaner): record all material operations in database, including successful deletions

Previously only skipped and failed materials were persisted. Now every
material (deleted, uncertain, skipped, failed) is recorded in
CleanerMaterialDetail for full audit traceability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-04-13 14:24:18 +08:00
parent 0286df94dd
commit 116539ff42
3 changed files with 30 additions and 1 deletions

View File

@@ -433,9 +433,22 @@ export class CleanerApplicationService {
detail.errors.length > 0 ? detail.errors.join('\n') : undefined detail.errors.length > 0 ? detail.errors.join('\n') : undefined
) )
// Insert material details for skipped and failed materials // Insert material details for all materials
const materialDetails: InsertMaterialDetailInput[] = [] const materialDetails: InsertMaterialDetailInput[] = []
for (const deleted of detail.deletedMaterials) {
materialDetails.push({
orderNumber: detail.orderNumber,
materialCode: deleted.materialCode,
materialName: deleted.materialName,
rowNumber: deleted.rowNumber,
result: deleted.outcome,
reason: null,
attemptCount: 1,
finalErrorCategory: null
})
}
for (const skipped of detail.skippedMaterials) { for (const skipped of detail.skippedMaterials) {
materialDetails.push({ materialDetails.push({
orderNumber: detail.orderNumber, orderNumber: detail.orderNumber,

View File

@@ -758,6 +758,7 @@ export class CleanerService {
materialsSkipped: 0, materialsSkipped: 0,
errors: [], errors: [],
skippedMaterials: [], skippedMaterials: [],
deletedMaterials: [],
retryCount: 0, retryCount: 0,
retryAttempts: [], retryAttempts: [],
retriedAt: undefined, retriedAt: undefined,
@@ -925,6 +926,12 @@ export class CleanerService {
deleteResult.outcome === DeletionOutcome.Uncertain deleteResult.outcome === DeletionOutcome.Uncertain
) { ) {
detail.materialsDeleted += 1 detail.materialsDeleted += 1
detail.deletedMaterials.push({
materialCode,
materialName,
rowNumber: rowNumInt,
outcome: deleteResult.outcome
})
if (deleteResult.outcome === DeletionOutcome.Uncertain) { if (deleteResult.outcome === DeletionOutcome.Uncertain) {
detail.uncertainDeletions += 1 detail.uncertainDeletions += 1
} }
@@ -1106,6 +1113,7 @@ export class CleanerService {
materialsSkipped: 0, materialsSkipped: 0,
errors: [message], errors: [message],
skippedMaterials: [], skippedMaterials: [],
deletedMaterials: [],
retryCount: 0, retryCount: 0,
retryAttempts: [], retryAttempts: [],
retriedAt: undefined, retriedAt: undefined,

View File

@@ -44,6 +44,13 @@ export interface SkippedMaterial {
reason: string reason: string
} }
export interface DeletedMaterial {
materialCode: string
materialName: string
rowNumber: number
outcome: string
}
export interface RetryAttempt { export interface RetryAttempt {
attempt: number attempt: number
error: string error: string
@@ -56,6 +63,7 @@ export interface OrderCleanDetail {
materialsSkipped: number materialsSkipped: number
errors: string[] errors: string[]
skippedMaterials: SkippedMaterial[] skippedMaterials: SkippedMaterial[]
deletedMaterials: DeletedMaterial[]
// Retry-related fields // Retry-related fields
retryCount: number retryCount: number
retryAttempts?: RetryAttempt[] retryAttempts?: RetryAttempt[]