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
  1700000257,
  1700000057,
  '百顺游戏管理',
  'sys/game-config/baishun/index',
  2,
  'form',
  '0',
  '0',
  133,
  0,
  'baishun-game-manage',
  'OperateBaishunGameManage'
WHERE NOT EXISTS (
  SELECT 1 FROM sys_menu WHERE alias = 'OperateBaishunGameManage'
);

UPDATE sys_menu
SET
  parent_id = 1700000057,
  menu_name = '百顺游戏管理',
  path = 'sys/game-config/baishun/index',
  menu_type = 2,
  icon = 'form',
  create_user = '0',
  update_user = '0',
  sort = 133,
  status = 0,
  router = 'baishun-game-manage'
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',
    '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;
