PermissionJobController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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.12 9:35
  22. /// 描 述:职位权限
  23. /// </summary>
  24. public class PermissionJobController : 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. /// <summary>
  46. /// 职位成员
  47. /// </summary>
  48. /// <returns></returns>
  49. [HttpGet]
  50. [HandlerAuthorize(PermissionMode.Enforce)]
  51. public ActionResult AllotMember()
  52. {
  53. return View();
  54. }
  55. #endregion
  56. #region 获取数据
  57. /// <summary>
  58. /// 用户列表
  59. /// </summary>
  60. /// <param name="departmentId">部门Id</param>
  61. /// <param name="jobId">职位Id</param>
  62. /// <returns></returns>
  63. [HttpGet]
  64. public ActionResult GetUserListJson(string departmentId, string jobId)
  65. {
  66. var existMember = permissionBLL.GetMemberList(jobId);
  67. var userdata = userBLL.GetTable().DataFilter(" departmentid = '" + departmentId + "'");
  68. userdata.Columns.Add("isdefault", Type.GetType("System.Int32"));
  69. foreach (DataRow item in userdata.Rows)
  70. {
  71. string UserId = item["userid"].ToString();
  72. int ischeck = existMember.Count(t => t.UserId == UserId);
  73. item["ischeck"] = ischeck;
  74. if (ischeck > 0)
  75. {
  76. item["isdefault"] = existMember.First(t => t.UserId == UserId).IsDefault;
  77. }
  78. else
  79. {
  80. item["isdefault"] = 0;
  81. }
  82. }
  83. userdata = userdata.DataFilter("", "ischeck desc");
  84. return Content(userdata.ToJson());
  85. }
  86. /// <summary>
  87. /// 系统功能列表
  88. /// </summary>
  89. /// <param name="jobId">职位Id</param>
  90. /// <returns></returns>
  91. [HttpGet]
  92. public ActionResult ModuleTreeJson(string jobId)
  93. {
  94. var existModule = permissionBLL.GetModuleList(jobId);
  95. var data = moduleBLL.GetList();
  96. var treeList = new List<TreeEntity>();
  97. foreach (ModuleEntity item in data)
  98. {
  99. TreeEntity tree = new TreeEntity();
  100. bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
  101. tree.id = item.ModuleId;
  102. tree.text = item.FullName;
  103. tree.value = item.ModuleId;
  104. tree.title = "";
  105. tree.checkstate = existModule.Count(t => t.ItemId == item.ModuleId);
  106. tree.showcheck = true;
  107. tree.isexpand = true;
  108. tree.complete = true;
  109. tree.hasChildren = hasChildren;
  110. tree.parentId = item.ParentId;
  111. tree.img = item.Icon;
  112. treeList.Add(tree);
  113. }
  114. return Content(treeList.TreeToJson());
  115. }
  116. /// <summary>
  117. /// 系统按钮列表
  118. /// </summary>
  119. /// <param name="jobId">职位Id</param>
  120. /// <returns></returns>
  121. [HttpGet]
  122. public ActionResult ModuleButtonTreeJson(string jobId)
  123. {
  124. var existModuleButton = permissionBLL.GetModuleButtonList(jobId);
  125. var moduleData = moduleBLL.GetList();
  126. var moduleButtonData = moduleButtonBLL.GetList();
  127. var treeList = new List<TreeEntity>();
  128. foreach (ModuleEntity item in moduleData)
  129. {
  130. TreeEntity tree = new TreeEntity();
  131. tree.id = item.ModuleId;
  132. tree.text = item.FullName;
  133. tree.value = item.ModuleId;
  134. tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleId);
  135. tree.showcheck = true;
  136. tree.isexpand = true;
  137. tree.complete = true;
  138. tree.hasChildren = true;
  139. tree.parentId = item.ParentId;
  140. tree.img = item.Icon;
  141. treeList.Add(tree);
  142. }
  143. foreach (ModuleButtonEntity item in moduleButtonData)
  144. {
  145. TreeEntity tree = new TreeEntity();
  146. bool hasChildren = moduleButtonData.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
  147. tree.id = item.ModuleButtonId;
  148. tree.text = item.FullName;
  149. tree.value = item.ModuleButtonId;
  150. if (item.ParentId == "0")
  151. {
  152. tree.parentId = item.ModuleId;
  153. }
  154. else
  155. {
  156. tree.parentId = item.ParentId;
  157. }
  158. tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleButtonId);
  159. tree.showcheck = true;
  160. tree.isexpand = true;
  161. tree.complete = true;
  162. tree.img = "fa fa-wrench " + item.ModuleId;
  163. tree.hasChildren = hasChildren;
  164. treeList.Add(tree);
  165. }
  166. return Content(treeList.TreeToJson());
  167. }
  168. /// <summary>
  169. /// 系统视图列表
  170. /// </summary>
  171. /// <param name="jobId">职位Id</param>
  172. /// <returns></returns>
  173. [HttpGet]
  174. public ActionResult ModuleColumnTreeJson(string jobId)
  175. {
  176. var existModuleColumn = permissionBLL.GetModuleColumnList(jobId);
  177. var moduleData = moduleBLL.GetList();
  178. var moduleColumnData = moduleColumnBLL.GetList();
  179. var treeList = new List<TreeEntity>();
  180. foreach (ModuleEntity item in moduleData)
  181. {
  182. TreeEntity tree = new TreeEntity();
  183. tree.id = item.ModuleId;
  184. tree.text = item.FullName;
  185. tree.value = item.ModuleId;
  186. tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleId);
  187. tree.showcheck = true;
  188. tree.isexpand = true;
  189. tree.complete = true;
  190. tree.hasChildren = true;
  191. tree.parentId = item.ParentId;
  192. tree.img = item.Icon;
  193. treeList.Add(tree);
  194. }
  195. foreach (ModuleColumnEntity item in moduleColumnData)
  196. {
  197. TreeEntity tree = new TreeEntity();
  198. bool hasChildren = moduleColumnData.Count(t => t.ParentId == item.ModuleColumnId) == 0 ? false : true;
  199. tree.id = item.ModuleColumnId;
  200. tree.text = item.FullName;
  201. tree.value = item.ModuleColumnId;
  202. if (item.ParentId == "0")
  203. {
  204. tree.parentId = item.ModuleId;
  205. }
  206. else
  207. {
  208. tree.parentId = item.ParentId;
  209. }
  210. tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleColumnId);
  211. tree.showcheck = true;
  212. tree.isexpand = true;
  213. tree.complete = true;
  214. tree.img = "fa fa-filter " + item.ModuleId;
  215. tree.hasChildren = hasChildren;
  216. treeList.Add(tree);
  217. }
  218. return Content(treeList.TreeToJson());
  219. }
  220. /// <summary>
  221. /// 数据权限列表
  222. /// </summary>
  223. /// <param name="jobId">职位Id</param>
  224. /// <returns></returns>
  225. [HttpGet]
  226. public ActionResult OrganizeTreeJson(string jobId)
  227. {
  228. var existAuthorizeData = permissionBLL.GetAuthorizeDataList(jobId);
  229. var organizedata = organizeBLL.GetList();
  230. var departmentdata = departmentBLL.GetList();
  231. var treeList = new List<TreeEntity>();
  232. foreach (OrganizeEntity item in organizedata)
  233. {
  234. TreeEntity tree = new TreeEntity();
  235. bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
  236. if (hasChildren == false)
  237. {
  238. hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
  239. if (hasChildren == false)
  240. {
  241. continue;
  242. }
  243. }
  244. tree.id = item.OrganizeId;
  245. tree.text = item.FullName;
  246. tree.value = item.OrganizeId;
  247. tree.parentId = item.ParentId;
  248. if (item.ParentId == "0")
  249. {
  250. tree.img = "fa fa-sitemap";
  251. }
  252. else
  253. {
  254. tree.img = "fa fa-home";
  255. }
  256. tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.OrganizeId);
  257. tree.showcheck = true;
  258. tree.isexpand = true;
  259. tree.complete = true;
  260. tree.hasChildren = hasChildren;
  261. treeList.Add(tree);
  262. }
  263. foreach (DepartmentEntity item in departmentdata)
  264. {
  265. TreeEntity tree = new TreeEntity();
  266. bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
  267. tree.id = item.DepartmentId;
  268. tree.text = item.FullName;
  269. tree.value = item.DepartmentId;
  270. if (item.ParentId == "0")
  271. {
  272. tree.parentId = item.OrganizeId;
  273. }
  274. else
  275. {
  276. tree.parentId = item.ParentId;
  277. }
  278. tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.DepartmentId);
  279. tree.showcheck = true;
  280. tree.isexpand = true;
  281. tree.complete = true;
  282. tree.img = "fa fa-umbrella";
  283. tree.hasChildren = hasChildren;
  284. treeList.Add(tree);
  285. }
  286. int authorizeType = -1;
  287. if (existAuthorizeData.ToList().Count > 0)
  288. {
  289. authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt();
  290. }
  291. var JsonData = new
  292. {
  293. authorizeType = authorizeType,
  294. authorizeData = existAuthorizeData,
  295. treeJson = treeList.TreeToJson(),
  296. };
  297. return Content(JsonData.ToJson());
  298. }
  299. #endregion
  300. #region 提交数据
  301. /// <summary>
  302. /// 保存职位成员
  303. /// </summary>
  304. /// <param name="jobId">职位Id</param>
  305. /// <param name="userIds">成员Id</param>
  306. /// <returns></returns>
  307. [HttpPost]
  308. [ValidateAntiForgeryToken]
  309. [AjaxOnly]
  310. public ActionResult SaveMember(string jobId, string userIds)
  311. {
  312. permissionBLL.SaveMember(AuthorizeTypeEnum.Job, jobId, userIds);
  313. return Success("保存成功。");
  314. }
  315. /// <summary>
  316. /// 保存职位授权
  317. /// </summary>
  318. /// <param name="jobId">职位Id</param>
  319. /// <param name="moduleIds">功能Id</param>
  320. /// <param name="moduleButtonIds">按钮Id</param>
  321. /// <param name="moduleColumnIds">视图Id</param>
  322. /// <param name="authorizeDataJson">数据权限</param>
  323. /// <returns></returns>
  324. [HttpPost]
  325. [ValidateAntiForgeryToken]
  326. [AjaxOnly]
  327. public ActionResult SaveAuthorize(string jobId, string moduleIds, string moduleButtonIds, string moduleColumnIds, string authorizeDataJson)
  328. {
  329. permissionBLL.SaveAuthorize(AuthorizeTypeEnum.Job, jobId, moduleIds, moduleButtonIds, moduleColumnIds, authorizeDataJson);
  330. return Success("保存成功。");
  331. }
  332. #endregion
  333. }
  334. }