Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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