diff --git a/video-gen-api/app/main.py b/video-gen-api/app/main.py index da9f41d4..9a2a5e73 100644 --- a/video-gen-api/app/main.py +++ b/video-gen-api/app/main.py @@ -400,7 +400,7 @@ async def _seed_data(): ("/generated", "素材云", "CloudOutlined", 1, "资产管理", True), ("/authorization", "授权管理", "UserOutlined", 0, "媒体关联", False), ("/consume", "消耗列表", "FileTextOutlined", 1, "媒体关联", False), - ("/popular", "热门广场", "ThunderboltOutlined", 0, "AI项目行业生成", False), + ("/popular", "爆款榜单", "ThunderboltOutlined", 0, "AI项目行业生成", False), ("/creativeplaza", "创意广场", "GiftOutlined", 0, "AI对话生成", False), ] for path, label, icon, order, group_label, is_default in frontend_pages: @@ -411,15 +411,37 @@ async def _seed_data(): ).limit(1) ) existing_page = existing.scalar_one_or_none() + + parent_id = frontend_group_ids.get(group_label) + if not parent_id: + group_exists = await db.execute( + select(MenuConfig).where( + MenuConfig.label == group_label, + MenuConfig.menu_type == "group", + MenuConfig.menu_target == "frontend", + ).limit(1) + ) + group_record = group_exists.scalar_one_or_none() + if group_record: + parent_id = group_record.id + if existing_page: - # Update existing menu item if needed - if existing_page.label != label or existing_page.icon != icon or \ - existing_page.sort_order != order or existing_page.is_default != is_default: + needs_update = False + if existing_page.label != label: existing_page.label = label + needs_update = True + if existing_page.icon != icon: existing_page.icon = icon + needs_update = True + if existing_page.sort_order != order: existing_page.sort_order = order + needs_update = True + if existing_page.is_default != is_default: existing_page.is_default = is_default - existing_page.parent_id = frontend_group_ids.get(group_label) + needs_update = True + if parent_id and existing_page.parent_id != parent_id: + existing_page.parent_id = parent_id + needs_update = True else: db.add( MenuConfig( @@ -429,7 +451,7 @@ async def _seed_data(): icon=icon, sort_order=order, is_active=True, - parent_id=frontend_group_ids.get(group_label), + parent_id=parent_id, menu_type="page", menu_target="frontend", is_default=is_default, @@ -496,7 +518,36 @@ async def _seed_data(): MenuConfig.menu_target == "admin", ).limit(1) ) - if not existing.scalar_one_or_none(): + existing_page = existing.scalar_one_or_none() + + parent_id = admin_group_ids.get(parent_group) if parent_group else None + if not parent_id and parent_group: + group_exists = await db.execute( + select(MenuConfig).where( + MenuConfig.label == parent_group, + MenuConfig.menu_type == "group", + MenuConfig.menu_target == "admin", + ).limit(1) + ) + group_record = group_exists.scalar_one_or_none() + if group_record: + parent_id = group_record.id + + if existing_page: + needs_update = False + if existing_page.label != label: + existing_page.label = label + needs_update = True + if existing_page.icon != icon: + existing_page.icon = icon + needs_update = True + if existing_page.sort_order != order: + existing_page.sort_order = order + needs_update = True + if existing_page.parent_id != parent_id: + existing_page.parent_id = parent_id + needs_update = True + else: db.add( MenuConfig( id=generate_id(), @@ -507,7 +558,7 @@ async def _seed_data(): is_active=True, menu_type="page", menu_target="admin", - parent_id=admin_group_ids.get(parent_group), + parent_id=parent_id, ) )