-- 河湖管理菜单配置 (达梦数据库)
-- 在 DBeaver/Navicat 中执行

DECLARE
  v_pid INT;
  v_id INT;
BEGIN
  -- 获取最大menu_id + 1
  SELECT NVL(MAX(menu_id), 2000) + 1 INTO v_id FROM SYS_MENU;

  -- 顶级菜单：河湖管理
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '河湖管理', 0, 1, 'hzz', NULL, 1, 0, 'M', '0', '0', NULL, 'tree', 'admin', SYSDATE, 'admin', SYSDATE, '河湖管理系统');

  v_pid := v_id;
  v_id := v_id + 1;

  -- 1. 一张图（首页 - iframe嵌入老系统，后续用Vue3+ArcGIS重写）
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '一张图', v_pid, 1, 'onemap', 'hzz/onemap/index', 1, 0, 'C', '0', '0', 'hzz:onemap:list', 'map', 'admin', SYSDATE, 'admin', SYSDATE, '一张图首页');
  v_id := v_id + 1;

  -- 2. 水域岸线管理
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '水域岸线管理', v_pid, 2, 'bankline', 'hzz/bankline/index', 1, 0, 'C', '0', '0', 'hzz:bankline:list', 'form', 'admin', SYSDATE, 'admin', SYSDATE, '河湖长制工作制度');
  v_id := v_id + 1;

  -- 3. 涉河项目查询
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '涉河项目查询', v_pid, 3, 'riverproject', 'hzz/riverproject/index', 1, 0, 'C', '0', '0', 'hzz:riverproject:list', 'build', 'admin', SYSDATE, 'admin', SYSDATE, '涉河项目查询与地图可视化');
  v_id := v_id + 1;

  -- 4. 岸线功能区统计
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '岸线功能区统计', v_pid, 4, 'shoreline', 'hzz/shoreline/index', 1, 0, 'C', '0', '0', 'hzz:shoreline:list', 'chart', 'admin', SYSDATE, 'admin', SYSDATE, '岸线功能区长度统计');
  v_id := v_id + 1;

  -- 5. 考核评估
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '考核评估', v_pid, 5, 'assess', 'hzz/assess/index', 1, 0, 'C', '0', '0', 'hzz:assess:list', 'edit', 'admin', SYSDATE, 'admin', SYSDATE, '考核评估');
  v_id := v_id + 1;

  -- 6. 督导检查
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '督导检查', v_pid, 6, 'supervision', 'hzz/supervision/index', 1, 0, 'C', '0', '0', 'hzz:supervision:list', 'monitor', 'admin', SYSDATE, 'admin', SYSDATE, '督导检查');
  v_id := v_id + 1;

  -- 7. 涉河项目督查
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '涉河项目督查', v_pid, 7, 'wps', 'hzz/wps/index', 1, 0, 'C', '0', '0', 'hzz:wps:list', 'list', 'admin', SYSDATE, 'admin', SYSDATE, '涉河项目督查');
  v_id := v_id + 1;

  -- 8. 一湖两河清四乱
  INSERT INTO SYS_MENU (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
  VALUES (v_id, '一湖两河清四乱', v_pid, 8, 'eventclear', 'hzz/eventclear/index', 1, 0, 'C', '0', '0', 'hzz:eventclear:list', 'warning', 'admin', SYSDATE, 'admin', SYSDATE, '一湖两河清四乱');
  v_id := v_id + 1;

  -- 给超级管理员(role_id=1)分配所有河湖管理菜单
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+1);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+2);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+3);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+4);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+5);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+6);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+7);
  INSERT INTO SYS_ROLE_MENU (role_id, menu_id) VALUES ('1', v_pid+8);

  COMMIT;
END;
/
