fix: 待处理风险按风险类别去重,避免同一风险重复展示
This commit is contained in:
@@ -1778,15 +1778,13 @@ export async function getAnnualValueReport(orgId: string, year: number) {
|
|||||||
policiesPublished,
|
policiesPublished,
|
||||||
}
|
}
|
||||||
|
|
||||||
const summary = `${year} 年规避潜在损失 ${fmtMoney(lossAvoided)},节约 HR 工时 ${timeSaved} 小时,仍有 ${pendingRisks.length} 项风险待处理`
|
// 未解决风险按员工去重+风险类别去重(同一类别只取 estimatedLoss 最大的一条)
|
||||||
|
|
||||||
// 未解决风险按员工去重+风险类别去重
|
|
||||||
const pendingBreakdown: Record<string, {
|
const pendingBreakdown: Record<string, {
|
||||||
name: string
|
name: string
|
||||||
department: string
|
department: string
|
||||||
riskCount: number
|
riskCount: number
|
||||||
totalLoss: number
|
totalLoss: number
|
||||||
details: { title: string; estimatedLoss: number; legalBasis: string }[]
|
details: Map<string, { title: string; estimatedLoss: number; legalBasis: string }>
|
||||||
}> = {}
|
}> = {}
|
||||||
for (const r of pendingRisks) {
|
for (const r of pendingRisks) {
|
||||||
const personKey = r.employee?.idCardHash || r.employee?.name || r.employeeId || '_unknown'
|
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 || '-',
|
department: r.employee?.department || '-',
|
||||||
riskCount: 0,
|
riskCount: 0,
|
||||||
totalLoss: 0,
|
totalLoss: 0,
|
||||||
details: [],
|
details: new Map(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pendingBreakdown[personKey].riskCount++
|
const catKey = getRiskCategoryKey(r.title)
|
||||||
pendingBreakdown[personKey].totalLoss += r.estimatedLoss || 0
|
const loss = r.estimatedLoss || 0
|
||||||
pendingBreakdown[personKey].details.push({
|
const existing = pendingBreakdown[personKey].details.get(catKey)
|
||||||
title: r.title,
|
if (!existing || loss > existing.estimatedLoss) {
|
||||||
estimatedLoss: r.estimatedLoss || 0,
|
pendingBreakdown[personKey].details.set(catKey, {
|
||||||
legalBasis: getLegalBasis(r.title),
|
title: r.title,
|
||||||
})
|
estimatedLoss: loss,
|
||||||
|
legalBasis: getLegalBasis(r.title),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const pendingRiskDetails = Object.values(pendingBreakdown)
|
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)
|
.sort((a, b) => b.totalLoss - a.totalLoss)
|
||||||
|
|
||||||
|
const summary = `${year} 年规避潜在损失 ${fmtMoney(lossAvoided)},节约 HR 工时 ${timeSaved} 小时,仍有 ${pendingRiskDetails.length} 人待处理风险`
|
||||||
|
|
||||||
return {
|
return {
|
||||||
year,
|
year,
|
||||||
totalValue,
|
totalValue,
|
||||||
|
|||||||
Reference in New Issue
Block a user