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.
 
 
 
 
 
 

408 lines
12 KiB

  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="companyId">公司主键</param>
  143. /// <param name="departmentId">部门主键</param>
  144. /// <param name="keyword">查询关键词</param>
  145. /// <returns></returns>
  146. [HttpGet]
  147. [AjaxOnly]
  148. public ActionResult GetMyDepartmentList()
  149. {
  150. UserInfo userinfo = LoginUserInfo.Get();
  151. var data = userIBLL.GetList(userinfo.companyId, userinfo.departmentId, "");
  152. return JsonResult(data);
  153. }
  154. /// <summary>
  155. /// 获取用户信息列表
  156. /// </summary>
  157. /// <param name="userIds">用户主键串</param>
  158. /// <returns></returns>
  159. [HttpGet]
  160. [AjaxOnly]
  161. public ActionResult GetListByUserIds(string keyValue)
  162. {
  163. var list = userIBLL.GetListByUserIds(keyValue);
  164. string text = "";
  165. if (list != null)
  166. {
  167. foreach (var item in list)
  168. {
  169. if (!string.IsNullOrEmpty(text))
  170. {
  171. text += ",";
  172. }
  173. text += item.F_RealName;
  174. }
  175. }
  176. return SuccessString(text);
  177. }
  178. /// <summary>
  179. /// 获取用户信息列表
  180. /// </summary>
  181. /// <param name="userIds">用户主键串</param>
  182. /// <returns></returns>
  183. [HttpGet]
  184. [AjaxOnly]
  185. public ActionResult GetEntityListByUserIds(string keyValue)
  186. {
  187. var list = userIBLL.GetListByUserIds(keyValue);
  188. return JsonResult(list);
  189. }
  190. /// <summary>
  191. /// 获取用户信息
  192. /// </summary>
  193. /// <param name="userIds">用户主键</param>
  194. /// <returns></returns>
  195. [HttpGet]
  196. [AjaxOnly]
  197. public ActionResult GetUserEntity(string userId)
  198. {
  199. var data = userIBLL.GetEntityByUserId(userId);
  200. return JsonResult(data);
  201. }
  202. /// <summary>
  203. /// 获取映射数据
  204. /// </summary>
  205. /// <returns></returns>
  206. [HttpGet]
  207. [AjaxOnly]
  208. public ActionResult GetMap(string ver)
  209. {
  210. var data = userIBLL.GetModelMap();
  211. string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
  212. if (md5 == ver)
  213. {
  214. return Success("no update");
  215. }
  216. else
  217. {
  218. var jsondata = new
  219. {
  220. data = data,
  221. ver = md5
  222. };
  223. return JsonResult(jsondata);
  224. }
  225. }
  226. /// <summary>
  227. /// 获取头像
  228. /// </summary>
  229. /// <param name="userId">用户主键</param>
  230. /// <returns></returns>
  231. [HttpGet]
  232. public ActionResult GetImg(string userId)
  233. {
  234. userIBLL.GetImg(userId);
  235. return Success("获取成功。");
  236. }
  237. /// <summary>
  238. /// 获取头像For大厂
  239. /// </summary>
  240. /// <param name="userId"></param>
  241. /// <returns></returns>
  242. [HttpGet]
  243. public ActionResult GetImgForDC(string userId)
  244. {
  245. userIBLL.GetImgForDC(userId);
  246. return Success("获取成功。");
  247. }
  248. [HttpGet]
  249. public ActionResult GetRoleList(string objectId)
  250. {
  251. var roleList = userRelationIBLL.GetRoleListByUserId(objectId);
  252. var jsonResult = new { roleInfoList = roleList };
  253. return Success(jsonResult);
  254. }
  255. [HttpGet]
  256. [AjaxOnly]
  257. public ActionResult GetLastLoginTime(string userId)
  258. {
  259. return Success(LogBLL.GetUserLogList(userId)?.F_OperateTime);
  260. }
  261. #endregion
  262. #region 提交数据
  263. /// <summary>
  264. /// 保存表单数据
  265. /// </summary>
  266. /// <param name="keyValue">主键</param>
  267. /// <param name="entity">实体</param>
  268. /// <returns></returns>
  269. [HttpPost]
  270. [ValidateAntiForgeryToken]
  271. [AjaxOnly]
  272. public ActionResult SaveForm(string keyValue, UserEntity entity)
  273. {
  274. userIBLL.SaveEntity(keyValue, entity);
  275. return Success("保存成功!");
  276. }
  277. /// <summary>
  278. /// 删除表单数据
  279. /// </summary>
  280. /// <param name="keyValue">主键</param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [AjaxOnly]
  284. public ActionResult DeleteForm(string keyValue)
  285. {
  286. //userIBLL.VirtualDelete(keyValue);
  287. userIBLL.VirtualDeleteBatch(keyValue);
  288. return Success("删除成功!");
  289. }
  290. /// <summary>
  291. /// 启用禁用账号
  292. /// </summary>
  293. /// <param name="keyValue">主键</param>
  294. /// <returns></returns>
  295. [HttpPost]
  296. [AjaxOnly]
  297. public ActionResult UpdateState(string keyValue, int state)
  298. {
  299. userIBLL.UpdateState(keyValue, state);
  300. return Success("操作成功!");
  301. }
  302. /// <summary>
  303. /// 重置用户账号密码
  304. /// </summary>
  305. /// <param name="keyValue">主键</param>
  306. /// <returns></returns>
  307. [HttpPost]
  308. [AjaxOnly]
  309. public ActionResult ResetPassword(string keyValue)
  310. {
  311. userIBLL.ResetPassword(keyValue);
  312. return Success("操作成功!");
  313. }
  314. /// <summary>
  315. /// 重置用户账号密码(八位)
  316. /// </summary>
  317. /// <param name="keyValue">主键</param>
  318. /// <returns></returns>
  319. [HttpPost]
  320. [AjaxOnly]
  321. public ActionResult ResetPasswordEight(string keyValue)
  322. {
  323. userIBLL.ResetPasswordEight(keyValue);
  324. return Success("操作成功!");
  325. }
  326. [HttpGet]
  327. [AjaxOnly]
  328. public ActionResult ResetStudentRelation()
  329. {
  330. var allStudents = userIBLL.GetStudents();
  331. var studentRoleId = roleIBLL.GetIdByRoleName("学生");
  332. var hasStudentsRolePeople = userRelationIBLL.GetUserIdList(studentRoleId).Select(a => a.F_UserId);
  333. var studentList = allStudents.Where(a => !hasStudentsRolePeople.Contains(a.F_UserId));
  334. var relationList = new List<UserRelationEntity>();
  335. var userIds = "";
  336. foreach (var item in allStudents)
  337. {
  338. if (userIds != "")
  339. {
  340. userIds += ",";
  341. }
  342. userIds += item.F_UserId;
  343. }
  344. userRelationIBLL.SaveEntityList(studentRoleId, 1, userIds);
  345. return Success("操作成功");
  346. }
  347. #endregion
  348. #region 数据导出
  349. /// <summary>
  350. /// 导出用户列表
  351. /// </summary>
  352. /// <returns></returns>
  353. [HttpGet]
  354. public ActionResult ExportUserList()
  355. {
  356. userIBLL.GetExportList();
  357. return Success("导出成功。");
  358. }
  359. /// <summary>
  360. /// 导出用户列表【学生】
  361. /// </summary>
  362. /// <returns></returns>
  363. [HttpGet]
  364. public ActionResult ExportUserListOfStudent()
  365. {
  366. userIBLL.GetExportListOfStudent();
  367. return Success("导出成功。");
  368. }
  369. #endregion
  370. #region 验证数据
  371. /// <summary>
  372. /// 账号不能重复
  373. /// </summary>
  374. /// <param name="keyValue">主键</param>
  375. /// <param name="F_Account">账号</param>
  376. /// <returns></returns>
  377. [HttpGet]
  378. [AjaxOnly]
  379. public ActionResult ExistAccount(string keyValue, string F_Account)
  380. {
  381. bool res = userIBLL.ExistAccount(F_Account, keyValue);
  382. return JsonResult(res);
  383. }
  384. #endregion
  385. }
  386. }