fix:修复通知调试状态和重复命中问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.echo.app.notification
|
||||
package com.echo.app.notification
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
@@ -118,6 +118,14 @@ object NotificationDb {
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasRawNotification(db: SQLiteDatabase, sourceId: String): Boolean {
|
||||
if (sourceId.isBlank()) return false
|
||||
val cursor = db.rawQuery("SELECT 1 FROM notifications_raw WHERE source_id = ? LIMIT 1", arrayOf(sourceId))
|
||||
cursor.use {
|
||||
return it.moveToFirst()
|
||||
}
|
||||
}
|
||||
|
||||
private fun ensureSchema(db: SQLiteDatabase) {
|
||||
if (schemaInitialized) return
|
||||
db.execSQL(SQL_CREATE_TRANSACTIONS)
|
||||
@@ -140,6 +148,10 @@ object NotificationDb {
|
||||
val db = getHelper(context).writableDatabase
|
||||
ensureSchema(db)
|
||||
|
||||
if (hasRawNotification(db, raw.sourceId)) {
|
||||
return
|
||||
}
|
||||
|
||||
val rawId = UUID.randomUUID().toString()
|
||||
var status = "unmatched"
|
||||
var ruleId: String? = null
|
||||
@@ -174,6 +186,8 @@ object NotificationDb {
|
||||
val merchantKnown = parsed.merchant.isNotBlank() && parsed.merchant != "Unknown"
|
||||
val requiresConfirmation = !(parsed.autoCapture && hasAmount && merchantKnown)
|
||||
|
||||
status = if (requiresConfirmation) "review" else "matched"
|
||||
|
||||
if (!requiresConfirmation) {
|
||||
val signedAmount = if (parsed.isExpense) -abs(parsed.amount) else abs(parsed.amount)
|
||||
transactionId = UUID.randomUUID().toString()
|
||||
|
||||
@@ -126,7 +126,7 @@ internal object NotificationRuleData {
|
||||
impactIncome = false,
|
||||
defaultCategory = "Expense",
|
||||
autoCapture = false,
|
||||
merchantPattern = Regex("(?:商户|商家|消费商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)"),
|
||||
merchantPattern = Regex("(?:在【([^】]+)】发生|商户|商家|消费商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)?"),
|
||||
defaultMerchant = null,
|
||||
),
|
||||
NotificationRuleDefinition(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.echo.app.notification
|
||||
package com.echo.app.notification
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
@@ -156,7 +156,7 @@ object NotificationRuleEngine {
|
||||
rule.merchantPattern?.let { regex ->
|
||||
val match = regex.find(content)
|
||||
if (match != null && match.groupValues.size > 1) {
|
||||
val candidate = match.groupValues[1].trim()
|
||||
val candidate = match.groupValues.drop(1).firstOrNull { it.isNotBlank() }?.trim().orEmpty()
|
||||
if (candidate.isNotEmpty()) return candidate
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user