diff --git a/backend/src/services/risk.service.ts b/backend/src/services/risk.service.ts index 57d1219..a4651e3 100644 --- a/backend/src/services/risk.service.ts +++ b/backend/src/services/risk.service.ts @@ -1778,15 +1778,13 @@ export async function getAnnualValueReport(orgId: string, year: number) { policiesPublished, } - const summary = `${year} 年规避潜在损失 ${fmtMoney(lossAvoided)},节约 HR 工时 ${timeSaved} 小时,仍有 ${pendingRisks.length} 项风险待处理` - - // 未解决风险按员工去重+风险类别去重 + // 未解决风险按员工去重+风险类别去重(同一类别只取 estimatedLoss 最大的一条) const pendingBreakdown: Record }> = {} for (const r of pendingRisks) { const personKey = r.employee?.idCardHash || r.employee?.name || r.employeeId || '_unknown' @@ -1796,21 +1794,35 @@ export async function getAnnualValueReport(orgId: string, year: number) { department: r.employee?.department || '-', riskCount: 0, totalLoss: 0, - details: [], + details: new Map(), } } - pendingBreakdown[personKey].riskCount++ - pendingBreakdown[personKey].totalLoss += r.estimatedLoss || 0 - pendingBreakdown[personKey].details.push({ - title: r.title, - estimatedLoss: r.estimatedLoss || 0, - legalBasis: getLegalBasis(r.title), - }) + const catKey = getRiskCategoryKey(r.title) + const loss = r.estimatedLoss || 0 + const existing = pendingBreakdown[personKey].details.get(catKey) + if (!existing || loss > existing.estimatedLoss) { + pendingBreakdown[personKey].details.set(catKey, { + title: r.title, + estimatedLoss: loss, + legalBasis: getLegalBasis(r.title), + }) + } } const pendingRiskDetails = Object.values(pendingBreakdown) - .map(p => ({ ...p, details: p.details.sort((a, b) => b.estimatedLoss - a.estimatedLoss) })) + .map(p => { + const details = Array.from(p.details.values()).sort((a, b) => b.estimatedLoss - a.estimatedLoss) + return { + name: p.name, + department: p.department, + riskCount: details.length, + totalLoss: details.reduce((sum, d) => sum + d.estimatedLoss, 0), + details, + } + }) .sort((a, b) => b.totalLoss - a.totalLoss) + const summary = `${year} 年规避潜在损失 ${fmtMoney(lossAvoided)},节约 HR 工时 ${timeSaved} 小时,仍有 ${pendingRiskDetails.length} 人待处理风险` + return { year, totalValue,