UserController.cs 19 KB

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