diff --git a/backend/src/services/risk.service.ts b/backend/src/services/risk.service.ts index 6e6db1b..02dd61d 100644 --- a/backend/src/services/risk.service.ts +++ b/backend/src/services/risk.service.ts @@ -1419,7 +1419,7 @@ export async function getComplianceScore(orgId: string) { prisma.riskItem.count({ where: { orgId, status: 'PENDING' } }), prisma.riskItem.count({ where: { orgId, status: 'PENDING', level: 'HIGH' } }), prisma.riskItem.count({ where: { orgId, status: 'RESOLVED' } }), - prisma.policyDocument.count({ where: { orgId, democracyProgress: { lt: 4 } } }), + prisma.policyDocument.count({ where: { orgId, status: { not: 'PUBLISHED' } } }), prisma.attendanceConfirmation.count({ where: { orgId, status: 'PENDING' } }), prisma.payslip.count({ where: { orgId, confirmedAt: null } }), prisma.payslip.count({ where: { orgId } }), @@ -1589,12 +1589,14 @@ export async function getHealthCheck(orgId: string) { }, }), prisma.laborContract.count({ where: { orgId, attachmentUrl: null, employee: { status: 'ACTIVE' } } }), - prisma.policyDocument.count({ where: { orgId, democracyProgress: { lt: 4 } } }), + // democracyProgress 是 JSONB,用 status 字段判断未完成 + prisma.policyDocument.count({ where: { orgId, status: { not: 'PUBLISHED' } } }), prisma.policyDocument.count({ where: { orgId } }), prisma.socialInsuranceConfig.findFirst({ where: { orgId, isCurrent: true } }), prisma.housingFundConfig.findFirst({ where: { orgId, isCurrent: true } }), - prisma.employeeSocialInsRecord.count({ where: { orgId, endMonth: null } }), - prisma.employeeHousingFundRecord.count({ where: { orgId, endMonth: null } }), + // 社保/公积金记录按员工去重 + prisma.employeeSocialInsRecord.groupBy({ by: ['employeeId'], where: { orgId, endMonth: null }, _count: true }).then(r => r.length), + prisma.employeeHousingFundRecord.groupBy({ by: ['employeeId'], where: { orgId, endMonth: null }, _count: true }).then(r => r.length), prisma.employee.count({ where: { orgId, status: 'ACTIVE', id: { notIn: [] } } }), prisma.overtimeRecord.count({ where: { orgId, weekdayHours: { gt: 36 } } }), prisma.employee.count({ where: { orgId, status: 'ACTIVE', contracts: { none: { contractType: 'FIXED' } } } }),