Files
Omni_kernel.db/permission/get_menustructure.txt
T
2026-02-06 15:09:39 +08:00

103 lines
2.7 KiB
Plaintext

delimiter //
create or replace procedure get_menustructure()
/*
Function : 配合 amis 的 transfer, 取得 module-menu 資料, 主要是建立 role-menu permissions 用
Description: 本 sp 修改自 get_orgstructure
Build Date : 2021/10/19
Modify History
Item Who Date Modify Docs
==== ========== ========== ================================================
1 Michael 2021/10/19
*/
begin
declare max_val int;
declare curr_id int;
declare group_id int;
declare next_group_id int;
declare datas nvarchar(max);
declare footer varchar(600);
declare dept_name varchar(100);
declare emp_name varchar(100);
declare person_id varchar(100);
declare crlf varchar(2);
declare comm varchar(1);
set crlf = char(10) + char(13);
select
bp.moduleid, bp.menuid, '(' || bp.moduleid || ')' || bm.modulename as deptname,
'(' || bp.menuid || ')' || bp.caption as empname,
ROW_NUMBER() OVER(PARTITION BY bp.moduleid ORDER BY bp.moduleid, bp.menuid) AS groupid,
ROW_NUMBER() OVER(ORDER BY bp.moduleid, bp.menuid) AS rowid
into #tmp
from sys_menutable bp
left join sys_module bm on bp.moduleid = bm.moduleid
where coalesce(bp.moduleid, '') <> ''
order by bp.moduleid, bp.menuid;
select count(*) into max_val from #tmp;
select min(rowid) into curr_id from #tmp;
set datas = '';
set comm = '';
while (curr_id <= max_val) do
-- 取得現有資料
select groupid, deptname, empname, menuid into group_id, dept_name, emp_name, person_id
from #tmp where rowid = curr_id;
if curr_id = max_val then
set comm = '';
else
select groupid into next_group_id from #tmp where rowid = curr_id + 1;
if next_group_id = 1 then
set comm = '';
else
set comm = ',';
end if;
end if;
if group_id = 1 then
if curr_id > 1 then
set footer = ' ]' || crlf ||
' },' || crlf;
else
set footer = '';
end if;
set datas = datas || footer ||
' {' || crlf ||
' "label": "' || dept_name || '",' || crlf ||
' "children": [' || crlf ||
' {' || crlf ||
' "label": "' || emp_name || '",' || crlf ||
' "value": "' || person_id || '"' || crlf ||
' }' || comm || crlf;
else
set datas = datas ||
' {' || crlf ||
' "label": "' || emp_name || '",' || crlf ||
' "value": "' || person_id || '"' || crlf ||
' }' || comm || crlf;
end if;
set curr_id = curr_id + 1;
end while;
set datas = ' [' || crlf || datas ||
' ]' || crlf ||
' }' || crlf ||
' ]';
drop table #tmp;
select 0 as code, 'ok' as msg;
select datas as jsoncode;
end //
delimiter ;