fix: 日历风险截止事件按 employeeId:type 去重,避免重复提醒
This commit is contained in:
@@ -1167,7 +1167,7 @@ export async function getMonthlyCalendar(orgId: string, month: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 风险截止日期
|
||||
// 5. 风险截止日期(按 employeeId:type 去重,同一员工同一类型只保留最新一条)
|
||||
const riskDeadlines = await prisma.riskItem.findMany({
|
||||
where: {
|
||||
orgId,
|
||||
@@ -1175,8 +1175,13 @@ export async function getMonthlyCalendar(orgId: string, month: string) {
|
||||
deadline: { gte: monthStart, lte: monthEnd },
|
||||
},
|
||||
include: { employee: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
const seenRiskKeys = new Set<string>()
|
||||
for (const r of riskDeadlines) {
|
||||
const dedupKey = `${r.employeeId}:${r.type}`
|
||||
if (r.employeeId && seenRiskKeys.has(dedupKey)) continue
|
||||
if (r.employeeId) seenRiskKeys.add(dedupKey)
|
||||
events.push({
|
||||
date: r.deadline!.toISOString().slice(0, 10),
|
||||
type: 'RISK_DEADLINE',
|
||||
|
||||
Reference in New Issue
Block a user