简历诊断抽象查询简历功能
This commit is contained in:
@@ -14,11 +14,7 @@ from app.core.logger import log
|
|||||||
from app.models.resume_diagnosis_issue import ResumeDiagnosisIssue
|
from app.models.resume_diagnosis_issue import ResumeDiagnosisIssue
|
||||||
from app.models.resume_diagnosis_report import ResumeDiagnosisReport
|
from app.models.resume_diagnosis_report import ResumeDiagnosisReport
|
||||||
from app.models.user_resume import UserResume
|
from app.models.user_resume import UserResume
|
||||||
from app.models.user_resume_competition import UserResumeCompetition
|
from app.services.resume_loader import load_resume_detail
|
||||||
from app.models.user_resume_education import UserResumeEducation
|
|
||||||
from app.models.user_resume_internship import UserResumeInternship
|
|
||||||
from app.models.user_resume_project import UserResumeProject
|
|
||||||
from app.models.user_resume_work import UserResumeWork
|
|
||||||
from app.tool.snowflake import next_id
|
from app.tool.snowflake import next_id
|
||||||
|
|
||||||
# 模块中文名映射
|
# 模块中文名映射
|
||||||
@@ -35,11 +31,8 @@ class ResumeDiagnoseService:
|
|||||||
|
|
||||||
async def load_resume_data(self, resume_id: int, user_id: int) -> tuple[UserResume, list[dict]]:
|
async def load_resume_data(self, resume_id: int, user_id: int) -> tuple[UserResume, list[dict]]:
|
||||||
"""加载简历主表 + 5 张子表数据,组装 AI 任务列表"""
|
"""加载简历主表 + 5 张子表数据,组装 AI 任务列表"""
|
||||||
result = await self.session.execute(
|
detail = await load_resume_detail(self.session, resume_id, user_id)
|
||||||
select(UserResume).where(UserResume.id == resume_id, UserResume.user_id == user_id))
|
resume = detail.resume
|
||||||
resume = result.scalar_one_or_none()
|
|
||||||
if resume is None:
|
|
||||||
raise ValueError("简历不存在")
|
|
||||||
|
|
||||||
target_position = resume.target_position or ""
|
target_position = resume.target_position or ""
|
||||||
tasks: list[dict] = []
|
tasks: list[dict] = []
|
||||||
@@ -54,23 +47,23 @@ class ResumeDiagnoseService:
|
|||||||
})
|
})
|
||||||
|
|
||||||
# 子表
|
# 子表
|
||||||
await self._collect_tasks(tasks, target_position, "education", UserResumeEducation, resume_id,
|
self._collect_tasks(tasks, target_position, "education", detail.education,
|
||||||
lambda r: f"学校: {r.school or ''}, 专业: {r.major or ''}, 学历: {r.degree or ''}")
|
lambda r: f"学校: {r.school or ''}, 专业: {r.major or ''}, 学历: {r.degree or ''}")
|
||||||
await self._collect_tasks(tasks, target_position, "work", UserResumeWork, resume_id,
|
self._collect_tasks(tasks, target_position, "work", detail.work,
|
||||||
lambda r: f"公司: {r.company_name or ''}, 职位: {r.position or ''}")
|
lambda r: f"公司: {r.company_name or ''}, 职位: {r.position or ''}")
|
||||||
await self._collect_tasks(tasks, target_position, "internship", UserResumeInternship, resume_id,
|
self._collect_tasks(tasks, target_position, "internship", detail.internship,
|
||||||
lambda r: f"公司: {r.company_name or ''}, 职位: {r.position or ''}")
|
lambda r: f"公司: {r.company_name or ''}, 职位: {r.position or ''}")
|
||||||
await self._collect_tasks(tasks, target_position, "project", UserResumeProject, resume_id,
|
self._collect_tasks(tasks, target_position, "project", detail.project,
|
||||||
lambda r: f"公司: {r.company_name or ''}, 项目: {r.project_name or ''}, 角色: {r.role or ''}")
|
lambda r: f"公司: {r.company_name or ''}, 项目: {r.project_name or ''}, 角色: {r.role or ''}")
|
||||||
await self._collect_tasks(tasks, target_position, "competition", UserResumeCompetition, resume_id,
|
self._collect_tasks(tasks, target_position, "competition", detail.competition,
|
||||||
lambda r: f"竞赛: {r.competition_name or ''}, 获奖: {r.award or ''}")
|
lambda r: f"竞赛: {r.competition_name or ''}, 获奖: {r.award or ''}")
|
||||||
return resume, tasks
|
return resume, tasks
|
||||||
|
|
||||||
async def _collect_tasks(self, tasks: list[dict], target_position: str,
|
@staticmethod
|
||||||
module_type: str, model_cls, resume_id: int, context_fn):
|
def _collect_tasks(tasks: list[dict], target_position: str,
|
||||||
"""查询子表记录,将有 description 的记录加入 tasks"""
|
module_type: str, records: list, context_fn):
|
||||||
result = await self.session.execute(select(model_cls).where(model_cls.resume_id == resume_id))
|
"""将有 description 的记录加入 tasks"""
|
||||||
for record in result.scalars().all():
|
for record in records:
|
||||||
desc_text = _build_description_text(record.description)
|
desc_text = _build_description_text(record.description)
|
||||||
if not desc_text:
|
if not desc_text:
|
||||||
continue
|
continue
|
||||||
@@ -80,7 +73,7 @@ class ResumeDiagnoseService:
|
|||||||
"context": context_fn(record),
|
"context": context_fn(record),
|
||||||
"description_text": desc_text,
|
"description_text": desc_text,
|
||||||
"_module_type_key": module_type, "_module_record_id": record.id,
|
"_module_type_key": module_type, "_module_record_id": record.id,
|
||||||
"_original_description": record.description, # 原始 [{id,text}],用于映射 optimized_content
|
"_original_description": record.description,
|
||||||
})
|
})
|
||||||
|
|
||||||
async def save_report(self, resume_id: int, user_id: int, grade: str, summary: str,
|
async def save_report(self, resume_id: int, user_id: int, grade: str, summary: str,
|
||||||
|
|||||||
Reference in New Issue
Block a user