123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- using LeaRun.Application.Busines.AuthorizeManage;
- using LeaRun.Application.Busines.BaseManage;
- using LeaRun.Application.Code;
- using LeaRun.Application.Entity.AuthorizeManage;
- using LeaRun.Application.Entity.BaseManage;
- using LeaRun.Util;
- using LeaRun.Util.Extension;
- using LeaRun.Util.WebControl;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web.Mvc;
- namespace LeaRun.Application.Web.Areas.AuthorizeManage.Controllers
- {
- /// <summary>
- /// 版 本
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:佘赐雄
- /// 日 期:2015.11.2 2:35
- /// 描 述:用户权限
- /// </summary>
- public class PermissionUserController : MvcControllerBase
- {
- private OrganizeBLL organizeBLL = new OrganizeBLL();
- private DepartmentBLL departmentBLL = new DepartmentBLL();
- private RoleBLL roleBLL = new RoleBLL();
- private UserBLL userBLL = new UserBLL();
- private ModuleBLL moduleBLL = new ModuleBLL();
- private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL();
- private ModuleColumnBLL moduleColumnBLL = new ModuleColumnBLL();
- private PermissionBLL permissionBLL = new PermissionBLL();
- private AuthorizeBLL authorizeBll = new AuthorizeBLL();
- #region 视图功能
- /// <summary>
- /// 用户权限
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult AllotAuthorize()
- {
- return View();
- }
- #endregion
- #region 获取数据
- /// <summary>
- /// 系统功能列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ModuleTreeJson(string userId)
- {
- var existModule = permissionBLL.GetModuleListN(userId);
- //var data = moduleBLL.GetList();
- var data = authorizeBll.GetModuleListN(SystemInfo.CurrentUserId);
- var treeList = new List<TreeEntity>();
- foreach (ModuleEntity item in data)
- {
- TreeEntity tree = new TreeEntity();
- bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
- tree.id = item.ModuleId;
- tree.text = item.FullName;
- tree.value = item.ModuleId;
- tree.title = "";
- tree.checkstate = existModule.Count(t => t.ItemId == item.ModuleId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.hasChildren = hasChildren;
- tree.parentId = item.ParentId;
- tree.img = item.Icon;
- treeList.Add(tree);
- }
- return Content(treeList.TreeToJson());
- }
- /// <summary>
- /// 系统按钮列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ModuleButtonTreeJson(string userId)
- {
- var existModuleButton = permissionBLL.GetModuleButtonList(userId);
- var moduleData = moduleBLL.GetList();
- var moduleButtonData = moduleButtonBLL.GetList();
- var treeList = new List<TreeEntity>();
- foreach (ModuleEntity item in moduleData)
- {
- TreeEntity tree = new TreeEntity();
- tree.id = item.ModuleId;
- tree.text = item.FullName;
- tree.value = item.ModuleId;
- tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.hasChildren = true;
- tree.parentId = item.ParentId;
- tree.img = item.Icon;
- treeList.Add(tree);
- }
- foreach (ModuleButtonEntity item in moduleButtonData)
- {
- TreeEntity tree = new TreeEntity();
- bool hasChildren = moduleButtonData.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
- tree.id = item.ModuleButtonId;
- tree.text = item.FullName;
- tree.value = item.ModuleButtonId;
- if (item.ParentId == "0")
- {
- tree.parentId = item.ModuleId;
- }
- else
- {
- tree.parentId = item.ParentId;
- }
- tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleButtonId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.img = "fa fa-wrench " + item.ModuleId;
- tree.hasChildren = hasChildren;
- treeList.Add(tree);
- }
- return Content(treeList.TreeToJson());
- }
- /// <summary>
- /// 系统视图列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ModuleColumnTreeJson(string userId)
- {
- var existModuleColumn = permissionBLL.GetModuleColumnList(userId);
- var moduleData = moduleBLL.GetList();
- var moduleColumnData = moduleColumnBLL.GetList();
- var treeList = new List<TreeEntity>();
- foreach (ModuleEntity item in moduleData)
- {
- TreeEntity tree = new TreeEntity();
- tree.id = item.ModuleId;
- tree.text = item.FullName;
- tree.value = item.ModuleId;
- tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.hasChildren = true;
- tree.parentId = item.ParentId;
- tree.img = item.Icon;
- treeList.Add(tree);
- }
- foreach (ModuleColumnEntity item in moduleColumnData)
- {
- TreeEntity tree = new TreeEntity();
- bool hasChildren = moduleColumnData.Count(t => t.ParentId == item.ModuleColumnId) == 0 ? false : true;
- tree.id = item.ModuleColumnId;
- tree.text = item.FullName;
- tree.value = item.ModuleColumnId;
- if (item.ParentId == "0")
- {
- tree.parentId = item.ModuleId;
- }
- else
- {
- tree.parentId = item.ParentId;
- }
- tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleColumnId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.img = "fa fa-filter " + item.ModuleId;
- tree.hasChildren = hasChildren;
- treeList.Add(tree);
- }
- return Content(treeList.TreeToJson());
- }
- /// <summary>
- /// 数据权限列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult OrganizeTreeJson(string userId)
- {
- var existAuthorizeData = permissionBLL.GetAuthorizeDataList(userId);
- var organizedata = organizeBLL.GetList();
- var departmentdata = departmentBLL.GetList();
- var treeList = new List<TreeEntity>();
- foreach (OrganizeEntity item in organizedata)
- {
- TreeEntity tree = new TreeEntity();
- bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
- if (hasChildren == false)
- {
- hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
- if (hasChildren == false)
- {
- continue;
- }
- }
- tree.id = item.OrganizeId;
- tree.text = item.FullName;
- tree.value = item.OrganizeId;
- tree.parentId = item.ParentId;
- if (item.ParentId == "0")
- {
- tree.img = "fa fa-sitemap";
- }
- else
- {
- tree.img = "fa fa-home";
- }
- tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.OrganizeId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.hasChildren = hasChildren;
- treeList.Add(tree);
- }
- foreach (DepartmentEntity item in departmentdata)
- {
- TreeEntity tree = new TreeEntity();
- bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
- tree.id = item.DepartmentId;
- tree.text = item.FullName;
- tree.value = item.DepartmentId;
- if (item.ParentId == "0")
- {
- tree.parentId = item.OrganizeId;
- }
- else
- {
- tree.parentId = item.ParentId;
- }
- tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.DepartmentId);
- tree.showcheck = true;
- tree.isexpand = true;
- tree.complete = true;
- tree.img = "fa fa-umbrella";
- tree.hasChildren = hasChildren;
- treeList.Add(tree);
- }
- int authorizeType = -1;
- if (existAuthorizeData.ToList().Count > 0)
- {
- authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt();
- }
- var JsonData = new
- {
- authorizeType = authorizeType,
- authorizeData = existAuthorizeData,
- treeJson = treeList.TreeToJson(),
- };
- return Content(JsonData.ToJson());
- }
- #endregion
- #region 提交数据
- /// <summary>
- /// 保存用户授权
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <param name="moduleIds">功能Id</param>
- /// <param name="moduleButtonIds">按钮Id</param>
- /// <param name="moduleColumnIds">视图Id</param>
- /// <param name="authorizeDataJson">数据权限</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- public ActionResult SaveAuthorize(string userId, string moduleIds, string moduleButtonIds, string moduleColumnIds, string authorizeDataJson)
- {
- permissionBLL.SaveAuthorize(AuthorizeTypeEnum.User, userId, moduleIds, moduleButtonIds, moduleColumnIds, authorizeDataJson);
- return Success("保存成功。");
- }
- #endregion
- }
- }
|