SystemMenuPermissionRepository.cs 11 KB

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