feat: 扩展数据库模型,新增消息、订单和套餐实体

- 新增Message实体和MessageDao用于消息管理
- 新增Order实体用于订单管理
- 新增Plan实体用于套餐管理
- 更新AppDatabase集成新实体
- 更新现有数据库实体(Book、Chapter、Conversation)
This commit is contained in:
徐在坤
2026-01-21 18:17:25 +08:00
parent 8567a8fece
commit 6351981555
8 changed files with 94 additions and 6 deletions

View File

@@ -11,15 +11,17 @@ import androidx.room.RoomDatabase
Conversation::class,
ConversationSegment::class,
Chapter::class,
Book::class
Book::class,
Message::class
],
version = 1,
version = 2,
exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {
abstract fun conversationDao(): ConversationDao
abstract fun conversationSegmentDao(): ConversationSegmentDao
abstract fun chapterDao(): ChapterDao
abstract fun messageDao(): MessageDao
companion object {
@Volatile

View File

@@ -8,8 +8,10 @@ data class Book(
@PrimaryKey val id: String,
val userId: String,
val title: String,
val subtitle: String? = null,
val totalPages: Int,
val totalWords: Int,
val updatedAt: Long
val updatedAt: Long,
val lastUpdatedAt: Long? = null
)

View File

@@ -9,8 +9,9 @@ data class Chapter(
val title: String,
val content: String,
val orderIndex: Int,
val status: String, // draft, completed
val status: String, // draft, partial, completed
val updatedAt: Long,
val category: String
val category: String,
val pageCount: Int? = null
)

View File

@@ -12,6 +12,10 @@ data class Conversation(
val durationSeconds: Int,
val summary: String?,
val currentTopic: String?,
val conversationStage: String? // CHILDHOOD, EDUCATION, CAREER, FAMILY, BELIEFS, SUMMARY
val conversationStage: String?, // CHILDHOOD, EDUCATION, CAREER, FAMILY, BELIEFS, SUMMARY
val avatarUrl: String? = null,
val title: String? = null,
val latestMessagePreview: String? = null,
val latestMessageTime: Long? = null
)

View File

@@ -0,0 +1,14 @@
package com.huaga.life_echo.data.database
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "messages")
data class Message(
@PrimaryKey val id: String,
val conversationId: String,
val content: String,
val senderType: String, // "user" or "assistant"
val timestamp: Long,
val messageType: String = "text" // "text", "audio", "image"
)

View File

@@ -0,0 +1,28 @@
package com.huaga.life_echo.data.database
import androidx.room.*
import kotlinx.coroutines.flow.Flow
@Dao
interface MessageDao {
@Query("SELECT * FROM messages WHERE conversationId = :conversationId ORDER BY timestamp ASC")
fun getMessagesByConversationId(conversationId: String): Flow<List<Message>>
@Query("SELECT * FROM messages WHERE id = :id")
suspend fun getMessageById(id: String): Message?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertMessage(message: Message)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertMessages(messages: List<Message>)
@Update
suspend fun updateMessage(message: Message)
@Delete
suspend fun deleteMessage(message: Message)
@Query("DELETE FROM messages WHERE conversationId = :conversationId")
suspend fun deleteMessagesByConversationId(conversationId: String)
}

View File

@@ -0,0 +1,19 @@
package com.huaga.life_echo.data.database
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "orders")
data class Order(
@PrimaryKey val id: String,
val userId: String,
val planId: String,
val planName: String,
val amount: Double,
val currency: String = "CNY",
val status: String, // "pending", "paid", "failed", "cancelled"
val paymentMethod: String? = null, // "wechat", "alipay"
val createdAt: Long,
val paidAt: Long? = null,
val expiresAt: Long? = null
)

View File

@@ -0,0 +1,18 @@
package com.huaga.life_echo.data.database
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "plans")
data class Plan(
@PrimaryKey val id: String,
val name: String,
val displayName: String,
val price: Double,
val currency: String = "CNY",
val billingCycle: String, // "monthly", "yearly"
val features: String, // JSON string of features list
val isActive: Boolean = true,
val isCurrentPlan: Boolean = false,
val cachedAt: Long = System.currentTimeMillis()
)