简历诊断添加日志
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"""简历诊断接口"""
|
||||
|
||||
import time
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@@ -7,6 +9,7 @@ from app.ai.resume_diagnoser.diagnoser import diagnose_all, generate_summary, po
|
||||
from app.core.auth import func_permission
|
||||
from app.core.context import RequestContext
|
||||
from app.core.database import get_db
|
||||
from app.core.logger import log
|
||||
from app.services.resume_diagnose_service import ResumeDiagnoseService, aggregate_results
|
||||
|
||||
router = APIRouter(prefix="/resume/diagnose", tags=["简历诊断"])
|
||||
@@ -20,6 +23,7 @@ class DiagnoseParam(BaseModel):
|
||||
async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permission("resume_diag"))):
|
||||
"""触发简历AI诊断,返回报告ID"""
|
||||
user_id = RequestContext.user_id.get()
|
||||
log.info(f"简历诊断开始, resumeId={param.resume_id}, userId={user_id}")
|
||||
|
||||
# 1. 短事务:加载简历数据
|
||||
async for session in get_db():
|
||||
@@ -27,21 +31,29 @@ async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permissio
|
||||
resume, tasks = await service.load_resume_data(param.resume_id, user_id)
|
||||
|
||||
if not tasks:
|
||||
log.warning(f"简历无可诊断内容, resumeId={param.resume_id}")
|
||||
raise ValueError("简历没有可诊断的描述内容")
|
||||
|
||||
log.info(f"加载简历数据完成, 待诊断任务数={len(tasks)}")
|
||||
|
||||
# 2. 并行 AI 诊断(不持有数据库连接)
|
||||
ai_tasks = [{k: v for k, v in t.items() if not k.startswith("_")} for t in tasks]
|
||||
t0 = time.time()
|
||||
ai_results = await diagnose_all(ai_tasks)
|
||||
log.info(f"AI诊断全部完成, 耗时{time.time() - t0:.2f}s")
|
||||
|
||||
# 3. 统计 + 评级(纯计算)
|
||||
stats = aggregate_results(tasks, ai_results)
|
||||
log.info(f"统计完成, grade={stats['grade']}, urgent={stats['urgent_total']}, important={stats['important_total']}, expression={stats['expression_total']}")
|
||||
|
||||
# 4. AI 生成整体评价(不持有数据库连接)
|
||||
t1 = time.time()
|
||||
summary = await generate_summary(
|
||||
grade=stats["grade"], urgent_total=stats["urgent_total"],
|
||||
important_total=stats["important_total"], expression_total=stats["expression_total"],
|
||||
target_position=resume.target_position or "", all_findings=stats["all_findings"],
|
||||
)
|
||||
log.info(f"AI生成整体评价完成, 耗时{time.time() - t1:.2f}s")
|
||||
|
||||
# 5. 短事务:纯写入
|
||||
async for session in get_db():
|
||||
@@ -52,6 +64,7 @@ async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permissio
|
||||
tasks, ai_results,
|
||||
)
|
||||
|
||||
log.info(f"简历诊断完成, reportId={report_id}")
|
||||
return {"reportId": report_id}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user