场景
为菜单表中所以机构(organization_id唯一标识)课程项目(一级菜单)菜单下新增图书管理子菜单并为所有机构增加该子菜单的绑定关系。具体查询步骤:
(1)查询菜单表中有菜单配置的所有机构id;
(2)查询相应机构对于的一级菜单 课程项目 的id;
(3)为所有机构新增图书管理子菜单绑定关系。
实现过程
delimiter //
drop procedure if exists menu_insert;
create procedure menu_insert()
begin
declare organizationId varchar(32);
declare flag int default 0;
declare s_list cursor for SELECT organization_id AS "organizationId" FROM menu_info GROUP BY organization_id;
# 为下面while循环建立一个退出标志,当游标遍历完后将flag的值设置为1
declare continue handler for not found set flag=1;
open s_list;
fetch s_list into organizationId;
while flag <> 1 do
set @org_id = organizationId;
set @parent_id = (SELECT id FROM menu_info WHERE menu_name = "课程项目" AND organization_id = @org_id) ;
INSERT INTO `menu_info`
VALUES
(
REPLACE (UUID(), "-", ""),
@org_id,
@parent_id,
"图书管理",
"/projectMana/bookList",
"30",
6,
NULL,
"0",
NULL,
NULL,
NULL,
NULL,
NULL,
"0",
NULL,
NULL
);
fetch s_list into organizationId;
end while;
close s_list;
end
//
delimiter ;
call menu_insert();