sol1dphp

Permissão Financeira

Jul 26th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.35 KB | None | 0 0
  1. :setvar cliente FundacaoLemann4600Tests
  2.  
  3. /****** Object:  StoredProcedure [dbo].[SpVisaoHistorica]    Script Date: 19/06/2017 18:40:11 ******/ DW-FundacaoLemann4600Tests
  4. use [DW-$(cliente)]
  5.  
  6.  
  7. create  Procedure Sp_ListaMembrosPermissoes (
  8.  
  9. @idMatriz int, -- 18
  10. @idDimX varchar(4), --2047
  11. @idDimY varchar(4), --2050
  12. @idDimz varchar(4),  --2048
  13. @idVisao int, --27
  14. @IdColaborador int -- 1
  15. )
  16.  
  17. as  begin
  18.  
  19. /* Created Paulo Henrique Patrício */
  20.  
  21. /* Construção do filtro Membros no Where */
  22.  
  23. declare @membros varchar(400)
  24.  
  25. /* Preenchimento de @iddimx e @iddimy obrigatórios apenas @iddimz opcional */
  26.  
  27. if (@idDimX <> '' or @idDimX is null) and (@idDimY <> '' or @idDimY is null) and (@idDimz <> '' or @idDimz is null)
  28. begin
  29. set @membros  = ' IdDimensao in (' + @idDimX + ',' + @idDimY + ','  +  @idDimz + ')'
  30. end
  31.  
  32. if (@idDimX <> '' or @idDimX is null) and (@idDimY <> '' or @idDimY is null) and (@idDimz = '')
  33. begin
  34. set @membros  = ' IdDimensao in (' + @idDimX + ',' + @idDimY +') '
  35. end
  36.  
  37. declare @sql  varchar(max)
  38.  
  39. if object_id('tempdb..##temppermissoes') is not null  drop table ##temppermissoes
  40.  
  41. set @sql = '  
  42.  
  43. /* neste cenário, nós temos exatamente os membros que o colaborador possui acesso */
  44. select
  45. m.idEixoXYZ
  46. ,m.Codigo
  47. ,m.Nome
  48. ,m.IdDimensao
  49. ,m.idParent
  50. ,m.TipoComponente  
  51. into ##temppermissoes from DimEixoXYZ as m where idEixoXYZ in
  52.     (
  53.     select IdMembroDimensao
  54.         from PermissaoFinanceira as p
  55.             where
  56.             IdMatriz = 18 -- = @idMatriz
  57.  
  58.             and ' + @membros + '
  59.            
  60.             and IdColaborador = 1 -- =@idColaborador
  61.             and idVisao = 27 -- =@idVisao
  62.      )
  63.  
  64. /* Querry recursiva para retornar os membros e os parents cujo o usuário possui acesso */
  65. ;WITH cteMenuNivel(
  66. Nivel,
  67. idEixoXYZ
  68. ,Codigo
  69. ,Nome
  70. ,IdDimensao
  71. ,idParent
  72. ,TipoComponente)
  73. AS
  74. (
  75. -- Ancora
  76.  
  77. select
  78. 1 as Nivel
  79. ,m.idEixoXYZ
  80. ,m.Codigo
  81. ,m.Nome
  82. ,m.IdDimensao
  83. ,m.idParent
  84. ,m.TipoComponente
  85. from ##temppermissoes as  m
  86. --where idParent is null  
  87. union ALL
  88. -- Recursivo
  89. select
  90. Nivel + 1 as Nivel
  91. ,p.idEixoXYZ
  92. ,p.Codigo
  93. ,p.Nome
  94. ,p.IdDimensao
  95. ,p.idParent
  96. ,p.TipoComponente from DimEixoXYZ p
  97. INNER JOIN cteMenuNivel as c ON c.idParent = p.idEixoXYZ
  98. )
  99. select
  100.  
  101. idEixoXYZ
  102. ,Nome
  103. ,Codigo
  104. ,IdDimensao
  105. ,TipoComponente
  106. ,0 as Checked
  107. ,idParent    from ctemenunivel
  108. order by IdDimensao asc, idParent asc  
  109.  
  110. '
  111.  
  112. exec (@sql)
  113.  
  114. end
Advertisement
Add Comment
Please, Sign In to add comment