SystemMenuPermissionRepository.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using OASystem.Domain;
  2. using OASystem.Domain.Entities.System;
  3. using OASystem.Domain.ViewModels.System;
  4. using System.Collections;
  5. namespace OASystem.Infrastructure.Repositories.System
  6. {
  7. public class SystemMenuPermissionRepository : BaseRepository<Sys_SystemMenuPermission, SystemMenuPermissionView>
  8. {
  9. public SystemMenuPermissionRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  10. {
  11. }
  12. /// <summary>
  13. /// 分页查询页面表
  14. /// </summary>
  15. /// <param name="_SystemMenuPermissionRepository"></param>
  16. /// <param name="mid">模块id</param>
  17. /// <param name="pageSize">行数</param>
  18. /// <param name="currentPage">页码</param>
  19. /// <returns></returns>
  20. public Result GetSystemMenuViweData(SystemMenuPermissionRepository _SystemMenuPermissionRepository,int mid,int pageSize,int currentPage)
  21. {
  22. Result result = new Result();
  23. if (currentPage == 0 || pageSize == 0)
  24. {
  25. return result;
  26. }
  27. string sql = $@"select top {pageSize} * from (select row_number()
  28. over(order by id asc) as rownumber,*
  29. from Sys_SystemMenuPermission where mid = {mid} and isdel = 0 and IsEnable = 1 ) temp_row
  30. where rownumber> {(currentPage - 1) * pageSize};";
  31. var DBdata = _SystemMenuPermissionRepository.GetListBySqlWithNolock(sql);
  32. if (DBdata == null || DBdata.Count == 0)
  33. {
  34. result.Code = -1;
  35. result.Msg = "暂无数据!";
  36. result.Data = new
  37. {
  38. DBdata,
  39. total = 0
  40. };
  41. return result;
  42. }
  43. var total = _SystemMenuPermissionRepository.Query<Sys_SystemMenuPermission>(x => x.Mid == mid).Count();
  44. result.Code = 0;
  45. result.Msg = "成功!";
  46. result.Data = new
  47. {
  48. DBdata = DBdata.Select(x => new SystemMenuPermissionView
  49. {
  50. Id = x.Id,
  51. Name = x.Name,
  52. Mid = mid,
  53. SystemMenuCode = x.SystemMenuCode
  54. }),
  55. total = total
  56. };
  57. return result;
  58. }
  59. public Result QueryMenuLoad(int uid,int PortType)
  60. {
  61. Result result = new Result();
  62. result.Data = new string [0];
  63. if (uid != 0)
  64. {
  65. List<MenuLoadView> DBData = new List<MenuLoadView>();
  66. string sql = $@"
  67. select a.UId,a.SmId,b.Id as Funid,b.FunctionName,b.FunctionCode,c.Id as modulid,
  68. c.Name as modulName,c.STid,d.Id as pageid ,d.Name as PageName,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
  69. d.IosUrl
  70. from Sys_UserAuthority a inner join Sys_PageFunctionPermission b on a.FId = b.Id
  71. inner join Sys_SystemMenuPermission d on a.SmId = d.Id inner join Sys_SetData c on c.Id = d.Mid
  72. where uid = {uid} and a.IsDel= 0 and b.IsDel = 0
  73. and b.IsEnable = 1 and c.IsDel = 0 and d.IsDel = 0 ";
  74. if (PortType == 1)
  75. {
  76. //只返回查看权限
  77. //sql += $@" and b.Id = 1 and d.IsEnable = 1 group by
  78. // a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
  79. // c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
  80. // d.IosUrl";
  81. //返回所有权限
  82. sql += $@" and d.IsEnable = 1 group by
  83. a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
  84. c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
  85. d.IosUrl";
  86. DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
  87. }
  88. else if (PortType == 2)
  89. {
  90. sql += $@" and d.phoneIsEnable = 1 group by
  91. a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
  92. c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
  93. d.IosUrl ";
  94. DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
  95. }
  96. result.Code = -1;
  97. result.Msg = "暂无数据!";
  98. if (DBData.Count > 0)
  99. {
  100. result.Code = 0;
  101. result.Msg = "成功!";
  102. var arr = new ArrayList();
  103. var setDataArr = _sqlSugar.SqlQueryable<Sys_SetData>("select * from Sys_SetData ssd WHERE IsDel = 0 AND STid = 5").ToList();
  104. if (PortType == 1)
  105. {
  106. var menuGroup = DBData.GroupBy(x => x.modulid);
  107. foreach (var item in menuGroup)
  108. {
  109. var modul = item.FirstOrDefault();
  110. if (modul != null)
  111. {
  112. var pageInitData = item.GroupBy(it => it.pageid);
  113. var pageData = item.Where(it => it.pageid == modul.pageid).Select(it => new
  114. {
  115. it.Uid,
  116. it.SmId,
  117. it.Funid,
  118. it.FunctionName,
  119. it.FunctionCode,
  120. it.modulid,
  121. it.modulName,
  122. it.STid,
  123. it.pageid,
  124. it.PageName,
  125. PageAuth = item.Where(it => it.pageid == modul.pageid).Select(it => new { it.Funid,it.FunctionCode,it.FunctionName }),
  126. it.SystemMenuCode,
  127. it.webUrl,
  128. it.AndroidUrl,
  129. it.IosUrl,
  130. it.icon,
  131. });
  132. string Remark = setDataArr.Find(x => x.Id == modul.modulid)?.Remark;
  133. var modulData = new
  134. {
  135. modulName = modul.modulName,
  136. modulid = modul.modulid,
  137. pageList = pageData,
  138. Remark
  139. };
  140. if (modul.modulName.Contains("主页"))
  141. {
  142. arr.Insert(0, modulData);
  143. }
  144. else
  145. {
  146. arr.Add(modulData);
  147. }
  148. }
  149. }
  150. }
  151. else if (PortType == 2)
  152. {
  153. var AndMenu = DBData.GroupBy(x => x.SmId).ToList();
  154. foreach (var item in AndMenu)
  155. {
  156. arr.Add(new
  157. {
  158. pageId = item.Key,
  159. opList = item.Select(x=>x.Funid).ToList(),
  160. });
  161. }
  162. }
  163. result.Data = arr;
  164. }
  165. }
  166. return result;
  167. }
  168. }
  169. }