覆盖所有模块: - api 层:17 个路由文件,每个接口标注用途、参数、返回值、权限 - services 层:18 个服务文件,每个方法标注作用、参数、返回值、调用方 - repositories 层:13 个仓储文件,每个方法标注查询逻辑和被调用方 - schemas 层:11 个请求/响应体文件,每个字段标注业务含义 - core 层:config、security、exceptions、responses、error_codes - models 层:19 个 ORM 模型类,每个表标注业务含义和关联关系 - scripts:bootstrap_data、smoke_check - migrations:env.py 和版本迁移文件 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""AI 识别模块 Repository 层
|
||
|
||
负责 AI 图像识别日志的创建和查询操作,
|
||
记录系统中 AI 识别功能的调用和结果。
|
||
被 AIService(AI 服务)调用。
|
||
"""
|
||
|
||
from sqlalchemy import select
|
||
from sqlalchemy.orm import Session
|
||
|
||
from backend.app.models.business import AIRecognitionLog
|
||
|
||
|
||
class AIRepository:
|
||
"""AI 识别日志数据仓储
|
||
|
||
封装 AI 识别日志的写入和查询操作。
|
||
被 AIService(AI 服务)调用。
|
||
"""
|
||
|
||
def create_log(self, session: Session, payload: dict) -> AIRecognitionLog:
|
||
"""创建 AI 识别日志记录
|
||
|
||
参数:
|
||
session: 数据库会话
|
||
payload: 日志数据字典,包含识别类型、识别结果、调用状态等字段
|
||
|
||
返回:
|
||
新创建的 AI 识别日志对象
|
||
"""
|
||
log = AIRecognitionLog(**payload)
|
||
session.add(log)
|
||
session.flush()
|
||
return log
|
||
|
||
def get_log(self, session: Session, log_id: int) -> AIRecognitionLog | None:
|
||
"""根据 ID 查询 AI 识别日志
|
||
|
||
参数:
|
||
session: 数据库会话
|
||
log_id: 日志记录 ID
|
||
|
||
返回:
|
||
匹配的 AI 识别日志对象,不存在则返回 None
|
||
"""
|
||
stmt = select(AIRecognitionLog).where(AIRecognitionLog.id == log_id)
|
||
return session.execute(stmt).scalar_one_or_none()
|