From c8d8e5c2927d6c57bec1abd512719549dcaa2da7 Mon Sep 17 00:00:00 2001 From: selfrelease Date: Sat, 1 Aug 2026 14:52:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E5=B7=A5=E4=BD=93=E6=A3=80?= =?UTF-8?q?=E8=AF=8A=E6=96=AD=E6=95=B0=E6=8D=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 合同管理:移除合同附件扣分(查所有历史合同导致624虚高,附件非合规问题) 2. 规章制度:democracyProgress是JSONB不能用lt查询,改用status!=PUBLISHED 3. 社保/公积金记录异常:按员工去重,避免一个员工多条记录被重复计数 4. getComplianceScore中同样的democracyProgress查询问题修复 --- backend/src/services/risk.service.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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' } } } }),