2222from xpack .models .application_setting import ApplicationSetting
2323from xpack .models .platform import Platform
2424from system_manage .models import Log
25+ from application .models import Application
2526
2627
2728def convert_image_path (image_path ):
@@ -89,8 +90,15 @@ def application_setting_import(application_setting_list, source_name, current_pa
8990 # 删除数据
9091 ApplicationSetting .objects .filter (
9192 application_id__in = [s .application_id for s in application_setting_model_list ]).delete ()
92- # 插入数据
93- ApplicationSetting .objects .bulk_create (application_setting_model_list )
93+ # 检查对应的应用是否存在
94+ existing_app_ids = set (Application .objects .filter (
95+ id__in = [s .application_id for s in application_setting_model_list ]
96+ ).values_list ('id' , flat = True ))
97+
98+ # 只创建对应应用存在的记录
99+ valid_application_settings = [s for s in application_setting_model_list
100+ if s .application_id in existing_app_ids ]
101+ ApplicationSetting .objects .bulk_create (valid_application_settings )
94102 # 修改标识
95103 rename (application_setting )
96104
@@ -306,6 +314,7 @@ def import_user_relation():
306314 if user_role_relations :
307315 UserRoleRelation .objects .bulk_create (user_role_relations , ignore_conflicts = True )
308316
317+
309318def to_v2_log (log ):
310319 log_obj = Log (
311320 id = log .get ('id' ),
@@ -322,6 +331,7 @@ def to_v2_log(log):
322331 )
323332 return log_obj
324333
334+
325335@preserve_time_fields (Log , "create_time" , "update_time" )
326336def log_import (log_list , source_name , current_page ):
327337 for log in log_list :
@@ -335,16 +345,18 @@ def log_import(log_list, source_name, current_page):
335345
336346
337347def import_ ():
338- import_page (ImportQuerySet ('application_setting' ), 1 , application_setting_import , "application_setting" , "导入应用设置" ,
339- check = import_check )
348+ import_page (ImportQuerySet ('application_setting' ), 1 , application_setting_import , "application_setting" ,
349+ "导入应用设置" ,
350+ check = import_check )
340351 import_page (ImportQuerySet ('platform' ), 1 , platform_import , "platform" , "导入三方平台" , check = import_check )
341352 import_page (ImportQuerySet ('auth_config' ), 1 , auth_config_import , "auth_config" , "导入认证配置" , check = import_check )
342353 import_page (ImportQuerySet ('platform_source' ), 1 , platform_source_import , "platform_source" , "导出三方平台认证" ,
343- check = import_check )
354+ check = import_check )
344355 import_page (ImportQuerySet ('platform_user' ), 1 , platform_user_import , "platform_user" , "导入三方平台用户" ,
345- check = import_check )
356+ check = import_check )
346357 import_page (ImportQuerySet ('system_api_key' ), 1 , system_api_key_import , "system_api_key" , "导入系统api密钥" ,
347- check = import_check )
348- import_page (ImportQuerySet ('system_params' ), 1 , system_params_import , "system_params" , "导入系统参数" , check = import_check )
358+ check = import_check )
359+ import_page (ImportQuerySet ('system_params' ), 1 , system_params_import , "system_params" , "导入系统参数" ,
360+ check = import_check )
349361 import_user_relation ()
350362 import_page (ImportQuerySet ('log' ), 1 , log_import , "log" , "导入操作日志" , check = import_check )
0 commit comments