-- 帆软报表上传菜单（父级 1965981757204459521），请根据需要调整排序/图标

-- DM8 兼容写法：匿名块 + 变量赋值 + SELECT ... INTO
BEGIN
    DECLARE
        v_parent_id   BIGINT;
        v_menu_id     BIGINT;
        v_button_id   BIGINT;
    BEGIN
        v_parent_id := 1965981757204459521;

        -- 计算主菜单 ID（非自增：使用当前最大值 + 1）
        SELECT COALESCE(MAX(id), 0) + 1 INTO v_menu_id FROM system_menu;

        INSERT INTO system_menu(
            id, name, permission, type, sort, parent_id,
            path, icon, component, status, component_name
        ) VALUES (
            v_menu_id, '帆软报表上传', '', 2, 0, v_parent_id,
            'fine-report-upload', 'ep:upload-filled', 'base/fineReportUpload/index', 0, 'FineReportUpload'
        );

        -- 计算按钮 ID（非自增：再取最大值 + 1）
        SELECT COALESCE(MAX(id), 0) + 1 INTO v_button_id FROM system_menu;

        INSERT INTO system_menu(
            id, name, permission, type, sort, parent_id,
            path, icon, component, status
        ) VALUES (
            v_button_id, '帆软报表上传-上传', 'base:fine-report-template:upload', 3, 1, v_menu_id,
            '', '', '', 0
        );
    END;
END;
/
