-- ============================================================
-- 引江济太(YJJT)菜单初始化SQL
-- 适配达梦数据库(DAMENG)版本
-- ============================================================

-- 设置当前模式
SET SCHEMA PUBLIC;

-- 一级菜单：引江济太管理
INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
VALUES ('引江济太管理', 0, 11, 'yjjt', NULL, NULL, 1, 0, 'M', '0', '0', '', 'skill', 'admin', SYSDATE, '引江济太管理目录');

-- 获取一级菜单ID
DECLARE
    V_PARENT_ID BIGINT;
BEGIN
    SELECT ID INTO V_PARENT_ID FROM SYS_MENU WHERE MENU_NAME = '引江济太管理' AND PARENT_ID = 0;
    
    -- 二级菜单：YJJT站点管理
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('YJJT站点管理', V_PARENT_ID, 1, 'station', 'yjjt/station/index', NULL, 1, 0, 'C', '0', '0', 'yjjt:station:list', 'server', 'admin', SYSDATE, '引江济太站点管理菜单');
    
    -- 二级菜单：水量数据
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水量数据', V_PARENT_ID, 2, 'sl', 'yjjt/sl/index', NULL, 1, 0, 'C', '0', '0', 'yjjt:sl:list', 'chart', 'admin', SYSDATE, '引江济太水量数据菜单');
    
    -- 二级菜单：水质数据
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水质数据', V_PARENT_ID, 3, 'sz', 'yjjt/sz/index', NULL, 1, 0, 'C', '0', '0', 'yjjt:sz:list', 'chart', 'admin', SYSDATE, '引江济太水质数据菜单');
    
    -- 二级菜单：文件管理
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('YJJT文件管理', V_PARENT_ID, 4, 'file', 'yjjt/file/index', NULL, 1, 0, 'C', '0', '0', 'yjjt:file:list', 'upload', 'admin', SYSDATE, '引江济太文件管理菜单');
    
    -- 二级菜单：数据统计
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('YJJT数据统计', V_PARENT_ID, 5, 'statistics', 'yjjt/statistics/index', NULL, 1, 0, 'C', '0', '0', 'yjjt:data:list', 'dashboard', 'admin', SYSDATE, '引江济太数据统计菜单');
    
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        PRINT '未找到引江济太管理菜单';
END;
/

-- ============================================================
-- 按钮权限：YJJT站点管理
-- ============================================================
DECLARE
    V_PARENT_ID BIGINT;
BEGIN
    SELECT ID INTO V_PARENT_ID FROM SYS_MENU WHERE MENU_NAME = 'YJJT站点管理' AND PERMS = 'yjjt:station:list';
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('站点查询', V_PARENT_ID, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:station:query', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('站点新增', V_PARENT_ID, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:station:add', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('站点修改', V_PARENT_ID, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:station:edit', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('站点删除', V_PARENT_ID, 4, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:station:remove', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('站点导出', V_PARENT_ID, 5, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:station:export', '#', 'admin', SYSDATE, '');
    
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        PRINT '未找到YJJT站点管理菜单';
END;
/

-- ============================================================
-- 按钮权限：水量数据
-- ============================================================
DECLARE
    V_PARENT_ID BIGINT;
BEGIN
    SELECT ID INTO V_PARENT_ID FROM SYS_MENU WHERE MENU_NAME = '水量数据' AND PERMS = 'yjjt:sl:list';
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水量查询', V_PARENT_ID, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:sl:query', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水量删除', V_PARENT_ID, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:sl:remove', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水量导出', V_PARENT_ID, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:sl:export', '#', 'admin', SYSDATE, '');
    
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        PRINT '未找到水量数据菜单';
END;
/

-- ============================================================
-- 按钮权限：水质数据
-- ============================================================
DECLARE
    V_PARENT_ID BIGINT;
BEGIN
    SELECT ID INTO V_PARENT_ID FROM SYS_MENU WHERE MENU_NAME = '水质数据' AND PERMS = 'yjjt:sz:list';
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水质查询', V_PARENT_ID, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:sz:query', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水质删除', V_PARENT_ID, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:sz:remove', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('水质导出', V_PARENT_ID, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:sz:export', '#', 'admin', SYSDATE, '');
    
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        PRINT '未找到水质数据菜单';
END;
/

-- ============================================================
-- 按钮权限：YJJT文件管理
-- ============================================================
DECLARE
    V_PARENT_ID BIGINT;
BEGIN
    SELECT ID INTO V_PARENT_ID FROM SYS_MENU WHERE MENU_NAME = 'YJJT文件管理' AND PERMS = 'yjjt:file:list';
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('文件查询', V_PARENT_ID, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:file:query', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('文件新增', V_PARENT_ID, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:file:add', '#', 'admin', SYSDATE, '');
    
    INSERT INTO SYS_MENU (MENU_NAME, PARENT_ID, ORDER_NUM, PATH, COMPONENT, QUERY, IS_FRAME, IS_CACHE, MENU_TYPE, VISIBLE, STATUS, PERMS, ICON, CREATE_BY, CREATE_TIME, REMARK)
    VALUES ('文件删除', V_PARENT_ID, 3, '', NULL, NULL, 1, 0, 'F', '0', '0', 'yjjt:file:remove', '#', 'admin', SYSDATE, '');
    
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        PRINT '未找到YJJT文件管理菜单';
END;
/

COMMIT;
PRINT '引江济太菜单初始化完成';
