Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

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