- 语音:序数解析(第一个/第二个等)、解析失败计数与 API detail.retry_remaining; 百度 ASR 固定 dev_pid 为普通话;SurgeryPipelineError 支持 extra 并入 HTTP detail。 - Demo:demo 路由与假 RTSP、客户端 index 与 README;BackendResolver 与配置调整。 - 可观测:消耗 TSV 日志、语音文件日志、终端 Markdown 辅助;相关测试与依赖更新。 - 注意:.env 仍被 gitignore,本地密钥不会进入本提交。 Made-with: Cursor
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import func, select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db.models import VoiceConfirmationAudit
|
|
|
|
|
|
class VoiceAuditRepository:
|
|
"""Persist voice confirmation audit rows."""
|
|
|
|
async def list_by_surgery(
|
|
self,
|
|
session: AsyncSession,
|
|
surgery_id: str,
|
|
*,
|
|
limit: int = 50,
|
|
offset: int = 0,
|
|
) -> tuple[list[VoiceConfirmationAudit], int]:
|
|
"""按手术号分页列出审计行,按 `created_at` 降序(新在前)。"""
|
|
c = select(func.count()).select_from(VoiceConfirmationAudit).where(
|
|
VoiceConfirmationAudit.surgery_id == surgery_id
|
|
)
|
|
total = int((await session.execute(c)).scalar_one())
|
|
q = (
|
|
select(VoiceConfirmationAudit)
|
|
.where(VoiceConfirmationAudit.surgery_id == surgery_id)
|
|
.order_by(VoiceConfirmationAudit.created_at.desc())
|
|
.offset(offset)
|
|
.limit(limit)
|
|
)
|
|
rows = list((await session.execute(q)).scalars().all())
|
|
return rows, total
|
|
|
|
async def save_audit(
|
|
self,
|
|
session: AsyncSession,
|
|
*,
|
|
surgery_id: str,
|
|
confirmation_id: str,
|
|
status: str,
|
|
audio_object_key: str | None,
|
|
audio_content_type: str | None,
|
|
audio_size_bytes: int | None,
|
|
audio_sha256: str | None,
|
|
asr_text: str | None,
|
|
resolved_label: str | None,
|
|
options_snapshot_json: str | None,
|
|
error_message: str | None,
|
|
created_at: datetime | None = None,
|
|
) -> None:
|
|
when = created_at or datetime.now(timezone.utc)
|
|
row = VoiceConfirmationAudit(
|
|
surgery_id=surgery_id,
|
|
confirmation_id=confirmation_id,
|
|
status=status,
|
|
audio_object_key=audio_object_key,
|
|
audio_content_type=audio_content_type,
|
|
audio_size_bytes=audio_size_bytes,
|
|
audio_sha256=audio_sha256,
|
|
asr_text=asr_text,
|
|
resolved_label=resolved_label,
|
|
options_snapshot_json=options_snapshot_json,
|
|
error_message=error_message,
|
|
created_at=when,
|
|
)
|
|
session.add(row)
|
|
await session.flush()
|