|
|
@@ -50,6 +50,44 @@ def _validate_pattern_param(param: PatternContentParam) -> Optional[str]:
|
|
|
return None
|
|
|
|
|
|
|
|
|
+def _validate_decode_status(contents: List[ContentParam]) -> Optional[str]:
|
|
|
+ """校验每个channel_content_id的解构状态"""
|
|
|
+ STATUS_SUCCESS = 2 # 成功状态
|
|
|
+
|
|
|
+ for content in contents:
|
|
|
+ channel_content_id = content.channel_content_id
|
|
|
+
|
|
|
+ # 查询workflow_decode_task_result表,获取最新的解构任务记录
|
|
|
+ sql = """
|
|
|
+ SELECT task_id
|
|
|
+ FROM workflow_decode_task_result
|
|
|
+ WHERE channel_content_id = %s
|
|
|
+ ORDER BY created_time DESC
|
|
|
+ LIMIT 1
|
|
|
+ """
|
|
|
+ result_record = mysql.fetchone(sql, (channel_content_id,))
|
|
|
+
|
|
|
+ if not result_record:
|
|
|
+ return f"channel_content_id {channel_content_id} 找不到解构结果"
|
|
|
+
|
|
|
+ task_id = result_record.get("task_id")
|
|
|
+ if not task_id:
|
|
|
+ return f"channel_content_id {channel_content_id} 找不到解构结果"
|
|
|
+
|
|
|
+ # 查询workflow_task表,获取任务状态
|
|
|
+ task_sql = "SELECT status FROM workflow_task WHERE task_id = %s"
|
|
|
+ task_record = mysql.fetchone(task_sql, (task_id,))
|
|
|
+
|
|
|
+ if not task_record:
|
|
|
+ return f"channel_content_id {channel_content_id} 找不到解构结果"
|
|
|
+
|
|
|
+ status = task_record.get("status")
|
|
|
+ if status != STATUS_SUCCESS:
|
|
|
+ return f"channel_content_id {channel_content_id} 找不到解构结果"
|
|
|
+
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
def _create_pattern_task(scene: SceneEnum, content_type: ContentTypeEnum) -> Optional[WorkflowTask]:
|
|
|
"""创建聚类 workflow_task 任务"""
|
|
|
try:
|
|
|
@@ -173,6 +211,11 @@ def begin_pattern_task(param: PatternContentParam) -> Dict[str, Any]:
|
|
|
error_msg = _validate_pattern_param(param)
|
|
|
if error_msg:
|
|
|
return _build_error_response(ERROR_CODE_FAILED, error_msg)
|
|
|
+
|
|
|
+ # 1.1 校验解构状态
|
|
|
+ error_msg = _validate_decode_status(param.contents)
|
|
|
+ if error_msg:
|
|
|
+ return _build_error_response(ERROR_CODE_FAILED, error_msg)
|
|
|
|
|
|
# 2. 创建 workflow_task 任务
|
|
|
task = _create_pattern_task(param.scene, param.content_type)
|