123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- 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
- {
- /// <summary>
- /// 版 本
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:佘赐雄
- /// 日 期:2015.11.03 10:58
- /// 描 述:用户管理
- /// </summary>
- 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 视图功能
- /// <summary>
- /// 用户管理
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// 用户表单
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult Form()
- {
- return View();
- }
- /// <summary>
- /// 重置密码
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult RevisePassword()
- {
- return View();
- }
- #endregion
- #region 获取数据
- /// <summary>
- /// 用户列表
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns>返回机构+部门+用户树形Json</returns>
- [HttpGet]
- public ActionResult GetTreeJson(string keyword)
- {
- var organizedata = organizeCache.GetList();
- var departmentdata = departmentCache.GetList();
- var userdata = userCache.GetList();
- var treeList = new List<TreeEntity>();
- 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());
- }
- /// <summary>
- /// 用户列表
- /// </summary>
- /// <param name="departmentId">部门Id</param>
- /// <returns>返回用户列表Json</returns>
- [HttpGet]
- public ActionResult GetListJson(string departmentId)
- {
- var data = userCache.GetList(departmentId);
- return Content(data.ToJson());
- }
- /// <summary>
- /// 用户列表
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns>返回分页列表Json</returns>
- [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());
- }
- /// <summary>
- /// 用户实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns>返回对象Json</returns>
- [HttpGet]
- public ActionResult GetFormJson(string keyValue)
- {
- var data = userBLL.GetEntity(keyValue);
- return Content(data.ToJson());
- }
- #endregion
- #region 验证数据
- /// <summary>
- /// 账户不能重复
- /// </summary>
- /// <param name="Account">账户值</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ExistAccount(string Account, string keyValue)
- {
- bool IsOk = userBLL.ExistAccount(Account, keyValue);
- return Content(IsOk.ToString());
- }
- #endregion
- #region 提交数据
- /// <summary>
- /// 删除用户
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult RemoveForm(string keyValue)
- {
- if (keyValue == "100000")
- {
- throw new Exception("当前账户不能删除");
- }
- userBLL.RemoveForm(keyValue);
- return Success("删除成功。");
- }
- /// <summary>
- /// 保存用户表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="userEntity">用户实体</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- public ActionResult SaveForm(string keyValue, string strUserEntity, string FormInstanceId, string strModuleFormInstanceEntity)
- {
- UserEntity userEntity = strUserEntity.ToObject<UserEntity>();
- ModuleFormInstanceEntity moduleFormInstanceEntity = strModuleFormInstanceEntity.ToObject<ModuleFormInstanceEntity>();
- userEntity.CreateUserId = SystemInfo.CurrentUserId;
- string objectId = userBLL.SaveForm(keyValue, userEntity);
- moduleFormInstanceEntity.ObjectId = objectId;
- moduleFormInstanceBll.SaveEntity(FormInstanceId, moduleFormInstanceEntity);
- return Success("操作成功。");
- }
- /// <summary>
- /// 保存重置修改密码
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="Password">新密码</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- public ActionResult SaveRevisePassword(string keyValue, string Password)
- {
- if (keyValue == "100000")
- {
- throw new Exception("当前账户不能重置密码");
- }
- userBLL.RevisePassword(keyValue, Password);
- return Success("密码修改成功,请牢记新密码。");
- }
- /// <summary>
- /// 禁用账户
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult DisabledAccount(string keyValue)
- {
- if (keyValue == "100000")
- {
- throw new Exception("当前账户不禁用");
- }
- userBLL.UpdateState(keyValue, 0);
- return Success("账户禁用成功。");
- }
- /// <summary>
- /// 启用账户
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult EnabledAccount(string keyValue)
- {
- userBLL.UpdateState(keyValue, 1);
- return Success("账户启用成功。");
- }
- #endregion
- #region 数据导出
- /// <summary>
- /// 导出用户列表
- /// </summary>
- /// <returns></returns>
- public ActionResult ExportUserList()
- {
- userBLL.GetExportList();
- return Success("导出成功。");
- }
- #endregion
- }
- }
|