123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.ViewModel;
- using EMIS.Web.Controls;
- using EMIS.Utility.OnlinePay;
- using Bowin.Web.Controls.Mvc;
- using EMIS.ViewModel.SystemView;
- using Bowin.Common.Exceptions;
- using EMIS.Entities;
- using Bowin.Common.Log;
- namespace EMIS.Web.Controllers
- {
- [Authorization]
- public class AnnouncementController : Controller
- {
- public IAnnouncementServices AnnouncementServices { get; set; }
- public IParameterServices parameterServices { get; set; }
- public IWechatMPServices WechatMPServices { get; set; }
- /// <summary>
- /// 公告类型页面
- /// </summary>
- /// <returns></returns>
- public ActionResult TypeList()
- {
- return View();
- }
- public ActionResult TipEdit()
- {
- var value = parameterServices.GetParameterValue(CF_ParameterType.LoginTip);
- CF_Parameter param = new CF_Parameter();
- param.Value = value;
- return View(param);
- }
- [HttpPost]
- public ActionResult TipEdit(CF_Parameter view)
- {
- try
- {
- parameterServices.SaveTo(CF_ParameterType.LoginTip,view.Value);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- [HttpPost]
- public ActionResult TypeList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(AnnouncementServices.GetAnnouncementTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows));
- }
- [HttpPost]
- public ActionResult TypeDropdownList(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList()
- .Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- /// 公告发布页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- return View();
- }
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(AnnouncementServices.GetAnnouncementViewList(configuretView, (int)pararms.page, (int)pararms.rows));
- }
- [HttpGet]
- public ActionResult TypeEdit(Guid? announcementTypeID)
- {
- AnnouncementTypeView announcementTypeView = new AnnouncementTypeView();
- if (announcementTypeID != null && announcementTypeID != Guid.Empty)
- {
- announcementTypeView = AnnouncementServices.GetAnnouncementTypeViewInfo(announcementTypeID);
- }
- return View(announcementTypeView);
- }
- [HttpGet]
- public ActionResult Edit(Guid? announcementID)
- {
- AnnouncementView announcementView = new AnnouncementView();
- if (announcementID != null && announcementID != Guid.Empty)
- {
- announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
- }
- return View(announcementView);
- }
- [HttpGet]
- public ActionResult EditGDCX(Guid? announcementID)
- {
- AnnouncementView announcementView = new AnnouncementView();
- if (announcementID != null && announcementID != Guid.Empty)
- {
- announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
- }
- return View(announcementView);
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult EditGDCX(AnnouncementView announcementView)
- {
- try
- {
- var roleList = DataGrid.GetTableData<RoleView>("dgRoleList");
- var userList = DataGrid.GetTableData<StudentUserView>("dgUserList");
- var roleIDList = roleList.Select(x => (Guid?)x.RoleID).ToList();
- var userIDList = userList.Select(x => (Guid?)x.UserID).ToList();
- var msg = "";
- Sys_Announcement Announcement = AnnouncementServices.Save(announcementView, roleIDList, userIDList);
- if (announcementView.IsSendWXEdit)
- {
- var ann = AnnouncementServices.GetAnnouncementViewInfo(Announcement.AnnouncementID);
- var openIDList = WechatMPServices.GetOpenIDList(roleIDList, userIDList);
- openIDList.Remove("null");
- //暂时不考虑针对角色发送的消息
- if (openIDList.Count() < userIDList.Count())
- {
- msg = "但有部分学生未在微信端登陆或未关注公众号,无法发送消息给他们!";
- }
- WechatHelper.SendAnnouncementGDCX(announcementView.Title,announcementView.textContent,ann.CreateUserName, openIDList, null, Announcement.CreateTime);
- }
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!" + msg
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 保存公告类型
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult TypeEdit(AnnouncementTypeView announcementTypeView)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- AnnouncementServices.SaveType(announcementTypeView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(AnnouncementView announcementView)
- {
- try
- {
- var roleList = DataGrid.GetTableData<RoleView>("dgRoleList");
- var userList = DataGrid.GetTableData<StudentUserView>("dgUserList");
- var roleIDList = roleList.Select(x => (Guid?)x.RoleID).ToList();
- var userIDList = userList.Select(x => (Guid?)x.UserID).ToList();
- var msg = "";
- Sys_Announcement Announcement = AnnouncementServices.Save(announcementView, roleIDList, userIDList);
- if (announcementView.IsSendWXEdit)
- {
- var openIDList = WechatMPServices.GetOpenIDList(roleIDList, userIDList);
- openIDList.Remove("null");
- //暂时不考虑针对角色发送的消息
- if (openIDList.Count() < userIDList.Count())
- {
- msg = "但有部分学生未在微信端登陆或未关注公众号,无法发送消息给他们!";
- }
- WechatHelper.SendAnnouncement(announcementView.Title, announcementView.textContent, openIDList, null, Announcement.CreateTime);
- }
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!" + msg
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除公告类型
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult DeleteType(string typeIDs)
- {
- try
- {
- var announcementTypeIDList = typeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
- AnnouncementServices.DeleteType(announcementTypeIDList);
- return base.Json("删除成功!");
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
- if(num!=null)
- {
- if (num.Number == 547)
- mge = "该公告被引用请先删除所有关联的数据";
- }
- return base.Json("删除失败,原因:" + mge + "。");
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string announcementIDs)
- {
- try
- {
- var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
- AnnouncementServices.Delete(announcementIDList);
- return base.Json("删除成功!");
- }
- catch (Exception ex)
- {
- return base.Json("删除失败,原因:" + ex.Message + "。");
- }
- }
- [HttpPost]
- public ActionResult GetRoleViewList(Guid? announcementID)
- {
- if (announcementID.HasValue)
- {
- var resultList = AnnouncementServices.GetAnnouncementRoleViewList(announcementID.Value);
- return Json(new JsonDataGridResult<RoleView> { rows = resultList, total = resultList.Count });
- }
- else
- {
- return Json(new JsonDataGridResult<RoleView>());
- }
- }
- [HttpPost]
- public ActionResult GetUserViewList(Guid? announcementID)
- {
- if (announcementID.HasValue)
- {
- var resultList = AnnouncementServices.GetAnnouncementUserViewList(announcementID.Value);
- return Json(new JsonDataGridResult<StudentUserView> { rows = resultList, total = resultList.Count });
- }
- else
- {
- return Json(new JsonDataGridResult<StudentUserView>());
- }
- }
- /// <summary>
- /// 页面查询列获取公告名称
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AnnouncementTypeDropdownList(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList().Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- [HttpPost]
- public ActionResult GetUserAnnouncementViewList(QueryParamsModel pararms, Guid? type)
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- return Json(AnnouncementServices.GetUserAnnouncementView(user.UserID, pararms.page.Value, pararms.rows.Value, type));
- }
- public ActionResult AnnouncementView(Guid announcementID)
- {
- AnnouncementView announcementView = new AnnouncementView();
- announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
- return View(announcementView);
- }
- public ActionResult AnnouncementSetTop(string announcementIDs)
- {
- try
- {
- var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
- AnnouncementServices.SetTop(announcementIDList, true);
- return base.Json("设置成功");
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- return base.Json("设置失败,原因:" + mge + "!");
- }
- }
- }
- }
|