using LeaRun.Application.Busines.AuthorizeManage; using LeaRun.Application.Busines.BaseManage; using LeaRun.Application.Cache; using LeaRun.Application.Code; using LeaRun.Application.Entity.AuthorizeManage; using LeaRun.Application.Entity.BaseManage; using LeaRun.Util; 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.BaseManage.Controllers { /// /// 版 本 /// Copyright (c) 2013-2016 上海力软信息技术有限公司 /// 创建人:佘赐雄 /// 日 期:2015.11.03 10:58 /// 描 述:用户管理 /// public class UserController : MvcControllerBase { private UserBLL userBLL = new UserBLL(); private UserCache userCache = new UserCache(); private OrganizeBLL organizeBLL = new OrganizeBLL(); private OrganizeCache organizeCache = new OrganizeCache(); private DepartmentBLL departmentBLL = new DepartmentBLL(); private DepartmentCache departmentCache = new DepartmentCache(); private ModuleFormInstanceBLL moduleFormInstanceBll = new ModuleFormInstanceBLL(); #region 视图功能 /// /// 用户管理 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Index() { return View(); } /// /// 用户表单 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Form() { return View(); } /// /// 重置密码 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult RevisePassword() { return View(); } #endregion #region 获取数据 /// /// 用户列表 /// /// 关键字 /// 返回机构+部门+用户树形Json [HttpGet] public ActionResult GetTreeJson(string keyword) { var organizedata = organizeCache.GetList(); var departmentdata = departmentCache.GetList(); var userdata = userCache.GetList(); var treeList = new List(); foreach (OrganizeEntity item in organizedata) { #region 机构 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; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; tree.Attribute = "Sort"; tree.AttributeValue = "Organize"; treeList.Add(tree); #endregion } foreach (DepartmentEntity item in departmentdata) { #region 部门 TreeEntity tree = new TreeEntity(); 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.isexpand = true; tree.complete = true; tree.hasChildren = true; tree.Attribute = "Sort"; tree.AttributeValue = "Department"; treeList.Add(tree); #endregion } foreach (UserEntity item in userdata) { #region 用户 TreeEntity tree = new TreeEntity(); tree.id = item.UserId; tree.text = item.RealName; tree.value = item.Account; tree.parentId = item.DepartmentId; tree.title = item.RealName + "(" + item.Account + ")"; tree.isexpand = true; tree.complete = true; tree.hasChildren = false; tree.Attribute = "Sort"; tree.AttributeValue = "User"; tree.img = "fa fa-user"; treeList.Add(tree); #endregion } if (!string.IsNullOrEmpty(keyword)) { treeList = treeList.TreeWhere(t => t.text.Contains(keyword), "id", "parentId"); } return Content(treeList.TreeToJson()); } /// /// 用户列表 /// /// 部门Id /// 返回用户列表Json [HttpGet] public ActionResult GetListJson(string departmentId) { var data = userCache.GetList(departmentId); return Content(data.ToJson()); } /// /// 用户列表 /// /// 分页参数 /// 查询参数 /// 返回分页列表Json [HttpGet] public ActionResult GetPageListJson(Pagination pagination, string queryJson) { var watch = CommonHelper.TimerStart(); var data = userBLL.GetPageList(pagination, queryJson); var JsonData = new { rows = data, total = pagination.total, page = pagination.page, records = pagination.records, costtime = CommonHelper.TimerEnd(watch) }; return Content(JsonData.ToJson()); } /// /// 用户实体 /// /// 主键值 /// 返回对象Json [HttpGet] public ActionResult GetFormJson(string keyValue) { var data = userBLL.GetEntity(keyValue); return Content(data.ToJson()); } #endregion #region 验证数据 /// /// 账户不能重复 /// /// 账户值 /// 主键 /// [HttpGet] public ActionResult ExistAccount(string Account, string keyValue) { bool IsOk = userBLL.ExistAccount(Account, keyValue); return Content(IsOk.ToString()); } #endregion #region 提交数据 /// /// 删除用户 /// /// 主键值 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult RemoveForm(string keyValue) { if (keyValue == "100000") { throw new Exception("当前账户不能删除"); } userBLL.RemoveForm(keyValue); return Success("删除成功。"); } /// /// 保存用户表单(新增、修改) /// /// 主键值 /// 用户实体 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, string strUserEntity, string FormInstanceId, string strModuleFormInstanceEntity) { UserEntity userEntity = strUserEntity.ToObject(); ModuleFormInstanceEntity moduleFormInstanceEntity = strModuleFormInstanceEntity.ToObject(); userEntity.CreateUserId = SystemInfo.CurrentUserId; string objectId = userBLL.SaveForm(keyValue, userEntity); moduleFormInstanceEntity.ObjectId = objectId; moduleFormInstanceBll.SaveEntity(FormInstanceId, moduleFormInstanceEntity); return Success("操作成功。"); } /// /// 保存重置修改密码 /// /// 主键值 /// 新密码 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveRevisePassword(string keyValue, string Password) { if (keyValue == "100000") { throw new Exception("当前账户不能重置密码"); } userBLL.RevisePassword(keyValue, Password); return Success("密码修改成功,请牢记新密码。"); } /// /// 禁用账户 /// /// 主键值 /// [HttpPost] [AjaxOnly] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult DisabledAccount(string keyValue) { if (keyValue == "100000") { throw new Exception("当前账户不禁用"); } userBLL.UpdateState(keyValue, 0); return Success("账户禁用成功。"); } /// /// 启用账户 /// /// 主键值 /// [HttpPost] [AjaxOnly] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult EnabledAccount(string keyValue) { userBLL.UpdateState(keyValue, 1); return Success("账户启用成功。"); } #endregion #region 数据导出 /// /// 导出用户列表 /// /// public ActionResult ExportUserList() { userBLL.GetExportList(); return Success("导出成功。"); } #endregion } }