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.
 
 
 
 
 
 

406 lines
16 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. private CdDeptIBLL cdDeptIBLL = new CdDeptBLL();
  33. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  34. #region 视图功能
  35. /// <summary>
  36. /// 主页面
  37. /// <summary>
  38. /// <returns></returns>
  39. [HttpGet]
  40. public ActionResult Index()
  41. {
  42. return View();
  43. }
  44. /// <summary>
  45. /// 表单页
  46. /// <summary>
  47. /// <returns></returns>
  48. [HttpGet]
  49. public ActionResult Form()
  50. {
  51. return View();
  52. }
  53. /// <summary>
  54. /// 按条件清空排课数据
  55. /// <summary>
  56. /// <returns></returns>
  57. [HttpGet]
  58. public ActionResult EmptyByConditionForm()
  59. {
  60. return View();
  61. }
  62. [HttpGet]
  63. public ActionResult EmptyByConditionFormNew()
  64. {
  65. return View();
  66. }
  67. /// <summary>
  68. /// 按条件同步排课数据
  69. /// <summary>
  70. /// <returns></returns>
  71. [HttpGet]
  72. public ActionResult SyncByConditionForm()
  73. {
  74. return View();
  75. }
  76. [HttpGet]
  77. public ActionResult ClearByConditionForm()
  78. {
  79. return View();
  80. }
  81. /// <summary>
  82. /// 课时统计
  83. /// </summary>
  84. /// <returns></returns>
  85. [HttpGet]
  86. public ActionResult coursestatictis()
  87. {
  88. return View();
  89. }
  90. /// <summary>
  91. /// 课时统计打印
  92. /// </summary>
  93. /// <returns></returns>
  94. [HttpGet]
  95. public ActionResult PrintCourseStatistic(string weeks, string deptNo, string StartTime, string EndTime, string status)
  96. {
  97. Pagination paginationobj = new Pagination() { rows = 100000, page = 1, sidx = "empno ", sord = "asc" };
  98. var queryJson = "{\"weeks\":\"" + weeks + "\",\"status\":\"" + status + "\",\"deptNo\":\"" + deptNo + "\",\"StartTime\":\"" + StartTime + "\",\"EndTime\":\"" + EndTime + "\"}";
  99. var data = arrangeLessonTermIBLL.GetcoursestatictisList(paginationobj, queryJson).ToList();
  100. if(data.Any())
  101. {
  102. decimal hj = 0;
  103. foreach (var item in data)
  104. {
  105. if(!item.actfeestandard.IsEmpty() && Convert.ToDecimal(item.actfeestandard)>0)
  106. {
  107. hj += Convert.ToDecimal(item.actfeestandard);
  108. }
  109. }
  110. var tj = new LessonStatictisEntity
  111. {
  112. empname = "合计",
  113. actfeestandard = hj.ToString()
  114. };
  115. data.Add(tj);
  116. }
  117. ViewBag.data = data;
  118. ViewBag.startTime = StartTime;
  119. ViewBag.endTime = EndTime;
  120. ViewBag.deptName = "";
  121. if (!string.IsNullOrEmpty(deptNo))
  122. {
  123. var deptEntity = departmentIBLL.GetEntity(deptNo);
  124. if (deptEntity != null)
  125. {
  126. ViewBag.deptName = deptEntity.F_FullName;
  127. }
  128. }
  129. return View();
  130. }
  131. #endregion
  132. #region 获取数据
  133. /// <summary>
  134. /// 获取列表数据
  135. /// <summary>
  136. /// <returns></returns>
  137. [HttpGet]
  138. [AjaxOnly]
  139. public ActionResult GetList(string queryJson)
  140. {
  141. var data = arrangeLessonTermIBLL.GetList(queryJson).ToList()
  142. .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);
  143. return Success(data);
  144. }
  145. /// <summary>
  146. /// 获取列表分页数据
  147. /// <param name="pagination">分页参数</param>
  148. /// <summary>
  149. /// <returns></returns>
  150. [HttpGet]
  151. [AjaxOnly]
  152. public ActionResult GetPageList(string pagination, string queryJson)
  153. {
  154. Pagination paginationobj = pagination.ToObject<Pagination>();
  155. var data = arrangeLessonTermIBLL.GetPageList(paginationobj, queryJson);
  156. var jsonData = new
  157. {
  158. rows = data,
  159. total = paginationobj.total,
  160. page = paginationobj.page,
  161. records = paginationobj.records
  162. };
  163. return Success(jsonData);
  164. }
  165. /// <summary>
  166. /// 获取表单数据
  167. /// <param name="keyValue">主键</param>
  168. /// <summary>
  169. /// <returns></returns>
  170. [HttpGet]
  171. [AjaxOnly]
  172. public ActionResult GetFormData(string keyValue)
  173. {
  174. var data = arrangeLessonTermIBLL.GetEntity(keyValue);
  175. return Success(data);
  176. }
  177. /// <summary>
  178. /// 获取调度时间数据
  179. /// <summary>
  180. /// <returns></returns>
  181. [HttpGet]
  182. [AjaxOnly]
  183. public ActionResult GetLessonDateList(string queryJson)
  184. {
  185. var data = arrangeLessonTermIBLL.GetList(queryJson).Where(x => x.LessonDate.HasValue).Select(x => x.LessonDate).Distinct().Select(x => new
  186. {
  187. text = x,
  188. value = x
  189. }).OrderBy(x => x.value);
  190. return Success(data);
  191. }
  192. #endregion
  193. #region 提交数据
  194. /// <summary>
  195. /// 删除实体数据
  196. /// <param name="keyValue">主键</param>
  197. /// <summary>
  198. /// <returns></returns>
  199. [HttpPost]
  200. [AjaxOnly]
  201. public ActionResult DeleteForm(string keyValue)
  202. {
  203. arrangeLessonTermIBLL.DeleteEntity(keyValue);
  204. return Success("删除成功!");
  205. }
  206. /// <summary>
  207. /// 保存实体数据(新增、修改)
  208. /// <param name="keyValue">主键</param>
  209. /// <summary>
  210. /// <returns></returns>
  211. [HttpPost]
  212. [ValidateAntiForgeryToken]
  213. [AjaxOnly]
  214. public ActionResult SaveForm(string keyValue, ArrangeLessonTermEntity entity)
  215. {
  216. arrangeLessonTermIBLL.SaveEntity(keyValue, entity);
  217. return Success("保存成功!");
  218. }
  219. #endregion
  220. #region MyRegion
  221. /// <summary>
  222. /// 当前学期排课数据同步
  223. /// </summary>
  224. /// <returns></returns>
  225. [HttpGet]
  226. [AjaxOnly]
  227. public async Task<ActionResult> AsyncArrangeLessonData()
  228. {
  229. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonData();
  230. return Success(data);
  231. }
  232. /// <summary>
  233. /// 清空当前学期排课数据
  234. /// </summary>
  235. /// <returns></returns>
  236. [HttpGet]
  237. [AjaxOnly]
  238. public async Task<ActionResult> AsyncModifyArrangeLessonData()
  239. {
  240. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonData();
  241. return Success(data);
  242. }
  243. /// <summary>
  244. /// 按条件清空排课数据
  245. /// </summary>
  246. /// <returns></returns>
  247. [HttpPost]
  248. [AjaxOnly]
  249. public async Task<ActionResult> AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  250. {
  251. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonDataByCondition(entity);
  252. return Success(data);
  253. }
  254. [HttpPost]
  255. [AjaxOnly]
  256. public async Task<ActionResult> AsyncModifyArrangeLessonDataByConditionNew(ArrangeLessonTermEntity entity)
  257. {
  258. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonDataByConditionNew(entity);
  259. return Success(data);
  260. }
  261. /// <summary>
  262. /// 按条件同步排课数据
  263. /// </summary>
  264. /// <returns></returns>
  265. [HttpPost]
  266. [AjaxOnly]
  267. public async Task<ActionResult> AsyncArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  268. {
  269. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonDataByCondition(entity);
  270. if (data)
  271. {
  272. //读取信息推送管理-课表同步推送(09)的配置
  273. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("09");
  274. if (informationPushEntity != null && informationPushEntity.Status == true)
  275. {
  276. var title = string.Format("{0}学年第{1}学期必修课课表同步", entity.AcademicYearNo, entity.Semester);
  277. var needpostuserlist = userIbll.GetAllList().Where(m => m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师").ToList();
  278. //微信推送
  279. try
  280. {
  281. PushWeixin(needpostuserlist, title);
  282. }
  283. catch (Exception e)
  284. {
  285. }
  286. //飞星推送
  287. await Task.Run(async () =>
  288. {
  289. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  290. {
  291. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  292. await hubConnection.Start();
  293. 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)), "");
  294. }
  295. });
  296. }
  297. }
  298. return Success(data);
  299. }
  300. /// <summary>
  301. /// 按条件重置基础数据同步状态
  302. /// </summary>
  303. /// <param name="entity"></param>
  304. /// <returns></returns>
  305. [HttpPost]
  306. [AjaxOnly]
  307. public ActionResult InitAsyncDataByCondition(ArrangeLessonTermEntity entity)
  308. {
  309. var data = arrangeLessonTermIBLL.InitAsyncDataByCondition(entity);
  310. return Success(data);
  311. }
  312. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  313. {
  314. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  315. string appid = WeChatConfigentity.APPId;
  316. string secret = WeChatConfigentity.secret;
  317. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  318. string weixintaskurl = wechatemplete.TUrl;
  319. string weixintasktempid = wechatemplete.TempId;
  320. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  321. OperateLogModel operateLogModel = new OperateLogModel();
  322. operateLogModel.title = title;
  323. operateLogModel.type = OperationType.Other;
  324. operateLogModel.url = "ArrangeLessonTermController";
  325. operateLogModel.sourceObjectId = "002";
  326. operateLogModel.sourceContentJson = responsejson;
  327. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  328. foreach (UserEntity userinfo in needpostuserlist)
  329. {
  330. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  331. {
  332. //执行推送任务
  333. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  334. {
  335. if (!string.IsNullOrEmpty(responsejson))
  336. {
  337. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  338. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  339. {
  340. string access_token = weixintokenobj.access_token;
  341. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  342. "\"template_id\":\"" + weixintasktempid + "\"," +
  343. "\"url\":\"" + weixintaskurl + "\"," +
  344. "\"data\":{" +
  345. "\"first\": {\"value\":\"您有新的课表同步\",\"color\":\"#173177\"}," +
  346. "\"keyword1\":{\"value\":\"课表同步\",\"color\":\"#173177\"}," +
  347. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  348. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  349. "\"keyword4\": {\"value\":\"您有新的课表同步【" + title + "】\",\"color\":\"#173177\"}" +
  350. "}" +
  351. "}";
  352. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  353. operateLogModel.title = title;
  354. operateLogModel.type = OperationType.Other;
  355. operateLogModel.url = "ArrangeLessonTermController";
  356. operateLogModel.sourceObjectId = "002";
  357. operateLogModel.sourceContentJson = pushresult;
  358. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. #endregion
  366. #region 课时统计
  367. [HttpGet]
  368. [AjaxOnly]
  369. public ActionResult GetcoursestatictisList(string pagination, string queryJson)
  370. {
  371. Pagination paginationobj = pagination.ToObject<Pagination>();
  372. var data = arrangeLessonTermIBLL.GetcoursestatictisList(paginationobj, queryJson);
  373. var jsonData = new
  374. {
  375. rows = data,
  376. total = paginationobj.total,
  377. page = paginationobj.page,
  378. records = paginationobj.records
  379. };
  380. return Success(jsonData);
  381. }
  382. #endregion
  383. }
  384. }