ClientDataController.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. using LeaRun.Application.Cache;
  2. using LeaRun.Application.Entity.SystemManage.ViewModel;
  3. using LeaRun.Util;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web.Mvc;
  7. using LeaRun.Application.Entity.BaseManage;
  8. using LeaRun.Application.Busines.AuthorizeManage;
  9. using LeaRun.Application.Code;
  10. using LeaRun.Application.Entity.AuthorizeManage;
  11. namespace LeaRun.Application.Web.Controllers
  12. {
  13. /// <summary>
  14. /// 版 本 6.1
  15. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  16. /// 创建人:佘赐雄
  17. /// 日 期:2015.09.01 13:32
  18. /// 描 述:客户端数据
  19. /// </summary>
  20. public class ClientDataController : MvcControllerBase
  21. {
  22. private DataItemCache dataItemCache = new DataItemCache();
  23. private OrganizeCache organizeCache = new OrganizeCache();
  24. private DepartmentCache departmentCache = new DepartmentCache();
  25. private PostCache postCache = new PostCache();
  26. private RoleCache roleCache = new RoleCache();
  27. private UserGroupCache userGroupCache = new UserGroupCache();
  28. private UserCache userCache = new UserCache();
  29. private AuthorizeBLL authorizeBLL = new AuthorizeBLL();
  30. #region 获取数据
  31. /// <summary>
  32. /// 批量加载数据给客户端(把常用数据全部加载到浏览器中 这样能够减少数据库交互)
  33. /// </summary>
  34. /// <returns></returns>
  35. [HttpPost]
  36. [AjaxOnly]
  37. public ActionResult GetClientDataJson()
  38. {
  39. var jsonData = new
  40. {
  41. organize = this.GetOrganizeData(), //公司
  42. department = this.GetDepartmentData(), //部门
  43. post = this.GetPostData(), //岗位
  44. role = this.GetRoleData(), //角色
  45. userGroup = this.GetUserGroupData(), //用户组
  46. user = this.GetUserData(), //用户
  47. dataItem = this.GetDataItem(), //字典
  48. authorizeMenu = this.GetModuleData(), //导航菜单
  49. authorizeButton = this.GetModuleButtonData(), //功能按钮
  50. authorizeColumn = this.GetModuleColumnData(), //功能视图
  51. };
  52. return ToJsonResult(jsonData);
  53. }
  54. #endregion
  55. #region 处理基础数据
  56. /// <summary>
  57. /// 获取公司数据
  58. /// </summary>
  59. /// <returns></returns>
  60. private object GetOrganizeData()
  61. {
  62. var data = organizeCache.GetList();
  63. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  64. foreach (OrganizeEntity item in data)
  65. {
  66. var fieldItem = new
  67. {
  68. EnCode = item.EnCode,
  69. FullName = item.FullName
  70. };
  71. dictionary.Add(item.OrganizeId, fieldItem);
  72. }
  73. return dictionary;
  74. }
  75. /// <summary>
  76. /// 获取部门数据
  77. /// </summary>
  78. /// <returns></returns>
  79. private object GetDepartmentData()
  80. {
  81. var data = departmentCache.GetList();
  82. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  83. foreach (DepartmentEntity item in data)
  84. {
  85. var fieldItem = new
  86. {
  87. EnCode = item.EnCode,
  88. FullName = item.FullName,
  89. OrganizeId = item.OrganizeId
  90. };
  91. dictionary.Add(item.DepartmentId, fieldItem);
  92. }
  93. return dictionary;
  94. }
  95. /// <summary>
  96. /// 获取岗位数据
  97. /// </summary>
  98. /// <returns></returns>
  99. private object GetUserGroupData()
  100. {
  101. var data = userGroupCache.GetList();
  102. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  103. foreach (RoleEntity item in data)
  104. {
  105. var fieldItem = new
  106. {
  107. EnCode = item.EnCode,
  108. FullName = item.FullName
  109. };
  110. dictionary.Add(item.RoleId, fieldItem);
  111. }
  112. return dictionary;
  113. }
  114. /// <summary>
  115. /// 获取岗位数据
  116. /// </summary>
  117. /// <returns></returns>
  118. private object GetPostData()
  119. {
  120. var data = postCache.GetList();
  121. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  122. foreach (RoleEntity item in data)
  123. {
  124. var fieldItem = new
  125. {
  126. EnCode = item.EnCode,
  127. FullName = item.FullName
  128. };
  129. dictionary.Add(item.RoleId, fieldItem);
  130. }
  131. return dictionary;
  132. }
  133. /// <summary>
  134. /// 获取角色数据
  135. /// </summary>
  136. /// <returns></returns>
  137. private object GetRoleData()
  138. {
  139. var data = roleCache.GetList();
  140. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  141. foreach (RoleEntity item in data)
  142. {
  143. var fieldItem = new
  144. {
  145. EnCode = item.EnCode,
  146. FullName = item.FullName
  147. };
  148. dictionary.Add(item.RoleId, fieldItem);
  149. }
  150. return dictionary;
  151. }
  152. /// <summary>
  153. /// 获取用户数据
  154. /// </summary>
  155. /// <returns></returns>
  156. private object GetUserData()
  157. {
  158. var data = userCache.GetList();
  159. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  160. foreach (UserEntity item in data)
  161. {
  162. var fieldItem = new
  163. {
  164. EnCode = item.EnCode,
  165. Account = item.Account,
  166. RealName = item.RealName,
  167. OrganizeId = item.OrganizeId,
  168. DepartmentId = item.DepartmentId
  169. };
  170. dictionary.Add(item.UserId, fieldItem);
  171. }
  172. return dictionary;
  173. }
  174. /// <summary>
  175. /// 获取数据字典
  176. /// </summary>
  177. /// <returns></returns>
  178. private object GetDataItem()
  179. {
  180. var dataList = dataItemCache.GetDataItemList();
  181. var dataSort = dataList.Distinct(new Comparint<DataItemModel>("EnCode"));
  182. Dictionary<string, object> dictionarySort = new Dictionary<string, object>();
  183. foreach (DataItemModel itemSort in dataSort)
  184. {
  185. var dataItemList = dataList.Where(t => t.EnCode.Equals(itemSort.EnCode));
  186. Dictionary<string, string> dictionaryItemList = new Dictionary<string, string>();
  187. foreach (DataItemModel itemList in dataItemList)
  188. {
  189. dictionaryItemList.Add(itemList.ItemValue, itemList.ItemName);
  190. }
  191. foreach (DataItemModel itemList in dataItemList)
  192. {
  193. dictionaryItemList.Add(itemList.ItemDetailId, itemList.ItemName);
  194. }
  195. dictionarySort.Add(itemSort.EnCode, dictionaryItemList);
  196. }
  197. return dictionarySort;
  198. }
  199. #endregion
  200. #region 处理授权数据
  201. /// <summary>
  202. /// 获取功能数据
  203. /// </summary>
  204. /// <returns></returns>
  205. private object GetModuleData()
  206. {
  207. return authorizeBLL.GetModuleList(SystemInfo.CurrentUserId);
  208. }
  209. /// <summary>
  210. /// 获取功能按钮数据
  211. /// </summary>
  212. /// <returns></returns>
  213. private object GetModuleButtonData()
  214. {
  215. var data = authorizeBLL.GetModuleButtonList(SystemInfo.CurrentUserId);
  216. var dataModule = data.Distinct(new Comparint<ModuleButtonEntity>("ModuleId"));
  217. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  218. foreach (ModuleButtonEntity item in dataModule)
  219. {
  220. var buttonList = data.Where(t => t.ModuleId.Equals(item.ModuleId));
  221. dictionary.Add(item.ModuleId, buttonList);
  222. }
  223. return dictionary;
  224. }
  225. /// <summary>
  226. /// 获取功能视图数据
  227. /// </summary>
  228. /// <returns></returns>
  229. private object GetModuleColumnData()
  230. {
  231. var data = authorizeBLL.GetModuleColumnList(SystemInfo.CurrentUserId);
  232. var dataModule = data.Distinct(new Comparint<ModuleColumnEntity>("ModuleId"));
  233. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  234. foreach (ModuleColumnEntity item in dataModule)
  235. {
  236. var columnList = data.Where(t => t.ModuleId.Equals(item.ModuleId));
  237. dictionary.Add(item.ModuleId, columnList);
  238. }
  239. return dictionary;
  240. }
  241. #endregion
  242. }
  243. }