-- 自录转化统计菜单（挂在「数据统计」目录下）
-- 主页面: /stats/self_input
-- 账户消耗: /stats/self_input/account_cost

SET @stats_root_id = (
    SELECT `id` FROM `zyt_system_menu`
    WHERE `paths` = '/stats' AND `type` = 'M'
    ORDER BY `id` ASC
    LIMIT 1
);

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @stats_root_id, 'C', '自录转化统计', '', 5, 'stats.self_input/overview', '/stats/self_input', '/stats/self_input/index', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @stats_root_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM `zyt_system_menu`
      WHERE `perms` = 'stats.self_input/overview'
  );

SET @self_input_menu_id = (
    SELECT `id` FROM `zyt_system_menu`
    WHERE `perms` = 'stats.self_input/overview'
    LIMIT 1
);

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @self_input_menu_id, 'A', '查看业绩', '', 1, 'stats.personal_yeji/lists', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @self_input_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_yeji/lists');

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @self_input_menu_id, 'A', '新增业绩', '', 2, 'stats.personal_yeji/add', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @self_input_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_yeji/add');

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @self_input_menu_id, 'A', '编辑业绩', '', 3, 'stats.personal_yeji/edit', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @self_input_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_yeji/edit');

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @self_input_menu_id, 'A', '删除业绩', '', 4, 'stats.personal_yeji/delete', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @self_input_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_yeji/delete');

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @stats_root_id, 'C', '账户消耗录入', '', 6, 'stats.personal_account_cost/lists', '/stats/self_input/account_cost', '/stats/self_input/account_cost', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @stats_root_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM `zyt_system_menu`
      WHERE `perms` = 'stats.personal_account_cost/lists'
  );

SET @personal_cost_menu_id = (
    SELECT `id` FROM `zyt_system_menu`
    WHERE `perms` = 'stats.personal_account_cost/lists'
    LIMIT 1
);

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @personal_cost_menu_id, 'A', '新增消耗', '', 1, 'stats.personal_account_cost/add', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @personal_cost_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_account_cost/add');

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @personal_cost_menu_id, 'A', '编辑消耗', '', 2, 'stats.personal_account_cost/edit', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @personal_cost_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_account_cost/edit');

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @personal_cost_menu_id, 'A', '删除消耗', '', 3, 'stats.personal_account_cost/delete', '', '', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL WHERE @personal_cost_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM `zyt_system_menu` WHERE `perms` = 'stats.personal_account_cost/delete');
