UPDATE `la_system_menu`
SET
    `name` = '自注册账号',
    `paths` = 'lists',
    `component` = 'consumer/lists/index',
    `params` = '{\"account_scope\":\"registered\"}',
    `is_show` = 1,
    `update_time` = UNIX_TIMESTAMP()
WHERE `perms` = 'user.user/lists'
  AND `component` = 'consumer/lists/index';

INSERT INTO `la_system_menu` (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT COALESCE((SELECT `id` FROM `la_system_menu` WHERE `paths` = 'consumer' AND `type` = 'M' LIMIT 1), 117),
       'C', '系统账号', '', 95, 'user.user/lists', 'system_lists', 'consumer/lists/index', '', '{\"account_scope\":\"system\"}', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_system_menu`
    WHERE `paths` = 'system_lists'
      AND `component` = 'consumer/lists/index'
);

INSERT INTO `la_system_role_menu` (`role_id`, `menu_id`)
SELECT 1, m.`id`
FROM `la_system_menu` m
WHERE m.`paths` IN ('lists', 'system_lists')
  AND m.`component` = 'consumer/lists/index'
  AND NOT EXISTS (
      SELECT 1
      FROM `la_system_role_menu` rm
      WHERE rm.`role_id` = 1
        AND rm.`menu_id` = m.`id`
  );
