fix: 待处理风险按风险类别去重,避免同一风险重复展示
This commit is contained in:
@@ -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<string, {
|
||||
name: string
|
||||
department: string
|
||||
riskCount: number
|
||||
totalLoss: number
|
||||
details: { title: string; estimatedLoss: number; legalBasis: string }[]
|
||||
details: Map<string, { title: string; estimatedLoss: number; legalBasis: string }>
|
||||
}> = {}
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user