feat(contribution): 系统账户明细记录改为软删除
- 在 SystemContributionRecord 模型添加 deleted_at 字段 - 修改 deleteContributionRecordsByAdoption 方法为软删除(设置 deleted_at) - 修改 findContributionRecords 方法过滤已删除记录(deletedAt: null) - 添加数据库迁移文件 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e0eb734196
commit
eeaa43e044
|
|
@ -0,0 +1,5 @@
|
||||||
|
-- AlterTable: Add soft delete column to system_contribution_records
|
||||||
|
ALTER TABLE "system_contribution_records" ADD COLUMN "deleted_at" TIMESTAMP(3);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "system_contribution_records_deleted_at_idx" ON "system_contribution_records"("deleted_at");
|
||||||
|
|
@ -334,12 +334,14 @@ model SystemContributionRecord {
|
||||||
expireDate DateTime? @map("expire_date") @db.Date
|
expireDate DateTime? @map("expire_date") @db.Date
|
||||||
isExpired Boolean @default(false) @map("is_expired")
|
isExpired Boolean @default(false) @map("is_expired")
|
||||||
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
deletedAt DateTime? @map("deleted_at") // 软删除标记
|
||||||
|
|
||||||
systemAccount SystemAccount @relation(fields: [systemAccountId], references: [id])
|
systemAccount SystemAccount @relation(fields: [systemAccountId], references: [id])
|
||||||
|
|
||||||
@@index([systemAccountId])
|
@@index([systemAccountId])
|
||||||
@@index([sourceAdoptionId])
|
@@index([sourceAdoptionId])
|
||||||
|
@@index([deletedAt])
|
||||||
@@map("system_contribution_records")
|
@@map("system_contribution_records")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ export class SystemAccountRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除指定来源认种的明细记录
|
* 软删除指定来源认种的明细记录
|
||||||
*/
|
*/
|
||||||
async deleteContributionRecordsByAdoption(
|
async deleteContributionRecordsByAdoption(
|
||||||
accountType: SystemAccountType,
|
accountType: SystemAccountType,
|
||||||
|
|
@ -204,11 +204,15 @@ export class SystemAccountRepository {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.client.systemContributionRecord.deleteMany({
|
const result = await this.client.systemContributionRecord.updateMany({
|
||||||
where: {
|
where: {
|
||||||
systemAccountId: systemAccount.id,
|
systemAccountId: systemAccount.id,
|
||||||
sourceAdoptionId,
|
sourceAdoptionId,
|
||||||
sourceAccountSequence,
|
sourceAccountSequence,
|
||||||
|
deletedAt: null, // 只软删除未删除的记录
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
deletedAt: new Date(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -256,15 +260,20 @@ export class SystemAccountRepository {
|
||||||
return { data: [], total: 0 };
|
return { data: [], total: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const whereClause = {
|
||||||
|
systemAccountId: systemAccount.id,
|
||||||
|
deletedAt: null, // 过滤已软删除的记录
|
||||||
|
};
|
||||||
|
|
||||||
const [records, total] = await Promise.all([
|
const [records, total] = await Promise.all([
|
||||||
this.client.systemContributionRecord.findMany({
|
this.client.systemContributionRecord.findMany({
|
||||||
where: { systemAccountId: systemAccount.id },
|
where: whereClause,
|
||||||
skip: (page - 1) * pageSize,
|
skip: (page - 1) * pageSize,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
}),
|
}),
|
||||||
this.client.systemContributionRecord.count({
|
this.client.systemContributionRecord.count({
|
||||||
where: { systemAccountId: systemAccount.id },
|
where: whereClause,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue