|
|
@@ -54,7 +54,7 @@ def _create_workflow_task(scene: SceneEnum, content_type: ContentTypeEnum) -> Op
|
|
|
|
|
|
|
|
|
def _initialize_task_result(task_id: str, content) -> Optional[WorkflowDecodeTaskResult]:
|
|
|
- """初始化任务结果"""
|
|
|
+ """初始化选题解构任务结果"""
|
|
|
try:
|
|
|
result = WorkflowDecodeTaskResult.create_result(
|
|
|
task_id=task_id,
|
|
|
@@ -67,6 +67,21 @@ def _initialize_task_result(task_id: str, content) -> Optional[WorkflowDecodeTas
|
|
|
return None
|
|
|
|
|
|
|
|
|
+def _initialize_script_task_result(task_id: str, content) -> Optional[WorkflowDecodeTaskResult]:
|
|
|
+ """初始化创作解构任务结果(写入 workflow_script_task_result 表)"""
|
|
|
+ try:
|
|
|
+ result = WorkflowDecodeTaskResult.create_result(
|
|
|
+ task_id=task_id,
|
|
|
+ content=content,
|
|
|
+ table_name="workflow_script_task_result",
|
|
|
+ )
|
|
|
+ logger.info(f"初始化创作解构任务结果成功,task_id: {task_id}")
|
|
|
+ return result
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"初始化创作解构任务结果失败,task_id: {task_id}, error: {str(e)}")
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
def _check_quota(scene: SceneEnum, capability: CapabilityEnum = CapabilityEnum.DECODE, content_type: ContentTypeEnum = ContentTypeEnum.TEXT) -> bool:
|
|
|
"""检查配额是否充足(并发安全版本)"""
|
|
|
try:
|
|
|
@@ -196,10 +211,11 @@ def decode_topic(param: DecodeContentParam) -> Dict[str, Any]:
|
|
|
def begin_decode_task(param: DecodeContentParam) -> Dict[str, Any]:
|
|
|
"""根据场景分发任务"""
|
|
|
if param.scene == SceneEnum.TOPIC:
|
|
|
+ # 选题解构
|
|
|
return decode_topic(param)
|
|
|
elif param.scene == SceneEnum.CREATION:
|
|
|
- # TODO: 实现创作场景
|
|
|
- return _build_error_response(ERROR_CODE_FAILED, "创作场景暂未实现")
|
|
|
+ # 创作解构:流程与选题相同,只是结果表不同
|
|
|
+ return decode_creation(param)
|
|
|
elif param.scene == SceneEnum.PRODUCTION:
|
|
|
# TODO: 实现制作场景
|
|
|
return _build_error_response(ERROR_CODE_FAILED, "制作场景暂未实现")
|
|
|
@@ -207,6 +223,38 @@ def begin_decode_task(param: DecodeContentParam) -> Dict[str, Any]:
|
|
|
return _build_error_response(ERROR_CODE_FAILED, f"未知场景: {param.scene}")
|
|
|
|
|
|
|
|
|
+def decode_creation(param: DecodeContentParam) -> Dict[str, Any]:
|
|
|
+ """创作解构方法"""
|
|
|
+ try:
|
|
|
+ # 步骤1: 创建工作流task任务(scene 为 CREATION)
|
|
|
+ task = _create_workflow_task(param.scene, param.content_type)
|
|
|
+ if not task or not task.task_id:
|
|
|
+ return _build_error_response(
|
|
|
+ ERROR_CODE_TASK_CREATE_FAILED,
|
|
|
+ "创建创作解构任务失败"
|
|
|
+ )
|
|
|
+
|
|
|
+ # 步骤2: 初始化创作解构任务结果到 workflow_script_task_result
|
|
|
+ result = _initialize_script_task_result(task.task_id, param.content)
|
|
|
+ if not result or not result.task_id:
|
|
|
+ return _build_error_response(
|
|
|
+ ERROR_CODE_FAILED,
|
|
|
+ "初始化创作解构任务结果失败"
|
|
|
+ )
|
|
|
+
|
|
|
+ # 步骤3:(可选)触发创作解构工作流,目前按选题逻辑仅返回 task_id
|
|
|
+
|
|
|
+ # 所有步骤成功
|
|
|
+ return _build_success_response(task.task_id)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"创作解构失败: {str(e)}")
|
|
|
+ return _build_error_response(
|
|
|
+ ERROR_CODE_TASK_CREATE_FAILED,
|
|
|
+ f"创作解构任务创建失败: {str(e)}"
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def _trigger_topic_decode_workflow(task_id: str) -> Dict[str, Any]:
|
|
|
"""发起解构任务(调用上游工作流服务)"""
|
|
|
try:
|