feat: 修正章节排序和分类逻辑
- 新增 SQL 脚本以修正章节排序索引,确保与 8 个分类体系对齐。 - 更新 API 章节获取逻辑,始终返回所有 8 个预定义类别,未填充内容的类别使用占位符。 - 引入章节分类功能,支持从 5-stage 关键词映射到 8 个章节类别,提升内容分类准确性。 - 更新 Android 客户端以适应新的章节定义和占位逻辑,确保用户界面一致性。
This commit is contained in:
@@ -37,8 +37,8 @@ import com.huaga.life_echo.ui.viewmodel.ViewModelFactory
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 默认章节定义(5个人生阶段)
|
||||
* 即使没有从API获取到内容,也会显示在页面上
|
||||
* 默认章节定义(8 个章节类别)
|
||||
* 后端 API 已返回全部章节(含占位),此处作为离线兜底
|
||||
*/
|
||||
private data class DefaultChapterInfo(
|
||||
val category: String,
|
||||
@@ -47,18 +47,25 @@ private data class DefaultChapterInfo(
|
||||
)
|
||||
|
||||
private val DEFAULT_CHAPTERS = listOf(
|
||||
DefaultChapterInfo("childhood", "童年时光", 0),
|
||||
DefaultChapterInfo("education", "求学经历", 1),
|
||||
DefaultChapterInfo("career", "职业生涯", 2),
|
||||
DefaultChapterInfo("family", "家庭生活", 5),
|
||||
DefaultChapterInfo("belief", "人生信念", 6),
|
||||
DefaultChapterInfo("childhood", "童年与成长背景", 0),
|
||||
DefaultChapterInfo("education", "教育经历与青年时期", 1),
|
||||
DefaultChapterInfo("career_early", "崭露头角", 2),
|
||||
DefaultChapterInfo("career_achievement", "主要成就与巅峰时刻", 3),
|
||||
DefaultChapterInfo("career_challenge", "挑战与重大转折", 4),
|
||||
DefaultChapterInfo("family", "家庭与情感", 5),
|
||||
DefaultChapterInfo("beliefs", "信念与价值观", 6),
|
||||
DefaultChapterInfo("summary", "人生总结", 7),
|
||||
)
|
||||
|
||||
/**
|
||||
* 合并 API 章节和默认章节占位
|
||||
* 确保所有5个阶段都有显示,有内容的用API数据,没内容的用占位
|
||||
* 后端 API 已返回含占位的完整列表,此处做兜底确保所有类别都显示
|
||||
*/
|
||||
private fun mergeChaptersWithDefaults(apiChapters: List<ChapterDto>): List<ChapterDto> {
|
||||
if (apiChapters.size >= DEFAULT_CHAPTERS.size) {
|
||||
return apiChapters.sortedBy { it.order_index }
|
||||
}
|
||||
|
||||
val apiCategoryMap = apiChapters.associateBy { it.category }
|
||||
val result = mutableListOf<ChapterDto>()
|
||||
|
||||
@@ -67,7 +74,6 @@ private fun mergeChaptersWithDefaults(apiChapters: List<ChapterDto>): List<Chapt
|
||||
if (existing != null) {
|
||||
result.add(existing)
|
||||
} else {
|
||||
// 创建占位章节(空内容)
|
||||
result.add(
|
||||
ChapterDto(
|
||||
id = "placeholder_${default.category}",
|
||||
@@ -85,7 +91,6 @@ private fun mergeChaptersWithDefaults(apiChapters: List<ChapterDto>): List<Chapt
|
||||
}
|
||||
}
|
||||
|
||||
// 添加不在默认列表中的 API 章节(如 career_early, career_achievement 等)
|
||||
for (apiChapter in apiChapters) {
|
||||
if (!DEFAULT_CHAPTERS.any { it.category == apiChapter.category }) {
|
||||
result.add(apiChapter)
|
||||
|
||||
Reference in New Issue
Block a user