UserController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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.WebControl;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Linq;
  13. using System.Web.Mvc;
  14. namespace LeaRun.Application.Web.Areas.BaseManage.Controllers
  15. {
  16. /// <summary>
  17. /// 版 本
  18. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  19. /// 创建人:佘赐雄
  20. /// 日 期:2015.11.03 10:58
  21. /// 描 述:用户管理
  22. /// </summary>
  23. public class UserController : MvcControllerBase
  24. {
  25. private UserBLL userBLL = new UserBLL();
  26. private UserCache userCache = new UserCache();
  27. private OrganizeBLL organizeBLL = new OrganizeBLL();
  28. private OrganizeCache organizeCache = new OrganizeCache();
  29. private DepartmentBLL departmentBLL = new DepartmentBLL();
  30. private DepartmentCache departmentCache = new DepartmentCache();
  31. private ModuleFormInstanceBLL moduleFormInstanceBll = new ModuleFormInstanceBLL();
  32. #region 视图功能
  33. /// <summary>
  34. /// 用户管理
  35. /// </summary>
  36. /// <returns></returns>
  37. [HttpGet]
  38. [HandlerAuthorize(PermissionMode.Enforce)]
  39. public ActionResult Index()
  40. {
  41. return View();
  42. }
  43. /// <summary>
  44. /// 用户表单
  45. /// </summary>
  46. /// <returns></returns>
  47. [HttpGet]
  48. [HandlerAuthorize(PermissionMode.Enforce)]
  49. public ActionResult Form()
  50. {
  51. return View();
  52. }
  53. /// <summary>
  54. /// 重置密码
  55. /// </summary>
  56. /// <returns></returns>
  57. [HttpGet]
  58. [HandlerAuthorize(PermissionMode.Enforce)]
  59. public ActionResult RevisePassword()
  60. {
  61. return View();
  62. }
  63. #endregion
  64. #region 获取数据
  65. /// <summary>
  66. /// 用户列表
  67. /// </summary>
  68. /// <param name="keyword">关键字</param>
  69. /// <returns>返回机构+部门+用户树形Json</returns>
  70. [HttpGet]
  71. public ActionResult GetTreeJson(string keyword)
  72. {
  73. var organizedata = organizeCache.GetList();
  74. var departmentdata = departmentCache.GetList();
  75. var userdata = userCache.GetList();
  76. var treeList = new List<TreeEntity>();
  77. foreach (OrganizeEntity item in organizedata)
  78. {
  79. #region 机构
  80. TreeEntity tree = new TreeEntity();
  81. bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
  82. if (hasChildren == false)
  83. {
  84. hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
  85. if (hasChildren == false)
  86. {
  87. continue;
  88. }
  89. }
  90. tree.id = item.OrganizeId;
  91. tree.text = item.FullName;
  92. tree.value = item.OrganizeId;
  93. tree.parentId = item.ParentId;
  94. tree.isexpand = true;
  95. tree.complete = true;
  96. tree.hasChildren = hasChildren;
  97. tree.Attribute = "Sort";
  98. tree.AttributeValue = "Organize";
  99. treeList.Add(tree);
  100. #endregion
  101. }
  102. foreach (DepartmentEntity item in departmentdata)
  103. {
  104. #region 部门
  105. TreeEntity tree = new TreeEntity();
  106. tree.id = item.DepartmentId;
  107. tree.text = item.FullName;
  108. tree.value = item.DepartmentId;
  109. if (item.ParentId == "0")
  110. {
  111. tree.parentId = item.OrganizeId;
  112. }
  113. else
  114. {
  115. tree.parentId = item.ParentId;
  116. }
  117. tree.isexpand = true;
  118. tree.complete = true;
  119. tree.hasChildren = true;
  120. tree.Attribute = "Sort";
  121. tree.AttributeValue = "Department";
  122. treeList.Add(tree);
  123. #endregion
  124. }
  125. foreach (UserEntity item in userdata)
  126. {
  127. #region 用户
  128. TreeEntity tree = new TreeEntity();
  129. tree.id = item.UserId;
  130. tree.text = item.RealName;
  131. tree.value = item.Account;
  132. tree.parentId = item.DepartmentId;
  133. tree.title = item.RealName + "(" + item.Account + ")";
  134. tree.isexpand = true;
  135. tree.complete = true;
  136. tree.hasChildren = false;
  137. tree.Attribute = "Sort";
  138. tree.AttributeValue = "User";
  139. tree.img = "fa fa-user";
  140. treeList.Add(tree);
  141. #endregion
  142. }
  143. if (!string.IsNullOrEmpty(keyword))
  144. {
  145. treeList = treeList.TreeWhere(t => t.text.Contains(keyword), "id", "parentId");
  146. }
  147. return Content(treeList.TreeToJson());
  148. }
  149. /// <summary>
  150. /// 用户列表
  151. /// </summary>
  152. /// <param name="departmentId">部门Id</param>
  153. /// <returns>返回用户列表Json</returns>
  154. [HttpGet]
  155. public ActionResult GetListJson(string departmentId)
  156. {
  157. var data = userCache.GetList(departmentId);
  158. return Content(data.ToJson());
  159. }
  160. /// <summary>
  161. /// 用户列表
  162. /// </summary>
  163. /// <param name="pagination">分页参数</param>
  164. /// <param name="queryJson">查询参数</param>
  165. /// <returns>返回分页列表Json</returns>
  166. [HttpGet]
  167. public ActionResult GetPageListJson(Pagination pagination, string queryJson)
  168. {
  169. var watch = CommonHelper.TimerStart();
  170. var data = userBLL.GetPageList(pagination, queryJson);
  171. var JsonData = new
  172. {
  173. rows = data,
  174. total = pagination.total,
  175. page = pagination.page,
  176. records = pagination.records,
  177. costtime = CommonHelper.TimerEnd(watch)
  178. };
  179. return Content(JsonData.ToJson());
  180. }
  181. /// <summary>
  182. /// 用户实体
  183. /// </summary>
  184. /// <param name="keyValue">主键值</param>
  185. /// <returns>返回对象Json</returns>
  186. [HttpGet]
  187. public ActionResult GetFormJson(string keyValue)
  188. {
  189. var data = userBLL.GetEntity(keyValue);
  190. return Content(data.ToJson());
  191. }
  192. #endregion
  193. #region 验证数据
  194. /// <summary>
  195. /// 账户不能重复
  196. /// </summary>
  197. /// <param name="Account">账户值</param>
  198. /// <param name="keyValue">主键</param>
  199. /// <returns></returns>
  200. [HttpGet]
  201. public ActionResult ExistAccount(string Account, string keyValue)
  202. {
  203. bool IsOk = userBLL.ExistAccount(Account, keyValue);
  204. return Content(IsOk.ToString());
  205. }
  206. #endregion
  207. #region 提交数据
  208. /// <summary>
  209. /// 删除用户
  210. /// </summary>
  211. /// <param name="keyValue">主键值</param>
  212. /// <returns></returns>
  213. [HttpPost]
  214. [ValidateAntiForgeryToken]
  215. [AjaxOnly]
  216. [HandlerAuthorize(PermissionMode.Enforce)]
  217. public ActionResult RemoveForm(string keyValue)
  218. {
  219. if (keyValue == "100000")
  220. {
  221. throw new Exception("当前账户不能删除");
  222. }
  223. userBLL.RemoveForm(keyValue);
  224. return Success("删除成功。");
  225. }
  226. /// <summary>
  227. /// 保存用户表单(新增、修改)
  228. /// </summary>
  229. /// <param name="keyValue">主键值</param>
  230. /// <param name="userEntity">用户实体</param>
  231. /// <returns></returns>
  232. [HttpPost]
  233. [ValidateAntiForgeryToken]
  234. [AjaxOnly]
  235. public ActionResult SaveForm(string keyValue, string strUserEntity, string FormInstanceId, string strModuleFormInstanceEntity)
  236. {
  237. UserEntity userEntity = strUserEntity.ToObject<UserEntity>();
  238. ModuleFormInstanceEntity moduleFormInstanceEntity = strModuleFormInstanceEntity.ToObject<ModuleFormInstanceEntity>();
  239. userEntity.CreateUserId = SystemInfo.CurrentUserId;
  240. string objectId = userBLL.SaveForm(keyValue, userEntity);
  241. moduleFormInstanceEntity.ObjectId = objectId;
  242. moduleFormInstanceBll.SaveEntity(FormInstanceId, moduleFormInstanceEntity);
  243. return Success("操作成功。");
  244. }
  245. /// <summary>
  246. /// 保存重置修改密码
  247. /// </summary>
  248. /// <param name="keyValue">主键值</param>
  249. /// <param name="Password">新密码</param>
  250. /// <returns></returns>
  251. [HttpPost]
  252. [ValidateAntiForgeryToken]
  253. [AjaxOnly]
  254. public ActionResult SaveRevisePassword(string keyValue, string Password)
  255. {
  256. if (keyValue == "100000")
  257. {
  258. throw new Exception("当前账户不能重置密码");
  259. }
  260. userBLL.RevisePassword(keyValue, Password);
  261. return Success("密码修改成功,请牢记新密码。");
  262. }
  263. /// <summary>
  264. /// 禁用账户
  265. /// </summary>
  266. /// <param name="keyValue">主键值</param>
  267. /// <returns></returns>
  268. [HttpPost]
  269. [AjaxOnly]
  270. [HandlerAuthorize(PermissionMode.Enforce)]
  271. public ActionResult DisabledAccount(string keyValue)
  272. {
  273. if (keyValue == "100000")
  274. {
  275. throw new Exception("当前账户不禁用");
  276. }
  277. userBLL.UpdateState(keyValue, 0);
  278. return Success("账户禁用成功。");
  279. }
  280. /// <summary>
  281. /// 启用账户
  282. /// </summary>
  283. /// <param name="keyValue">主键值</param>
  284. /// <returns></returns>
  285. [HttpPost]
  286. [AjaxOnly]
  287. [HandlerAuthorize(PermissionMode.Enforce)]
  288. public ActionResult EnabledAccount(string keyValue)
  289. {
  290. userBLL.UpdateState(keyValue, 1);
  291. return Success("账户启用成功。");
  292. }
  293. #endregion
  294. #region 数据导出
  295. /// <summary>
  296. /// 导出用户列表
  297. /// </summary>
  298. /// <returns></returns>
  299. public ActionResult ExportUserList()
  300. {
  301. userBLL.GetExportList();
  302. return Success("导出成功。");
  303. }
  304. #endregion
  305. }
  306. }