补充公司log
This commit is contained in:
@@ -10,6 +10,7 @@ from sqlalchemy import text, insert
|
||||
from app.config import settings
|
||||
from app.core.database import PgSession, MysqlSession
|
||||
from app.core.logger import log
|
||||
from app.core.oss import upload_base64
|
||||
from app.ai.model_config import JobCleanModel
|
||||
from app.ai.prompts import JOB_STRUCTURE_SYSTEM, MAJOR_MATCH_SYSTEM, SKILL_EXTRACT_SYSTEM
|
||||
from app.models.mysql.job import Job
|
||||
@@ -134,7 +135,7 @@ async def _do_clean(data: dict) -> None:
|
||||
|
||||
# 公司处理
|
||||
company_short_name = result.get("companyShortName") or data.get("company") or ""
|
||||
company_id = await _find_or_create_company(company_short_name)
|
||||
company_id = await _find_or_create_company(company_short_name, data.get("urllistid"))
|
||||
|
||||
# 地区处理
|
||||
region_codes = []
|
||||
@@ -284,8 +285,8 @@ async def _find_or_create_skill_tag(name: str) -> int | None:
|
||||
return row.scalar()
|
||||
|
||||
|
||||
async def _find_or_create_company(short_name: str) -> int:
|
||||
"""查找或创建公司(加锁防并发重复)"""
|
||||
async def _find_or_create_company(short_name: str, urllistid: int | None = None) -> int:
|
||||
"""查找或创建公司(加锁防并发重复);新建公司时若有 logo 则上传 OSS 并回填地址"""
|
||||
async with _company_lock:
|
||||
async with MysqlSession() as mysql:
|
||||
row = await mysql.execute(
|
||||
@@ -309,7 +310,35 @@ async def _find_or_create_company(short_name: str) -> int:
|
||||
)
|
||||
)
|
||||
await mysql.commit()
|
||||
return company_id
|
||||
|
||||
# 锁外处理 logo:仅新建公司时执行,上传是网络IO,不阻塞其他协程;失败不影响主流程
|
||||
try:
|
||||
logo_b64 = await _get_logo_base64(urllistid)
|
||||
if logo_b64:
|
||||
logo_url = await upload_base64(logo_b64, "logo.png")
|
||||
if logo_url:
|
||||
async with MysqlSession() as mysql:
|
||||
await mysql.execute(
|
||||
text("UPDATE bg_company SET logo_url = :url, update_time = :t WHERE id = :id"),
|
||||
{"url": logo_url, "t": datetime.now(), "id": company_id},
|
||||
)
|
||||
await mysql.commit()
|
||||
except Exception as e:
|
||||
log.warning("[company={}] logo 上传失败: {}", company_id, e)
|
||||
|
||||
return company_id
|
||||
|
||||
|
||||
async def _get_logo_base64(urllistid: int | None) -> str | None:
|
||||
"""从 PG app_url_list 按 urllistid 读取 logo(base64)"""
|
||||
if not urllistid:
|
||||
return None
|
||||
async with PgSession() as pg:
|
||||
row = await pg.execute(
|
||||
text("SELECT logo FROM app_url_list WHERE id = :id"),
|
||||
{"id": urllistid},
|
||||
)
|
||||
return row.scalar()
|
||||
|
||||
|
||||
async def _update_pg_status(data_id: int, status: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user