SET NAMES utf8mb4;

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000251,
  0,
  '常驻活动',
  '/resident-activity/manager',
  1,
  'example',
  '0',
  '0',
  195,
  0,
  NULL,
  'ResidentActivityManager'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'ResidentActivityManager'
);

UPDATE sys_menu
SET
  parent_id = 0,
  menu_name = '常驻活动',
  path = '/resident-activity/manager',
  menu_type = 1,
  icon = 'example',
  create_user = '0',
  update_user = '0',
  sort = 195,
  status = 0,
  router = NULL
WHERE alias = 'ResidentActivityManager';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000252,
  (SELECT id FROM sys_menu WHERE alias = 'ResidentActivityManager' LIMIT 1),
  '签到奖励配置',
  'resident-activity/sign-in-reward-config/index',
  2,
  'form',
  '0',
  '0',
  1,
  0,
  'sign-in-reward/config',
  'ResidentSignInRewardConfig'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'ResidentSignInRewardConfig'
);

UPDATE sys_menu
SET
  parent_id = (
    SELECT resident_menu.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'ResidentActivityManager'
      LIMIT 1
    ) AS resident_menu
  ),
  menu_name = '签到奖励配置',
  path = 'resident-activity/sign-in-reward-config/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 1,
  status = 0,
  router = 'sign-in-reward/config'
WHERE alias = 'ResidentSignInRewardConfig';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000253,
  (SELECT id FROM sys_menu WHERE alias = 'ResidentActivityManager' LIMIT 1),
  '注册奖励配置',
  'resident-activity/register-reward-config/index',
  2,
  'form',
  '0',
  '0',
  2,
  0,
  'register-reward/config',
  'ResidentRegisterRewardConfig'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'ResidentRegisterRewardConfig'
);

UPDATE sys_menu
SET
  parent_id = (
    SELECT resident_menu.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'ResidentActivityManager'
      LIMIT 1
    ) AS resident_menu
  ),
  menu_name = '注册奖励配置',
  path = 'resident-activity/register-reward-config/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 2,
  status = 0,
  router = 'register-reward/config'
WHERE alias = 'ResidentRegisterRewardConfig';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000254,
  (SELECT id FROM sys_menu WHERE alias = 'ResidentActivityManager' LIMIT 1),
  '邀请活动配置',
  'resident-activity/invite-config/index',
  2,
  'form',
  '0',
  '0',
  3,
  0,
  'invite/config',
  'ResidentInviteConfig'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'ResidentInviteConfig'
);

UPDATE sys_menu
SET
  parent_id = (
    SELECT resident_menu.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'ResidentActivityManager'
      LIMIT 1
    ) AS resident_menu
  ),
  menu_name = '邀请活动配置',
  path = 'resident-activity/invite-config/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 3,
  status = 0,
  router = 'invite/config'
WHERE alias = 'ResidentInviteConfig';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000255,
  (SELECT id FROM sys_menu WHERE alias = 'ResidentActivityManager' LIMIT 1),
  '邀请活动列表',
  'resident-activity/invite-list/index',
  2,
  'form',
  '0',
  '0',
  4,
  0,
  'invite/list',
  'ResidentInviteList'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'ResidentInviteList'
);

UPDATE sys_menu
SET
  parent_id = (
    SELECT resident_menu.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'ResidentActivityManager'
      LIMIT 1
    ) AS resident_menu
  ),
  menu_name = '邀请活动列表',
  path = 'resident-activity/invite-list/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 4,
  status = 0,
  router = 'invite/list'
WHERE alias = 'ResidentInviteList';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000256,
  (SELECT id FROM sys_menu WHERE alias = 'ResidentActivityManager' LIMIT 1),
  '指定礼物周榜',
  'resident-activity/week-star/index',
  2,
  'form',
  '0',
  '0',
  5,
  0,
  'specified-gift-weekly-rank',
  'ResidentSpecifiedGiftWeeklyRank'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'ResidentSpecifiedGiftWeeklyRank'
);

UPDATE sys_menu
SET
  parent_id = (
    SELECT resident_menu.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'ResidentActivityManager'
      LIMIT 1
    ) AS resident_menu
  ),
  menu_name = '指定礼物周榜',
  path = 'resident-activity/week-star/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 5,
  status = 0,
  router = 'specified-gift-weekly-rank'
WHERE alias = 'ResidentSpecifiedGiftWeeklyRank';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000258,
  0,
  '游戏管理',
  '/game-manager',
  1,
  'form',
  '0',
  '0',
  133,
  0,
  NULL,
  'OperateGameManager'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'OperateGameManager'
);

UPDATE sys_menu
SET
  parent_id = 0,
  menu_name = '游戏管理',
  path = '/game-manager',
  menu_type = 1,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 133,
  status = 0,
  router = NULL
WHERE alias = 'OperateGameManager';

UPDATE sys_menu
SET
  parent_id = (
    SELECT game_manager.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'OperateGameManager'
      LIMIT 1
    ) AS game_manager
  ),
  menu_name = '游戏列表',
  path = 'sys/game-manager/list/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 1,
  status = 0,
  router = 'game-config'
WHERE alias = 'GameConfig';

INSERT INTO sys_menu (
  id,
  parent_id,
  menu_name,
  path,
  menu_type,
  icon,
  create_user,
  update_user,
  sort,
  status,
  router,
  alias
)
SELECT
  1700000257,
  (
    SELECT game_manager.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'OperateGameManager'
      LIMIT 1
    ) AS game_manager
  ),
  '百顺配置',
  'sys/game-manager/baishun-config/index',
  2,
  'form',
  '0',
  '0',
  2,
  0,
  'baishun-config',
  'OperateBaishunGameManage'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'OperateBaishunGameManage'
);

UPDATE sys_menu
SET
  parent_id = (
    SELECT game_manager.id
    FROM (
      SELECT id
      FROM sys_menu
      WHERE alias = 'OperateGameManager'
      LIMIT 1
    ) AS game_manager
  ),
  menu_name = '百顺配置',
  path = 'sys/game-manager/baishun-config/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 2,
  status = 0,
  router = 'baishun-config'
WHERE alias = 'OperateBaishunGameManage';

INSERT INTO sys_role_menu (role_id, menu_id)
SELECT DISTINCT
  parent_role.role_id,
  target_menu.id
FROM sys_role_menu AS parent_role
JOIN sys_menu AS target_menu
  ON target_menu.alias IN (
    'ResidentActivityManager',
    'ResidentSignInRewardConfig',
    'ResidentRegisterRewardConfig',
    'ResidentInviteConfig',
    'ResidentInviteList',
    'ResidentSpecifiedGiftWeeklyRank',
    'OperateGameManager',
    'GameConfig',
    'OperateBaishunGameManage'
  )
LEFT JOIN sys_role_menu AS existing_role_menu
  ON existing_role_menu.role_id = parent_role.role_id
  AND existing_role_menu.menu_id = target_menu.id
WHERE parent_role.menu_id = 1700000057
  AND existing_role_menu.id IS NULL;

UPDATE sys_menu
SET menu_name = CONVERT(0xE5B8B8E9A9BBE6B4BBE58AA8 USING utf8mb4)
WHERE alias = 'ResidentActivityManager';

UPDATE sys_menu
SET menu_name = CONVERT(0xE7ADBEE588B0E5A596E58AB1E9858DE7BDAE USING utf8mb4)
WHERE alias = 'ResidentSignInRewardConfig';

UPDATE sys_menu
SET menu_name = CONVERT(0xE6B3A8E5868CE5A596E58AB1E9858DE7BDAE USING utf8mb4)
WHERE alias = 'ResidentRegisterRewardConfig';

UPDATE sys_menu
SET menu_name = CONVERT(0xE98280E8AFB7E6B4BBE58AA8E9858DE7BDAE USING utf8mb4)
WHERE alias = 'ResidentInviteConfig';

UPDATE sys_menu
SET menu_name = CONVERT(0xE98280E8AFB7E6B4BBE58AA8E58897E8A1A8 USING utf8mb4)
WHERE alias = 'ResidentInviteList';

UPDATE sys_menu
SET menu_name = CONVERT(0xE68C87E5AE9AE7A4BCE789A9E591A8E6A69C USING utf8mb4)
WHERE alias = 'ResidentSpecifiedGiftWeeklyRank';

UPDATE sys_menu
SET menu_name = CONVERT(0xE6B8B8E6888FE7AEA1E79086 USING utf8mb4)
WHERE alias = 'OperateGameManager';

UPDATE sys_menu
SET menu_name = CONVERT(0xE6B8B8E6888FE58897E8A1A8 USING utf8mb4)
WHERE alias = 'GameConfig';

UPDATE sys_menu
SET menu_name = CONVERT(0xE799BEE9A1BAE9858DE7BDAE USING utf8mb4)
WHERE alias = 'OperateBaishunGameManage';
