fix:修复通知调试状态和重复命中问题
This commit is contained in:
@@ -22,6 +22,28 @@ const mapRow = (row) => ({
|
||||
errorMessage: row.error_message || '',
|
||||
})
|
||||
|
||||
const dedupeRecords = (rows = []) => {
|
||||
const bucket = new Map()
|
||||
|
||||
rows.forEach((row) => {
|
||||
const item = mapRow(row)
|
||||
const key = item.sourceId || item.id
|
||||
if (!bucket.has(key)) {
|
||||
bucket.set(key, item)
|
||||
return
|
||||
}
|
||||
|
||||
const existing = bucket.get(key)
|
||||
const existingScore = Number(Boolean(existing.transactionId)) + Number(existing.status === NOTIFICATION_DEBUG_STATUS.matched) + Number(Boolean(existing.ruleId))
|
||||
const nextScore = Number(Boolean(item.transactionId)) + Number(item.status === NOTIFICATION_DEBUG_STATUS.matched) + Number(Boolean(item.ruleId))
|
||||
if (nextScore > existingScore) {
|
||||
bucket.set(key, item)
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(bucket.values())
|
||||
}
|
||||
|
||||
const getLatestBySourceId = async (sourceId) => {
|
||||
if (!sourceId) return null
|
||||
const db = await getDb()
|
||||
@@ -150,5 +172,5 @@ export const fetchNotificationDebugRecords = async (options = {}) => {
|
||||
params,
|
||||
)
|
||||
|
||||
return (result?.values || []).map(mapRow)
|
||||
return dedupeRecords(result?.values || [])
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DEFAULT_LEDGER_BY_ENTRY_TYPE } from '../config/ledger.js'
|
||||
import { DEFAULT_LEDGER_BY_ENTRY_TYPE } from '../config/ledger.js'
|
||||
import notificationRulesSource from '../config/notificationRules.js'
|
||||
|
||||
const fallbackRules = notificationRulesSource.map((rule) => ({
|
||||
@@ -115,7 +115,8 @@ const extractMerchant = (text, rule) => {
|
||||
|
||||
if (rule?.merchantPattern instanceof RegExp) {
|
||||
const matched = content.match(rule.merchantPattern)
|
||||
if (matched?.[1]) return matched[1].trim()
|
||||
const candidate = matched?.slice(1).find((item) => item && String(item).trim())
|
||||
if (candidate) return candidate.trim()
|
||||
}
|
||||
|
||||
const routeMatch = content.match(/([\u4e00-\u9fa5]{2,}\s*(?:-|->|→|至|到)\s*[\u4e00-\u9fa5]{2,})/)
|
||||
|
||||
Reference in New Issue
Block a user