From 2a117297daf83b2e1a104603e9641226d5beeba3 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期二, 04 三月 2025 10:41:38 +0800
Subject: [PATCH] fix: 按天统计相关逻辑
---
app/src/main/java/com/example/firstapp/database/AppDatabase.kt | 53 ++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/database/AppDatabase.kt b/app/src/main/java/com/example/firstapp/database/AppDatabase.kt
index 15e5bec..626aae1 100644
--- a/app/src/main/java/com/example/firstapp/database/AppDatabase.kt
+++ b/app/src/main/java/com/example/firstapp/database/AppDatabase.kt
@@ -10,20 +10,31 @@
import com.example.firstapp.database.dao.CodeDao
import com.example.firstapp.database.dao.KeywordDao
import com.example.firstapp.database.dao.MsgDao
+import com.example.firstapp.database.dao.ReminderDao
import com.example.firstapp.database.entity.Code
import com.example.firstapp.database.entity.KeywordEntity
import com.example.firstapp.database.entity.Msg
+import com.example.firstapp.database.entity.Reminder
import com.example.firstapp.utils.DATABASE_NAME
import com.example.firstapp.utils.SettingUtils
import com.example.firstapp.utils.TAG_LIST
import com.example.firstapp.database.ext.ConvertersDate
-
+import com.example.firstapp.model.CourierStat
+import com.example.firstapp.model.DailyStat
@Database(
- entities = [ Msg::class, Code::class, KeywordEntity::class],
-// views = [LogsDetail::class],
+ entities = [
+ Msg::class,
+ Code::class,
+ KeywordEntity::class,
+ Reminder::class
+ ],
+ views = [
+ CourierStat::class,
+ DailyStat::class
+ ],
version = 20,
exportSchema = false
)
@@ -32,6 +43,7 @@
abstract fun msgDao(): MsgDao
abstract fun codeDao(): CodeDao
abstract fun keywordDao(): KeywordDao
+ abstract fun reminderDao(): ReminderDao
companion object {
@Volatile
@@ -69,16 +81,6 @@
-
-
-
-
-
-
-
-
-
-
private val MIGRATION_MSG = object : Migration(19, 20) {
override fun migrate(database: SupportSQLiteDatabase) {
//database.execSQL("Create table Msg as Select id,type,`from`,content,(case when sim_info like 'SIM1%' then '0' when sim_info like 'SIM2%' then '1' else '-1' end) as sim_slot,sim_info,sub_id,time from Logs where 1 = 1")
@@ -109,6 +111,31 @@
)
""")
+ // 创建 CourierStat 视图
+ database.execSQL("""
+ CREATE VIEW IF NOT EXISTS CourierStat AS
+ SELECT courierName, COUNT(*) as count
+ FROM packages
+ GROUP BY courierName
+ """)
+
+ // 创建 DailyStat 视图
+ database.execSQL("""
+ CREATE VIEW IF NOT EXISTS DailyStat AS
+ SELECT date(receivedTime/1000, 'unixepoch', 'localtime') as date,
+ COUNT(*) as count
+ FROM packages
+ GROUP BY date(receivedTime/1000, 'unixepoch', 'localtime')
+ """)
+// database.execSQL("""
+// CREATE TABLE IF NOT EXISTS `reminders` (
+// id INTEGER PRIMARY KEY AUTOINCREMENT,
+// type TEXT NOT NULL,
+// nickname TEXT NOT NULL,
+// keywords TEXT NOT NULL,
+// );
+// """)
+
}
}
--
Gitblit v1.9.3