feat: 支持治理配置通过admin维护
This commit is contained in:
@@ -2,6 +2,7 @@ from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from django.conf import settings
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
|
||||
|
||||
def governance_defaults() -> dict:
|
||||
@@ -81,8 +82,61 @@ def read_governance_yaml() -> dict:
|
||||
def load_governance_config() -> dict:
|
||||
defaults = governance_defaults()
|
||||
config = read_governance_yaml()
|
||||
db_config = load_governance_config_from_db()
|
||||
for key, default_value in defaults.items():
|
||||
configured_value = config.get(key)
|
||||
configured_value = db_config.get(key) or config.get(key)
|
||||
if isinstance(default_value, list) and configured_value:
|
||||
defaults[key] = configured_value
|
||||
return defaults
|
||||
|
||||
|
||||
def load_governance_config_from_db() -> dict:
|
||||
try:
|
||||
from apps.platform_ui.models import FeishuNotifyConfig, OwnerMapping, WordTemplateMapping
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
try:
|
||||
owner_mappings = [
|
||||
{
|
||||
"owner_role": item.owner_role,
|
||||
"owner_name": item.owner_name,
|
||||
"department": item.department,
|
||||
"chapter_scope": item.chapter_scope,
|
||||
"risk_scope": item.risk_scope,
|
||||
"feishu_user_id": item.feishu_user_id,
|
||||
"feishu_open_id": item.feishu_open_id,
|
||||
"feishu_name": item.feishu_name,
|
||||
"notify_enabled": "是" if item.notify_enabled else "否",
|
||||
}
|
||||
for item in OwnerMapping.objects.filter(is_active=True)
|
||||
]
|
||||
feishu_configs = [
|
||||
{
|
||||
"config_name": item.config_name,
|
||||
"notify_reason": item.notify_reason,
|
||||
"channel": item.channel,
|
||||
"message_template": item.message_template,
|
||||
"status": item.status,
|
||||
}
|
||||
for item in FeishuNotifyConfig.objects.filter(is_active=True)
|
||||
]
|
||||
template_mappings = [
|
||||
{
|
||||
"template_name": item.template_name,
|
||||
"output_type": item.output_type,
|
||||
"version": item.version,
|
||||
"placeholder_count": item.placeholder_count,
|
||||
"status": item.status,
|
||||
"field_mapping_summary": item.field_mapping_summary,
|
||||
}
|
||||
for item in WordTemplateMapping.objects.filter(is_active=True)
|
||||
]
|
||||
except (OperationalError, ProgrammingError, RuntimeError):
|
||||
return {}
|
||||
|
||||
return {
|
||||
"owner_mappings": owner_mappings,
|
||||
"feishu_configs": feishu_configs,
|
||||
"template_mappings": template_mappings,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user