ExaminationMessageController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Bowin.Common.Log;
  2. using Bowin.Web.Controls.Mvc;
  3. using EMIS.CommonLogic.EducationManage;
  4. using EMIS.CommonLogic.SystemServices;
  5. using EMIS.ViewModel;
  6. using EMIS.ViewModel.EducationManage;
  7. using EMIS.ViewModel.SystemView;
  8. using EMIS.Web.Controls;
  9. using EMIS.Utility.OnlinePay;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Web;
  14. using System.Web.Mvc;
  15. namespace EMIS.Web.Controllers.EducationManage
  16. {
  17. [Authorization]
  18. public class ExaminationMessageController : Controller
  19. {
  20. public IExaminationMessageServices ExaminationMessageServices { get; set; }
  21. public IWechatMPServices WechatMPServices { get; set; }
  22. public ActionResult List()
  23. {
  24. return View();
  25. }
  26. public ActionResult Announce()
  27. {
  28. return View(new ExaminationMessageSaveView() { ExaminationTime = DateTime.Today, Remark = "" });
  29. }
  30. [HttpPost]
  31. public ActionResult List(QueryParamsModel pararms)
  32. {
  33. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  34. var schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
  35. var examinationBatchID = pararms.getExtraGuid("cgExaminationBatch");
  36. var examinationTypeID = pararms.getExtraGuid("cgExaminationType");
  37. var examinationProjectID = pararms.getExtraGuid("cgExaminationProject");
  38. var schoolAreaID = pararms.getExtraInt("ddlSchoolArea") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlSchoolArea");
  39. var collegeID = pararms.getExtraGuid("cgCollege");
  40. var year = pararms.getExtraInt("ddlYear") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlYear");
  41. var classmajorID = pararms.getExtraGuid("cgClassmajor");
  42. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  43. return base.Json(ExaminationMessageServices.GetExaminationMessageViewGrid(configuretView, schoolyearID, examinationBatchID, examinationTypeID,
  44. examinationProjectID, schoolAreaID, collegeID, year, classmajorID, pararms.page, pararms.rows));
  45. }
  46. [HttpPost]
  47. public ActionResult Announce(string examinationRegistrationIDs, DateTime? examinationTime, string remark)
  48. {
  49. ExaminationMessageSaveView examinationMessageSaveView = new ExaminationMessageSaveView();
  50. examinationMessageSaveView.ExaminationRegistrationIDList = examinationRegistrationIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => new Guid(x)).ToList();
  51. examinationMessageSaveView.ExaminationTime = examinationTime;
  52. examinationMessageSaveView.Remark = remark;
  53. try
  54. {
  55. var msg = "";
  56. var announceViewList = ExaminationMessageServices.Save(examinationMessageSaveView);
  57. try
  58. {
  59. announceViewList.ForEach(x =>
  60. {
  61. var openIDList = WechatMPServices.GetOpenIDList(null, x.UserIDList);
  62. openIDList.Remove("null");
  63. //暂时不考虑针对角色发送的消息
  64. if (openIDList.Count() < x.UserIDList.Count())
  65. {
  66. msg = "但有部分学生未在微信端登陆或未关注公众号,无法发送消息给他们!";
  67. }
  68. WechatHelper.SendAnnouncement("考试通知", x.Remark, openIDList, x.ExaminationProjectName, x.ExaminationTime);
  69. });
  70. }
  71. catch (Exception ex)
  72. {
  73. LogHelper.WriteLog(LogType.CommmLog, ex.Message);
  74. }
  75. return Json(new ReturnMessage()
  76. {
  77. IsSuccess = true,
  78. Message = "保存成功。" + msg
  79. });
  80. }
  81. catch (Exception ex)
  82. {
  83. return Json(new ReturnMessage()
  84. {
  85. IsSuccess = false,
  86. Message = "保存失败:" + ex.Message
  87. });
  88. }
  89. }
  90. }
  91. }