重构:删 5 零引用 crate(df-evolve/plugin/stages/task/traceability)+ 清死模块、ai.rs 拆 11 子 module、ai.ts 拆 6 composable、i18n 拆目录 功能:知识库全栈(df-project/scan + CRUD + 时间线 + 前端)、Settings 拆分、appSettings KV 迁移、模型池、LLM 并发 Semaphore 修复:审批持久化根治、ConditionEngine 默认拒绝、NodeRegistry unimplemented 清除、promote 补偿删除、工具结果截断 50KB、路径校验防 symlink 逃逸 文档:B-03 人工审批设计、决策记录三分档、规格契约自检、经验记录、todo 看板、PROGRESS 更新 详见 PROGRESS.md。src-tauri/儿童每日打卡应用/ 与本项目无关,已排除。
92 lines
2.2 KiB
Rust
92 lines
2.2 KiB
Rust
//! 任务相关命令
|
|
|
|
use serde::Deserialize;
|
|
use tauri::State;
|
|
|
|
use df_core::types::new_id;
|
|
use df_storage::models::TaskRecord;
|
|
|
|
use crate::state::AppState;
|
|
|
|
use super::now_millis;
|
|
|
|
/// 创建任务入参
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct CreateTaskInput {
|
|
pub project_id: String,
|
|
pub title: String,
|
|
#[serde(default)]
|
|
pub description: String,
|
|
#[serde(default = "default_priority")]
|
|
pub priority: i32,
|
|
pub branch_name: Option<String>,
|
|
pub assignee: Option<String>,
|
|
}
|
|
|
|
fn default_priority() -> i32 {
|
|
2 // medium — 新任务默认中优先级(非 high),符合常识
|
|
}
|
|
|
|
/// 列出任务,可按 project_id 过滤
|
|
#[tauri::command]
|
|
pub async fn list_tasks(
|
|
state: State<'_, AppState>,
|
|
project_id: Option<String>,
|
|
) -> Result<Vec<TaskRecord>, String> {
|
|
let result = match project_id {
|
|
Some(pid) => state.tasks.query("project_id", &pid).await,
|
|
None => state.tasks.list_all().await,
|
|
};
|
|
result.map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// 创建任务,返回完整记录
|
|
#[tauri::command]
|
|
pub async fn create_task(
|
|
state: State<'_, AppState>,
|
|
input: CreateTaskInput,
|
|
) -> Result<TaskRecord, String> {
|
|
let now = now_millis();
|
|
let record = TaskRecord {
|
|
id: new_id(),
|
|
project_id: input.project_id,
|
|
title: input.title,
|
|
description: input.description,
|
|
status: "todo".to_string(),
|
|
priority: input.priority,
|
|
branch_name: input.branch_name,
|
|
assignee: input.assignee,
|
|
workflow_def_id: None,
|
|
base_branch: None,
|
|
created_at: now.clone(),
|
|
updated_at: now,
|
|
};
|
|
state
|
|
.tasks
|
|
.insert(record.clone())
|
|
.await
|
|
.map_err(|e| e.to_string())?;
|
|
Ok(record)
|
|
}
|
|
|
|
/// 更新任务单个字段(字段名走 df-storage 白名单校验)
|
|
#[tauri::command]
|
|
pub async fn update_task(
|
|
state: State<'_, AppState>,
|
|
id: String,
|
|
field: String,
|
|
value: String,
|
|
) -> Result<bool, String> {
|
|
state
|
|
.tasks
|
|
.update_field(&id, &field, &value)
|
|
.await
|
|
.map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// 删除任务
|
|
#[tauri::command]
|
|
pub async fn delete_task(state: State<'_, AppState>, id: String) -> Result<bool, String> {
|
|
state.tasks.delete(&id).await.map_err(|e| e.to_string())
|
|
}
|