重构简历导入

This commit is contained in:
zk
2026-07-01 18:41:51 +08:00
parent dfe7cca5a4
commit 89d033c9f9
6 changed files with 172 additions and 241 deletions
+6 -8
View File
@@ -1,12 +1,10 @@
"""简历 Service
上传简历文件 → 解析为纯文本 → AI 两阶段并行结构化 → 写入数据库。
依赖:file_parser(文件解析工具)、resume_extractorAI两阶段并行提取)
依赖:resume_text_extractor(文件文本提取)、resume_extractorAI两阶段并行提取)
使用表:bg_user_resume(主表)、bg_user_resume_education/work/internship/project/competition5张子表)
"""
import asyncio
import shortuuid
from sqlalchemy.ext.asyncio import AsyncSession
@@ -19,7 +17,7 @@ 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.file_parser import parse_to_segments
from app.tool.resume_text_extractor import extract_text
from app.tool.snowflake import next_id
@@ -28,13 +26,13 @@ class ResumeService:
async def parse_and_extract(self, filename: str, content: bytes) -> dict:
"""文件解析 + AI 两阶段并行结构化,不涉及数据库操作"""
log.info(f"开始解析简历文件: {filename}")
segments = await asyncio.to_thread(parse_to_segments, filename, content)
if not segments:
text = await extract_text(filename, content)
if not text or not text.strip():
raise ValueError("文件内容为空,无法解析")
log.info(f"文件解析完成,文本单元数: {len(segments)}")
log.info(f"文件解析完成,文本字符数: {len(text)}")
log.info("开始AI两阶段并行结构化提取")
parsed = await extract_all(segments)
parsed = await extract_all(text)
log.info("AI两阶段并行结构化提取完成")
return parsed