Jelajahi Sumber

Merge branch 'dev_api_init' of weapp/video_decode into master

jihuaqiang 12 jam lalu
induk
melakukan
9ae49b4d2c
5 mengubah file dengan 44 tambahan dan 10 penghapusan
  1. 1 1
      .gitignore
  2. 2 0
      README.md
  3. 24 3
      models/decode_task_result.py
  4. 16 6
      tasks/decode.py
  5. 1 0
      utils/params.py

+ 1 - 1
.gitignore

@@ -128,7 +128,7 @@ dmypy.json
 .vscode/
 .DS_Store
 
-mysql_work/
+mysql_work*/
 output/
 video_detail_output/
 *.xlsx

+ 2 - 0
README.md

@@ -1,5 +1,7 @@
 # Video Decode 项目本地运行指南
 
+## 部署地址
+[票圈-内容供给API-video-decode-生产-更新-docker](https://jenkins-on.yishihui.com/view/%E7%A5%A8%E5%9C%88-%E5%86%85%E5%AE%B9%E8%A7%A3%E6%9E%84/job/%E7%A5%A8%E5%9C%88-%E5%86%85%E5%AE%B9%E4%BE%9B%E7%BB%99API-video-decode-%E7%94%9F%E4%BA%A7-%E6%9B%B4%E6%96%B0-docker/)
 ## 环境要求
 
 - Python 3.13+ (当前版本: 3.13.2)

+ 24 - 3
models/decode_task_result.py

@@ -5,7 +5,7 @@ from typing_extensions import Annotated
 from utils.sync_mysql_help import mysql
 
 if TYPE_CHECKING:
-    from utils.params import ContentParam
+    from utils.params import ContentParam, ContentTypeEnum
 
 
 class WorkflowDecodeTaskResult(BaseModel):
@@ -24,6 +24,21 @@ class WorkflowDecodeTaskResult(BaseModel):
     body_text: Annotated[Optional[str], Field(description='内容上下文', default=None)]
     video_url: Annotated[Optional[str], Field(description='内容视频地址', default=None)]
     merge_leve2: Annotated[Optional[str], Field(description='二级品类/标签', default=None)]
+    channel: Annotated[Optional[str], Field(description='内容渠道', default=None)]
+
+    @staticmethod
+    def _resolve_channel(content: 'ContentParam', content_type: 'ContentTypeEnum') -> Optional[str]:
+        """确定渠道字段:优先使用入参 channel,否则按 content_type 映射。"""
+        if content.channel:
+            normalized_channel = content.channel.strip()
+            if normalized_channel:
+                return normalized_channel
+
+        if content_type.value == 3:
+            return "票圈"
+        if content_type.value in {1, 4, 5}:
+            return "公众号"
+        return None
 
     def save(self):
         """保存结果到数据库"""
@@ -39,7 +54,12 @@ class WorkflowDecodeTaskResult(BaseModel):
         return [url.strip() for url in self.images.split(',') if url.strip()]
 
     @staticmethod
-    def create_result(task_id: str, content: 'ContentParam', table_name: Optional[str] = None) -> 'WorkflowDecodeTaskResult':
+    def create_result(
+        task_id: str,
+        content: 'ContentParam',
+        content_type: 'ContentTypeEnum',
+        table_name: Optional[str] = None
+    ) -> 'WorkflowDecodeTaskResult':
         """创建并初始化结果记录
 
         :param task_id: 任务ID
@@ -70,8 +90,9 @@ class WorkflowDecodeTaskResult(BaseModel):
             channel_account_id=content.channel_account_id,
             channel_account_name=content.channel_account_name[:64] if content.channel_account_name and len(content.channel_account_name) > 64 else (content.channel_account_name or ''),
             body_text=content.body_text or '',
-            video_url=content.video_url[:100] if content.video_url and len(content.video_url) > 100 else (content.video_url or ''),
+            video_url=content.video_url[:512] if content.video_url and len(content.video_url) > 512 else (content.video_url or ''),
             merge_leve2=merge_leve2_val,
+            channel=WorkflowDecodeTaskResult._resolve_channel(content, content_type),
             result_payload=None,
             result_size=0
         )

+ 16 - 6
tasks/decode.py

@@ -1,4 +1,4 @@
-from utils.params import DecodeContentParam, SceneEnum, ContentTypeEnum, CapabilityEnum
+from utils.params import DecodeContentParam, SceneEnum, ContentTypeEnum, CapabilityEnum, ContentParam
 from models.task import WorkflowTask
 from models.decode_task_result import WorkflowDecodeTaskResult
 from utils.sync_mysql_help import mysql
@@ -53,12 +53,17 @@ def _create_workflow_task(scene: SceneEnum, content_type: ContentTypeEnum) -> Op
         return None
 
 
-def _initialize_task_result(task_id: str, content) -> Optional[WorkflowDecodeTaskResult]:
+def _initialize_task_result(
+    task_id: str,
+    content: ContentParam,
+    content_type: ContentTypeEnum
+) -> Optional[WorkflowDecodeTaskResult]:
     """初始化选题解构任务结果(`content` 中 title、images、merge_leve2 等字段一并写入 workflow_decode_task_result)。"""
     try:
         result = WorkflowDecodeTaskResult.create_result(
             task_id=task_id,
-            content=content
+            content=content,
+            content_type=content_type
         )
         logger.info(f"初始化任务结果成功,task_id: {task_id}")
         return result
@@ -67,12 +72,17 @@ def _initialize_task_result(task_id: str, content) -> Optional[WorkflowDecodeTas
         return None
 
 
-def _initialize_script_task_result(task_id: str, content) -> Optional[WorkflowDecodeTaskResult]:
+def _initialize_script_task_result(
+    task_id: str,
+    content: ContentParam,
+    content_type: ContentTypeEnum
+) -> Optional[WorkflowDecodeTaskResult]:
     """初始化创作解构任务结果(`content` 含 merge_leve2 等字段,写入 workflow_script_task_result)"""
     try:
         result = WorkflowDecodeTaskResult.create_result(
             task_id=task_id,
             content=content,
+            content_type=content_type,
             table_name="workflow_script_task_result",
         )
         logger.info(f"初始化创作解构任务结果成功,task_id: {task_id}")
@@ -182,7 +192,7 @@ def decode_topic(param: DecodeContentParam) -> Dict[str, Any]:
             )
         
         # 步骤2: 初始化任务结果(merge_leve2 与 title/images 等同属 content,由 create_result 落库)
-        result = _initialize_task_result(task.task_id, param.content)
+        result = _initialize_task_result(task.task_id, param.content, param.content_type)
         if not result or not result.task_id:
             return _build_error_response(
                 ERROR_CODE_FAILED,
@@ -235,7 +245,7 @@ def decode_creation(param: DecodeContentParam) -> Dict[str, Any]:
             )
 
         # 步骤2: 初始化创作解构任务结果(merge_leve2 等同 content 字段一并落库)
-        result = _initialize_script_task_result(task.task_id, param.content)
+        result = _initialize_script_task_result(task.task_id, param.content, param.content_type)
         if not result or not result.task_id:
             return _build_error_response(
                 ERROR_CODE_FAILED,

+ 1 - 0
utils/params.py

@@ -31,6 +31,7 @@ class ContentParam(BaseModel):
     channel_account_name: Optional[str] = None
     weight_score: Optional[float] = None  # 表现力分数,聚类必传
     merge_leve2: Optional[str] = None
+    channel: Optional[str] = None
 
 
 class DecodeContentParam(BaseModel):