UserController.cs 11 KB

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