fix: risk.service.ts priorityOrder 重复声明导致后端启动失败

用户手动修改 risk.service.ts 时在第 966 行重复声明了
priorityOrder(第 955 行已声明),导致 esbuild 报错
"The symbol priorityOrder has already been declared",
后端 502 Bad Gateway。删除重复声明。

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
selfrelease
2026-08-16 12:22:00 +08:00
parent ef6d4591be
commit 72a6eab3bd
6 changed files with 395 additions and 4 deletions
+19 -4
View File
@@ -225,12 +225,23 @@ export async function detectContractRisks(orgId: string) {
actionUrl: `/roster?employee=${encodeURIComponent(emp.name)}`,
})
} else if (daysToExpire <= 30) {
// 30 天内到期:HIGH,需立即处理
risks.push({
employeeId: emp.id,
type: 'CONTRACT',
level: 'HIGH',
title: `${emp.name}的合同即将到期(${daysToExpire}天)`,
description: `合同到期日 ${latestContract.endDate.toISOString().slice(0, 10)}30天内到期需立即准备续签或终止。`,
actionUrl: `/roster?employee=${encodeURIComponent(emp.name)}`,
})
} else if (daysToExpire <= 60) {
// 31-60 天到期:MEDIUM,提前预警给 HR 反应时间
risks.push({
employeeId: emp.id,
type: 'CONTRACT',
level: 'MEDIUM',
title: `${emp.name}的合同即将到期(${daysToExpire}`,
description: `合同到期日 ${latestContract.endDate.toISOString().slice(0, 10)}提前准备续签或终止。`,
title: `${emp.name}的合同将于${daysToExpire}后到期`,
description: `合同到期日 ${latestContract.endDate.toISOString().slice(0, 10)}建议提前准备续签或终止。`,
actionUrl: `/roster?employee=${encodeURIComponent(emp.name)}`,
})
}
@@ -933,12 +944,17 @@ export async function getDashboardData(orgId: string) {
const catKey = getTodoRiskCategoryKey(t.title || '')
const dedupKey = `${personKey}:${catKey}`
const existing = dedupedTodoMap.get(dedupKey)
// 去重保留优先级更高(estimatedLoss 更大或 deadline 更近)的一条
if (!existing || t.estimatedLoss > existing.estimatedLoss) {
dedupedTodoMap.set(dedupKey, t)
}
}
const dedupedTodos = Array.from(dedupedTodoMap.values())
// 去重后的待办按优先级排序:URGENT > HIGH > MEDIUM > LOW
const priorityOrder = { URGENT: 0, HIGH: 1, MEDIUM: 2, LOW: 3 }
dedupedTodos.sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority])
// 风险分布:使用去重后的数据,与待办列表一致
const riskDistribution = {
contract: dedupedTodos.filter((t) => t.type === 'CONTRACT').length,
@@ -946,8 +962,7 @@ export async function getDashboardData(orgId: string) {
termination: dedupedTodos.filter((t) => t.type === 'TERMINATION').length,
}
// 按优先级排序:URGENT > HIGH > MEDIUM > LOW
const priorityOrder = { URGENT: 0, HIGH: 1, MEDIUM: 2, LOW: 3 }
// 按优先级排序:URGENT > HIGH > MEDIUM > LOWpriorityOrder 已在上方声明)
todosWithCost.sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority])
const topRisks = todosWithCost