diff --git a/backend/scripts/check-beijing-social.ts b/backend/scripts/check-beijing-social.ts new file mode 100644 index 0000000..9752a95 --- /dev/null +++ b/backend/scripts/check-beijing-social.ts @@ -0,0 +1,10 @@ +import { PrismaClient } from '@prisma/client' +const prisma = new PrismaClient() +async function main() { + const accounts = await prisma.socialAccount.findMany({ where: { type: 'SOCIAL', city: '北京' }, select: { id: true, name: true } }) + for (const a of accounts) { + const std = await prisma.socialYearStandard.findFirst({ where: { accountId: a.id, isCurrent: true }, select: { medicalOrgExtra: true, medicalEmpExtra: true, extraInsurances: true, effectiveFrom: true } }) + console.log(a.name + ' | effective=' + std?.effectiveFrom + ' | medicalOrgExtra=' + std?.medicalOrgExtra + ' | medicalEmpExtra=' + std?.medicalEmpExtra + ' | extraInsurances=' + JSON.stringify(std?.extraInsurances)) + } +} +main().then(() => process.exit(0)) diff --git a/backend/scripts/fix-medical-extra.ts b/backend/scripts/fix-medical-extra.ts new file mode 100644 index 0000000..24734b3 --- /dev/null +++ b/backend/scripts/fix-medical-extra.ts @@ -0,0 +1,25 @@ +/** + * 更新北京社保账户的大病医疗个人附加(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) }) diff --git a/backend/src/routes/social.routes.ts b/backend/src/routes/social.routes.ts index 760122f..7010471 100644 --- a/backend/src/routes/social.routes.ts +++ b/backend/src/routes/social.routes.ts @@ -263,6 +263,22 @@ router.post('/accounts/:accountId/standards', async (req: AuthRequest, res: Resp const account = await prisma.socialAccount.findFirst({ where: { id: accountId, orgId } }) if (!account) return res.status(404).json({ success: false, error: { code: 'NOT_FOUND', message: '账户不存在' } }) + // 检查是否已存在同 effectiveFrom 的标准 + const existing = await prisma.socialYearStandard.findFirst({ where: { accountId, effectiveFrom: data.effectiveFrom } }) + if (existing) { + // 已存在:更新而非报错 + const standard = await prisma.socialYearStandard.update({ + where: { id: existing.id }, + data: { ...data, isCurrent: true, effectiveTo: null }, + }) + // 将其他当前版本标记为失效 + await prisma.socialYearStandard.updateMany({ + where: { accountId, isCurrent: true, id: { not: existing.id } }, + data: { isCurrent: false, effectiveTo: data.effectiveFrom }, + }) + return res.json({ success: true, data: standard }) + } + // 将旧当前版本标记为失效 const current = await prisma.socialYearStandard.findFirst({ where: { accountId, isCurrent: true } }) if (current) {