1d9890e607
问题:创建年度标准时如果该账户已有同 effectiveFrom 的标准, 会触发 P2002 唯一约束冲突,返回400"数据已存在"。 修复:先查是否已存在同 effectiveFrom 的标准,存在则更新, 不存在才创建新标准。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
/**
|
|
* 更新北京社保账户的大病医疗个人附加(3元/月)
|
|
*/
|
|
import { PrismaClient } from '@prisma/client'
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
// 北京社保账户:医疗个人附加3元(大病医疗)
|
|
const beijingSocial = await prisma.socialAccount.findMany({ where: { type: 'SOCIAL', city: '北京' }, select: { id: true, name: true } })
|
|
for (const a of beijingSocial) {
|
|
const result = await prisma.socialYearStandard.updateMany({
|
|
where: { accountId: a.id, isCurrent: true },
|
|
data: { medicalEmpExtra: 3 },
|
|
})
|
|
console.log(`[更新] ${a.name} → medicalEmpExtra=3,影响 ${result.count} 条`)
|
|
}
|
|
|
|
// 验证
|
|
for (const a of beijingSocial) {
|
|
const std = await prisma.socialYearStandard.findFirst({ where: { accountId: a.id, isCurrent: true }, select: { medicalEmpExtra: true, effectiveFrom: true } })
|
|
console.log(`[验证] ${a.name} | effective=${std?.effectiveFrom} | medicalEmpExtra=${std?.medicalEmpExtra}`)
|
|
}
|
|
}
|
|
|
|
main().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1) })
|