feat: 移除冗余的AI任务和项目生成逻辑,优化代码结构

This commit is contained in:
kuaifan
2025-11-08 20:45:21 +00:00
parent 0deb3113b5
commit 0434bde16f
8 changed files with 2 additions and 700 deletions

View File

@@ -3024,115 +3024,6 @@ class ProjectController extends AbstractController
return Base::retSuccess('复制成功', $data);
}
/**
* @api {post} api/project/task/ai_generate 使用 AI 助手生成任务
*
* @apiDescription 需要token身份使用AI根据用户输入和上下文信息生成任务标题和详细描述
* @apiVersion 1.0.0
* @apiGroup project
* @apiName task__ai_generate
*
* @apiParam {String} content 用户输入的任务描述(必填)
* @apiParam {String} [current_title] 当前已有的任务标题(用于优化改进)
* @apiParam {String} [current_content] 当前已有的任务内容HTML格式用于优化改进
* @apiParam {String} [template_name] 选中的任务模板名称
* @apiParam {String} [template_content] 选中的任务模板内容HTML格式
* @apiParam {Boolean} [has_owner] 是否已设置负责人
* @apiParam {Boolean} [has_time_plan] 是否已设置计划时间
* @apiParam {String} [priority_level] 任务优先级等级名称
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
* @apiSuccess {String} data.title AI 生成的任务标题
* @apiSuccess {String} data.content AI 生成的任务内容HTML 格式)
* @apiSuccess {Array} data.subtasks 当任务较复杂时生成的子任务名称列表
*/
public function task__ai_generate()
{
User::auth();
// 获取用户输入的任务描述
$content = Request::input('content');
if (empty($content)) {
return Base::retError('任务描述不能为空');
}
// 获取上下文信息
$context = [
'current_title' => Request::input('current_title', ''),
'current_content' => Request::input('current_content', ''),
'template_name' => Request::input('template_name', ''),
'template_content' => Request::input('template_content', ''),
'has_owner' => boolval(Request::input('has_owner', false)),
'has_time_plan' => boolval(Request::input('has_time_plan', false)),
'priority_level' => Request::input('priority_level', ''),
];
// 如果当前内容是HTML格式转换为markdown
if (!empty($context['current_content'])) {
$context['current_content'] = Base::html2markdown($context['current_content']);
}
if (!empty($context['template_content'])) {
$context['template_content'] = Base::html2markdown($context['template_content']);
}
$result = AI::generateTask($content, $context);
if (Base::isError($result)) {
return Base::retError('生成任务失败', $result);
}
return Base::retSuccess('生成任务成功', $result['data']);
}
/**
* @api {post} api/project/ai/generate 使用 AI 助手生成项目
*
* @apiDescription 需要token身份根据需求说明自动生成项目名称及任务列表
* @apiVersion 1.0.0
* @apiGroup project
* @apiName ai__generate
*
* @apiParam {String} content 项目需求或背景描述(必填)
* @apiParam {String} [current_name] 当前草拟的项目名称
* @apiParam {Array|String} [current_columns] 已有任务列表(数组或以逗号/换行分隔的字符串)
* @apiParam {Array} [template_examples] 可参考的模板示例,格式:[ {name: 模板名, columns: [列表...] }, ... ]
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
* @apiSuccess {String} data.name AI 生成的项目名称
* @apiSuccess {Array} data.columns AI 生成的任务列表名称数组
*/
public function ai__generate()
{
User::auth();
$content = trim((string)Request::input('content', ''));
if ($content === '') {
return Base::retError('项目需求描述不能为空');
}
$templateExamples = Request::input('template_examples', []);
if (!is_array($templateExamples)) {
$templateExamples = [];
} else {
$templateExamples = array_slice($templateExamples, 0, 6);
}
$context = [
'current_name' => Request::input('current_name', ''),
'current_columns' => Request::input('current_columns', []),
'template_examples' => $templateExamples,
];
$result = AI::generateProject($content, $context);
if (Base::isError($result)) {
return Base::retError('生成项目失败', $result);
}
return Base::retSuccess('生成项目成功', $result['data']);
}
/**
* @api {get} api/project/flow/list 工作流列表
*