feat: 补齐会话冲突出口、预期必填与报告闭环,精简悬浮窗
- 会话冲突出口:开始新任务前查其他任务上的未结束会话,给出「前往继续 / 结束它并开始 / 放弃它」三个出口,避免同时存在两个进行中的会话 - 学习预期必填:未填预期时用不可关闭弹窗挡住,只能保存预期或走误操作结束 - 收敛提示:把服务端 systemMessage / autoConverged 原样告知用户 - 学习报告:结束会话时取 REPORT_DRAFT 草稿(AI 不可用由后端规则降级)作为编辑起点,可直接手写结束;任务页新增报告查看(三段 + 本会话碎片) - 悬浮窗只保留三件事:展示倒计时、记一条碎片、暂停/继续;结束、报告、预期等一律回到 App 页面 - 修复前台服务在进程被系统拉起时把「还不知道」当成「没有会话」而自杀(以 State.resolved 为准)
This commit is contained in:
@@ -2,6 +2,9 @@ package com.catshark.lpt.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonNull
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
/** lpt-be 的统一响应包装:{ code, message, data } */
|
||||
@Serializable
|
||||
@@ -63,6 +66,8 @@ data class ActiveSession(
|
||||
val taskName: String? = null,
|
||||
val sessionState: String? = null,
|
||||
val autoConverged: Boolean = false,
|
||||
/** 服务端自动收敛时的用户可见文案 */
|
||||
val systemMessage: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@@ -116,6 +121,10 @@ data class ReportSections(
|
||||
val allBlank: Boolean
|
||||
get() = sessionSummary.isBlank() && expectationVerdict.isBlank() && freeSummary.isBlank()
|
||||
|
||||
companion object {
|
||||
val EMPTY = ReportSections("", "", "")
|
||||
}
|
||||
|
||||
/**
|
||||
* 旧版后端(部署版)只要一段 content。把三段拼成一段,并保留小标题,
|
||||
* 这样旧后端的报告页也能看出结构;全空时给一个占位,避免被「请填写学习报告内容」拦下。
|
||||
@@ -130,14 +139,65 @@ data class ReportSections(
|
||||
/** 从登录响应里取 token:线上实际返回纯字符串,源码契约是 {token, aiAdmin},两者都兼容 */
|
||||
fun extractToken(element: JsonElement?): String? {
|
||||
if (element == null) return null
|
||||
return when {
|
||||
element is JsonElement && element.toString().trim().startsWith("\"") ->
|
||||
element.toString().trim().trim('"')
|
||||
else -> {
|
||||
val obj = element as? kotlinx.serialization.json.JsonObject
|
||||
obj?.get("token")?.let { token ->
|
||||
if (token.toString().trim().startsWith("\"")) token.toString().trim().trim('"') else token.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
val text = element.toString().trim()
|
||||
if (text.startsWith("\"")) return text.trim('"')
|
||||
val token = (element as? JsonObject)?.get("token") ?: return null
|
||||
val raw = token.toString().trim()
|
||||
return if (raw.startsWith("\"")) raw.trim('"') else raw
|
||||
}
|
||||
|
||||
/** 某次学习会话产出的学习报告(报告三段 + 该会话的学习预期) */
|
||||
@Serializable
|
||||
data class StudyReport(
|
||||
val id: Int = 0,
|
||||
val sessionNum: String = "",
|
||||
val sessionSummary: String? = null,
|
||||
val expectationVerdict: String? = null,
|
||||
val freeSummary: String? = null,
|
||||
/** 会话对应的学习预期,随报告返回,不落库 */
|
||||
val sessionExpectation: String? = null,
|
||||
val createdTime: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ReportPage(
|
||||
val records: List<StudyReport> = emptyList(),
|
||||
val total: Int = 0,
|
||||
val size: Int = 0,
|
||||
val current: Int = 0,
|
||||
val pages: Int = 0,
|
||||
)
|
||||
|
||||
/** AI 异步任务(AI-02):提交秒级返回,之后轮询拿状态与结果 */
|
||||
@Serializable
|
||||
data class AiTask(
|
||||
val taskNum: String = "",
|
||||
val type: String = "",
|
||||
val targetNum: String = "",
|
||||
val status: String = "",
|
||||
val errorMessage: String? = null,
|
||||
val result: JsonObject? = null,
|
||||
) {
|
||||
val succeeded: Boolean get() = status == "SUCCEEDED"
|
||||
val failed: Boolean get() = status == "FAILED"
|
||||
val inProgress: Boolean get() = status == "PENDING" || status == "RUNNING"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class SubmitAiTaskRequest(
|
||||
val type: String,
|
||||
val targetNum: String,
|
||||
)
|
||||
|
||||
/** 取报告草稿三段:REPORT_DRAFT 任务的 result 就是三个同名字段 */
|
||||
fun AiTask.draftSections(): ReportSections = ReportSections(
|
||||
sessionSummary = result.text("sessionSummary"),
|
||||
expectationVerdict = result.text("expectationVerdict"),
|
||||
freeSummary = result.text("freeSummary"),
|
||||
)
|
||||
|
||||
private fun JsonObject?.text(key: String): String {
|
||||
val element = this?.get(key) ?: return ""
|
||||
if (element is JsonNull) return ""
|
||||
return runCatching { element.jsonPrimitive.content }.getOrDefault("")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user