|
|
@@ -1,5 +1,5 @@
|
|
|
from utils.sync_mysql_help import mysql
|
|
|
-from utils.params import CapabilityEnum
|
|
|
+from utils.params import CapabilityEnum, SceneEnum
|
|
|
from loguru import logger
|
|
|
import sys
|
|
|
import json
|
|
|
@@ -51,7 +51,7 @@ def _parse_web_url(web_url: Optional[str]) -> Any:
|
|
|
|
|
|
|
|
|
def _fetch_decode_result(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
- """获取解构任务结果"""
|
|
|
+ """获取选题解构任务结果"""
|
|
|
sql = "SELECT result_payload, error_message, web_url FROM workflow_decode_task_result WHERE task_id = %s"
|
|
|
result_record = mysql.fetchone(sql, (task_id,))
|
|
|
|
|
|
@@ -65,6 +65,21 @@ def _fetch_decode_result(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
}
|
|
|
|
|
|
|
|
|
+def _fetch_script_decode_result(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
+ """获取创作解构任务结果"""
|
|
|
+ sql = "SELECT result_payload, error_message, web_url FROM workflow_script_task_result WHERE task_id = %s"
|
|
|
+ result_record = mysql.fetchone(sql, (task_id,))
|
|
|
+
|
|
|
+ if not result_record:
|
|
|
+ return None
|
|
|
+
|
|
|
+ return {
|
|
|
+ "result": _parse_result_payload(result_record.get("result_payload")),
|
|
|
+ "error_message": result_record.get("error_message"),
|
|
|
+ "url": _parse_web_url(result_record.get("web_url")),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
def _fetch_pattern_result(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
"""获取聚类任务结果"""
|
|
|
sql = "SELECT result_payload, error_message, web_url FROM workflow_pattern_task_result WHERE task_id = %s"
|
|
|
@@ -102,11 +117,16 @@ def _build_result_data(
|
|
|
return data
|
|
|
|
|
|
|
|
|
-def _handle_success_status(task_id: str, capability: int) -> Dict[str, Any]:
|
|
|
+def _handle_success_status(task_id: str, capability: int, scene: Optional[int] = None) -> Dict[str, Any]:
|
|
|
"""处理成功状态(status=2)"""
|
|
|
# 解构任务
|
|
|
if capability == CapabilityEnum.DECODE.value:
|
|
|
- decode_result = _fetch_decode_result(task_id)
|
|
|
+ # 按业务场景区分:0 选题 -> 选题解构表;1 创作 -> 创作解构表
|
|
|
+ if scene is not None and scene == SceneEnum.CREATION.value:
|
|
|
+ decode_result = _fetch_script_decode_result(task_id)
|
|
|
+ else:
|
|
|
+ decode_result = _fetch_decode_result(task_id)
|
|
|
+
|
|
|
if not decode_result:
|
|
|
return _build_response(_build_result_data(task_id, STATUS_SUCCESS))
|
|
|
|
|
|
@@ -141,7 +161,7 @@ def _handle_success_status(task_id: str, capability: int) -> Dict[str, Any]:
|
|
|
def get_decode_detail_by_task_id(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
"""获取任务详情"""
|
|
|
# 查询任务基本信息
|
|
|
- sql = "SELECT task_id, status, capability FROM workflow_task WHERE task_id = %s"
|
|
|
+ sql = "SELECT task_id, status, capability, scene FROM workflow_task WHERE task_id = %s"
|
|
|
task = mysql.fetchone(sql, (task_id,))
|
|
|
|
|
|
if not task:
|
|
|
@@ -151,6 +171,7 @@ def get_decode_detail_by_task_id(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
task_id_value = task.get("task_id")
|
|
|
status = task.get("status")
|
|
|
capability = task.get("capability")
|
|
|
+ scene = task.get("scene")
|
|
|
|
|
|
# 不需要查询结果的状态,直接返回
|
|
|
if status in STATUS_WITHOUT_RESULT:
|
|
|
@@ -159,14 +180,19 @@ def get_decode_detail_by_task_id(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
|
|
|
# 成功状态,需要查询结果
|
|
|
if status == STATUS_SUCCESS:
|
|
|
- return _handle_success_status(task_id_value, capability)
|
|
|
+ return _handle_success_status(task_id_value, capability, scene)
|
|
|
|
|
|
# 失败状态,需要返回 error_message 到 reason 字段,result 固定为 "[]"
|
|
|
if status == STATUS_FAILED:
|
|
|
error_message: Optional[str] = None
|
|
|
# 解构任务失败原因
|
|
|
if capability == CapabilityEnum.DECODE.value:
|
|
|
- decode_result = _fetch_decode_result(task_id_value)
|
|
|
+ # 按业务场景区分:0 选题 -> 选题解构表;1 创作 -> 创作解构表
|
|
|
+ if scene is not None and scene == SceneEnum.CREATION.value:
|
|
|
+ decode_result = _fetch_script_decode_result(task_id_value)
|
|
|
+ else:
|
|
|
+ decode_result = _fetch_decode_result(task_id_value)
|
|
|
+
|
|
|
if decode_result:
|
|
|
error_message = decode_result.get("error_message")
|
|
|
# 聚类任务失败原因
|