新增: 任务灵感归档后端
This commit is contained in:
@@ -329,6 +329,7 @@ pub async fn create_task(
|
||||
queue,
|
||||
parent_id,
|
||||
content_json,
|
||||
archived: false,
|
||||
created_at: now.clone(),
|
||||
updated_at: now,
|
||||
};
|
||||
@@ -471,6 +472,11 @@ pub async fn update_task(
|
||||
.await
|
||||
.map_err(err_str)?;
|
||||
if !updated {
|
||||
// update_field_active 恒带 archived = 0:0 行时区分「已归档」与「不存在/已软删」,
|
||||
// 避免归档任务被误报为已删除(用户无从知道要先取消归档)。
|
||||
if current.as_ref().is_some_and(|c| c.archived) {
|
||||
return Err(format!("任务 ID {id} 已归档,请先取消归档再修改"));
|
||||
}
|
||||
return Err(format!("任务 ID {id} 不存在或已删除"));
|
||||
}
|
||||
// LW-9改 parent_id 后重算父聚合——旧父(任务已离开,计数减少)与新父(任务挂上)。
|
||||
@@ -588,6 +594,52 @@ pub async fn restore_task(state: State<'_, AppState>, id: String) -> Result<bool
|
||||
Ok(ok)
|
||||
}
|
||||
|
||||
/// 归档/取消归档任务(归档功能 P1,V46)。对标 ai_conversation_archive。
|
||||
///
|
||||
/// 纯元数据标记,与 status/queue 正交:归档后任务退出主视图与状态机(冻结:
|
||||
/// 不可推进/跨池/字段更新,repo 层活跃查询与写入路径恒带 archived = 0 收口),
|
||||
/// 仅在归档视图(list_archived_tasks)可见。软删优先:回收站任务不可直接归档。
|
||||
///
|
||||
/// 埋点 task_archived/task_unarchived(项目事件流,best-effort 不阻断)。
|
||||
#[tauri::command]
|
||||
pub async fn archive_task(
|
||||
state: State<'_, AppState>,
|
||||
id: String,
|
||||
archived: bool,
|
||||
) -> Result<bool, String> {
|
||||
let rec = state.tasks.get_by_id(&id).await.map_err(err_str)?;
|
||||
let ok = state.tasks.set_archived(&id, archived).await.map_err(err_str)?;
|
||||
if ok {
|
||||
if let Some(r) = rec {
|
||||
emit_event(
|
||||
&state,
|
||||
&r.project_id,
|
||||
if archived { "task_archived" } else { "task_unarchived" },
|
||||
Some("task"),
|
||||
Some(&r.id),
|
||||
None,
|
||||
Some(if archived { "archived" } else { "active" }),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
Ok(ok)
|
||||
}
|
||||
|
||||
/// 列出归档任务(archived = 1 且未删),按更新时间降序。归档视图数据源。
|
||||
#[tauri::command]
|
||||
pub async fn list_archived_tasks(
|
||||
state: State<'_, AppState>,
|
||||
project_id: Option<String>,
|
||||
) -> Result<Vec<TaskRecord>, String> {
|
||||
let tasks = state.tasks.list_archived().await.map_err(err_str)?;
|
||||
// 归档量级小(低频操作),内存过滤 project_id 足够;SQL 下推待归档量增长再说
|
||||
Ok(match project_id {
|
||||
Some(pid) => tasks.into_iter().filter(|t| t.project_id == pid).collect(),
|
||||
None => tasks,
|
||||
})
|
||||
}
|
||||
|
||||
/// 推进任务状态(任务推进链 F-260616-02,推进链唯一 status 写入路径)。
|
||||
///
|
||||
/// thin 入口业务逻辑(状态机校验 + 原子 CAS + review_rounds 累加 + 父聚合)
|
||||
|
||||
Reference in New Issue
Block a user