|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- using Learun.Application.Organization;
- using Learun.Application.TwoDevelopment.EducationalAdministration;
- using Learun.Application.TwoDevelopment.LR_Desktop;
- using Learun.Util;
- using Learun.Util.Operat;
- using Microsoft.AspNet.SignalR.Client;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web;
- using System.Web.Mvc;
-
- namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创 建:超级管理员
- /// 日 期:2019-02-27 11:05
- /// 描 述:排课
- /// </summary>
- public class ArrangeLessonTermController : MvcControllerBase
- {
- private ArrangeLessonTermIBLL arrangeLessonTermIBLL = new ArrangeLessonTermBLL();
- 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();
- private SchoolCalendarIBLL schoolCalendarIbll = new SchoolCalendarBLL();
- private StuInfoBasicIBLL stuInfoBasicIbll = new StuInfoBasicBLL();
- private EmpInfoIBLL empInfoIbll = new EmpInfoBLL();
-
- #region 视图功能
-
- /// <summary>
- /// 主页面
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// 表单页
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Form()
- {
- return View();
- }
- /// <summary>
- /// 按条件清空排课数据
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult EmptyByConditionForm()
- {
- return View();
- }
- /// <summary>
- /// 按条件同步排课数据
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult SyncByConditionForm()
- {
- return View();
- }
- [HttpGet]
- public ActionResult ClearByConditionForm()
- {
- return View();
- }
- [HttpGet]
- public ActionResult IndexLessonTerm()
- {
- return View();
- }
- /// <summary>
- /// 学生课表
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult IndexLessonTermStu()
- {
- var LogInfo = LoginUserInfo.Get();
- if (LogInfo.Description == "学生")
- {
- var StuInfo = stuInfoBasicIbll.GetAllList().Where(x => x.StuNo == LogInfo.account);
- if (StuInfo != null)
- {
- ViewBag.ClassNo = StuInfo.FirstOrDefault().ClassNo;
- }
- }
- return View();
- }
- /// <summary>
- /// 教师课表
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult IndexLessonTermTeach()
- {
- var LogInfo = LoginUserInfo.Get();
- if (LogInfo.Description == "教师")
- {
- var empInfo = empInfoIbll.GetAllList().Where(x => x.EmpNo == LogInfo.account);
- if (empInfo != null)
- {
- ViewBag.EmpNo = empInfo.FirstOrDefault().EmpNo;
- }
- }
- return View();
- }
-
- #endregion
-
- #region 获取数据
-
- /// <summary>
- /// 获取列表数据
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetList(string queryJson)
- {
- var data = arrangeLessonTermIBLL.GetList(queryJson).ToList()
- .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);
- return Success(data);
- }
- /// <summary>
- /// 获取列表分页数据
- /// <param name="pagination">分页参数</param>
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetPageList(string pagination, string queryJson)
- {
- Pagination paginationobj = pagination.ToObject<Pagination>();
- var data = arrangeLessonTermIBLL.GetPageList(paginationobj, queryJson);
- var jsonData = new
- {
- rows = data,
- total = paginationobj.total,
- page = paginationobj.page,
- records = paginationobj.records
- };
- return Success(jsonData);
- }
-
- /// <summary>
- /// 排课管理 获取左侧树结构
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetTree()
- {
- var data = arrangeLessonTermIBLL.GetTree();
- return Success(data);
- }
-
- /// <summary>
- /// 获取表单数据
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetFormData(string keyValue)
- {
- var data = arrangeLessonTermIBLL.GetEntity(keyValue);
- return Success(data);
- }
-
- /// <summary>
- /// 获取周次
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetWeekTime()
- {
- int weekTimes = 0;
- int curWeek = 0;
- //开始时间
- var startdate = DateTime.Today;
- var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
- //var endDate = Common.CalculateLastDateOfWeek(startdate).ToString("yyyy-MM-dd");
-
- var semesterAndYear = Common.GetSemesterAndYear(startDate);
- //var strAcademicYear = semesterAndYear.AcademicYearShort;
- //var strSemester = semesterAndYear.Semester;
- var entity = schoolCalendarIbll.GetSchoolCalendarEntityByNo(semesterAndYear.AcademicYearShort, semesterAndYear.Semester);
- if (entity.StartTime.HasValue && entity.EndTime.HasValue)
- {
- weekTimes = GetYearWeekCount(entity.StartTime.Value, entity.EndTime.Value);
- curWeek = WeekOfYear(startdate, entity.StartTime.Value, entity.EndTime.Value);
- }
-
- var listObj = new List<Object>();
- for (int i = 1; i <= weekTimes; i++)
- {
- listObj.Add(new { text = i + "周", value = i });
- }
- var jsonData = new
- {
- weekList = listObj,
- curWeek = curWeek,
- };
- return Success(jsonData);
- }
- /// <summary>
- /// 有多少周
- /// 返回 int
- /// </summary>
- /// <returns>int</returns>
- private static int GetYearWeekCount(DateTime startTime, DateTime endTime)
- {
- string returnStr = "";
- var startDate = DateTime.Parse(Common.CalculateFirstDateOfWeek(startTime).ToString("yyyy-MM-dd"));
- //int k = Convert.ToInt32(startTime.DayOfWeek);//得到开始时间的第一天是周几
- int countDay = endTime.Subtract(startDate).Days;
- int countWeek = countDay / 14 + 1;
- return countWeek;
-
- }
- /// <summary>
- /// 求当前日期是第几周
- /// </summary>
- /// <param name="date"></param>
- /// <returns></returns>
- private static int WeekOfYear(DateTime curDay, DateTime startTime, DateTime endTime)
- {
- int firstdayofweek = Convert.ToInt32(startTime.DayOfWeek);
- var startDate = DateTime.Parse(Common.CalculateFirstDateOfWeek(startTime).ToString("yyyy-MM-dd"));
- int k = Convert.ToInt32(startTime.DayOfWeek);//得到开始时间的第一天是周几
- int days = curDay.Subtract(startTime).Days;
- //int days = curDay.DayOfYear;
- int daysOutOneWeek = days - (14 - firstdayofweek);
-
- if (daysOutOneWeek <= 0)
- {
- return 1;
- }
- else
- {
- int weeks = daysOutOneWeek / 14;
- if (daysOutOneWeek % 14 != 0)
- weeks++;
-
- return weeks + 1;
-
- }
-
- }
-
-
- /// <summary>
- /// 课程表【教务】
- /// </summary>
- /// <param name="classNo">班级</param>
- /// <param name="curWeek">当前第几周</param>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetDataInEducation(string classNo, int curWeek)
- {
- var userInfo = LoginUserInfo.Get();
- //开始时间
- var startdate = DateTime.Today;
- var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
- var endDate = Common.CalculateLastDateOfWeek(startdate).ToString("yyyy-MM-dd");
-
- var semesterAndYear = Common.GetSemesterAndYear(startDate);
- var strAcademicYear = semesterAndYear.AcademicYearLong;
- var strSemester = semesterAndYear.Semester;
- if (string.IsNullOrEmpty(classNo))
- {
- if (userInfo.Description != "教师")
- {
- var res = new
- { schoolName = "课程表", semester = $"{strAcademicYear}学年度 第{strSemester}学期", weekList = "" };
- return JsonResult(res);
- }
- }
-
- //校历
- var entity = schoolCalendarIbll.GetSchoolCalendarEntityByNo(semesterAndYear.AcademicYearShort, semesterAndYear.Semester);
- var StartTime = entity.StartTime.Value;
- //根据第几周,计算查询的开始和结束日期
- startDate = Common.CalculateFirstDateOfWeek(StartTime.AddDays(((curWeek - 1) * 14))).ToString("yyyy-MM-dd");//StartTime.AddDays(((curWeek - 1) * 14)).ToString("yyyy-MM-dd");
- if (curWeek == 1 && Convert.ToDateTime(startDate) < StartTime)
- {
- startDate = StartTime.ToString("yyyy-MM-dd");
- }
-
- endDate = Common.CalculateFirstDateOfWeek(StartTime.AddDays(((curWeek - 1) * 14))).AddDays(10)
- .ToString("yyyy-MM-dd");// StartTime.AddDays(((curWeek - 1) * 14)).AddDays(10).ToString("yyyy-MM-dd");
-
- var timeTableList = new List<TimeTable>();
-
- //课程表
- var data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
- if (!string.IsNullOrEmpty(classNo))
- {
- var PKRoleId = Config.GetValue("PKRoleId");
- var loginInfoRoleIds = LoginUserInfo.Get().roleIds;
- if (loginInfoRoleIds.IndexOf(',') == -1)
- {
- if (loginInfoRoleIds == PKRoleId)
- {
- data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
- }
- }
- else
- {
- if (loginInfoRoleIds.Split(',').Contains(PKRoleId))
- {
- data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
- }
- }
- }
- else
- {
- if (userInfo.Description == "学生")
- {
- data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
- }
- else if (userInfo.Description == "教师")
- {
- var empInfo = empInfoIbll.GetAllList().Where(x => x.EmpNo == userInfo.account);
- if (empInfo != null)
- {
- data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, "", empInfo.FirstOrDefault().EmpNo, "");
- }
- }
- else
- {
- data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
- }
- }
-
- timeTableList.AddRange(data);
- //选修课课程表
- //var dataOfElective = arrangeLessonTermOfElectiveIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
- //timeTableList.AddRange(dataOfElective);
-
- var timeTables = timeTableList.ToList();
- var noDataResult = new
- { schoolName = "课程表", semester = $"{strAcademicYear}学年度 第{strSemester}学期", weekList = "" };
- if (!timeTables.Any())
- {
- return JsonResult(noDataResult);
- }
- var formatData = from d in timeTables.AsEnumerable()
- let tt = d.LessonTime.Split('-')[1]
- group d by tt into g
- orderby g.Key
- select new
- {
- time = g.Key,
- list = from e in timeTables.AsEnumerable()
- let ee = e.LessonTime.Split('-')[1]
- where ee == g.Key
- select new
- {
- ALTId = e.ALTId,
- day = e.LessonTime.Split('-')[0],
- curriculum = e.LessonSortNo == "2" ? e.LessonName + "[选修]" : e.LessonName,
- teacher = e?.EmpName,
- classRoom = string.IsNullOrEmpty(e.ClassroomName) ? "" : e.ClassroomName.Trim(),
- academicyear = semesterAndYear.AcademicYearShort,
- semester = strSemester,
- lessonNo = e?.LessonNo,
- teachClassNo = e?.TeachClassNo,
- empno = e?.EmpNo,
- lessonTime = e.LessonTime,
- lessonDate = e.LessonDate.ToString("yyyy-MM-dd"),
- classRoomNo = string.IsNullOrEmpty(e.ClassRoomNo) ? "" : e.ClassRoomNo.Trim(),
- lessonSortNo = e.LessonSortNo,
- e?.OLPEId,
- className = string.IsNullOrEmpty(e.ClassName) ? "" : e.ClassName
- }
- }
- ;
-
- var result = new
- { schoolName = "课程表", semester = $"{strAcademicYear}学年度 第{strSemester}学期", weekList = formatData };
- return JsonResult(result);
- }
-
-
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult DeleteForm(string keyValue)
- {
- arrangeLessonTermIBLL.DeleteEntity(keyValue);
- return Success("删除成功!");
- }
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- public ActionResult SaveForm(string keyValue, ArrangeLessonTermEntity entity)
- {
- arrangeLessonTermIBLL.SaveEntity(keyValue, entity);
- return Success("保存成功!");
- }
-
-
- /// <summary>
- /// 删除课程
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult DeleteLessonTerm(string keyValue, string WeekTime)
- {
- arrangeLessonTermIBLL.DeleteLessonTerm(keyValue, WeekTime);
- return Success("删除成功!");
- }
-
- /// <summary>
- ///修改课程
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult UpdateLessonTerm(string keyValue, string postdata)
- {
- UpdateLessonTermEntity model = postdata.ToObject<UpdateLessonTermEntity>();
- var res = arrangeLessonTermIBLL.UpdateLessonTerm(keyValue, model);
- if (!string.IsNullOrEmpty(res))
- {
- return Fail(res);
- }
-
- return Success("操作成功!");
- }
-
-
- #endregion
-
- /// <summary>
- /// 当前学期排课数据同步
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public async Task<ActionResult> AsyncArrangeLessonData()
- {
- var data = await arrangeLessonTermIBLL.AsyncArrangeLessonData();
- return Success(data);
- }
-
- /// <summary>
- /// 清空当前学期排课数据
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public async Task<ActionResult> AsyncModifyArrangeLessonData()
- {
- var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonData();
- return Success(data);
- }
-
- /// <summary>
- /// 按条件清空排课数据
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public async Task<ActionResult> AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
- {
- var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonDataByCondition(entity);
- return Success(data);
- }
-
- /// <summary>
- /// 按条件同步排课数据
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public async Task<ActionResult> AsyncArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
- {
- var data = await arrangeLessonTermIBLL.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);
- }
- /// <summary>
- /// 按条件重置基础数据同步状态
- /// </summary>
- /// <param name="entity"></param>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult InitAsyncDataByCondition(ArrangeLessonTermEntity entity)
- {
- var data = arrangeLessonTermIBLL.InitAsyncDataByCondition(entity);
- return Success(data);
- }
- public void PushWeixin(List<UserEntity> 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 = "ArrangeLessonTermController";
- 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<dynamic>(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 = "ArrangeLessonTermController";
- operateLogModel.sourceObjectId = "002";
- operateLogModel.sourceContentJson = pushresult;
- OperatorHelper.Instance.WriteOperateLog(operateLogModel);
- }
- }
- }
- }
- }
- }
-
-
- }
- }
|