纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.4 KiB

3 years ago
  1. using NFine.Application.SystemManage;
  2. using NFine.Code;
  3. using NFine.Domain.Entity.SystemManage;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Web.Mvc;
  8. namespace NFine.Web.Controllers
  9. {
  10. [HandlerLogin]
  11. public class ClientsDataController : Controller
  12. {
  13. [HttpGet]
  14. [HandlerAjaxOnly]
  15. public ActionResult GetClientsDataJson()
  16. {
  17. var data = new
  18. {
  19. dataItems = this.GetDataItemList(),
  20. organize = this.GetOrganizeList(),
  21. role = this.GetRoleList(),
  22. duty = this.GetDutyList(),
  23. user = this.GetUserList(),
  24. authorizeMenu = this.GetMenuList(),
  25. authorizeButton = this.GetMenuButtonList(),
  26. };
  27. return Content(data.ToJson());
  28. }
  29. private object GetDataItemList()
  30. {
  31. var itemdata = new ItemsDetailApp().GetList();
  32. Dictionary<string, object> dictionaryItem = new Dictionary<string, object>();
  33. foreach (var item in new ItemsApp().GetList())
  34. {
  35. var dataItemList = itemdata.FindAll(t => t.F_ItemId.Equals(item.F_Id));
  36. Dictionary<string, string> dictionaryItemList = new Dictionary<string, string>();
  37. foreach (var itemList in dataItemList)
  38. {
  39. dictionaryItemList.Add(itemList.F_ItemCode, itemList.F_ItemName);
  40. }
  41. dictionaryItem.Add(item.F_EnCode, dictionaryItemList);
  42. }
  43. return dictionaryItem;
  44. }
  45. private object GetUserList()
  46. {
  47. UserApp userApp = new UserApp();
  48. var data = userApp.GetList();
  49. Dictionary<string,object> dictionary = new Dictionary<string,object>();
  50. foreach (UserEntity item in data)
  51. {
  52. var fieldItem = new
  53. {
  54. realname = item.F_RealName,
  55. nickname = item.F_NickName
  56. };
  57. dictionary.Add(item.F_Id,fieldItem);
  58. }
  59. return dictionary;
  60. }
  61. private object GetOrganizeList()
  62. {
  63. OrganizeApp organizeApp = new OrganizeApp();
  64. var data = organizeApp.GetList();
  65. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  66. foreach (OrganizeEntity item in data)
  67. {
  68. var fieldItem = new
  69. {
  70. encode = item.F_EnCode,
  71. fullname = item.F_FullName
  72. };
  73. dictionary.Add(item.F_Id, fieldItem);
  74. }
  75. return dictionary;
  76. }
  77. private object GetRoleList()
  78. {
  79. RoleApp roleApp = new RoleApp();
  80. var data = roleApp.GetList();
  81. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  82. foreach (RoleEntity item in data)
  83. {
  84. var fieldItem = new
  85. {
  86. encode = item.F_EnCode,
  87. fullname = item.F_FullName
  88. };
  89. dictionary.Add(item.F_Id, fieldItem);
  90. }
  91. return dictionary;
  92. }
  93. private object GetDutyList()
  94. {
  95. DutyApp dutyApp = new DutyApp();
  96. var data = dutyApp.GetList();
  97. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  98. foreach (RoleEntity item in data)
  99. {
  100. var fieldItem = new
  101. {
  102. encode = item.F_EnCode,
  103. fullname = item.F_FullName
  104. };
  105. dictionary.Add(item.F_Id, fieldItem);
  106. }
  107. return dictionary;
  108. }
  109. private object GetMenuList()
  110. {
  111. var roleId = OperatorProvider.Provider.GetCurrent().RoleId;
  112. return ToMenuJson(new RoleAuthorizeApp().GetMenuList(roleId), "0");
  113. }
  114. private string ToMenuJson(List<ModuleEntity> data, string parentId)
  115. {
  116. StringBuilder sbJson = new StringBuilder();
  117. sbJson.Append("[");
  118. List<ModuleEntity> entitys = data.FindAll(t => t.F_ParentId == parentId);
  119. if (entitys.Count > 0)
  120. {
  121. foreach (var item in entitys)
  122. {
  123. string strJson = item.ToJson();
  124. strJson = strJson.Insert(strJson.Length - 1, ",\"ChildNodes\":" + ToMenuJson(data, item.F_Id) + "");
  125. sbJson.Append(strJson + ",");
  126. }
  127. sbJson = sbJson.Remove(sbJson.Length - 1, 1);
  128. }
  129. sbJson.Append("]");
  130. return sbJson.ToString();
  131. }
  132. private object GetMenuButtonList()
  133. {
  134. var roleId = OperatorProvider.Provider.GetCurrent().RoleId;
  135. var data = new RoleAuthorizeApp().GetButtonList(roleId);
  136. var dataModuleId = data.Distinct(new ExtList<ModuleButtonEntity>("F_ModuleId"));
  137. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  138. foreach (ModuleButtonEntity item in dataModuleId)
  139. {
  140. var buttonList = data.Where(t => t.F_ModuleId.Equals(item.F_ModuleId));
  141. dictionary.Add(item.F_ModuleId, buttonList);
  142. }
  143. return dictionary;
  144. }
  145. }
  146. }