PermissionUserController.cs 11 KB

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