AnnouncementController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.SystemServices;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using EMIS.Utility.OnlinePay;
  10. using Bowin.Web.Controls.Mvc;
  11. using EMIS.ViewModel.SystemView;
  12. using Bowin.Common.Exceptions;
  13. using EMIS.Entities;
  14. using Bowin.Common.Log;
  15. namespace EMIS.Web.Controllers
  16. {
  17. [Authorization]
  18. public class AnnouncementController : Controller
  19. {
  20. public IAnnouncementServices AnnouncementServices { get; set; }
  21. public IParameterServices parameterServices { get; set; }
  22. public IWechatMPServices WechatMPServices { get; set; }
  23. /// <summary>
  24. /// 公告类型页面
  25. /// </summary>
  26. /// <returns></returns>
  27. public ActionResult TypeList()
  28. {
  29. return View();
  30. }
  31. public ActionResult TipEdit()
  32. {
  33. var value = parameterServices.GetParameterValue(CF_ParameterType.LoginTip);
  34. CF_Parameter param = new CF_Parameter();
  35. param.Value = value;
  36. return View(param);
  37. }
  38. [HttpPost]
  39. public ActionResult TipEdit(CF_Parameter view)
  40. {
  41. try
  42. {
  43. parameterServices.SaveTo(CF_ParameterType.LoginTip,view.Value);
  44. return Json(new ReturnMessage()
  45. {
  46. IsSuccess = true,
  47. Message = "保存成功!"
  48. });
  49. }
  50. catch (Exception ex)
  51. {
  52. return Json(new ReturnMessage()
  53. {
  54. IsSuccess = false,
  55. Message = "保存失败:" + ex.Message
  56. });
  57. }
  58. }
  59. [HttpPost]
  60. public ActionResult TypeList(QueryParamsModel pararms)
  61. {
  62. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  63. //避开全选值
  64. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  65. return base.Json(AnnouncementServices.GetAnnouncementTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows));
  66. }
  67. [HttpPost]
  68. public ActionResult TypeDropdownList(DropdownListBindType? bindType)
  69. {
  70. List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList()
  71. .Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
  72. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  73. DropdownList.FormatDropdownItemList(dbt, list);
  74. return base.Json(list);
  75. }
  76. /// <summary>
  77. /// 公告发布页面
  78. /// </summary>
  79. /// <returns></returns>
  80. public ActionResult List()
  81. {
  82. return View();
  83. }
  84. [HttpPost]
  85. public ActionResult List(QueryParamsModel pararms)
  86. {
  87. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  88. //避开全选值
  89. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  90. return base.Json(AnnouncementServices.GetAnnouncementViewList(configuretView, (int)pararms.page, (int)pararms.rows));
  91. }
  92. [HttpGet]
  93. public ActionResult TypeEdit(Guid? announcementTypeID)
  94. {
  95. AnnouncementTypeView announcementTypeView = new AnnouncementTypeView();
  96. if (announcementTypeID != null && announcementTypeID != Guid.Empty)
  97. {
  98. announcementTypeView = AnnouncementServices.GetAnnouncementTypeViewInfo(announcementTypeID);
  99. }
  100. return View(announcementTypeView);
  101. }
  102. [HttpGet]
  103. public ActionResult Edit(Guid? announcementID)
  104. {
  105. AnnouncementView announcementView = new AnnouncementView();
  106. if (announcementID != null && announcementID != Guid.Empty)
  107. {
  108. announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
  109. }
  110. return View(announcementView);
  111. }
  112. [HttpGet]
  113. public ActionResult EditGDCX(Guid? announcementID)
  114. {
  115. AnnouncementView announcementView = new AnnouncementView();
  116. if (announcementID != null && announcementID != Guid.Empty)
  117. {
  118. announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
  119. }
  120. return View(announcementView);
  121. }
  122. /// <summary>
  123. /// 保存
  124. /// </summary>
  125. /// <returns></returns>
  126. [HttpPost]
  127. public ActionResult EditGDCX(AnnouncementView announcementView)
  128. {
  129. try
  130. {
  131. var roleList = DataGrid.GetTableData<RoleView>("dgRoleList");
  132. var userList = DataGrid.GetTableData<StudentUserView>("dgUserList");
  133. var roleIDList = roleList.Select(x => (Guid?)x.RoleID).ToList();
  134. var userIDList = userList.Select(x => (Guid?)x.UserID).ToList();
  135. var msg = "";
  136. Sys_Announcement Announcement = AnnouncementServices.Save(announcementView, roleIDList, userIDList);
  137. if (announcementView.IsSendWXEdit)
  138. {
  139. var ann = AnnouncementServices.GetAnnouncementViewInfo(Announcement.AnnouncementID);
  140. var openIDList = WechatMPServices.GetOpenIDList(roleIDList, userIDList);
  141. openIDList.Remove("null");
  142. //暂时不考虑针对角色发送的消息
  143. if (openIDList.Count() < userIDList.Count())
  144. {
  145. msg = "但有部分学生未在微信端登陆或未关注公众号,无法发送消息给他们!";
  146. }
  147. WechatHelper.SendAnnouncementGDCX(announcementView.Title,announcementView.textContent,ann.CreateUserName, openIDList, null, Announcement.CreateTime);
  148. }
  149. return Json(new ReturnMessage()
  150. {
  151. IsSuccess = true,
  152. Message = "保存成功!" + msg
  153. });
  154. }
  155. catch (Exception ex)
  156. {
  157. return Json(new ReturnMessage()
  158. {
  159. IsSuccess = false,
  160. Message = "保存失败:" + ex.Message
  161. });
  162. }
  163. }
  164. /// <summary>
  165. /// 保存公告类型
  166. /// </summary>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public ActionResult TypeEdit(AnnouncementTypeView announcementTypeView)
  170. {
  171. try
  172. {
  173. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  174. AnnouncementServices.SaveType(announcementTypeView);
  175. return Json(new ReturnMessage()
  176. {
  177. IsSuccess = true,
  178. Message = "保存成功!"
  179. });
  180. }
  181. catch (Exception ex)
  182. {
  183. return Json(new ReturnMessage()
  184. {
  185. IsSuccess = false,
  186. Message = "保存失败:" + ex.Message
  187. });
  188. }
  189. }
  190. /// <summary>
  191. /// 保存
  192. /// </summary>
  193. /// <returns></returns>
  194. [HttpPost]
  195. public ActionResult Edit(AnnouncementView announcementView)
  196. {
  197. try
  198. {
  199. var roleList = DataGrid.GetTableData<RoleView>("dgRoleList");
  200. var userList = DataGrid.GetTableData<StudentUserView>("dgUserList");
  201. var roleIDList = roleList.Select(x => (Guid?)x.RoleID).ToList();
  202. var userIDList = userList.Select(x => (Guid?)x.UserID).ToList();
  203. var msg = "";
  204. Sys_Announcement Announcement = AnnouncementServices.Save(announcementView, roleIDList, userIDList);
  205. if (announcementView.IsSendWXEdit)
  206. {
  207. var openIDList = WechatMPServices.GetOpenIDList(roleIDList, userIDList);
  208. openIDList.Remove("null");
  209. //暂时不考虑针对角色发送的消息
  210. if (openIDList.Count() < userIDList.Count())
  211. {
  212. msg = "但有部分学生未在微信端登陆或未关注公众号,无法发送消息给他们!";
  213. }
  214. WechatHelper.SendAnnouncement(announcementView.Title, announcementView.textContent, openIDList, null, Announcement.CreateTime);
  215. }
  216. return Json(new ReturnMessage()
  217. {
  218. IsSuccess = true,
  219. Message = "保存成功!" + msg
  220. });
  221. }
  222. catch (Exception ex)
  223. {
  224. return Json(new ReturnMessage()
  225. {
  226. IsSuccess = false,
  227. Message = "保存失败:" + ex.Message
  228. });
  229. }
  230. }
  231. /// <summary>
  232. /// 删除公告类型
  233. /// </summary>
  234. /// <param name="roleID"></param>
  235. /// <returns></returns>
  236. [HttpPost]
  237. public ActionResult DeleteType(string typeIDs)
  238. {
  239. try
  240. {
  241. var announcementTypeIDList = typeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  242. AnnouncementServices.DeleteType(announcementTypeIDList);
  243. return base.Json("删除成功!");
  244. }
  245. catch (Exception ex)
  246. {
  247. string mge = ex.Message;
  248. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  249. if(num!=null)
  250. {
  251. if (num.Number == 547)
  252. mge = "该公告被引用请先删除所有关联的数据";
  253. }
  254. return base.Json("删除失败,原因:" + mge + "。");
  255. }
  256. }
  257. /// <summary>
  258. /// 删除
  259. /// </summary>
  260. /// <param name="roleID"></param>
  261. /// <returns></returns>
  262. [HttpPost]
  263. public ActionResult Delete(string announcementIDs)
  264. {
  265. try
  266. {
  267. var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  268. AnnouncementServices.Delete(announcementIDList);
  269. return base.Json("删除成功!");
  270. }
  271. catch (Exception ex)
  272. {
  273. return base.Json("删除失败,原因:" + ex.Message + "。");
  274. }
  275. }
  276. [HttpPost]
  277. public ActionResult GetRoleViewList(Guid? announcementID)
  278. {
  279. if (announcementID.HasValue)
  280. {
  281. var resultList = AnnouncementServices.GetAnnouncementRoleViewList(announcementID.Value);
  282. return Json(new JsonDataGridResult<RoleView> { rows = resultList, total = resultList.Count });
  283. }
  284. else
  285. {
  286. return Json(new JsonDataGridResult<RoleView>());
  287. }
  288. }
  289. [HttpPost]
  290. public ActionResult GetUserViewList(Guid? announcementID)
  291. {
  292. if (announcementID.HasValue)
  293. {
  294. var resultList = AnnouncementServices.GetAnnouncementUserViewList(announcementID.Value);
  295. return Json(new JsonDataGridResult<StudentUserView> { rows = resultList, total = resultList.Count });
  296. }
  297. else
  298. {
  299. return Json(new JsonDataGridResult<StudentUserView>());
  300. }
  301. }
  302. /// <summary>
  303. /// 页面查询列获取公告名称
  304. /// </summary>
  305. /// <param name="bindType"></param>
  306. /// <returns></returns>
  307. [HttpPost]
  308. public ActionResult AnnouncementTypeDropdownList(DropdownListBindType? bindType)
  309. {
  310. List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList().Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
  311. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  312. DropdownList.FormatDropdownItemList(dbt, list);
  313. return base.Json(list);
  314. }
  315. [HttpPost]
  316. public ActionResult GetUserAnnouncementViewList(QueryParamsModel pararms, Guid? type)
  317. {
  318. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  319. return Json(AnnouncementServices.GetUserAnnouncementView(user.UserID, pararms.page.Value, pararms.rows.Value, type));
  320. }
  321. public ActionResult AnnouncementView(Guid announcementID)
  322. {
  323. AnnouncementView announcementView = new AnnouncementView();
  324. announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
  325. return View(announcementView);
  326. }
  327. public ActionResult AnnouncementSetTop(string announcementIDs)
  328. {
  329. try
  330. {
  331. var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  332. AnnouncementServices.SetTop(announcementIDList, true);
  333. return base.Json("设置成功");
  334. }
  335. catch (Exception ex)
  336. {
  337. string mge = ex.Message;
  338. return base.Json("设置失败,原因:" + mge + "!");
  339. }
  340. }
  341. }
  342. }