UserController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.ViewModel;
  7. using Bowin.Web.Controls.Mvc;
  8. using EMIS.CommonLogic.SystemServices;
  9. using EMIS.CommonLogic.AdministrativeOrgan;
  10. using EMIS.Web.Controls;
  11. using Bowin.Common.Data;
  12. using Bowin.Common.Utility;
  13. using EMIS.ViewModel.SystemView;
  14. using EMIS.Utility;
  15. using EMIS.CommonLogic.TeacherManagement;
  16. using EMIS.ViewModel.TeacherManagement;
  17. using EMIS.Utility.FormValidate;
  18. using System.Text.RegularExpressions;
  19. namespace EMIS.Web.Controllers.UserManagement
  20. {
  21. [Authorization]
  22. public class UserController : Controller
  23. {
  24. public IUserServices UserServices { get; set; }
  25. public IUserInfoChangeServices UserInfoChangeServices { get; set; }
  26. public IParameterServices parameterServices { get; set; }
  27. public Lazy<IStaffServices> staffServices { get; set; }
  28. /// <summary>
  29. /// 教师用户页面
  30. /// </summary>
  31. /// <returns></returns>
  32. public ActionResult List()
  33. {
  34. return View();
  35. }
  36. /// <summary>
  37. /// 学生用户页面
  38. /// </summary>
  39. /// <returns></returns>
  40. public ActionResult StudentList()
  41. {
  42. return View();
  43. }
  44. /// <summary>
  45. /// 教师列表查询
  46. /// </summary>
  47. /// <param name="pararms"></param>
  48. /// <returns></returns>
  49. [HttpPost]
  50. public ActionResult List(QueryParamsModel pararms)
  51. {
  52. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  53. //避开全选值
  54. var campusID = pararms.getExtraGuid("CampusDropdown");
  55. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  56. var departmentID = pararms.getExtraGuid("DepartmentDropdown");
  57. var roleID = pararms.getExtraGuid("Role");
  58. var dataRange = pararms.getExtraInt("DataRange");
  59. var stauts = pararms.getExtraInt("Stauts");
  60. if (dataRange == DropdownList.SELECT_ALL) dataRange = null;
  61. if (stauts == DropdownList.SELECT_ALL) stauts = null;
  62. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  63. return base.Json(UserServices.GetUserViewList(configuretView, campusID, collegeID, departmentID, roleID, dataRange, stauts,
  64. (int)pararms.page, (int)pararms.rows));
  65. }
  66. /// <summary>
  67. /// 学生列表查询
  68. /// </summary>
  69. /// <param name="pararms"></param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. public ActionResult StudentList(QueryParamsModel pararms)
  73. {
  74. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  75. //避开全选值
  76. var campusID = pararms.getExtraGuid("CampusDropdown");
  77. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  78. var educationID = pararms.getExtraInt("Education");
  79. var schoolYearID = pararms.getExtraInt("SchoolYear");
  80. var standardID = pararms.getExtraInt("Standard");
  81. var learnFormID = pararms.getExtraInt("Learningform");
  82. var classID = pararms.getExtraGuid("ClassmajorDropdown");
  83. var LearnSystem = pararms.getExtraString("DictionaryLearnSystem");
  84. if (educationID == DropdownList.SELECT_ALL) educationID = null;
  85. if (schoolYearID == DropdownList.SELECT_ALL) schoolYearID = null;
  86. if (standardID == DropdownList.SELECT_ALL) standardID = null;
  87. if (learnFormID == DropdownList.SELECT_ALL) learnFormID = null;
  88. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  89. return base.Json(UserServices.GetStudentUserViewList(configuretView, campusID, collegeID, educationID, schoolYearID,
  90. standardID, learnFormID, classID,LearnSystem, (int)pararms.page, (int)pararms.rows));
  91. }
  92. [HttpPost]
  93. public ActionResult Excel()
  94. {
  95. NpoiExcelHelper neh = new NpoiExcelHelper();
  96. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  97. //避开全选值
  98. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  99. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  100. var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
  101. var roleID = Request.Form["Role"].ParseStrTo<Guid>();
  102. var dataRange = Request.Form["DataRange"].ParseStrTo<int>();
  103. if (dataRange == DropdownList.SELECT_ALL) dataRange = null;
  104. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  105. var dt = UserServices.GetUserViewList(configuretView, campusID, collegeID, departmentID, roleID, dataRange)
  106. .Select(x => new
  107. {
  108. x.LoginID,
  109. x.Name,
  110. x.SexName,
  111. x.CollegeName,
  112. x.RoleName,
  113. x.DataRangeName,
  114. x.RecordStatusDesc,
  115. x.CreateTime,
  116. x.ModifyTime
  117. }).ToTable();
  118. string[] liststring = { "用户名", "姓名", "性别", "院系所", "角色名称", "数据范围", "允许登录", "创建时间", "修改时间" };
  119. neh.Export(dt, liststring, "用户信息");
  120. return RedirectToAction("MsgShow", "Common", new
  121. {
  122. msg = "导出成功!",
  123. url = Url.Content("~/User/List").AddMenuParameter()
  124. });
  125. }
  126. [HttpPost]
  127. public ActionResult StudentExcel()
  128. {
  129. NpoiExcelHelper neh = new NpoiExcelHelper();
  130. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  131. //避开全选值
  132. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  133. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  134. var educationID = Request.Form["Education"].ParseStrTo<int>();
  135. var schoolYearID = Request.Form["SchoolYear"].ParseStrTo<int>();
  136. var standardID = Request.Form["Standard"].ParseStrTo<int>();
  137. var learnFormID = Request.Form["Learningform"].ParseStrTo<int>();
  138. var classID = Request.Form["ClassmajorDropdown"].ParseStrTo<Guid>();
  139. var LearnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  140. if (educationID == DropdownList.SELECT_ALL) educationID = null;
  141. if (schoolYearID == DropdownList.SELECT_ALL) schoolYearID = null;
  142. if (standardID == DropdownList.SELECT_ALL) standardID = null;
  143. if (learnFormID == DropdownList.SELECT_ALL) learnFormID = null;
  144. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  145. var dt = UserServices.GetStudentUserViewList(configuretView, campusID, collegeID, educationID, schoolYearID,
  146. standardID, learnFormID, classID, LearnSystem)
  147. .Select(x => new
  148. {
  149. x.LoginID,
  150. x.Name,
  151. x.RoleName,
  152. x.ClassmajorName,
  153. x.RecordStatusDesc,
  154. x.Remarks,
  155. x.CreateTime,
  156. x.CreateUserName
  157. }).ToTable();
  158. string[] liststring = { "用户名", "用户名称", "角色类型", "在校班级", "是否可用", "备注", "创建时间", "创建人" };
  159. neh.Export(dt, liststring, "学生用户信息");
  160. return RedirectToAction("MsgShow", "Common", new
  161. {
  162. msg = "导出成功!",
  163. url = Url.Content("~/User/StudentList").AddMenuParameter()
  164. });
  165. }
  166. /// <summary>
  167. ///
  168. /// </summary>
  169. /// <param name="userID"></param>
  170. /// <param name="type"></param>
  171. /// <returns></returns>
  172. [HttpGet]
  173. public ActionResult BatchInitPassword(string userID,int type)
  174. {
  175. BatchInitPasswordView batchInitPasswordView = new BatchInitPasswordView();
  176. batchInitPasswordView.User = userID;
  177. var parameter=parameterServices.GetParameterValue(ViewModel.CF_ParameterType.TeacherInitPassword);
  178. if(type==1){
  179. parameter = parameterServices.GetParameterValue(ViewModel.CF_ParameterType.StudentInitPassword);
  180. }
  181. if (parameter == null)
  182. {
  183. batchInitPasswordView.BatchInt = false;
  184. }
  185. else
  186. {
  187. batchInitPasswordView.BatchInt = true;
  188. }
  189. batchInitPasswordView.type = type;
  190. return View(batchInitPasswordView);
  191. }
  192. /// <summary>
  193. ///
  194. /// </summary>
  195. /// <param name="batchInitPasswordView"></param>
  196. /// <returns></returns>
  197. [HttpPost]
  198. public ActionResult BatchInitPassword(string userID, BatchInitPasswordView batchInitPasswordView)
  199. {
  200. //由于历史原因,目前先采取这种做法,后期再调整
  201. //batchInitPasswordView.User = userID;
  202. if (batchInitPasswordView.User != null && batchInitPasswordView.User != "student" && batchInitPasswordView.User != "staff")
  203. {
  204. try
  205. {
  206. List<Guid?> userid = batchInitPasswordView.User.SplitIDString();
  207. bool isChange = false;
  208. if (batchInitPasswordView.BatchInt == true)
  209. {
  210. isChange = true;
  211. }
  212. var pwd = batchInitPasswordView.Password;
  213. UserServices.BatchInitPassword(userid, isChange, pwd);
  214. return Json(new ReturnMessage
  215. {
  216. IsSuccess = true,
  217. Message = "初始化成功"
  218. });
  219. }
  220. catch (Exception ex)
  221. {
  222. return Json(new ReturnMessage
  223. {
  224. IsSuccess = false,
  225. Message = "初始化失败!" + ex.Message
  226. });
  227. }
  228. }
  229. else
  230. {
  231. try
  232. {
  233. string pwd = batchInitPasswordView.Password;
  234. if (!(new Regex("^(?=.*?[0-9])(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-]).{8,}$").IsMatch(pwd)))
  235. {
  236. return Json(new ReturnMessage()
  237. {
  238. IsSuccess = true,
  239. Message = "保存失败,原因:密码须包含大小写英文、特殊字符、数字且长度大于或等于8位!"
  240. });
  241. }
  242. if (pwd != null && batchInitPasswordView.BatchInt == true)
  243. {
  244. pwd = pwd.MD5();
  245. }
  246. if (batchInitPasswordView.type == 0)
  247. {
  248. parameterServices.SaveTo(ViewModel.CF_ParameterType.TeacherInitPassword, pwd);
  249. }
  250. if (batchInitPasswordView.type == 1)
  251. {
  252. parameterServices.SaveTo(ViewModel.CF_ParameterType.StudentInitPassword, pwd);
  253. }
  254. return Json(new ReturnMessage()
  255. {
  256. IsSuccess = true,
  257. Message = "保存成功!"
  258. });
  259. }
  260. catch (Exception ex)
  261. {
  262. return Json(new ReturnMessage()
  263. {
  264. IsSuccess = true,
  265. Message = "保存失败,原因:" + ex.Message + "!"
  266. });
  267. }
  268. }
  269. }
  270. [HttpPost]
  271. public ActionResult Usable(string userIDList)
  272. {
  273. try
  274. {
  275. UserServices.Usable(userIDList.SplitIDString());
  276. return Json(new ReturnMessage
  277. {
  278. IsSuccess = true,
  279. Message = "启用成功"
  280. });
  281. }
  282. catch (Exception ex)
  283. {
  284. return Json(new ReturnMessage
  285. {
  286. IsSuccess = false,
  287. Message = "启用失败!" + ex.Message
  288. });
  289. }
  290. }
  291. [HttpPost]
  292. public ActionResult UnUsable(string userIDList)
  293. {
  294. try
  295. {
  296. UserServices.UnUsable(userIDList.SplitIDString());
  297. return Json(new ReturnMessage
  298. {
  299. IsSuccess = true,
  300. Message = "禁用成功"
  301. });
  302. }
  303. catch (Exception ex)
  304. {
  305. return Json(new ReturnMessage
  306. {
  307. IsSuccess = false,
  308. Message = "禁用失败!" + ex.Message
  309. });
  310. }
  311. }
  312. public ActionResult ModifyRole(Guid userID)
  313. {
  314. return View();
  315. }
  316. public ActionResult DataRange(Guid userID)
  317. {
  318. return View();
  319. }
  320. /// <summary>
  321. /// 教师用户页面修改角色
  322. /// </summary>
  323. /// <param name="userID"></param>
  324. /// <param name="roleIDs"></param>
  325. /// <returns></returns>
  326. [HttpPost]
  327. public ActionResult SaveRoles(Guid userID, string roleIDs)
  328. {
  329. try
  330. {
  331. UserServices.SaveUserRoles(userID, roleIDs.SplitIDString());
  332. return Json(new ReturnMessage
  333. {
  334. IsSuccess = true,
  335. Message = "保存成功"
  336. });
  337. }
  338. catch (Exception ex)
  339. {
  340. return Json(new ReturnMessage
  341. {
  342. IsSuccess = false,
  343. Message = "保存失败!" + ex.Message
  344. });
  345. }
  346. }
  347. [HttpPost]
  348. public ActionResult SaveUserCampus(Guid userID, string campusIDList)
  349. {
  350. try
  351. {
  352. UserServices.SaveUserCampus(userID, campusIDList.SplitIDString());
  353. return Json(new ReturnMessage
  354. {
  355. IsSuccess = true,
  356. Message = "保存成功"
  357. });
  358. }
  359. catch (Exception ex)
  360. {
  361. return Json(new ReturnMessage
  362. {
  363. IsSuccess = false,
  364. Message = "保存失败!" + ex.Message
  365. });
  366. }
  367. }
  368. [HttpPost]
  369. public ActionResult SaveUserCollege(Guid userID, string collegeIDList)
  370. {
  371. try
  372. {
  373. UserServices.SaveUserCollege(userID, collegeIDList.SplitIDString());
  374. return Json(new ReturnMessage
  375. {
  376. IsSuccess = true,
  377. Message = "保存成功"
  378. });
  379. }
  380. catch (Exception ex)
  381. {
  382. return Json(new ReturnMessage
  383. {
  384. IsSuccess = false,
  385. Message = "保存失败!" + ex.Message
  386. });
  387. }
  388. }
  389. [HttpPost]
  390. public ActionResult SaveUserDepartment(Guid userID, string departmentIDList)
  391. {
  392. try
  393. {
  394. UserServices.SaveUserDepartment(userID, departmentIDList.SplitIDString());
  395. return Json(new ReturnMessage
  396. {
  397. IsSuccess = true,
  398. Message = "保存成功"
  399. });
  400. }
  401. catch (Exception ex)
  402. {
  403. return Json(new ReturnMessage
  404. {
  405. IsSuccess = false,
  406. Message = "保存失败!" + ex.Message
  407. });
  408. }
  409. }
  410. [HttpPost]
  411. public ActionResult GetUserRoleList(Guid userID)
  412. {
  413. var roleViewList = UserServices.GetUserRolesView(userID);
  414. return Json(new JsonDataGridResult<RoleView> { rows = roleViewList, total = roleViewList.Count });
  415. }
  416. [HttpPost]
  417. public ActionResult GetUserRoleDropdownList(DropdownListBindType? bindType)
  418. {
  419. var user = CustomPrincipal.Current;
  420. var list = UserServices.GetUserRolesView(user.UserID)
  421. .Select(x => new DropdownListItem { Text = x.RoleName, Value = x.RoleID.ToString() }).ToList();
  422. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  423. DropdownList.FormatDropdownItemList(dbt, list);
  424. return base.Json(list);
  425. }
  426. [HttpGet]
  427. public ActionResult UserInfoChange()
  428. {
  429. Guid? userID = null;
  430. var query = UserInfoChangeServices.GetStaffView(userID);
  431. return View(query);
  432. }
  433. [HttpPost]
  434. public ActionResult UserInfoChange(StaffView staffView)
  435. {
  436. try
  437. {
  438. //string photoUrl = FileUploadHelper.UploadFile(Request.Files["PhotoUrl"]);
  439. staffServices.Value.UpdateForSelf(staffView);
  440. return RedirectToAction("MsgShow", "Common", new
  441. {
  442. WindowID = Request["WindowID"],
  443. msg = "保存成功!",
  444. url = Url.Action("UserInfoChange").AddMenuParameter()
  445. });
  446. }
  447. catch (Exception ex)
  448. {
  449. return RedirectToAction("MsgShow", "Common", new
  450. {
  451. WindowID = Request["WindowID"],
  452. msg = "保存失败,原因:" + ex.Message + "!",
  453. url = Url.Action("UserInfoChange").AddMenuParameter()
  454. });
  455. }
  456. }
  457. public object staffView { get; set; }
  458. }
  459. }