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.
 
 
 
 
 
 

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