using Bowin.Common.Log; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.EducationManage; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel; using EMIS.ViewModel.EducationManage; using EMIS.ViewModel.SystemView; using EMIS.Web.Controls; using EMIS.Utility.OnlinePay; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace EMIS.Web.Controllers.EducationManage { [Authorization] public class ExaminationMessageController : Controller { public IExaminationMessageServices ExaminationMessageServices { get; set; } public IWechatMPServices WechatMPServices { get; set; } public ActionResult List() { return View(); } public ActionResult Announce() { return View(new ExaminationMessageSaveView() { ExaminationTime = DateTime.Today, Remark = "" }); } [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var schoolyearID = pararms.getExtraGuid("SchoolYearDropdown"); var examinationBatchID = pararms.getExtraGuid("cgExaminationBatch"); var examinationTypeID = pararms.getExtraGuid("cgExaminationType"); var examinationProjectID = pararms.getExtraGuid("cgExaminationProject"); var schoolAreaID = pararms.getExtraInt("ddlSchoolArea") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlSchoolArea"); var collegeID = pararms.getExtraGuid("cgCollege"); var year = pararms.getExtraInt("ddlYear") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlYear"); var classmajorID = pararms.getExtraGuid("cgClassmajor"); if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; return base.Json(ExaminationMessageServices.GetExaminationMessageViewGrid(configuretView, schoolyearID, examinationBatchID, examinationTypeID, examinationProjectID, schoolAreaID, collegeID, year, classmajorID, pararms.page, pararms.rows)); } [HttpPost] public ActionResult Announce(string examinationRegistrationIDs, DateTime? examinationTime, string remark) { ExaminationMessageSaveView examinationMessageSaveView = new ExaminationMessageSaveView(); examinationMessageSaveView.ExaminationRegistrationIDList = examinationRegistrationIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => new Guid(x)).ToList(); examinationMessageSaveView.ExaminationTime = examinationTime; examinationMessageSaveView.Remark = remark; try { var msg = ""; var announceViewList = ExaminationMessageServices.Save(examinationMessageSaveView); try { announceViewList.ForEach(x => { var openIDList = WechatMPServices.GetOpenIDList(null, x.UserIDList); openIDList.Remove("null"); //暂时不考虑针对角色发送的消息 if (openIDList.Count() < x.UserIDList.Count()) { msg = "但有部分学生未在微信端登陆或未关注公众号,无法发送消息给他们!"; } WechatHelper.SendAnnouncement("考试通知", x.Remark, openIDList, x.ExaminationProjectName, x.ExaminationTime); }); } catch (Exception ex) { LogHelper.WriteLog(LogType.CommmLog, ex.Message); } return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" + msg }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } } }