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.
 
 
 
 
 
 

303 line
12 KiB

  1. using Learun.Application.Organization;
  2. using Learun.Application.TwoDevelopment.EducationalAdministration;
  3. using Learun.Application.TwoDevelopment.LR_Desktop;
  4. using Learun.Util;
  5. using Learun.Util.Operat;
  6. using Microsoft.AspNet.SignalR.Client;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using System.Data;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. using System.Web;
  15. using System.Web.Mvc;
  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-02-27 11:05
  23. /// 描 述:排课
  24. /// </summary>
  25. public class ArrangeLessonTermController : MvcControllerBase
  26. {
  27. private ArrangeLessonTermIBLL arrangeLessonTermIBLL = new ArrangeLessonTermBLL();
  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 Index()
  39. {
  40. return View();
  41. }
  42. /// <summary>
  43. /// 表单页
  44. /// <summary>
  45. /// <returns></returns>
  46. [HttpGet]
  47. public ActionResult Form()
  48. {
  49. return View();
  50. }
  51. /// <summary>
  52. /// 按条件清空排课数据
  53. /// <summary>
  54. /// <returns></returns>
  55. [HttpGet]
  56. public ActionResult EmptyByConditionForm()
  57. {
  58. return View();
  59. }
  60. /// <summary>
  61. /// 按条件同步排课数据
  62. /// <summary>
  63. /// <returns></returns>
  64. [HttpGet]
  65. public ActionResult SyncByConditionForm()
  66. {
  67. return View();
  68. }
  69. [HttpGet]
  70. public ActionResult ClearByConditionForm()
  71. {
  72. return View();
  73. }
  74. #endregion
  75. #region 获取数据
  76. /// <summary>
  77. /// 获取列表数据
  78. /// <summary>
  79. /// <returns></returns>
  80. [HttpGet]
  81. [AjaxOnly]
  82. public ActionResult GetList(string queryJson)
  83. {
  84. var data = arrangeLessonTermIBLL.GetList(queryJson).ToList()
  85. .OrderBy(x => x.AcademicYearNo).ThenBy(x => x.Semester).ThenBy(x => x.DeptNo).ThenBy(x => x.MajorNo).ThenBy(x => x.LessonNo).ThenBy(x => x.TeachClassNo.Replace(x.LessonName, "")).ThenBy(x => x.EmpNo).ThenBy(x => x.ClassroomNo).ThenBy(x => x.LessonDate);
  86. return Success(data);
  87. }
  88. /// <summary>
  89. /// 获取列表分页数据
  90. /// <param name="pagination">分页参数</param>
  91. /// <summary>
  92. /// <returns></returns>
  93. [HttpGet]
  94. [AjaxOnly]
  95. public ActionResult GetPageList(string pagination, string queryJson)
  96. {
  97. Pagination paginationobj = pagination.ToObject<Pagination>();
  98. var data = arrangeLessonTermIBLL.GetPageList(paginationobj, queryJson);
  99. var jsonData = new
  100. {
  101. rows = data,
  102. total = paginationobj.total,
  103. page = paginationobj.page,
  104. records = paginationobj.records
  105. };
  106. return Success(jsonData);
  107. }
  108. /// <summary>
  109. /// 获取表单数据
  110. /// <param name="keyValue">主键</param>
  111. /// <summary>
  112. /// <returns></returns>
  113. [HttpGet]
  114. [AjaxOnly]
  115. public ActionResult GetFormData(string keyValue)
  116. {
  117. var data = arrangeLessonTermIBLL.GetEntity(keyValue);
  118. return Success(data);
  119. }
  120. #endregion
  121. #region 提交数据
  122. /// <summary>
  123. /// 删除实体数据
  124. /// <param name="keyValue">主键</param>
  125. /// <summary>
  126. /// <returns></returns>
  127. [HttpPost]
  128. [AjaxOnly]
  129. public ActionResult DeleteForm(string keyValue)
  130. {
  131. arrangeLessonTermIBLL.DeleteEntity(keyValue);
  132. return Success("删除成功!");
  133. }
  134. /// <summary>
  135. /// 保存实体数据(新增、修改)
  136. /// <param name="keyValue">主键</param>
  137. /// <summary>
  138. /// <returns></returns>
  139. [HttpPost]
  140. [ValidateAntiForgeryToken]
  141. [AjaxOnly]
  142. public ActionResult SaveForm(string keyValue, ArrangeLessonTermEntity entity)
  143. {
  144. arrangeLessonTermIBLL.SaveEntity(keyValue, entity);
  145. return Success("保存成功!");
  146. }
  147. #endregion
  148. /// <summary>
  149. /// 当前学期排课数据同步
  150. /// </summary>
  151. /// <returns></returns>
  152. [HttpGet]
  153. [AjaxOnly]
  154. public async Task<ActionResult> AsyncArrangeLessonData()
  155. {
  156. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonData();
  157. return Success(data);
  158. }
  159. /// <summary>
  160. /// 清空当前学期排课数据
  161. /// </summary>
  162. /// <returns></returns>
  163. [HttpGet]
  164. [AjaxOnly]
  165. public async Task<ActionResult> AsyncModifyArrangeLessonData()
  166. {
  167. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonData();
  168. return Success(data);
  169. }
  170. /// <summary>
  171. /// 按条件清空排课数据
  172. /// </summary>
  173. /// <returns></returns>
  174. [HttpPost]
  175. [AjaxOnly]
  176. public async Task<ActionResult> AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  177. {
  178. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonDataByCondition(entity);
  179. return Success(data);
  180. }
  181. /// <summary>
  182. /// 按条件同步排课数据
  183. /// </summary>
  184. /// <returns></returns>
  185. [HttpPost]
  186. [AjaxOnly]
  187. public async Task<ActionResult> AsyncArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  188. {
  189. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonDataByCondition(entity);
  190. if (data)
  191. {
  192. //读取信息推送管理-课表同步推送(09)的配置
  193. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("09");
  194. if (informationPushEntity != null && informationPushEntity.Status == true)
  195. {
  196. var title = string.Format("{0}学年第{1}学期必修课课表同步", entity.AcademicYearNo, entity.Semester);
  197. var needpostuserlist = userIbll.GetAllList().Where(m => m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师").ToList();
  198. //微信推送
  199. try
  200. {
  201. PushWeixin(needpostuserlist, title);
  202. }
  203. catch (Exception e)
  204. {
  205. }
  206. //飞星推送
  207. await Task.Run(async () =>
  208. {
  209. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  210. {
  211. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  212. await hubConnection.Start();
  213. 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)), "");
  214. }
  215. });
  216. }
  217. }
  218. return Success(data);
  219. }
  220. /// <summary>
  221. /// 按条件重置基础数据同步状态
  222. /// </summary>
  223. /// <param name="entity"></param>
  224. /// <returns></returns>
  225. [HttpPost]
  226. [AjaxOnly]
  227. public ActionResult InitAsyncDataByCondition(ArrangeLessonTermEntity entity)
  228. {
  229. var data = arrangeLessonTermIBLL.InitAsyncDataByCondition(entity);
  230. return Success(data);
  231. }
  232. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  233. {
  234. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  235. string appid = WeChatConfigentity.APPId;
  236. string secret = WeChatConfigentity.secret;
  237. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  238. string weixintaskurl = wechatemplete.TUrl;
  239. string weixintasktempid = wechatemplete.TempId;
  240. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  241. OperateLogModel operateLogModel = new OperateLogModel();
  242. operateLogModel.title = title;
  243. operateLogModel.type = OperationType.Other;
  244. operateLogModel.url = "ArrangeLessonTermController";
  245. operateLogModel.sourceObjectId = "002";
  246. operateLogModel.sourceContentJson = responsejson;
  247. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  248. foreach (UserEntity userinfo in needpostuserlist)
  249. {
  250. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  251. {
  252. //执行推送任务
  253. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  254. {
  255. if (!string.IsNullOrEmpty(responsejson))
  256. {
  257. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  258. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  259. {
  260. string access_token = weixintokenobj.access_token;
  261. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  262. "\"template_id\":\"" + weixintasktempid + "\"," +
  263. "\"url\":\"" + weixintaskurl + "\"," +
  264. "\"data\":{" +
  265. "\"first\": {\"value\":\"您有新的课表同步\",\"color\":\"#173177\"}," +
  266. "\"keyword1\":{\"value\":\"课表同步\",\"color\":\"#173177\"}," +
  267. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  268. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  269. "\"keyword4\": {\"value\":\"您有新的课表同步【" + title + "】\",\"color\":\"#173177\"}" +
  270. "}" +
  271. "}";
  272. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  273. operateLogModel.title = title;
  274. operateLogModel.type = OperationType.Other;
  275. operateLogModel.url = "ArrangeLessonTermController";
  276. operateLogModel.sourceObjectId = "002";
  277. operateLogModel.sourceContentJson = pushresult;
  278. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }