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' }, })