PermissionUserGroupController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. using LeaRun.Application.Busines.AuthorizeManage;
  2. using LeaRun.Application.Busines.BaseManage;
  3. using LeaRun.Application.Cache;
  4. using LeaRun.Application.Code;
  5. using LeaRun.Application.Entity.AuthorizeManage;
  6. using LeaRun.Application.Entity.BaseManage;
  7. using LeaRun.Util;
  8. using LeaRun.Util.Extension;
  9. using LeaRun.Util.WebControl;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Linq;
  14. using System.Web.Mvc;
  15. namespace LeaRun.Application.Web.Areas.AuthorizeManage.Controllers
  16. {
  17. /// <summary>
  18. /// 版 本
  19. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  20. /// 创建人:佘赐雄
  21. /// 日 期:2015.11.1 1:35
  22. /// 描 述:用户组权限
  23. /// </summary>
  24. public class PermissionUserGroupController : MvcControllerBase
  25. {
  26. private OrganizeBLL organizeBLL = new OrganizeBLL();
  27. private DepartmentBLL departmentBLL = new DepartmentBLL();
  28. private DepartmentCache departmentCache = new DepartmentCache();
  29. private RoleBLL roleBLL = new RoleBLL();
  30. private UserBLL userBLL = new UserBLL();
  31. private ModuleBLL moduleBLL = new ModuleBLL();
  32. private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL();
  33. private ModuleColumnBLL moduleColumnBLL = new ModuleColumnBLL();
  34. private PermissionBLL permissionBLL = new PermissionBLL();
  35. #region 视图功能
  36. /// <summary>
  37. /// 用户组权限
  38. /// </summary>
  39. /// <returns></returns>
  40. [HttpGet]
  41. [HandlerAuthorize(PermissionMode.Enforce)]
  42. public ActionResult AllotAuthorize()
  43. {
  44. return View();
  45. }
  46. /// <summary>
  47. /// 用户组成员
  48. /// </summary>
  49. /// <returns></returns>
  50. [HttpGet]
  51. [HandlerAuthorize(PermissionMode.Enforce)]
  52. public ActionResult AllotMember()
  53. {
  54. return View();
  55. }
  56. #endregion
  57. #region 获取数据
  58. /// <summary>
  59. /// 部门列表
  60. /// </summary>
  61. /// <param name="userGroupId">用户组Id</param>
  62. /// <param name="keyword">关键字</param>
  63. /// <returns>返回树形Json</returns>
  64. [HttpGet]
  65. public ActionResult GetDepartmentTreeJson(string userGroupId)
  66. {
  67. var roleEntity = roleBLL.GetEntity(userGroupId);
  68. var organizeEntity = organizeBLL.GetEntity(roleEntity.OrganizeId);
  69. var data = departmentCache.GetList(roleEntity.OrganizeId);
  70. var treeList = new List<TreeEntity>();
  71. TreeEntity tree = new TreeEntity();
  72. tree.id = organizeEntity.OrganizeId;
  73. tree.text = organizeEntity.FullName;
  74. tree.value = organizeEntity.OrganizeId;
  75. tree.isexpand = true;
  76. tree.complete = true;
  77. tree.hasChildren = true;
  78. tree.parentId = "0";
  79. treeList.Add(tree);
  80. foreach (DepartmentEntity item in data)
  81. {
  82. tree = new TreeEntity();
  83. bool hasChildren = data.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
  84. tree.id = item.DepartmentId;
  85. tree.text = item.FullName;
  86. tree.value = item.DepartmentId;
  87. if (item.ParentId == "0")
  88. {
  89. tree.parentId = roleEntity.OrganizeId;
  90. }
  91. else
  92. {
  93. tree.parentId = item.ParentId;
  94. }
  95. tree.isexpand = true;
  96. tree.complete = true;
  97. tree.hasChildren = hasChildren;
  98. treeList.Add(tree);
  99. }
  100. return Content(treeList.TreeToJson());
  101. }
  102. /// <summary>
  103. /// 用户列表
  104. /// </summary>
  105. /// <param name="userGroupId">用户组Id</param>
  106. /// <returns></returns>
  107. [HttpGet]
  108. public ActionResult GetUserListJson(string userGroupId)
  109. {
  110. var existMember = permissionBLL.GetMemberList(userGroupId);
  111. var userdata = userBLL.GetTable();
  112. userdata.Columns.Add("ischeck", Type.GetType("System.Int32"));//自定义添加一列 判断是否勾选
  113. foreach (DataRow item in userdata.Rows)
  114. {
  115. string UserId = item["userid"].ToString();
  116. item["ischeck"] = existMember.Count(t => t.UserId == UserId);
  117. }
  118. userdata = DataHelper.DataFilter(userdata, "", "ischeck desc");
  119. return Content(userdata.ToJson());
  120. }
  121. /// <summary>
  122. /// 系统功能列表
  123. /// </summary>
  124. /// <param name="RoleId">用户组Id</param>
  125. /// <returns></returns>
  126. [HttpGet]
  127. public ActionResult ModuleTreeJson(string userGroupId)
  128. {
  129. var existModule = permissionBLL.GetModuleList(userGroupId);
  130. var data = moduleBLL.GetList();
  131. var treeList = new List<TreeEntity>();
  132. foreach (ModuleEntity item in data)
  133. {
  134. TreeEntity tree = new TreeEntity();
  135. bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
  136. tree.id = item.ModuleId;
  137. tree.text = item.FullName;
  138. tree.value = item.ModuleId;
  139. tree.title = "";
  140. tree.checkstate = existModule.Count(t => t.ItemId == item.ModuleId);
  141. tree.showcheck = true;
  142. tree.isexpand = true;
  143. tree.complete = true;
  144. tree.hasChildren = hasChildren;
  145. tree.parentId = item.ParentId;
  146. tree.img = item.Icon;
  147. treeList.Add(tree);
  148. }
  149. return Content(treeList.TreeToJson());
  150. }
  151. /// <summary>
  152. /// 系统按钮列表
  153. /// </summary>
  154. /// <param name="userGroupId">用户组Id</param>
  155. /// <returns></returns>
  156. [HttpGet]
  157. public ActionResult ModuleButtonTreeJson(string userGroupId)
  158. {
  159. var existModuleButton = permissionBLL.GetModuleButtonList(userGroupId);
  160. var moduleData = moduleBLL.GetList();
  161. var moduleButtonData = moduleButtonBLL.GetList();
  162. var treeList = new List<TreeEntity>();
  163. foreach (ModuleEntity item in moduleData)
  164. {
  165. TreeEntity tree = new TreeEntity();
  166. tree.id = item.ModuleId;
  167. tree.text = item.FullName;
  168. tree.value = item.ModuleId;
  169. tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleId);
  170. tree.showcheck = true;
  171. tree.isexpand = true;
  172. tree.complete = true;
  173. tree.hasChildren = true;
  174. tree.parentId = item.ParentId;
  175. tree.img = item.Icon;
  176. treeList.Add(tree);
  177. }
  178. foreach (ModuleButtonEntity item in moduleButtonData)
  179. {
  180. TreeEntity tree = new TreeEntity();
  181. bool hasChildren = moduleButtonData.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
  182. tree.id = item.ModuleButtonId;
  183. tree.text = item.FullName;
  184. tree.value = item.ModuleButtonId;
  185. if (item.ParentId == "0")
  186. {
  187. tree.parentId = item.ModuleId;
  188. }
  189. else
  190. {
  191. tree.parentId = item.ParentId;
  192. }
  193. tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleButtonId);
  194. tree.showcheck = true;
  195. tree.isexpand = true;
  196. tree.complete = true;
  197. tree.img = "fa fa-wrench " + item.ModuleId;
  198. tree.hasChildren = hasChildren;
  199. treeList.Add(tree);
  200. }
  201. return Content(treeList.TreeToJson());
  202. }
  203. /// <summary>
  204. /// 系统视图列表
  205. /// </summary>
  206. /// <param name="userGroupId">用户组Id</param>
  207. /// <returns></returns>
  208. [HttpGet]
  209. public ActionResult ModuleColumnTreeJson(string userGroupId)
  210. {
  211. var existModuleColumn = permissionBLL.GetModuleColumnList(userGroupId);
  212. var moduleData = moduleBLL.GetList();
  213. var moduleColumnData = moduleColumnBLL.GetList();
  214. var treeList = new List<TreeEntity>();
  215. foreach (ModuleEntity item in moduleData)
  216. {
  217. TreeEntity tree = new TreeEntity();
  218. tree.id = item.ModuleId;
  219. tree.text = item.FullName;
  220. tree.value = item.ModuleId;
  221. tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleId);
  222. tree.showcheck = true;
  223. tree.isexpand = true;
  224. tree.complete = true;
  225. tree.hasChildren = true;
  226. tree.parentId = item.ParentId;
  227. tree.img = item.Icon;
  228. treeList.Add(tree);
  229. }
  230. foreach (ModuleColumnEntity item in moduleColumnData)
  231. {
  232. TreeEntity tree = new TreeEntity();
  233. bool hasChildren = moduleColumnData.Count(t => t.ParentId == item.ModuleColumnId) == 0 ? false : true;
  234. tree.id = item.ModuleColumnId;
  235. tree.text = item.FullName;
  236. tree.value = item.ModuleColumnId;
  237. if (item.ParentId == "0")
  238. {
  239. tree.parentId = item.ModuleId;
  240. }
  241. else
  242. {
  243. tree.parentId = item.ParentId;
  244. }
  245. tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleColumnId);
  246. tree.showcheck = true;
  247. tree.isexpand = true;
  248. tree.complete = true;
  249. tree.img = "fa fa-filter " + item.ModuleId;
  250. tree.hasChildren = hasChildren;
  251. treeList.Add(tree);
  252. }
  253. return Content(treeList.TreeToJson());
  254. }
  255. /// <summary>
  256. /// 数据权限列表
  257. /// </summary>
  258. /// <param name="userGroupId">用户组Id</param>
  259. /// <returns></returns>
  260. [HttpGet]
  261. public ActionResult OrganizeTreeJson(string userGroupId)
  262. {
  263. var existAuthorizeData = permissionBLL.GetAuthorizeDataList(userGroupId);
  264. var organizedata = organizeBLL.GetList();
  265. var departmentdata = departmentCache.GetList();
  266. var treeList = new List<TreeEntity>();
  267. foreach (OrganizeEntity item in organizedata)
  268. {
  269. TreeEntity tree = new TreeEntity();
  270. bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
  271. if (hasChildren == false)
  272. {
  273. hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
  274. if (hasChildren == false)
  275. {
  276. continue;
  277. }
  278. }
  279. tree.id = item.OrganizeId;
  280. tree.text = item.FullName;
  281. tree.value = item.OrganizeId;
  282. tree.parentId = item.ParentId;
  283. if (item.ParentId == "0")
  284. {
  285. tree.img = "fa fa-sitemap";
  286. }
  287. else
  288. {
  289. tree.img = "fa fa-home";
  290. }
  291. tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.OrganizeId);
  292. tree.showcheck = true;
  293. tree.isexpand = true;
  294. tree.complete = true;
  295. tree.hasChildren = hasChildren;
  296. treeList.Add(tree);
  297. }
  298. foreach (DepartmentEntity item in departmentdata)
  299. {
  300. TreeEntity tree = new TreeEntity();
  301. bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
  302. tree.id = item.DepartmentId;
  303. tree.text = item.FullName;
  304. tree.value = item.DepartmentId;
  305. if (item.ParentId == "0")
  306. {
  307. tree.parentId = item.OrganizeId;
  308. }
  309. else
  310. {
  311. tree.parentId = item.ParentId;
  312. }
  313. tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.DepartmentId);
  314. tree.showcheck = true;
  315. tree.isexpand = true;
  316. tree.complete = true;
  317. tree.img = "fa fa-umbrella";
  318. tree.hasChildren = hasChildren;
  319. treeList.Add(tree);
  320. }
  321. int authorizeType = -1;
  322. if (existAuthorizeData.ToList().Count > 0)
  323. {
  324. authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt();
  325. }
  326. var JsonData = new
  327. {
  328. authorizeType = authorizeType,
  329. authorizeData = existAuthorizeData,
  330. treeJson = treeList.TreeToJson(),
  331. };
  332. return Content(JsonData.ToJson());
  333. }
  334. #endregion
  335. #region 提交数据
  336. /// <summary>
  337. /// 保存用户组成员
  338. /// </summary>
  339. /// <param name="userGroupId">用户组Id</param>
  340. /// <param name="userIds">成员Id</param>
  341. /// <returns></returns>
  342. [HttpPost]
  343. [ValidateAntiForgeryToken]
  344. [AjaxOnly]
  345. public ActionResult SaveMember(string userGroupId, string userIds)
  346. {
  347. permissionBLL.SaveMember(AuthorizeTypeEnum.UserGroup, userGroupId, userIds);
  348. return Success("保存成功。");
  349. }
  350. /// <summary>
  351. /// 保存用户组授权
  352. /// </summary>
  353. /// <param name="userGroupId">用户组Id</param>
  354. /// <param name="moduleIds">功能Id</param>
  355. /// <param name="moduleButtonIds">按钮Id</param>
  356. /// <param name="moduleColumnIds">视图Id</param>
  357. /// <param name="authorizeDataJson">数据权限</param>
  358. /// <returns></returns>
  359. [HttpPost]
  360. [ValidateAntiForgeryToken]
  361. [AjaxOnly]
  362. public ActionResult SaveAuthorize(string userGroupId, string moduleIds, string moduleButtonIds, string moduleColumnIds, string authorizeDataJson)
  363. {
  364. permissionBLL.SaveAuthorize(AuthorizeTypeEnum.UserGroup, userGroupId, moduleIds, moduleButtonIds, moduleColumnIds, authorizeDataJson);
  365. return Success("保存成功。");
  366. }
  367. #endregion
  368. }
  369. }