PermissionUserController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using Lottomat.Application.Busines.AuthorizeManage;
  2. using Lottomat.Application.Busines.BaseManage;
  3. using Lottomat.Application.Code;
  4. using Lottomat.Application.Entity.AuthorizeManage;
  5. using Lottomat.Application.Entity.BaseManage;
  6. using Lottomat.Util;
  7. using Lottomat.Util.Extension;
  8. using Lottomat.Util.WebControl;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Linq;
  13. using System.Web.Mvc;
  14. using Lottomat.Application.Code.Authorize;
  15. namespace Lottomat.Application.Admin.Areas.AuthorizeManage.Controllers
  16. {
  17. /// <summary>
  18. /// 版 本
  19. /// Copyright (c) 2016-2017
  20. /// 创建人:赵轶
  21. /// 日 期:2015.11.2 2:35
  22. /// 描 述:用户权限
  23. /// </summary>
  24. public class PermissionUserController : MvcControllerBase
  25. {
  26. private OrganizeBLL organizeBLL = new OrganizeBLL();
  27. private DepartmentBLL departmentBLL = new DepartmentBLL();
  28. private RoleBLL roleBLL = new RoleBLL();
  29. private UserBLL userBLL = new UserBLL();
  30. private ModuleBLL moduleBLL = new ModuleBLL();
  31. private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL();
  32. private ModuleColumnBLL moduleColumnBLL = new ModuleColumnBLL();
  33. private PermissionBLL permissionBLL = new PermissionBLL();
  34. #region 视图功能
  35. /// <summary>
  36. /// 用户权限
  37. /// </summary>
  38. /// <returns></returns>
  39. [HttpGet]
  40. [HandlerAuthorize(PermissionMode.Enforce)]
  41. public ActionResult AllotAuthorize()
  42. {
  43. return View();
  44. }
  45. #endregion
  46. #region 获取数据
  47. /// <summary>
  48. /// 系统功能列表
  49. /// </summary>
  50. /// <param name="userId">用户Id</param>
  51. /// <returns></returns>
  52. [HttpGet]
  53. public ActionResult ModuleTreeJson(string userId)
  54. {
  55. var existModule = permissionBLL.GetModuleList(userId);
  56. var data = moduleBLL.GetList();
  57. var treeList = new List<TreeEntity>();
  58. foreach (ModuleEntity item in data)
  59. {
  60. TreeEntity tree = new TreeEntity();
  61. bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
  62. tree.id = item.ModuleId;
  63. tree.text = item.FullName;
  64. tree.value = item.ModuleId;
  65. tree.title = "";
  66. tree.checkstate = existModule.Count(t => t.ItemId == item.ModuleId);
  67. tree.showcheck = true;
  68. tree.isexpand = true;
  69. tree.complete = true;
  70. tree.hasChildren = hasChildren;
  71. tree.parentId = item.ParentId;
  72. tree.img = item.Icon;
  73. treeList.Add(tree);
  74. }
  75. return Content(treeList.TreeToJson());
  76. }
  77. /// <summary>
  78. /// 系统按钮列表
  79. /// </summary>
  80. /// <param name="userId">用户Id</param>
  81. /// <returns></returns>
  82. [HttpGet]
  83. public ActionResult ModuleButtonTreeJson(string userId)
  84. {
  85. var existModuleButton = permissionBLL.GetModuleButtonList(userId);
  86. var moduleData = moduleBLL.GetList();
  87. var moduleButtonData = moduleButtonBLL.GetList();
  88. var treeList = new List<TreeEntity>();
  89. foreach (ModuleEntity item in moduleData)
  90. {
  91. TreeEntity tree = new TreeEntity();
  92. tree.id = item.ModuleId;
  93. tree.text = item.FullName;
  94. tree.value = item.ModuleId;
  95. tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleId);
  96. tree.showcheck = true;
  97. tree.isexpand = true;
  98. tree.complete = true;
  99. tree.hasChildren = true;
  100. tree.parentId = item.ParentId;
  101. tree.img = item.Icon;
  102. treeList.Add(tree);
  103. }
  104. foreach (ModuleButtonEntity item in moduleButtonData)
  105. {
  106. TreeEntity tree = new TreeEntity();
  107. bool hasChildren = moduleButtonData.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
  108. tree.id = item.ModuleButtonId;
  109. tree.text = item.FullName;
  110. tree.value = item.ModuleButtonId;
  111. if (item.ParentId == "0")
  112. {
  113. tree.parentId = item.ModuleId;
  114. }
  115. else
  116. {
  117. tree.parentId = item.ParentId;
  118. }
  119. tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleButtonId);
  120. tree.showcheck = true;
  121. tree.isexpand = true;
  122. tree.complete = true;
  123. tree.img = "fa fa-wrench " + item.ModuleId;
  124. tree.hasChildren = hasChildren;
  125. treeList.Add(tree);
  126. }
  127. return Content(treeList.TreeToJson());
  128. }
  129. /// <summary>
  130. /// 系统视图列表
  131. /// </summary>
  132. /// <param name="userId">用户Id</param>
  133. /// <returns></returns>
  134. [HttpGet]
  135. public ActionResult ModuleColumnTreeJson(string userId)
  136. {
  137. var existModuleColumn = permissionBLL.GetModuleColumnList(userId);
  138. var moduleData = moduleBLL.GetList();
  139. var moduleColumnData = moduleColumnBLL.GetList();
  140. var treeList = new List<TreeEntity>();
  141. foreach (ModuleEntity item in moduleData)
  142. {
  143. TreeEntity tree = new TreeEntity();
  144. tree.id = item.ModuleId;
  145. tree.text = item.FullName;
  146. tree.value = item.ModuleId;
  147. tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleId);
  148. tree.showcheck = true;
  149. tree.isexpand = true;
  150. tree.complete = true;
  151. tree.hasChildren = true;
  152. tree.parentId = item.ParentId;
  153. tree.img = item.Icon;
  154. treeList.Add(tree);
  155. }
  156. foreach (ModuleColumnEntity item in moduleColumnData)
  157. {
  158. TreeEntity tree = new TreeEntity();
  159. bool hasChildren = moduleColumnData.Count(t => t.ParentId == item.ModuleColumnId) == 0 ? false : true;
  160. tree.id = item.ModuleColumnId;
  161. tree.text = item.FullName;
  162. tree.value = item.ModuleColumnId;
  163. if (item.ParentId == "0")
  164. {
  165. tree.parentId = item.ModuleId;
  166. }
  167. else
  168. {
  169. tree.parentId = item.ParentId;
  170. }
  171. tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleColumnId);
  172. tree.showcheck = true;
  173. tree.isexpand = true;
  174. tree.complete = true;
  175. tree.img = "fa fa-filter " + item.ModuleId;
  176. tree.hasChildren = hasChildren;
  177. treeList.Add(tree);
  178. }
  179. return Content(treeList.TreeToJson());
  180. }
  181. /// <summary>
  182. /// 数据权限列表
  183. /// </summary>
  184. /// <param name="userId">用户Id</param>
  185. /// <returns></returns>
  186. [HttpGet]
  187. public ActionResult OrganizeTreeJson(string userId)
  188. {
  189. var existAuthorizeData = permissionBLL.GetAuthorizeDataList(userId);
  190. var organizedata = organizeBLL.GetList();
  191. var departmentdata = departmentBLL.GetList();
  192. var treeList = new List<TreeEntity>();
  193. foreach (OrganizeEntity item in organizedata)
  194. {
  195. TreeEntity tree = new TreeEntity();
  196. bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
  197. if (hasChildren == false)
  198. {
  199. hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
  200. if (hasChildren == false)
  201. {
  202. continue;
  203. }
  204. }
  205. tree.id = item.OrganizeId;
  206. tree.text = item.FullName;
  207. tree.value = item.OrganizeId;
  208. tree.parentId = item.ParentId;
  209. if (item.ParentId == "0")
  210. {
  211. tree.img = "fa fa-sitemap";
  212. }
  213. else
  214. {
  215. tree.img = "fa fa-home";
  216. }
  217. tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.OrganizeId);
  218. tree.showcheck = true;
  219. tree.isexpand = true;
  220. tree.complete = true;
  221. tree.hasChildren = hasChildren;
  222. treeList.Add(tree);
  223. }
  224. foreach (DepartmentEntity item in departmentdata)
  225. {
  226. TreeEntity tree = new TreeEntity();
  227. bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
  228. tree.id = item.DepartmentId;
  229. tree.text = item.FullName;
  230. tree.value = item.DepartmentId;
  231. if (item.ParentId == "0")
  232. {
  233. tree.parentId = item.OrganizeId;
  234. }
  235. else
  236. {
  237. tree.parentId = item.ParentId;
  238. }
  239. tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.DepartmentId);
  240. tree.showcheck = true;
  241. tree.isexpand = true;
  242. tree.complete = true;
  243. tree.img = "fa fa-umbrella";
  244. tree.hasChildren = hasChildren;
  245. treeList.Add(tree);
  246. }
  247. int authorizeType = -1;
  248. if (existAuthorizeData.ToList().Count > 0)
  249. {
  250. authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt();
  251. }
  252. var JsonData = new
  253. {
  254. authorizeType = authorizeType,
  255. authorizeData = existAuthorizeData,
  256. treeJson = treeList.TreeToJson(),
  257. };
  258. return Content(JsonData.ToJson());
  259. }
  260. #endregion
  261. #region 提交数据
  262. /// <summary>
  263. /// 保存用户授权
  264. /// </summary>
  265. /// <param name="userId">用户Id</param>
  266. /// <param name="moduleIds">功能Id</param>
  267. /// <param name="moduleButtonIds">按钮Id</param>
  268. /// <param name="moduleColumnIds">视图Id</param>
  269. /// <param name="authorizeDataJson">数据权限</param>
  270. /// <returns></returns>
  271. [HttpPost]
  272. [ValidateAntiForgeryToken]
  273. [AjaxOnly]
  274. public ActionResult SaveAuthorize(string userId, string moduleIds, string moduleButtonIds, string moduleColumnIds, string authorizeDataJson)
  275. {
  276. permissionBLL.SaveAuthorize(AuthorizeTypeEnum.User, userId, moduleIds, moduleButtonIds, moduleColumnIds, authorizeDataJson);
  277. return Success("保存成功。");
  278. }
  279. #endregion
  280. }
  281. }