feat: 扩展数据库模型,新增消息、订单和套餐实体
- 新增Message实体和MessageDao用于消息管理 - 新增Order实体用于订单管理 - 新增Plan实体用于套餐管理 - 更新AppDatabase集成新实体 - 更新现有数据库实体(Book、Chapter、Conversation)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
@@ -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()
|
||||
)
|
||||
Reference in New Issue
Block a user