USE [xxxx]
GO
/****** Object: StoredProcedure [dbo].[P_Sys_GetModule_RoleRight] Script Date: 2020-10-10 9:54:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[P_Sys_GetModule_RoleRight]
@moduleId varchar(36)
as
/*
*/
create table #userModule
(
Id varchar(36),
name varchar(1024),
keyCode varchar(1024),
isValid bit
)
--declare @moduleId varchar(36)
--set @moduleId='000001'
select a.*,b.Name,c.KeyCode,c.IsValid into #right
from SysRight a ,SysRole b ,SysRightOperate c where a.ModuleId=@moduleId
and a.RoleId=b.Id
and a.Id=c.RightId
--select * from #right
select distinct Id,ModuleId,RoleId,Rightflag,Name
into #right2
from #right
--select * from #right2
select a.*,b.Name as keycode ,b.IsValid
into #right3
from #right2 a,SysModuleOperate b
where a.ModuleId=b.ModuleId
and RoleId+keycode not in(
select RoleId+KeyCode from #right
)
insert into #right
select * from #right3
where RoleId+keycode not in(
select RoleId+KeyCode from #right
)
update #right set keyCode=b.Name from #right a,SysModuleOperate b where a.ModuleId=b.ModuleId
and a.KeyCode=b.KeyCode
--select * from #right
insert into #userModule(Id,name,keyCode,isValid)
select RoleId,Name,KeyCode,IsValid from #right
-------------------------------------------------
--select * from #userModule
declare @sql varchar(1024)
create table #moduleKeyCode
(
Id varchar(36),
Name varchar(1024),
keyCode varchar(1024)
)
DECLARE @id varchar(128),@name varchar(128)
DECLARE @moduleKeyCodeIsTrue varchar(1024),@moduleKeyCodeIsFalse varchar(1024),@moduleKeyCode varchar(1024)
DECLARE @keyCode varchar(256),@isValid bit
DECLARE roleModule_cursor CURSOR FOR
SELECT distinct Id,name from #userModule
OPEN roleModule_cursor
FETCH NEXT FROM roleModule_cursor
INTO @id,@name
WHILE @@FETCH_STATUS = 0
BEGIN
set @moduleKeyCodeIsTrue=''
set @moduleKeyCodeIsFalse=''
--开始读取KeyCode
DECLARE keyCode_cursor CURSOR FOR
SELECT keycode,isvalid from #userModule where Id=@id
OPEN keyCode_cursor
FETCH NEXT FROM keyCode_cursor
INTO @keyCode,@isValid
WHILE @@FETCH_STATUS = 0
BEGIN
if(@isValid =1)
begin
set @moduleKeyCodeIsTrue =@moduleKeyCodeIsTrue+' <a class="fa fa-check-square-o color-green" /> ' +@keyCode
end
else
begin
set @moduleKeyCodeIsFalse =@moduleKeyCodeIsFalse+' <a class="fa fa-square-o color-red" /> ' +@keyCode
end
FETCH NEXT FROM keyCode_cursor
INTO @keyCode,@isValid
END
CLOSE keyCode_cursor;
DEALLOCATE keyCode_cursor;
--//
if(@moduleKeyCodeIsTrue!='')
begin
IF(@moduleKeyCodeIsFalse!='')
BEGIN
SET @moduleKeyCode=''+@moduleKeyCodeIsTrue +' '+@moduleKeyCodeIsFalse
END
ELSE
BEGIN
SET @moduleKeyCode=''+@moduleKeyCodeIsTrue
END
insert into #moduleKeyCode
values( @id,@name,@moduleKeyCode)
end
FETCH NEXT FROM roleModule_cursor
INTO @id,@name
END
CLOSE roleModule_cursor;
DEALLOCATE roleModule_cursor;
select Id,Name,keyCode from #moduleKeyCode
drop table #moduleKeyCode
drop table #userModule
drop table #right
https://blog.csdn.net/weixin_30925411/article/details/96640477