You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArrangeLessonTermOfElectiveController.cs 11 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using Learun.Util;
  2. using System.Data;
  3. using Learun.Application.TwoDevelopment.EducationalAdministration;
  4. using System.Web.Mvc;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using System;
  8. using Microsoft.AspNet.SignalR.Client;
  9. using System.Configuration;
  10. using System.Web;
  11. using System.Linq;
  12. using Learun.Application.Organization;
  13. using Learun.Util.Operat;
  14. using Newtonsoft.Json;
  15. using Learun.Application.TwoDevelopment.LR_Desktop;
  16. namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers
  17. {
  18. /// <summary>
  19. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  20. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  21. /// 创 建:超级管理员
  22. /// 日 期:2019-05-14 09:49
  23. /// 描 述:选修课排课
  24. /// </summary>
  25. public class ArrangeLessonTermOfElectiveController : MvcControllerBase
  26. {
  27. private ArrangeLessonTermOfElectiveIBLL arrangeLessonTermOfElectiveIBLL = new ArrangeLessonTermOfElectiveBLL();
  28. private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL();
  29. private UserIBLL userIbll = new UserBLL();
  30. private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
  31. private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
  32. #region 视图功能
  33. /// <summary>
  34. /// 主页面
  35. /// <summary>
  36. /// <returns></returns>
  37. [HttpGet]
  38. public ActionResult EmptyByConditionForm()
  39. {
  40. return View();
  41. }
  42. [HttpGet]
  43. public ActionResult SyncByConditionForm()
  44. {
  45. return View();
  46. }
  47. [HttpGet]
  48. public ActionResult Index()
  49. {
  50. return View();
  51. }
  52. /// <summary>
  53. /// 表单页
  54. /// <summary>
  55. /// <returns></returns>
  56. [HttpGet]
  57. public ActionResult Form()
  58. {
  59. return View();
  60. }
  61. #endregion
  62. #region 获取数据
  63. /// <summary>
  64. /// 获取页面显示列表数据
  65. /// <summary>
  66. /// <param name="queryJson">查询参数</param>
  67. /// <returns></returns>
  68. [HttpGet]
  69. [AjaxOnly]
  70. public ActionResult GetPageList(string pagination, string queryJson)
  71. {
  72. Pagination paginationobj = pagination.ToObject<Pagination>();
  73. var data = arrangeLessonTermOfElectiveIBLL.GetPageList(paginationobj, queryJson);
  74. var jsonData = new
  75. {
  76. rows = data,
  77. total = paginationobj.total,
  78. page = paginationobj.page,
  79. records = paginationobj.records
  80. };
  81. return Success(jsonData);
  82. }
  83. /// <summary>
  84. /// 获取表单数据
  85. /// <summary>
  86. /// <returns></returns>
  87. [HttpGet]
  88. [AjaxOnly]
  89. public ActionResult GetFormData(string keyValue)
  90. {
  91. var ArrangeLessonTermOfElectiveData = arrangeLessonTermOfElectiveIBLL.GetArrangeLessonTermOfElectiveEntity( keyValue );
  92. var jsonData = new {
  93. ArrangeLessonTermOfElective = ArrangeLessonTermOfElectiveData,
  94. };
  95. return Success(jsonData);
  96. }
  97. #endregion
  98. #region 提交数据
  99. /// <summary>
  100. /// 删除实体数据
  101. /// <param name="keyValue">主键</param>
  102. /// <summary>
  103. /// <returns></returns>
  104. [HttpPost]
  105. [AjaxOnly]
  106. public ActionResult DeleteForm(string keyValue)
  107. {
  108. arrangeLessonTermOfElectiveIBLL.DeleteEntity(keyValue);
  109. return Success("删除成功!");
  110. }
  111. /// <summary>
  112. /// 保存实体数据(新增、修改)
  113. /// <param name="keyValue">主键</param>
  114. /// <summary>
  115. /// <returns></returns>
  116. [HttpPost]
  117. [ValidateAntiForgeryToken]
  118. [AjaxOnly]
  119. public ActionResult SaveForm(string keyValue, string strEntity)
  120. {
  121. ArrangeLessonTermOfElectiveEntity entity = strEntity.ToObject<ArrangeLessonTermOfElectiveEntity>();
  122. arrangeLessonTermOfElectiveIBLL.SaveEntity(keyValue,entity);
  123. return Success("保存成功!");
  124. }
  125. #endregion
  126. #region 扩展数据
  127. /// <summary>
  128. /// 当前学期选修排课数据同步
  129. /// </summary>
  130. /// <returns></returns>
  131. [HttpGet]
  132. [AjaxOnly]
  133. public async Task<ActionResult> AsyncArrangeLessonOfElectiveData()
  134. {
  135. var data = await arrangeLessonTermOfElectiveIBLL.AsyncArrangeLessonOfElectiveData();
  136. return Success(data);
  137. }
  138. /// <summary>
  139. /// 清空当前学期选修排课数据
  140. /// </summary>
  141. /// <returns></returns>
  142. [HttpGet]
  143. [AjaxOnly]
  144. public async Task<ActionResult> AsyncModifyArrangeLessonOfElectiveData()
  145. {
  146. var data = await arrangeLessonTermOfElectiveIBLL.AsyncModifyArrangeLessonOfElectiveData();
  147. return Success(data);
  148. }
  149. /// <summary>
  150. /// 按条件清空排课数据
  151. /// </summary>
  152. /// <returns></returns>
  153. [HttpPost]
  154. [AjaxOnly]
  155. public async Task<ActionResult> AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermOfElectiveEntity entity)
  156. {
  157. var data = await arrangeLessonTermOfElectiveIBLL.AsyncModifyArrangeLessonDataByCondition(entity);
  158. return Success(data);
  159. }
  160. /// <summary>
  161. /// 按条件同步排课数据
  162. /// </summary>
  163. /// <returns></returns>
  164. [HttpPost]
  165. [AjaxOnly]
  166. public async Task<ActionResult> AsyncArrangeLessonDataByCondition(ArrangeLessonTermOfElectiveEntity entity)
  167. {
  168. var data = await arrangeLessonTermOfElectiveIBLL.AsyncArrangeLessonDataByCondition(entity);
  169. if (data)
  170. {
  171. //读取信息推送管理-课表同步推送(09)的配置
  172. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("09");
  173. if (informationPushEntity != null && informationPushEntity.Status == true)
  174. {
  175. var title = string.Format("{0}学年第{1}学期选修课课课表同步", entity.AcademicYearNo, entity.Semester);
  176. var needpostuserlist = userIbll.GetAllList().Where(m => m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师").ToList();
  177. //微信推送
  178. try
  179. {
  180. PushWeixin(needpostuserlist, title);
  181. }
  182. catch (Exception e)
  183. {
  184. }
  185. //飞星推送
  186. await Task.Run(async () =>
  187. {
  188. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  189. {
  190. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  191. await hubConnection.Start();
  192. await hubProxy.Invoke("PushAnnouncement", LoginUserInfo.Get().userId, "课表同步", Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(title)).Length < 20 ? Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(title)) : Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(title)).Substring(0, 20), "synclesson", string.Join(",", needpostuserlist.Select(m => m.F_UserId)), "");
  193. }
  194. });
  195. }
  196. }
  197. return Success(data);
  198. }
  199. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  200. {
  201. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  202. string appid = WeChatConfigentity.APPId;
  203. string secret = WeChatConfigentity.secret;
  204. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  205. string weixintaskurl = wechatemplete.TUrl;
  206. string weixintasktempid = wechatemplete.TempId;
  207. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  208. OperateLogModel operateLogModel = new OperateLogModel();
  209. operateLogModel.title = title;
  210. operateLogModel.type = OperationType.Other;
  211. operateLogModel.url = "ArrangeLessonTermOfElectiveController";
  212. operateLogModel.sourceObjectId = "002";
  213. operateLogModel.sourceContentJson = responsejson;
  214. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  215. foreach (UserEntity userinfo in needpostuserlist)
  216. {
  217. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  218. {
  219. //执行推送任务
  220. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  221. {
  222. if (!string.IsNullOrEmpty(responsejson))
  223. {
  224. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  225. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  226. {
  227. string access_token = weixintokenobj.access_token;
  228. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  229. "\"template_id\":\"" + weixintasktempid + "\"," +
  230. "\"url\":\"" + weixintaskurl + "\"," +
  231. "\"data\":{" +
  232. "\"first\": {\"value\":\"您有新的课表同步\",\"color\":\"#173177\"}," +
  233. "\"keyword1\":{\"value\":\"课表同步\",\"color\":\"#173177\"}," +
  234. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  235. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  236. "\"keyword4\": {\"value\":\"您有新的课表同步【" + title + "】\",\"color\":\"#173177\"}" +
  237. "}" +
  238. "}";
  239. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  240. operateLogModel.title = title;
  241. operateLogModel.type = OperationType.Other;
  242. operateLogModel.url = "ArrangeLessonTermOfElectiveController";
  243. operateLogModel.sourceObjectId = "002";
  244. operateLogModel.sourceContentJson = pushresult;
  245. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. #endregion
  253. }
  254. }