using Learun.Util; using System.Data; using Learun.Application.TwoDevelopment.EducationalAdministration; using System.Web.Mvc; using System.Collections.Generic; using System.Threading.Tasks; using System; using Microsoft.AspNet.SignalR.Client; using System.Configuration; using System.Web; using System.Linq; using Learun.Application.Organization; using Learun.Util.Operat; using Newtonsoft.Json; using Learun.Application.TwoDevelopment.LR_Desktop; namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创 建:超级管理员 /// 日 期:2019-05-14 09:49 /// 描 述:选修课排课 /// public class ArrangeLessonTermOfElectiveController : MvcControllerBase { private ArrangeLessonTermOfElectiveIBLL arrangeLessonTermOfElectiveIBLL = new ArrangeLessonTermOfElectiveBLL(); private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL(); private UserIBLL userIbll = new UserBLL(); private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL(); private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL(); #region 视图功能 /// /// 主页面 /// /// [HttpGet] public ActionResult EmptyByConditionForm() { return View(); } [HttpGet] public ActionResult SyncByConditionForm() { return View(); } [HttpGet] public ActionResult Index() { return View(); } /// /// 表单页 /// /// [HttpGet] public ActionResult Form() { return View(); } #endregion #region 获取数据 /// /// 获取页面显示列表数据 /// /// 查询参数 /// [HttpGet] [AjaxOnly] public ActionResult GetPageList(string pagination, string queryJson) { Pagination paginationobj = pagination.ToObject(); var data = arrangeLessonTermOfElectiveIBLL.GetPageList(paginationobj, queryJson); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records }; return Success(jsonData); } /// /// 获取表单数据 /// /// [HttpGet] [AjaxOnly] public ActionResult GetFormData(string keyValue) { var ArrangeLessonTermOfElectiveData = arrangeLessonTermOfElectiveIBLL.GetArrangeLessonTermOfElectiveEntity( keyValue ); var jsonData = new { ArrangeLessonTermOfElective = ArrangeLessonTermOfElectiveData, }; return Success(jsonData); } #endregion #region 提交数据 /// /// 删除实体数据 /// 主键 /// /// [HttpPost] [AjaxOnly] public ActionResult DeleteForm(string keyValue) { arrangeLessonTermOfElectiveIBLL.DeleteEntity(keyValue); return Success("删除成功!"); } /// /// 保存实体数据(新增、修改) /// 主键 /// /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, string strEntity) { ArrangeLessonTermOfElectiveEntity entity = strEntity.ToObject(); arrangeLessonTermOfElectiveIBLL.SaveEntity(keyValue,entity); return Success("保存成功!"); } #endregion #region 扩展数据 /// /// 当前学期选修排课数据同步 /// /// [HttpGet] [AjaxOnly] public async Task AsyncArrangeLessonOfElectiveData() { var data = await arrangeLessonTermOfElectiveIBLL.AsyncArrangeLessonOfElectiveData(); return Success(data); } /// /// 清空当前学期选修排课数据 /// /// [HttpGet] [AjaxOnly] public async Task AsyncModifyArrangeLessonOfElectiveData() { var data = await arrangeLessonTermOfElectiveIBLL.AsyncModifyArrangeLessonOfElectiveData(); return Success(data); } /// /// 按条件清空排课数据 /// /// [HttpPost] [AjaxOnly] public async Task AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermOfElectiveEntity entity) { var data = await arrangeLessonTermOfElectiveIBLL.AsyncModifyArrangeLessonDataByCondition(entity); return Success(data); } /// /// 按条件同步排课数据 /// /// [HttpPost] [AjaxOnly] public async Task AsyncArrangeLessonDataByCondition(ArrangeLessonTermOfElectiveEntity entity) { var data = await arrangeLessonTermOfElectiveIBLL.AsyncArrangeLessonDataByCondition(entity); if (data) { //读取信息推送管理-课表同步推送(09)的配置 var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("09"); if (informationPushEntity != null && informationPushEntity.Status == true) { var title = string.Format("{0}学年第{1}学期选修课课课表同步", entity.AcademicYearNo, entity.Semester); var needpostuserlist = userIbll.GetAllList().Where(m => m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师").ToList(); //微信推送 try { PushWeixin(needpostuserlist, title); } catch (Exception e) { } //飞星推送 await Task.Run(async () => { using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"])) { var hubProxy = hubConnection.CreateHubProxy("SignalRHub"); await hubConnection.Start(); 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)), ""); } }); } } return Success(data); } public void PushWeixin(List needpostuserlist, string title) { var WeChatConfigentity = weChatConfigIbll.GetEnableEntity(); string appid = WeChatConfigentity.APPId; string secret = WeChatConfigentity.secret; var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task"); string weixintaskurl = wechatemplete.TUrl; string weixintasktempid = wechatemplete.TempId; var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret); OperateLogModel operateLogModel = new OperateLogModel(); operateLogModel.title = title; operateLogModel.type = OperationType.Other; operateLogModel.url = "ArrangeLessonTermOfElectiveController"; operateLogModel.sourceObjectId = "002"; operateLogModel.sourceContentJson = responsejson; OperatorHelper.Instance.WriteOperateLog(operateLogModel); foreach (UserEntity userinfo in needpostuserlist) { if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin)) { //执行推送任务 if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid)) { if (!string.IsNullOrEmpty(responsejson)) { var weixintokenobj = JsonConvert.DeserializeObject(responsejson); if (string.IsNullOrEmpty(weixintokenobj.errcode)) { string access_token = weixintokenobj.access_token; string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," + "\"template_id\":\"" + weixintasktempid + "\"," + "\"url\":\"" + weixintaskurl + "\"," + "\"data\":{" + "\"first\": {\"value\":\"您有新的课表同步\",\"color\":\"#173177\"}," + "\"keyword1\":{\"value\":\"课表同步\",\"color\":\"#173177\"}," + "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," + "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," + "\"keyword4\": {\"value\":\"您有新的课表同步【" + title + "】\",\"color\":\"#173177\"}" + "}" + "}"; string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata); operateLogModel.title = title; operateLogModel.type = OperationType.Other; operateLogModel.url = "ArrangeLessonTermOfElectiveController"; operateLogModel.sourceObjectId = "002"; operateLogModel.sourceContentJson = pushresult; OperatorHelper.Instance.WriteOperateLog(operateLogModel); } } } } } } #endregion } }