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.
 
 
 
 
 
 

319 lines
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. /// <summary>
  121. /// 获取调度时间数据
  122. /// <summary>
  123. /// <returns></returns>
  124. [HttpGet]
  125. [AjaxOnly]
  126. public ActionResult GetLessonDateList(string queryJson)
  127. {
  128. var data = arrangeLessonTermIBLL.GetList(queryJson).Where(x => x.LessonDate.HasValue).Select(x => x.LessonDate).Distinct().Select(x => new
  129. {
  130. text = x,
  131. value = x
  132. }).OrderBy(x => x.value);
  133. return Success(data);
  134. }
  135. #endregion
  136. #region 提交数据
  137. /// <summary>
  138. /// 删除实体数据
  139. /// <param name="keyValue">主键</param>
  140. /// <summary>
  141. /// <returns></returns>
  142. [HttpPost]
  143. [AjaxOnly]
  144. public ActionResult DeleteForm(string keyValue)
  145. {
  146. arrangeLessonTermIBLL.DeleteEntity(keyValue);
  147. return Success("删除成功!");
  148. }
  149. /// <summary>
  150. /// 保存实体数据(新增、修改)
  151. /// <param name="keyValue">主键</param>
  152. /// <summary>
  153. /// <returns></returns>
  154. [HttpPost]
  155. [ValidateAntiForgeryToken]
  156. [AjaxOnly]
  157. public ActionResult SaveForm(string keyValue, ArrangeLessonTermEntity entity)
  158. {
  159. arrangeLessonTermIBLL.SaveEntity(keyValue, entity);
  160. return Success("保存成功!");
  161. }
  162. #endregion
  163. /// <summary>
  164. /// 当前学期排课数据同步
  165. /// </summary>
  166. /// <returns></returns>
  167. [HttpGet]
  168. [AjaxOnly]
  169. public async Task<ActionResult> AsyncArrangeLessonData()
  170. {
  171. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonData();
  172. return Success(data);
  173. }
  174. /// <summary>
  175. /// 清空当前学期排课数据
  176. /// </summary>
  177. /// <returns></returns>
  178. [HttpGet]
  179. [AjaxOnly]
  180. public async Task<ActionResult> AsyncModifyArrangeLessonData()
  181. {
  182. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonData();
  183. return Success(data);
  184. }
  185. /// <summary>
  186. /// 按条件清空排课数据
  187. /// </summary>
  188. /// <returns></returns>
  189. [HttpPost]
  190. [AjaxOnly]
  191. public async Task<ActionResult> AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  192. {
  193. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonDataByCondition(entity);
  194. return Success(data);
  195. }
  196. /// <summary>
  197. /// 按条件同步排课数据
  198. /// </summary>
  199. /// <returns></returns>
  200. [HttpPost]
  201. [AjaxOnly]
  202. public async Task<ActionResult> AsyncArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  203. {
  204. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonDataByCondition(entity);
  205. if (data)
  206. {
  207. //读取信息推送管理-课表同步推送(09)的配置
  208. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("09");
  209. if (informationPushEntity != null && informationPushEntity.Status == true)
  210. {
  211. var title = string.Format("{0}学年第{1}学期必修课课表同步", entity.AcademicYearNo, entity.Semester);
  212. var needpostuserlist = userIbll.GetAllList().Where(m => m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师").ToList();
  213. //微信推送
  214. try
  215. {
  216. PushWeixin(needpostuserlist, title);
  217. }
  218. catch (Exception e)
  219. {
  220. }
  221. //飞星推送
  222. await Task.Run(async () =>
  223. {
  224. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  225. {
  226. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  227. await hubConnection.Start();
  228. 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)), "");
  229. }
  230. });
  231. }
  232. }
  233. return Success(data);
  234. }
  235. /// <summary>
  236. /// 按条件重置基础数据同步状态
  237. /// </summary>
  238. /// <param name="entity"></param>
  239. /// <returns></returns>
  240. [HttpPost]
  241. [AjaxOnly]
  242. public ActionResult InitAsyncDataByCondition(ArrangeLessonTermEntity entity)
  243. {
  244. var data = arrangeLessonTermIBLL.InitAsyncDataByCondition(entity);
  245. return Success(data);
  246. }
  247. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  248. {
  249. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  250. string appid = WeChatConfigentity.APPId;
  251. string secret = WeChatConfigentity.secret;
  252. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  253. string weixintaskurl = wechatemplete.TUrl;
  254. string weixintasktempid = wechatemplete.TempId;
  255. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  256. OperateLogModel operateLogModel = new OperateLogModel();
  257. operateLogModel.title = title;
  258. operateLogModel.type = OperationType.Other;
  259. operateLogModel.url = "ArrangeLessonTermController";
  260. operateLogModel.sourceObjectId = "002";
  261. operateLogModel.sourceContentJson = responsejson;
  262. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  263. foreach (UserEntity userinfo in needpostuserlist)
  264. {
  265. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  266. {
  267. //执行推送任务
  268. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  269. {
  270. if (!string.IsNullOrEmpty(responsejson))
  271. {
  272. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  273. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  274. {
  275. string access_token = weixintokenobj.access_token;
  276. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  277. "\"template_id\":\"" + weixintasktempid + "\"," +
  278. "\"url\":\"" + weixintaskurl + "\"," +
  279. "\"data\":{" +
  280. "\"first\": {\"value\":\"您有新的课表同步\",\"color\":\"#173177\"}," +
  281. "\"keyword1\":{\"value\":\"课表同步\",\"color\":\"#173177\"}," +
  282. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  283. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  284. "\"keyword4\": {\"value\":\"您有新的课表同步【" + title + "】\",\"color\":\"#173177\"}" +
  285. "}" +
  286. "}";
  287. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  288. operateLogModel.title = title;
  289. operateLogModel.type = OperationType.Other;
  290. operateLogModel.url = "ArrangeLessonTermController";
  291. operateLogModel.sourceObjectId = "002";
  292. operateLogModel.sourceContentJson = pushresult;
  293. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }