fix: 修复员工同步功能开关保存失败的问题
Some checks failed
continuous-integration/drone/push Build is failing

当 feature_switches 表中没有默认记录时,set_feature_switch 函数
现在会使用预定义的默认值创建记录,而不是静默失败
This commit is contained in:
yuliang_guo
2026-01-31 17:46:35 +08:00
parent 41a2f7944a
commit 940777a86e

View File

@@ -168,7 +168,26 @@ async def set_feature_switch(db: AsyncSession, tenant_id: int, feature_code: str
)
default_row = result.fetchone()
# 定义功能开关默认值映射
FEATURE_DEFAULTS = {
'employee_sync': ('员工同步', 'system', '从钉钉同步员工信息'),
'dingtalk_login': ('钉钉免密登录', 'system', '允许通过钉钉免密登录'),
'ai_practice': ('AI 对练', 'feature', 'AI 对练功能'),
'dual_practice': ('双人对练', 'feature', '双人对练功能'),
}
if default_row:
feature_name = default_row[0]
feature_group = default_row[1]
description = default_row[2]
elif feature_code in FEATURE_DEFAULTS:
feature_name, feature_group, description = FEATURE_DEFAULTS[feature_code]
else:
# 未知功能码,使用默认值
feature_name = feature_code
feature_group = 'system'
description = f'{feature_code} 功能开关'
# 插入租户级配置
await db.execute(
text("""
@@ -178,10 +197,10 @@ async def set_feature_switch(db: AsyncSession, tenant_id: int, feature_code: str
{
"tenant_id": tenant_id,
"feature_code": feature_code,
"feature_name": default_row[0],
"feature_group": default_row[1],
"feature_name": feature_name,
"feature_group": feature_group,
"is_enabled": 1 if is_enabled else 0,
"description": default_row[2]
"description": description
}
)