UserController.cs 18 KB

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