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.

ArrangeLessonTermController.cs 24 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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 ArrangeLessonTermOfElectiveIBLL arrangeLessonTermOfElectiveIBLL = new ArrangeLessonTermOfElectiveBLL();
  29. private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL();
  30. private UserIBLL userIbll = new UserBLL();
  31. private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
  32. private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
  33. private SchoolCalendarIBLL schoolCalendarIbll = new SchoolCalendarBLL();
  34. private StuInfoBasicIBLL stuInfoBasicIbll = new StuInfoBasicBLL();
  35. private EmpInfoIBLL empInfoIbll = new EmpInfoBLL();
  36. #region 视图功能
  37. /// <summary>
  38. /// 主页面
  39. /// <summary>
  40. /// <returns></returns>
  41. [HttpGet]
  42. public ActionResult Index()
  43. {
  44. return View();
  45. }
  46. /// <summary>
  47. /// 表单页
  48. /// <summary>
  49. /// <returns></returns>
  50. [HttpGet]
  51. public ActionResult Form()
  52. {
  53. return View();
  54. }
  55. /// <summary>
  56. /// 按条件清空排课数据
  57. /// <summary>
  58. /// <returns></returns>
  59. [HttpGet]
  60. public ActionResult EmptyByConditionForm()
  61. {
  62. return View();
  63. }
  64. /// <summary>
  65. /// 按条件同步排课数据
  66. /// <summary>
  67. /// <returns></returns>
  68. [HttpGet]
  69. public ActionResult SyncByConditionForm()
  70. {
  71. return View();
  72. }
  73. [HttpGet]
  74. public ActionResult ClearByConditionForm()
  75. {
  76. return View();
  77. }
  78. [HttpGet]
  79. public ActionResult IndexLessonTerm()
  80. {
  81. return View();
  82. }
  83. /// <summary>
  84. /// 学生课表
  85. /// </summary>
  86. /// <returns></returns>
  87. [HttpGet]
  88. public ActionResult IndexLessonTermStu()
  89. {
  90. var LogInfo = LoginUserInfo.Get();
  91. if (LogInfo.Description == "学生")
  92. {
  93. var StuInfo = stuInfoBasicIbll.GetAllList().Where(x => x.StuNo == LogInfo.account);
  94. if (StuInfo != null)
  95. {
  96. ViewBag.ClassNo = StuInfo.FirstOrDefault().ClassNo;
  97. }
  98. }
  99. return View();
  100. }
  101. /// <summary>
  102. /// 教师课表
  103. /// </summary>
  104. /// <returns></returns>
  105. [HttpGet]
  106. public ActionResult IndexLessonTermTeach()
  107. {
  108. var LogInfo = LoginUserInfo.Get();
  109. if (LogInfo.Description == "教师")
  110. {
  111. var empInfo = empInfoIbll.GetAllList().Where(x => x.EmpNo == LogInfo.account);
  112. if (empInfo != null)
  113. {
  114. ViewBag.EmpNo = empInfo.FirstOrDefault().EmpNo;
  115. }
  116. }
  117. return View();
  118. }
  119. #endregion
  120. #region 获取数据
  121. /// <summary>
  122. /// 获取列表数据
  123. /// <summary>
  124. /// <returns></returns>
  125. [HttpGet]
  126. [AjaxOnly]
  127. public ActionResult GetList(string queryJson)
  128. {
  129. var data = arrangeLessonTermIBLL.GetList(queryJson).ToList()
  130. .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);
  131. return Success(data);
  132. }
  133. /// <summary>
  134. /// 获取列表分页数据
  135. /// <param name="pagination">分页参数</param>
  136. /// <summary>
  137. /// <returns></returns>
  138. [HttpGet]
  139. [AjaxOnly]
  140. public ActionResult GetPageList(string pagination, string queryJson)
  141. {
  142. Pagination paginationobj = pagination.ToObject<Pagination>();
  143. var data = arrangeLessonTermIBLL.GetPageList(paginationobj, queryJson);
  144. var jsonData = new
  145. {
  146. rows = data,
  147. total = paginationobj.total,
  148. page = paginationobj.page,
  149. records = paginationobj.records
  150. };
  151. return Success(jsonData);
  152. }
  153. /// <summary>
  154. /// 排课管理 获取左侧树结构
  155. /// <summary>
  156. /// <returns></returns>
  157. [HttpGet]
  158. [AjaxOnly]
  159. public ActionResult GetTree()
  160. {
  161. var data = arrangeLessonTermIBLL.GetTree();
  162. return Success(data);
  163. }
  164. /// <summary>
  165. /// 获取表单数据
  166. /// <param name="keyValue">主键</param>
  167. /// <summary>
  168. /// <returns></returns>
  169. [HttpGet]
  170. [AjaxOnly]
  171. public ActionResult GetFormData(string keyValue)
  172. {
  173. var data = arrangeLessonTermIBLL.GetEntity(keyValue);
  174. return Success(data);
  175. }
  176. /// <summary>
  177. /// 获取周次
  178. /// <summary>
  179. /// <returns></returns>
  180. [HttpGet]
  181. [AjaxOnly]
  182. public ActionResult GetWeekTime()
  183. {
  184. int weekTimes = 0;
  185. int curWeek = 0;
  186. //开始时间
  187. var startdate = DateTime.Today;
  188. var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
  189. //var endDate = Common.CalculateLastDateOfWeek(startdate).ToString("yyyy-MM-dd");
  190. var semesterAndYear = Common.GetSemesterAndYear(startDate);
  191. //var strAcademicYear = semesterAndYear.AcademicYearShort;
  192. //var strSemester = semesterAndYear.Semester;
  193. var entity = schoolCalendarIbll.GetSchoolCalendarEntityByNo(semesterAndYear.AcademicYearShort, semesterAndYear.Semester);
  194. if (entity.StartTime.HasValue && entity.EndTime.HasValue)
  195. {
  196. weekTimes = GetYearWeekCount(entity.StartTime.Value, entity.EndTime.Value);
  197. curWeek = WeekOfYear(startdate, entity.StartTime.Value, entity.EndTime.Value);
  198. }
  199. var listObj = new List<Object>();
  200. for (int i = 1; i <= weekTimes; i++)
  201. {
  202. listObj.Add(new { text = i + "周", value = i });
  203. }
  204. var jsonData = new
  205. {
  206. weekList = listObj,
  207. curWeek = curWeek,
  208. };
  209. return Success(jsonData);
  210. }
  211. /// <summary>
  212. /// 有多少周
  213. /// 返回 int
  214. /// </summary>
  215. /// <returns>int</returns>
  216. private static int GetYearWeekCount(DateTime startTime, DateTime endTime)
  217. {
  218. string returnStr = "";
  219. var startDate = DateTime.Parse(Common.CalculateFirstDateOfWeek(startTime).ToString("yyyy-MM-dd"));
  220. //int k = Convert.ToInt32(startTime.DayOfWeek);//得到开始时间的第一天是周几
  221. int countDay = endTime.Subtract(startDate).Days;
  222. int countWeek = countDay / 14 + 1;
  223. return countWeek;
  224. }
  225. /// <summary>
  226. /// 求当前日期是第几周
  227. /// </summary>
  228. /// <param name="date"></param>
  229. /// <returns></returns>
  230. private static int WeekOfYear(DateTime curDay, DateTime startTime, DateTime endTime)
  231. {
  232. int firstdayofweek = Convert.ToInt32(startTime.DayOfWeek);
  233. var startDate = DateTime.Parse(Common.CalculateFirstDateOfWeek(startTime).ToString("yyyy-MM-dd"));
  234. int k = Convert.ToInt32(startTime.DayOfWeek);//得到开始时间的第一天是周几
  235. int days = curDay.Subtract(startTime).Days;
  236. //int days = curDay.DayOfYear;
  237. int daysOutOneWeek = days - (14 - firstdayofweek);
  238. if (daysOutOneWeek <= 0)
  239. {
  240. return 1;
  241. }
  242. else
  243. {
  244. int weeks = daysOutOneWeek / 14;
  245. if (daysOutOneWeek % 14 != 0)
  246. weeks++;
  247. return weeks + 1;
  248. }
  249. }
  250. /// <summary>
  251. /// 课程表【教务】
  252. /// </summary>
  253. /// <param name="classNo">班级</param>
  254. /// <param name="curWeek">当前第几周</param>
  255. /// <returns></returns>
  256. [HttpGet]
  257. [AjaxOnly]
  258. public ActionResult GetDataInEducation(string classNo, int curWeek)
  259. {
  260. var userInfo = LoginUserInfo.Get();
  261. //开始时间
  262. var startdate = DateTime.Today;
  263. var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
  264. var endDate = Common.CalculateLastDateOfWeek(startdate).ToString("yyyy-MM-dd");
  265. var semesterAndYear = Common.GetSemesterAndYear(startDate);
  266. var strAcademicYear = semesterAndYear.AcademicYearLong;
  267. var strSemester = semesterAndYear.Semester;
  268. if (string.IsNullOrEmpty(classNo))
  269. {
  270. if (userInfo.Description != "教师")
  271. {
  272. var res = new
  273. { schoolName = "课程表", semester = $"{strAcademicYear}学年度 第{strSemester}学期", weekList = "" };
  274. return JsonResult(res);
  275. }
  276. }
  277. //校历
  278. var entity = schoolCalendarIbll.GetSchoolCalendarEntityByNo(semesterAndYear.AcademicYearShort, semesterAndYear.Semester);
  279. var StartTime = entity.StartTime.Value;
  280. //根据第几周,计算查询的开始和结束日期
  281. startDate = Common.CalculateFirstDateOfWeek(StartTime.AddDays(((curWeek - 1) * 14))).ToString("yyyy-MM-dd");//StartTime.AddDays(((curWeek - 1) * 14)).ToString("yyyy-MM-dd");
  282. if (curWeek == 1 && Convert.ToDateTime(startDate) < StartTime)
  283. {
  284. startDate = StartTime.ToString("yyyy-MM-dd");
  285. }
  286. endDate = Common.CalculateFirstDateOfWeek(StartTime.AddDays(((curWeek - 1) * 14))).AddDays(10)
  287. .ToString("yyyy-MM-dd");// StartTime.AddDays(((curWeek - 1) * 14)).AddDays(10).ToString("yyyy-MM-dd");
  288. var timeTableList = new List<TimeTable>();
  289. //课程表
  290. var data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
  291. if (!string.IsNullOrEmpty(classNo))
  292. {
  293. var PKRoleId = Config.GetValue("PKRoleId");
  294. var loginInfoRoleIds = LoginUserInfo.Get().roleIds;
  295. if (loginInfoRoleIds.IndexOf(',') == -1)
  296. {
  297. if (loginInfoRoleIds == PKRoleId)
  298. {
  299. data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
  300. }
  301. }
  302. else
  303. {
  304. if (loginInfoRoleIds.Split(',').Contains(PKRoleId))
  305. {
  306. data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
  307. }
  308. }
  309. }
  310. else
  311. {
  312. if (userInfo.Description == "学生")
  313. {
  314. data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
  315. }
  316. else if (userInfo.Description == "教师")
  317. {
  318. var empInfo = empInfoIbll.GetAllList().Where(x => x.EmpNo == userInfo.account);
  319. if (empInfo != null)
  320. {
  321. data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, "", empInfo.FirstOrDefault().EmpNo, "");
  322. }
  323. }
  324. else
  325. {
  326. data = arrangeLessonTermIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
  327. }
  328. }
  329. timeTableList.AddRange(data);
  330. //选修课课程表
  331. //var dataOfElective = arrangeLessonTermOfElectiveIBLL.GetTimeTableInEducation(startDate, endDate, classNo, "", "");
  332. //timeTableList.AddRange(dataOfElective);
  333. var timeTables = timeTableList.ToList();
  334. var noDataResult = new
  335. { schoolName = "课程表", semester = $"{strAcademicYear}学年度 第{strSemester}学期", weekList = "" };
  336. if (!timeTables.Any())
  337. {
  338. return JsonResult(noDataResult);
  339. }
  340. var formatData = from d in timeTables.AsEnumerable()
  341. let tt = d.LessonTime.Split('-')[1]
  342. group d by tt into g
  343. orderby g.Key
  344. select new
  345. {
  346. time = g.Key,
  347. list = from e in timeTables.AsEnumerable()
  348. let ee = e.LessonTime.Split('-')[1]
  349. where ee == g.Key
  350. select new
  351. {
  352. ALTId = e.ALTId,
  353. day = e.LessonTime.Split('-')[0],
  354. curriculum = e.LessonSortNo == "2" ? e.LessonName + "[选修]" : e.LessonName,
  355. teacher = e?.EmpName,
  356. classRoom = string.IsNullOrEmpty(e.ClassroomName) ? "" : e.ClassroomName.Trim(),
  357. academicyear = semesterAndYear.AcademicYearShort,
  358. semester = strSemester,
  359. lessonNo = e?.LessonNo,
  360. teachClassNo = e?.TeachClassNo,
  361. empno = e?.EmpNo,
  362. lessonTime = e.LessonTime,
  363. lessonDate = e.LessonDate.ToString("yyyy-MM-dd"),
  364. classRoomNo = string.IsNullOrEmpty(e.ClassRoomNo) ? "" : e.ClassRoomNo.Trim(),
  365. lessonSortNo = e.LessonSortNo,
  366. e?.OLPEId,
  367. className = string.IsNullOrEmpty(e.ClassName) ? "" : e.ClassName
  368. }
  369. }
  370. ;
  371. var result = new
  372. { schoolName = "课程表", semester = $"{strAcademicYear}学年度 第{strSemester}学期", weekList = formatData };
  373. return JsonResult(result);
  374. }
  375. #endregion
  376. #region 提交数据
  377. /// <summary>
  378. /// 删除实体数据
  379. /// <param name="keyValue">主键</param>
  380. /// <summary>
  381. /// <returns></returns>
  382. [HttpPost]
  383. [AjaxOnly]
  384. public ActionResult DeleteForm(string keyValue)
  385. {
  386. arrangeLessonTermIBLL.DeleteEntity(keyValue);
  387. return Success("删除成功!");
  388. }
  389. /// <summary>
  390. /// 保存实体数据(新增、修改)
  391. /// <param name="keyValue">主键</param>
  392. /// <summary>
  393. /// <returns></returns>
  394. [HttpPost]
  395. [ValidateAntiForgeryToken]
  396. [AjaxOnly]
  397. public ActionResult SaveForm(string keyValue, ArrangeLessonTermEntity entity)
  398. {
  399. arrangeLessonTermIBLL.SaveEntity(keyValue, entity);
  400. return Success("保存成功!");
  401. }
  402. /// <summary>
  403. /// 删除课程
  404. /// <param name="keyValue">主键</param>
  405. /// <summary>
  406. /// <returns></returns>
  407. [HttpPost]
  408. [AjaxOnly]
  409. public ActionResult DeleteLessonTerm(string keyValue, string WeekTime)
  410. {
  411. arrangeLessonTermIBLL.DeleteLessonTerm(keyValue, WeekTime);
  412. return Success("删除成功!");
  413. }
  414. /// <summary>
  415. ///修改课程
  416. /// <param name="keyValue">主键</param>
  417. /// <summary>
  418. /// <returns></returns>
  419. [HttpPost]
  420. [AjaxOnly]
  421. public ActionResult UpdateLessonTerm(string keyValue, string postdata)
  422. {
  423. UpdateLessonTermEntity model = postdata.ToObject<UpdateLessonTermEntity>();
  424. var res = arrangeLessonTermIBLL.UpdateLessonTerm(keyValue, model);
  425. if (!string.IsNullOrEmpty(res))
  426. {
  427. return Fail(res);
  428. }
  429. return Success("操作成功!");
  430. }
  431. #endregion
  432. /// <summary>
  433. /// 当前学期排课数据同步
  434. /// </summary>
  435. /// <returns></returns>
  436. [HttpGet]
  437. [AjaxOnly]
  438. public async Task<ActionResult> AsyncArrangeLessonData()
  439. {
  440. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonData();
  441. return Success(data);
  442. }
  443. /// <summary>
  444. /// 清空当前学期排课数据
  445. /// </summary>
  446. /// <returns></returns>
  447. [HttpGet]
  448. [AjaxOnly]
  449. public async Task<ActionResult> AsyncModifyArrangeLessonData()
  450. {
  451. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonData();
  452. return Success(data);
  453. }
  454. /// <summary>
  455. /// 按条件清空排课数据
  456. /// </summary>
  457. /// <returns></returns>
  458. [HttpPost]
  459. [AjaxOnly]
  460. public async Task<ActionResult> AsyncModifyArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  461. {
  462. var data = await arrangeLessonTermIBLL.AsyncModifyArrangeLessonDataByCondition(entity);
  463. return Success(data);
  464. }
  465. /// <summary>
  466. /// 按条件同步排课数据
  467. /// </summary>
  468. /// <returns></returns>
  469. [HttpPost]
  470. [AjaxOnly]
  471. public async Task<ActionResult> AsyncArrangeLessonDataByCondition(ArrangeLessonTermEntity entity)
  472. {
  473. var data = await arrangeLessonTermIBLL.AsyncArrangeLessonDataByCondition(entity);
  474. if (data)
  475. {
  476. //读取信息推送管理-课表同步推送(09)的配置
  477. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("09");
  478. if (informationPushEntity != null && informationPushEntity.Status == true)
  479. {
  480. var title = string.Format("{0}学年第{1}学期必修课课表同步", entity.AcademicYearNo, entity.Semester);
  481. var needpostuserlist = userIbll.GetAllList().Where(m => m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师").ToList();
  482. //微信推送
  483. try
  484. {
  485. PushWeixin(needpostuserlist, title);
  486. }
  487. catch (Exception e)
  488. {
  489. }
  490. //飞星推送
  491. await Task.Run(async () =>
  492. {
  493. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  494. {
  495. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  496. await hubConnection.Start();
  497. 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)), "");
  498. }
  499. });
  500. }
  501. }
  502. return Success(data);
  503. }
  504. /// <summary>
  505. /// 按条件重置基础数据同步状态
  506. /// </summary>
  507. /// <param name="entity"></param>
  508. /// <returns></returns>
  509. [HttpPost]
  510. [AjaxOnly]
  511. public ActionResult InitAsyncDataByCondition(ArrangeLessonTermEntity entity)
  512. {
  513. var data = arrangeLessonTermIBLL.InitAsyncDataByCondition(entity);
  514. return Success(data);
  515. }
  516. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  517. {
  518. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  519. string appid = WeChatConfigentity.APPId;
  520. string secret = WeChatConfigentity.secret;
  521. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  522. string weixintaskurl = wechatemplete.TUrl;
  523. string weixintasktempid = wechatemplete.TempId;
  524. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  525. OperateLogModel operateLogModel = new OperateLogModel();
  526. operateLogModel.title = title;
  527. operateLogModel.type = OperationType.Other;
  528. operateLogModel.url = "ArrangeLessonTermController";
  529. operateLogModel.sourceObjectId = "002";
  530. operateLogModel.sourceContentJson = responsejson;
  531. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  532. foreach (UserEntity userinfo in needpostuserlist)
  533. {
  534. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  535. {
  536. //执行推送任务
  537. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  538. {
  539. if (!string.IsNullOrEmpty(responsejson))
  540. {
  541. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  542. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  543. {
  544. string access_token = weixintokenobj.access_token;
  545. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  546. "\"template_id\":\"" + weixintasktempid + "\"," +
  547. "\"url\":\"" + weixintaskurl + "\"," +
  548. "\"data\":{" +
  549. "\"first\": {\"value\":\"您有新的课表同步\",\"color\":\"#173177\"}," +
  550. "\"keyword1\":{\"value\":\"课表同步\",\"color\":\"#173177\"}," +
  551. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  552. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  553. "\"keyword4\": {\"value\":\"您有新的课表同步【" + title + "】\",\"color\":\"#173177\"}" +
  554. "}" +
  555. "}";
  556. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  557. operateLogModel.title = title;
  558. operateLogModel.type = OperationType.Other;
  559. operateLogModel.url = "ArrangeLessonTermController";
  560. operateLogModel.sourceObjectId = "002";
  561. operateLogModel.sourceContentJson = pushresult;
  562. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  563. }
  564. }
  565. }
  566. }
  567. }
  568. }
  569. }
  570. }