From fe68f2761a6c20bc0cc85b2efb7cba84508faa78 Mon Sep 17 00:00:00 2001 From: "qinyong@9artedu.com" Date: Fri, 26 Jun 2026 13:43:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/asr/asr_voice_processor.py | 10 +++- app/models/mysql/archive_media_files.py | 50 +++++++++++++++++++ .../archive_media_files_repository.py | 6 ++- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 app/models/mysql/archive_media_files.py diff --git a/app/asr/asr_voice_processor.py b/app/asr/asr_voice_processor.py index 7b29aaa..379f1ab 100644 --- a/app/asr/asr_voice_processor.py +++ b/app/asr/asr_voice_processor.py @@ -117,10 +117,18 @@ class ASRVoiceProcessor: await redis_client_manager.close() +import argparse + + async def main(): + # parser = argparse.ArgumentParser(description='ASR语音文件处理') + # parser.add_argument('--batch-size', type=int, default=10, help='每批处理数量') + # parser.add_argument('--max-records', type=int, default=None, help='最大处理记录数,默认处理所有') + # args = parser.parse_args() + processor = ASRVoiceProcessor() try: - await processor.process_voice_files(batch_size=10, max_records=10000) + await processor.process_voice_files(batch_size=10, max_records=0) finally: await processor.close() diff --git a/app/models/mysql/archive_media_files.py b/app/models/mysql/archive_media_files.py new file mode 100644 index 0000000..a340ffd --- /dev/null +++ b/app/models/mysql/archive_media_files.py @@ -0,0 +1,50 @@ +import json +from datetime import datetime + +from sqlalchemy import BigInteger, String, Text, Integer, TIMESTAMP, UniqueConstraint, Index +from sqlalchemy.orm import mapped_column + +from app.models.mysql.archive_messages import Base + + +class ArchiveMediaFiles(Base): + __tablename__ = 'archive_media_files' + __table_args__ = { + 'comment': '企微会话存档媒体文件表', + 'mysql_charset': 'utf8mb4', + 'mysql_collate': 'utf8mb4_unicode_ci' + } + + id = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment='自增主键') + msg_id = mapped_column(String(255), nullable=False, comment='企微消息 msgid') + archive_message_id = mapped_column(BigInteger, nullable=False, comment='archive_messages.id') + sdkfileid = mapped_column(Text, nullable=True, comment='企微媒体文件 sdkfileid') + cos_url = mapped_column(String(1024), nullable=False, comment='COS 文件访问 URL') + file_size = mapped_column(BigInteger, default=0, comment='文件大小(字节)') + file_type = mapped_column(String(32), nullable=True, comment='文件类型:image/voice/video/file') + status = mapped_column(Integer, default=1, comment='状态:1-有效 0-无效') + created_at = mapped_column(TIMESTAMP, nullable=False, default=datetime.now, comment='创建时间') + updated_at = mapped_column(TIMESTAMP, nullable=False, default=datetime.now, onupdate=datetime.now, comment='更新时间') + + __table_args__ = ( + UniqueConstraint('archive_message_id', name='uk_archive_msg_id'), + UniqueConstraint('msg_id', name='uk_msg_id'), + Index('idx_status', 'status'), + ) + + def to_dict(self): + return { + 'id': self.id, + 'msg_id': self.msg_id, + 'archive_message_id': self.archive_message_id, + 'sdkfileid': self.sdkfileid, + 'cos_url': self.cos_url, + 'file_size': self.file_size, + 'file_type': self.file_type, + 'status': self.status, + 'created_at': self.created_at.isoformat() if self.created_at else None, + 'updated_at': self.updated_at.isoformat() if self.updated_at else None + } + + def __repr__(self): + return json.dumps(self.to_dict()) \ No newline at end of file diff --git a/app/repository/archive_media_files_repository.py b/app/repository/archive_media_files_repository.py index 694e8a3..699ff2d 100644 --- a/app/repository/archive_media_files_repository.py +++ b/app/repository/archive_media_files_repository.py @@ -42,12 +42,13 @@ class ArchiveMediaFilesRepository: result = await self.session.execute(query) return result.scalar() or 0 - async def get_by_archive_message_id(self, archive_message_id: int) -> Optional[ArchiveMediaFiles]: + async def get_by_archive_message_id(self, archive_message_id: int, file_type: str = "voice") -> Optional[ArchiveMediaFiles]: """ 根据 archive_message_id 查询媒体文件 Args: archive_message_id: 归档消息ID + file_type: 文件类型过滤,默认 voice Returns: ArchiveMediaFiles 对象或 None @@ -56,5 +57,8 @@ class ArchiveMediaFilesRepository: ArchiveMediaFiles.archive_message_id == archive_message_id ) + if file_type: + query = query.where(ArchiveMediaFiles.file_type == file_type) + result = await self.session.execute(query) return result.scalar_one_or_none()