section_reference_block/services/project_service.py
xxy aa98ea2623 @
Initial commit

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@
2026-06-05 18:45:29 +08:00

44 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
services/project_service.py
报告生成所需的最小项目查询,替代 eval_report 中重型的 write_service。
仅提供按 uuid / 数字 id 查询项目并返回 WriteProject用于校验项目存在性与取项目名。
"""
from __future__ import annotations
from fastapi import HTTPException
from sqlalchemy.orm import Session
from database.models import Project
from schemas.write import WriteProject
def get_project(project_id: str, db: Session) -> WriteProject:
"""获取后评价报告项目详情。支持 uuid 或数字 id优先 uuid。"""
project = None
if project_id:
project = db.query(Project).filter(Project.uuid == project_id).first()
if not project:
try:
pid = int(project_id)
project = db.query(Project).filter(Project.id == pid).first()
except (ValueError, TypeError):
pass
if not project:
raise HTTPException(status_code=404, detail="项目不存在")
return WriteProject(
id=str(project.id),
uuid=project.uuid,
name=project.name,
description=project.description or "",
createdAt=project.created_at.strftime("%Y-%m-%d") if project.created_at else "",
updatedAt=project.updated_at.strftime("%Y-%m-%d") if project.updated_at else "",
docCount=project.doc_count,
status=project.status,
kbProjectId=None,
color=project.color,
documents=[],
)