fix: 风险检测同步更新actionUrl+MONTHLY类型actionUrl修正
- runRiskDetection 更新逻辑增加 actionUrl 变化检测(非月度风险) - 新增 MONTHLY 类型 PENDING 记录的 actionUrl 同步更新逻辑 - existingRisks 查询补充 actionUrl 字段 - 修复存量月度待办跳转目标不更新问题 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -546,7 +546,7 @@ export async function runRiskDetection(orgId: string) {
|
||||
// 按 employeeId:type 归并,不依赖 actionUrl(actionUrl 可能因天数变化而不同)
|
||||
const existingRisks = await prisma.riskItem.findMany({
|
||||
where: { orgId, status: { in: ['PENDING', 'RESOLVED', 'IGNORED'] } },
|
||||
select: { id: true, employeeId: true, type: true, title: true, status: true },
|
||||
select: { id: true, employeeId: true, type: true, title: true, status: true, actionUrl: true },
|
||||
})
|
||||
const existingKeys = new Set(existingRisks.map((r: typeof existingRisks[number]) => `${r.employeeId}:${r.type}`))
|
||||
// PENDING 风险的 employeeId:type → record 映射,用于更新标题
|
||||
@@ -592,18 +592,19 @@ export async function runRiskDetection(orgId: string) {
|
||||
...monthlyTasks.filter((r) => !monthlyKeys.has(`${r.employeeId}:${r.title}`)),
|
||||
]
|
||||
|
||||
// 更新已存在的 PENDING 风险:标题/量化信息可能因天数变化而变化
|
||||
const toUpdate: { id: string; title: string; description: string; estimatedLoss: number; lossRange: [number, number]; deadline?: Date }[] = []
|
||||
// 更新已存在的 PENDING 风险:标题/量化信息/actionUrl 可能因天数变化或代码更新而变化
|
||||
const toUpdate: { id: string; title: string; description: string; actionUrl: string; estimatedLoss: number; lossRange: [number, number]; deadline?: Date }[] = []
|
||||
for (const r of nonMonthlyRisks) {
|
||||
const key = `${r.employeeId}:${r.type}`
|
||||
const existing = pendingRiskMap.get(key)
|
||||
if (existing && existing.title !== r.title) {
|
||||
if (existing && (existing.title !== r.title || existing.actionUrl !== r.actionUrl)) {
|
||||
const emp = r.employeeId ? empMap.get(r.employeeId) : null
|
||||
const cost = estimateRiskCost(r, emp)
|
||||
toUpdate.push({
|
||||
id: existing.id,
|
||||
title: r.title,
|
||||
description: r.description,
|
||||
actionUrl: r.actionUrl,
|
||||
estimatedLoss: cost.estimatedLoss,
|
||||
lossRange: cost.lossRange,
|
||||
deadline: cost.deadline,
|
||||
@@ -616,6 +617,7 @@ export async function runRiskDetection(orgId: string) {
|
||||
data: {
|
||||
title: u.title,
|
||||
description: u.description,
|
||||
actionUrl: u.actionUrl,
|
||||
estimatedLoss: u.estimatedLoss,
|
||||
lossRange: u.lossRange,
|
||||
deadline: u.deadline,
|
||||
@@ -623,6 +625,19 @@ export async function runRiskDetection(orgId: string) {
|
||||
})
|
||||
}
|
||||
|
||||
// 更新 MONTHLY 类型 PENDING 记录的 actionUrl(标题不变但 actionUrl 可能因代码更新而变化)
|
||||
const monthlyPending = existingRisks.filter((r: typeof existingRisks[number]) => r.status === 'PENDING' && r.type === 'MONTHLY')
|
||||
const monthlyActionUrlMap = new Map(monthlyTasks.map((r) => [r.title, r.actionUrl]))
|
||||
for (const r of monthlyPending) {
|
||||
const newUrl = monthlyActionUrlMap.get(r.title)
|
||||
if (newUrl && r.actionUrl !== newUrl) {
|
||||
await prisma.riskItem.update({
|
||||
where: { id: r.id },
|
||||
data: { actionUrl: newUrl },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (toCreate.length > 0) {
|
||||
// 为每个风险计算量化信息
|
||||
const createData = toCreate.map((r) => {
|
||||
|
||||
Reference in New Issue
Block a user