You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserController.cs 13 KiB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. using Learun.Application.Organization;
  2. using Learun.Util;
  3. using System.Collections.Generic;
  4. using System.Web.Mvc;
  5. using Learun.Application.Base.AuthorizeModule;
  6. using System.Linq;
  7. using System;
  8. using Learun.Application.Base.SystemModule;
  9. namespace Learun.Application.Web.Areas.LR_OrganizationModule.Controllers
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创建人:陈彬彬
  15. /// 日 期:2017.03.09
  16. /// 描 述:用户管理控制器
  17. /// </summary>
  18. public class UserController : MvcControllerBase
  19. {
  20. private UserIBLL userIBLL = new UserBLL();
  21. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  22. private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  23. private RoleIBLL roleIBLL = new RoleBLL();
  24. #region 获取视图
  25. [HttpGet]
  26. public ActionResult StudentIndex()
  27. {
  28. return View();
  29. }
  30. /// <summary>
  31. /// 用户管理主页
  32. /// </summary>
  33. /// <returns></returns>
  34. [HttpGet]
  35. public ActionResult Index()
  36. {
  37. return View();
  38. }
  39. /// <summary>
  40. /// 用户管理表单
  41. /// </summary>
  42. /// <returns></returns>
  43. [HttpGet]
  44. public ActionResult Form()
  45. {
  46. return View();
  47. }
  48. /// <summary>
  49. /// 人员选择
  50. /// </summary>
  51. /// <returns></returns>
  52. [HttpGet]
  53. public ActionResult SelectForm()
  54. {
  55. return View();
  56. }
  57. [HttpGet]
  58. public ActionResult LookForm()
  59. {
  60. return View();
  61. }
  62. /// <summary>
  63. /// 人员选择
  64. /// </summary>
  65. /// <returns></returns>
  66. [HttpGet]
  67. public ActionResult SelectOnlyForm()
  68. {
  69. return View();
  70. }
  71. #endregion
  72. #region 获取数据
  73. /// <summary>
  74. /// 获取分页数据
  75. /// </summary>
  76. /// <param name="pagination">分页参数</param>
  77. /// <param name="keyword">关键字</param>
  78. /// <param name="companyId">公司主键</param>
  79. /// <param name="departmentId">部门主键</param>
  80. /// <param name="tp">0 教师 1学生</param>
  81. /// <returns></returns>
  82. [HttpGet]
  83. [AjaxOnly]
  84. public ActionResult GetPageList(string pagination, string keyword, string companyId, string departmentId, string tp)
  85. {
  86. Pagination paginationobj = pagination.ToObject<Pagination>();
  87. var data = userIBLL.GetPageList(companyId, departmentId, paginationobj, keyword, tp);
  88. var jsonData = new
  89. {
  90. rows = data,
  91. total = paginationobj.total,
  92. page = paginationobj.page,
  93. records = paginationobj.records,
  94. };
  95. return JsonResult(jsonData);
  96. }
  97. /// <summary>
  98. /// 获取用户列表
  99. /// </summary>
  100. /// <param name="companyId">公司主键</param>
  101. /// <param name="departmentId">部门主键</param>
  102. /// <param name="keyword">查询关键词</param>
  103. /// <returns></returns>
  104. [HttpGet]
  105. [AjaxOnly]
  106. public ActionResult GetList(string companyId, string departmentId, string keyword)
  107. {
  108. if (string.IsNullOrEmpty(companyId))
  109. {
  110. var department = departmentIBLL.GetEntity(departmentId);
  111. if (department != null)
  112. {
  113. var data = userIBLL.GetList(department.F_CompanyId, departmentId, keyword);
  114. return JsonResult(data);
  115. }
  116. else
  117. {
  118. return JsonResult(new List<string>());
  119. }
  120. }
  121. else
  122. {
  123. var data = userIBLL.GetList(companyId, departmentId, keyword);
  124. return JsonResult(data);
  125. }
  126. }
  127. /// <summary>
  128. /// 根据部门获取用户
  129. /// </summary>
  130. /// <param name="departmentId">部门主键</param>
  131. /// <returns></returns>
  132. [HttpGet]
  133. [AjaxOnly]
  134. public ActionResult GetListByDepartmentId(string departmentId)
  135. {
  136. var data = userIBLL.GetListByDepartmentId(departmentId);
  137. return JsonResult(data);
  138. }
  139. /// <summary>
  140. /// 根据部门获取用户
  141. /// </summary>
  142. /// <param name="departmentId">部门主键</param>
  143. /// <returns></returns>
  144. [HttpGet]
  145. [AjaxOnly]
  146. public ActionResult GetListByDepartmentIds(string departmentId)
  147. {
  148. var data = userIBLL.GetListByDepartmentIds(departmentId);
  149. return JsonResult(data);
  150. }
  151. /// <summary>
  152. /// 获取本部门的人员
  153. /// </summary>
  154. /// <param name="companyId">公司主键</param>
  155. /// <param name="departmentId">部门主键</param>
  156. /// <param name="keyword">查询关键词</param>
  157. /// <returns></returns>
  158. [HttpGet]
  159. [AjaxOnly]
  160. public ActionResult GetMyDepartmentList()
  161. {
  162. UserInfo userinfo = LoginUserInfo.Get();
  163. var data = userIBLL.GetList(userinfo.companyId, userinfo.departmentId, "");
  164. return JsonResult(data);
  165. }
  166. /// <summary>
  167. /// 获取用户信息列表
  168. /// </summary>
  169. /// <param name="userIds">用户主键串</param>
  170. /// <returns></returns>
  171. [HttpGet]
  172. [AjaxOnly]
  173. public ActionResult GetListByUserIds(string keyValue)
  174. {
  175. var list = userIBLL.GetListByUserIds(keyValue);
  176. string text = "";
  177. if (list != null)
  178. {
  179. foreach (var item in list)
  180. {
  181. if (!string.IsNullOrEmpty(text))
  182. {
  183. text += ",";
  184. }
  185. text += item.F_RealName;
  186. }
  187. }
  188. return SuccessString(text);
  189. }
  190. /// <summary>
  191. /// 获取用户信息列表
  192. /// </summary>
  193. /// <param name="userIds">用户主键串</param>
  194. /// <returns></returns>
  195. [HttpGet]
  196. [AjaxOnly]
  197. public ActionResult GetEntityListByUserIds(string keyValue)
  198. {
  199. var list = userIBLL.GetListByUserIds(keyValue);
  200. return JsonResult(list);
  201. }
  202. /// <summary>
  203. /// 获取用户信息
  204. /// </summary>
  205. /// <param name="userIds">用户主键</param>
  206. /// <returns></returns>
  207. [HttpGet]
  208. [AjaxOnly]
  209. public ActionResult GetUserEntity(string userId)
  210. {
  211. var data = userIBLL.GetEntityByUserId(userId);
  212. return JsonResult(data);
  213. }
  214. /// <summary>
  215. /// 获取映射数据
  216. /// </summary>
  217. /// <returns></returns>
  218. [HttpGet]
  219. [AjaxOnly]
  220. public ActionResult GetMap(string ver)
  221. {
  222. var data = userIBLL.GetModelMap();
  223. string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
  224. if (md5 == ver)
  225. {
  226. return Success("no update");
  227. }
  228. else
  229. {
  230. var jsondata = new
  231. {
  232. data = data,
  233. ver = md5
  234. };
  235. return JsonResult(jsondata);
  236. }
  237. }
  238. /// <summary>
  239. /// 获取头像
  240. /// </summary>
  241. /// <param name="userId">用户主键</param>
  242. /// <returns></returns>
  243. [HttpGet]
  244. public ActionResult GetImg(string userId)
  245. {
  246. userIBLL.GetImg(userId);
  247. return Success("获取成功。");
  248. }
  249. /// <summary>
  250. /// 获取头像For大厂
  251. /// </summary>
  252. /// <param name="userId"></param>
  253. /// <returns></returns>
  254. [HttpGet]
  255. public ActionResult GetImgForDC(string userId)
  256. {
  257. userIBLL.GetImgForDC(userId);
  258. return Success("获取成功。");
  259. }
  260. [HttpGet]
  261. public ActionResult GetRoleList(string objectId)
  262. {
  263. var roleList = userRelationIBLL.GetRoleListByUserId(objectId);
  264. var jsonResult = new { roleInfoList = roleList };
  265. return Success(jsonResult);
  266. }
  267. [HttpGet]
  268. [AjaxOnly]
  269. public ActionResult GetLastLoginTime(string userId)
  270. {
  271. return Success(LogBLL.GetUserLogList(userId)?.F_OperateTime);
  272. }
  273. #endregion
  274. #region 提交数据
  275. /// <summary>
  276. /// 保存表单数据
  277. /// </summary>
  278. /// <param name="keyValue">主键</param>
  279. /// <param name="entity">实体</param>
  280. /// <returns></returns>
  281. [HttpPost]
  282. [ValidateAntiForgeryToken]
  283. [AjaxOnly]
  284. public ActionResult SaveForm(string keyValue, UserEntity entity)
  285. {
  286. userIBLL.SaveEntity(keyValue, entity);
  287. return Success("保存成功!");
  288. }
  289. /// <summary>
  290. /// 删除表单数据
  291. /// </summary>
  292. /// <param name="keyValue">主键</param>
  293. /// <returns></returns>
  294. [HttpPost]
  295. [AjaxOnly]
  296. public ActionResult DeleteForm(string keyValue)
  297. {
  298. //userIBLL.VirtualDelete(keyValue);
  299. userIBLL.VirtualDeleteBatch(keyValue);
  300. return Success("删除成功!");
  301. }
  302. /// <summary>
  303. /// 启用禁用账号
  304. /// </summary>
  305. /// <param name="keyValue">主键</param>
  306. /// <returns></returns>
  307. [HttpPost]
  308. [AjaxOnly]
  309. public ActionResult UpdateState(string keyValue, int state)
  310. {
  311. userIBLL.UpdateState(keyValue, state);
  312. return Success("操作成功!");
  313. }
  314. /// <summary>
  315. /// 重置用户账号密码
  316. /// </summary>
  317. /// <param name="keyValue">主键</param>
  318. /// <returns></returns>
  319. [HttpPost]
  320. [AjaxOnly]
  321. public ActionResult ResetPassword(string keyValue)
  322. {
  323. userIBLL.ResetPassword(keyValue);
  324. return Success("操作成功!");
  325. }
  326. /// <summary>
  327. /// 重置用户账号密码(八位)
  328. /// </summary>
  329. /// <param name="keyValue">主键</param>
  330. /// <returns></returns>
  331. [HttpPost]
  332. [AjaxOnly]
  333. public ActionResult ResetPasswordEight(string keyValue)
  334. {
  335. userIBLL.ResetPasswordEight(keyValue);
  336. return Success("操作成功!");
  337. }
  338. [HttpGet]
  339. [AjaxOnly]
  340. public ActionResult ResetStudentRelation()
  341. {
  342. var allStudents = userIBLL.GetStudents();
  343. var studentRoleId = roleIBLL.GetIdByRoleName("学生");
  344. var hasStudentsRolePeople = userRelationIBLL.GetUserIdList(studentRoleId).Select(a => a.F_UserId);
  345. var studentList = allStudents.Where(a => !hasStudentsRolePeople.Contains(a.F_UserId));
  346. var relationList = new List<UserRelationEntity>();
  347. var userIds = "";
  348. foreach (var item in allStudents)
  349. {
  350. if (userIds != "")
  351. {
  352. userIds += ",";
  353. }
  354. userIds += item.F_UserId;
  355. }
  356. userRelationIBLL.SaveEntityList(studentRoleId, 1, userIds);
  357. return Success("操作成功");
  358. }
  359. #endregion
  360. #region 数据导出
  361. /// <summary>
  362. /// 导出用户列表
  363. /// </summary>
  364. /// <returns></returns>
  365. [HttpGet]
  366. public ActionResult ExportUserList()
  367. {
  368. userIBLL.GetExportList();
  369. return Success("导出成功。");
  370. }
  371. /// <summary>
  372. /// 导出用户列表【学生】
  373. /// </summary>
  374. /// <returns></returns>
  375. [HttpGet]
  376. public ActionResult ExportUserListOfStudent()
  377. {
  378. userIBLL.GetExportListOfStudent();
  379. return Success("导出成功。");
  380. }
  381. #endregion
  382. #region 验证数据
  383. /// <summary>
  384. /// 账号不能重复
  385. /// </summary>
  386. /// <param name="keyValue">主键</param>
  387. /// <param name="F_Account">账号</param>
  388. /// <returns></returns>
  389. [HttpGet]
  390. [AjaxOnly]
  391. public ActionResult ExistAccount(string keyValue, string F_Account)
  392. {
  393. bool res = userIBLL.ExistAccount(F_Account, keyValue);
  394. return JsonResult(res);
  395. }
  396. #endregion
  397. }
  398. }