Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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