当 feature_switches 表中没有默认记录时,set_feature_switch 函数 现在会使用预定义的默认值创建记录,而不是静默失败
This commit is contained in:
@@ -168,22 +168,41 @@ async def set_feature_switch(db: AsyncSession, tenant_id: int, feature_code: str
|
|||||||
)
|
)
|
||||||
default_row = result.fetchone()
|
default_row = result.fetchone()
|
||||||
|
|
||||||
|
# 定义功能开关默认值映射
|
||||||
|
FEATURE_DEFAULTS = {
|
||||||
|
'employee_sync': ('员工同步', 'system', '从钉钉同步员工信息'),
|
||||||
|
'dingtalk_login': ('钉钉免密登录', 'system', '允许通过钉钉免密登录'),
|
||||||
|
'ai_practice': ('AI 对练', 'feature', 'AI 对练功能'),
|
||||||
|
'dual_practice': ('双人对练', 'feature', '双人对练功能'),
|
||||||
|
}
|
||||||
|
|
||||||
if default_row:
|
if default_row:
|
||||||
# 插入租户级配置
|
feature_name = default_row[0]
|
||||||
await db.execute(
|
feature_group = default_row[1]
|
||||||
text("""
|
description = default_row[2]
|
||||||
INSERT INTO feature_switches (tenant_id, feature_code, feature_name, feature_group, is_enabled, description)
|
elif feature_code in FEATURE_DEFAULTS:
|
||||||
VALUES (:tenant_id, :feature_code, :feature_name, :feature_group, :is_enabled, :description)
|
feature_name, feature_group, description = FEATURE_DEFAULTS[feature_code]
|
||||||
"""),
|
else:
|
||||||
{
|
# 未知功能码,使用默认值
|
||||||
"tenant_id": tenant_id,
|
feature_name = feature_code
|
||||||
"feature_code": feature_code,
|
feature_group = 'system'
|
||||||
"feature_name": default_row[0],
|
description = f'{feature_code} 功能开关'
|
||||||
"feature_group": default_row[1],
|
|
||||||
"is_enabled": 1 if is_enabled else 0,
|
# 插入租户级配置
|
||||||
"description": default_row[2]
|
await db.execute(
|
||||||
}
|
text("""
|
||||||
)
|
INSERT INTO feature_switches (tenant_id, feature_code, feature_name, feature_group, is_enabled, description)
|
||||||
|
VALUES (:tenant_id, :feature_code, :feature_name, :feature_group, :is_enabled, :description)
|
||||||
|
"""),
|
||||||
|
{
|
||||||
|
"tenant_id": tenant_id,
|
||||||
|
"feature_code": feature_code,
|
||||||
|
"feature_name": feature_name,
|
||||||
|
"feature_group": feature_group,
|
||||||
|
"is_enabled": 1 if is_enabled else 0,
|
||||||
|
"description": description
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|||||||
Reference in New Issue
Block a user