From c24cc68cd891e06299a41feb9aaece3dc15a9889 Mon Sep 17 00:00:00 2001 From: freedakgmail Date: Tue, 18 Aug 2026 07:15:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A4=BE=E4=BF=9D=E5=85=AC=E7=A7=AF?= =?UTF-8?q?=E9=87=91=E6=9C=88=E5=BA=A6=E5=8A=9E=E7=90=86=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E5=8A=B3=E5=8A=A1/=E5=AE=9E=E4=B9=A0=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E5=91=98=E5=B7=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/routes/social.routes.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/src/routes/social.routes.ts b/backend/src/routes/social.routes.ts index a3719eb..dc70436 100644 --- a/backend/src/routes/social.routes.ts +++ b/backend/src/routes/social.routes.ts @@ -1275,17 +1275,17 @@ router.get('/monthly-changes', async (req: AuthRequest, res: Response, next: Nex const month = (req.query.month as string) || new Date().toISOString().slice(0, 7) const orgId = req.user!.orgId - // 增员:startMonth == month + // 增员:startMonth == month(排除劳务/实习协议员工) const additions = await prisma.employeeSocialInsRecord.findMany({ - where: { orgId, startMonth: month }, - include: { employee: { select: { name: true, department: true, idCardNumber: true } } }, + where: { orgId, startMonth: month, employee: { contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } } }, + include: { employee: { select: { name: true, department: true, idCardNumber: true, contracts: { orderBy: { createdAt: 'desc' }, take: 1, select: { contractType: true } } } } }, orderBy: { createdAt: 'asc' }, }) // 减员:endMonth == month 且 changeType 为 TERMINATION 或 CITY_CHANGE const reductions = await prisma.employeeSocialInsRecord.findMany({ - where: { orgId, endMonth: month, changeType: { in: ['TERMINATION', 'CITY_CHANGE'] } }, - include: { employee: { select: { name: true, department: true, idCardNumber: true } } }, + where: { orgId, endMonth: month, changeType: { in: ['TERMINATION', 'CITY_CHANGE'] }, employee: { contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } } }, + include: { employee: { select: { name: true, department: true, idCardNumber: true, contracts: { orderBy: { createdAt: 'desc' }, take: 1, select: { contractType: true } } } } }, orderBy: { createdAt: 'asc' }, }) @@ -1350,14 +1350,14 @@ router.get('/housing/monthly-changes', async (req: AuthRequest, res: Response, n const orgId = req.user!.orgId const additions = await prisma.employeeHousingFundRecord.findMany({ - where: { orgId, startMonth: month }, - include: { employee: { select: { name: true, department: true, idCardNumber: true } } }, + where: { orgId, startMonth: month, employee: { contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } } }, + include: { employee: { select: { name: true, department: true, idCardNumber: true, contracts: { orderBy: { createdAt: 'desc' }, take: 1, select: { contractType: true } } } } }, orderBy: { createdAt: 'asc' }, }) const reductions = await prisma.employeeHousingFundRecord.findMany({ - where: { orgId, endMonth: month, changeType: { in: ['TERMINATION', 'CITY_CHANGE'] } }, - include: { employee: { select: { name: true, department: true, idCardNumber: true } } }, + where: { orgId, endMonth: month, changeType: { in: ['TERMINATION', 'CITY_CHANGE'] }, employee: { contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } } }, + include: { employee: { select: { name: true, department: true, idCardNumber: true, contracts: { orderBy: { createdAt: 'desc' }, take: 1, select: { contractType: true } } } } }, orderBy: { createdAt: 'asc' }, }) @@ -1421,8 +1421,9 @@ router.get('/active-declaration', async (req: AuthRequest, res: Response, next: orgId, startMonth: { lt: month }, OR: [{ endMonth: null }, { endMonth: { gt: month } }], + employee: { contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } }, }, - include: { employee: { select: { name: true, department: true, idCardNumber: true, hireDate: true } } }, + include: { employee: { select: { name: true, department: true, idCardNumber: true, hireDate: true, contracts: { orderBy: { createdAt: 'desc' }, take: 1, select: { contractType: true } } } } }, orderBy: { createdAt: 'asc' }, }) @@ -1483,8 +1484,9 @@ router.get('/housing/active-declaration', async (req: AuthRequest, res: Response orgId, startMonth: { lt: month }, OR: [{ endMonth: null }, { endMonth: { gt: month } }], + employee: { contracts: { some: { contractType: { in: ['FIXED', 'UNFIXED'] } } } }, }, - include: { employee: { select: { name: true, department: true, idCardNumber: true, hireDate: true } } }, + include: { employee: { select: { name: true, department: true, idCardNumber: true, hireDate: true, contracts: { orderBy: { createdAt: 'desc' }, take: 1, select: { contractType: true } } } } }, orderBy: { createdAt: 'asc' }, })