足力健后端,使用.netcore版本,合并1个项目使用

Sys_RoleFunctionRepository.cs 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IRepositories;
  5. using System.Model;
  6. using SqlSugar;
  7. using System.Common;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace System.Repositories
  11. {
  12. public class Sys_RoleFunctionRepository : BaseRepository<T_Sys_RoleFunction>, ISys_RoleFunctionRepository
  13. {
  14. /// <summary>
  15. /// 获取菜单和按钮
  16. /// </summary>
  17. /// <param name="roleid"></param>
  18. /// <returns></returns>
  19. public async Task<object> GetMenuAsync(int roleid)
  20. {
  21. var menulist = await Db.Queryable<T_Sys_RoleFunction>().With(SqlWith.NoLock)
  22. .Where(x => x.F_RoleId == roleid && x.F_FunctionType== (int)EnumRoleControlType.Moudle).Select(p=>p.F_FunctionId).ToListAsync();
  23. var buttonlist = await Db.Queryable<T_Sys_RoleFunction>().With(SqlWith.NoLock)
  24. .Where(x => x.F_RoleId == roleid && x.F_FunctionType == (int)EnumRoleControlType.Button).Select(p => p.F_FunctionId).ToListAsync();
  25. var menuinfolist = await Db.Queryable<T_Sys_ModuleInfo>().Where(x => x.F_State == (int)EnumDelState.Enabled && menulist.Contains(x.F_Id)).OrderBy(o => o.F_Sort).ToListAsync();
  26. var buttoninfolist = await Db.Queryable<T_Sys_ModuleButtonInfo>().Where(x => x.F_State == (int)EnumDelState.Enabled && buttonlist.Contains(x.F_Id)).OrderBy(o => o.F_Sort).ToListAsync();
  27. return TreeRecursion(menuinfolist, buttoninfolist);
  28. }
  29. /// <summary>
  30. /// 生成菜单数据方法
  31. /// </summary>
  32. /// <param name="data"></param>
  33. /// <param name="parentId"></param>
  34. /// <returns></returns>
  35. private object TreeRecursion(List<T_Sys_ModuleInfo> menuinfolist, List<T_Sys_ModuleButtonInfo> buttoninfolist, int parentId = 0)
  36. {
  37. List<T_Sys_ModuleInfo> item = menuinfolist.FindAll(t => t.F_ParentId == parentId);//data建议在调用此扩展方法前已经排序过
  38. var list = item.Select(p => new
  39. {
  40. id=p.F_Id,
  41. name = p.F_MenuName,
  42. code = p.F_MenuCode,
  43. url = p.F_OptUrl,
  44. type = p.F_Target,
  45. imgurl = p.F_ImgUrl,
  46. ismenu = p.F_IsMenu,
  47. sort=p.F_Sort,
  48. buttongroup = buttoninfolist.Where(q => q.F_MenuId == p.F_Id).Select(q => new {
  49. id=q.F_Id,
  50. name = q.F_ButtonName,
  51. code = q.F_ButtonCode,
  52. icon=q.F_Icon,
  53. jsevent=q.F_JSEvent,
  54. moudleid = q.F_MenuId,
  55. sort=q.F_Sort,
  56. url = q.F_UrlAddress
  57. }),
  58. children = TreeRecursion(menuinfolist, buttoninfolist, p.F_Id)
  59. });
  60. return list;
  61. }
  62. }
  63. }