v3.1 + 批次0: 智能回复重构基线 - ApprovalMatcher + 关键词降级 + 文档速修 + v4.0任务书面化
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.integrations.lianruan.client import LianruanClient
|
||||
@@ -21,78 +22,56 @@ from app.models.system_config import SystemConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 联软配置键前缀(与 admin_service INTEGRATION_DEFINITIONS 中的 key_prefix 一致)
|
||||
_PREFIX = "integration_lianruan_"
|
||||
|
||||
|
||||
async def _get_lianruan_config_value(db: AsyncSession, key_suffix: str) -> str:
|
||||
"""读取单个联软配置值。
|
||||
|
||||
Args:
|
||||
db: 数据库会话
|
||||
key_suffix: 配置键后缀(如 base_url / api_account)
|
||||
|
||||
Returns:
|
||||
str: 配置值,不存在返回空字符串
|
||||
"""
|
||||
full_key = f"{_PREFIX}{key_suffix}"
|
||||
from sqlalchemy import select
|
||||
result = await db.execute(select(SystemConfig).where(SystemConfig.key == full_key))
|
||||
config_row = result.scalar_one_or_none()
|
||||
return config_row.value if config_row else ""
|
||||
|
||||
|
||||
async def get_lianruan_config(db: AsyncSession) -> dict:
|
||||
"""从system_configs表读取联软配置。
|
||||
|
||||
Args:
|
||||
db: 数据库会话
|
||||
|
||||
Returns:
|
||||
dict: 包含 base_url / api_account / api_password / validate_key
|
||||
|
||||
Raises:
|
||||
LianruanConfigError: 配置缺失
|
||||
"""
|
||||
base_url = await _get_lianruan_config_value(db, "base_url")
|
||||
api_account = await _get_lianruan_config_value(db, "api_account")
|
||||
api_password = await _get_lianruan_config_value(db, "api_password")
|
||||
validate_key = await _get_lianruan_config_value(db, "validate_key")
|
||||
|
||||
if not base_url:
|
||||
raise LianruanConfigError("联软API未配置:缺少Base URL")
|
||||
if not api_account:
|
||||
raise LianruanConfigError("联软API未配置:缺少API账号")
|
||||
if not api_password:
|
||||
raise LianruanConfigError("联软API未配置:缺少API密码")
|
||||
|
||||
return {
|
||||
"base_url": base_url,
|
||||
"api_account": api_account,
|
||||
"api_password": api_password,
|
||||
"validate_key": validate_key,
|
||||
}
|
||||
# 联软配置在 system_configs 表中的 key 前缀
|
||||
LIANRUAN_CONFIG_PREFIX = "integration_lianruan_"
|
||||
|
||||
|
||||
async def get_lianruan_client(db: AsyncSession) -> LianruanClient:
|
||||
"""构建联软API客户端实例。
|
||||
"""从系统配置表构建联软API客户端。
|
||||
|
||||
从system_configs表读取配置,创建LianruanClient。
|
||||
读取 integration_lianruan_ 前缀的配置项,构建 LianruanClient 实例。
|
||||
如果任何必填配置缺失,抛出 LianruanConfigError。
|
||||
|
||||
Args:
|
||||
db: 数据库会话
|
||||
|
||||
Returns:
|
||||
LianruanClient: 已配置的联软客户端
|
||||
LianruanClient: 已配置的联软API客户端实例
|
||||
|
||||
Raises:
|
||||
LianruanConfigError: 配置缺失
|
||||
LianruanConfigError: 缺少必填配置
|
||||
"""
|
||||
cfg = await get_lianruan_config(db)
|
||||
# 读取四个配置
|
||||
result = await db.execute(
|
||||
select(SystemConfig).where(
|
||||
SystemConfig.config_key.startswith(LIANRUAN_CONFIG_PREFIX)
|
||||
)
|
||||
)
|
||||
configs = list(result.scalars().all())
|
||||
|
||||
# 构建 key→value 映射
|
||||
config_map = {cfg.config_key: cfg.config_value for cfg in configs}
|
||||
|
||||
base_url = config_map.get(f"{LIANRUAN_CONFIG_PREFIX}base_url", "")
|
||||
api_account = config_map.get(f"{LIANRUAN_CONFIG_PREFIX}api_account", "")
|
||||
api_password = config_map.get(f"{LIANRUAN_CONFIG_PREFIX}api_password", "")
|
||||
validate_key = config_map.get(f"{LIANRUAN_CONFIG_PREFIX}validate_key", "")
|
||||
|
||||
# 校验必填项
|
||||
missing = []
|
||||
if not base_url:
|
||||
missing.append("Base URL")
|
||||
if not api_account:
|
||||
missing.append("API账号")
|
||||
if not api_password:
|
||||
missing.append("API密码")
|
||||
|
||||
if missing:
|
||||
raise LianruanConfigError(f"联软API未配置:缺少{', '.join(missing)}")
|
||||
|
||||
return LianruanClient(
|
||||
base_url=cfg["base_url"],
|
||||
api_account=cfg["api_account"],
|
||||
api_password=cfg["api_password"],
|
||||
validate_key=cfg.get("validate_key", ""),
|
||||
base_url=base_url,
|
||||
api_account=api_account,
|
||||
api_password=api_password,
|
||||
validate_key=validate_key or None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user