-- 创建存储过程，作用是给按钮的 parent_id 赋值（菜单的 id）
-- 执行时要分布执行，先创建存储过程，然后执行其他语句，最好一句一句执行
CREATE OR REPLACE PROCEDURE system_menu_core_${table.tableName.toLowerCase()}_proc(IN_value IN INT)
IS
v_local_variable INT;
BEGIN
-- 设置变量值
v_local_variable := IN_value;
    -- 按钮 SQL
    #set ($functionNames = ['查询', '创建', '更新', '删除', '导出'])
    #set ($functionOps = ['query', 'create', 'update', 'delete', 'export'])
    #foreach ($functionName in $functionNames)
        #set ($index = $foreach.count - 1)
    INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
    )
    VALUES (
    '${table.classComment}${functionName}', '${permissionPrefix}:${functionOps.get($index)}', 3, $foreach.count, v_local_variable,
    '', '', '', 0
    );
    #end
END;

-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
    '${table.classComment}管理', '', 2, 0, ${table.parentMenuId},
    '${simpleClassName_strikeCase}', '', '${table.moduleName}/${table.businessName}/index', 0, '${table.className}'
);


CALL system_menu_core_${table.tableName.toLowerCase()}_proc(SELECT "id"  FROM  "system_menu" sm WHERE "name" = '${table.classComment}管理');

DROP PROCEDURE system_menu_core_${table.tableName.toLowerCase()}_proc;