-- 交控中心 > 数据采集站 > 采集站/媒体/执法记录仪 菜单
-- 执行前请确认 SYSTEM_MENU 中已存在 NAME='交控中心' 且 TYPE=1 的顶级菜单
-- 执行后请在「角色管理 → 授权菜单」中为相关角色勾选新菜单

-- 1. 文件夹：数据采集站
INSERT INTO `SYSTEM_MENU`(`PARENT_ID`, `TYPE`, `LINK_TYPE`, `NAME`, `PATH`, `PARAMS`, `ICON`, `DISABLED`, `SORT`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT jk.`ID`, 0, 0, '数据采集站', NULL, NULL, 'el-icon-upload2', 0,
  IFNULL((SELECT MAX(m.`SORT`) FROM `SYSTEM_MENU` m WHERE m.`PARENT_ID` = jk.`ID` AND m.`DELETED` = 0), -1) + 1,
  0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_MENU` jk
WHERE jk.`NAME` = '交控中心' AND jk.`TYPE` = 1 AND jk.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_MENU` m WHERE m.`PARENT_ID` = jk.`ID` AND m.`NAME` = '数据采集站' AND m.`DELETED` = 0
);

-- 2. 采集站管理
INSERT INTO `SYSTEM_MENU`(`PARENT_ID`, `TYPE`, `LINK_TYPE`, `NAME`, `PATH`, `PARAMS`, `ICON`, `DISABLED`, `SORT`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT folder.`ID`, 0, 0, '采集站管理', '/business/collectionStation', NULL, 'el-icon-monitor', 0, 1, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_MENU` folder
INNER JOIN `SYSTEM_MENU` jk ON jk.`ID` = folder.`PARENT_ID` AND jk.`DELETED` = 0
WHERE jk.`NAME` = '交控中心' AND jk.`TYPE` = 1
AND folder.`NAME` = '数据采集站' AND folder.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_MENU` m WHERE m.`PARENT_ID` = folder.`ID` AND m.`PATH` = '/business/collectionStation' AND m.`DELETED` = 0
);

-- 3. 媒体文件
INSERT INTO `SYSTEM_MENU`(`PARENT_ID`, `TYPE`, `LINK_TYPE`, `NAME`, `PATH`, `PARAMS`, `ICON`, `DISABLED`, `SORT`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT folder.`ID`, 0, 0, '媒体文件', '/business/collectionMedia', NULL, 'el-icon-video-camera', 0, 2, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_MENU` folder
INNER JOIN `SYSTEM_MENU` jk ON jk.`ID` = folder.`PARENT_ID` AND jk.`DELETED` = 0
WHERE jk.`NAME` = '交控中心' AND jk.`TYPE` = 1
AND folder.`NAME` = '数据采集站' AND folder.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_MENU` m WHERE m.`PARENT_ID` = folder.`ID` AND m.`PATH` = '/business/collectionMedia' AND m.`DELETED` = 0
);

-- 4. 执法记录仪
INSERT INTO `SYSTEM_MENU`(`PARENT_ID`, `TYPE`, `LINK_TYPE`, `NAME`, `PATH`, `PARAMS`, `ICON`, `DISABLED`, `SORT`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT folder.`ID`, 0, 0, '执法记录仪', '/business/collectionDockDevice', NULL, 'el-icon-mobile-phone', 0, 3, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_MENU` folder
INNER JOIN `SYSTEM_MENU` jk ON jk.`ID` = folder.`PARENT_ID` AND jk.`DELETED` = 0
WHERE jk.`NAME` = '交控中心' AND jk.`TYPE` = 1
AND folder.`NAME` = '数据采集站' AND folder.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_MENU` m WHERE m.`PARENT_ID` = folder.`ID` AND m.`PATH` = '/business/collectionDockDevice' AND m.`DELETED` = 0
);
