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.
 
 
 
 
 
 

233 lines
9.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Learun.Util;
  8. using Microsoft.AspNet.SignalR;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. public class SignUpOnlineHelper
  12. {
  13. public readonly static SignUpOnlineHelper Instance = new SignUpOnlineHelper();
  14. public SignUpOnlineHelper()
  15. { }
  16. public static Queue<StuSelectLessonListOfElectiveOnlineEntity> ListQueue = new Queue<StuSelectLessonListOfElectiveOnlineEntity>();
  17. private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
  18. private LessonInfoOfElectiveOnlineIBLL lessonInfoOfElectiveOnlineIBLL = new LessonInfoOfElectiveOnlineBLL();
  19. private StuSelectLessonListOfElectiveOnlineIBLL stuSelectLessonListOfElectiveOnlineIBLL = new StuSelectLessonListOfElectiveOnlineBLL();
  20. private Thread t;
  21. public static void AddQueue(string stuNo, string lioeoId) //入列
  22. {
  23. StuSelectLessonListOfElectiveOnlineEntity entity = new StuSelectLessonListOfElectiveOnlineEntity();
  24. entity.StuNo = stuNo;
  25. entity.LIOEOId = lioeoId;
  26. ListQueue.Enqueue(entity);
  27. }
  28. public void Start()//启动
  29. {
  30. if (t == null)
  31. {
  32. t = new Thread(threadStart);
  33. t.IsBackground = true;
  34. t.Start();
  35. }
  36. else
  37. {
  38. if (!t.IsAlive)
  39. {
  40. t = new Thread(threadStart);
  41. t.IsBackground = true;
  42. t.Start();
  43. }
  44. }
  45. }
  46. private void threadStart()
  47. {
  48. while (true)
  49. {
  50. if (ListQueue.Count > 0)
  51. {
  52. try
  53. {
  54. ScanQueue();
  55. }
  56. catch (Exception ex)
  57. {
  58. }
  59. }
  60. else
  61. {
  62. //没有任务,休息3秒钟
  63. Thread.Sleep(3000);
  64. }
  65. }
  66. }
  67. //要执行的方法
  68. private void ScanQueue()
  69. {
  70. while (ListQueue.Count > 0)
  71. {
  72. try
  73. {
  74. //从队列中取出
  75. StuSelectLessonListOfElectiveOnlineEntity entity = ListQueue.Dequeue();
  76. //处理数据:
  77. //学员信息
  78. var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(entity.StuNo);
  79. if (stuInfoBasicEntity == null)
  80. {
  81. //return Fail("当前学员不存在!");
  82. return;
  83. }
  84. //课程信息
  85. var olpeEntity = lessonInfoOfElectiveOnlineIBLL.GetLessonInfoOfElectiveOnlineEntity(entity.LIOEOId);
  86. if (olpeEntity == null)
  87. {
  88. //return Fail("当前课程不存在!");
  89. return;
  90. }
  91. //所选课程的报名人数是否已满
  92. var aa = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByOLPEId(olpeEntity.Id);
  93. var aaa = aa.Where(x => x.Status == 1 || x.Status == 2).Count();
  94. if (aaa >= olpeEntity.StuNumMax)
  95. {
  96. //return Fail("当前课程报名人数已满,请选择其他课程!");
  97. return;
  98. }
  99. //当前学员本学期是否有报名课程:每学期一门
  100. //var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(entity.StuNo, "");
  101. //if (sslleEntity != null)
  102. //{
  103. // if (sslleEntity.OLPEId != entity.OLPEId && sslleEntity.Status != 3)
  104. // {
  105. // //return Fail("已存在报名课程,每学期只能选择一门选修课!如需报名其他课程请先取消。");
  106. // return;
  107. // }
  108. // if (sslleEntity.Status == 1)
  109. // {
  110. // //return Fail("报名审核中,请耐心等待!");
  111. // return;
  112. // }
  113. // else if (sslleEntity.Status == 2)
  114. // {
  115. // //return Fail("已存在报名成功的课程,只能选择一门选修课!");
  116. // return;
  117. // }
  118. // else if (sslleEntity.Status == 3)//移除报名失败的数据
  119. // {
  120. // stuSelectLessonListOfElectiveOnlineIBLL.DeleteEntity(sslleEntity.Id);
  121. // }
  122. //}
  123. //每学期两门(几门根据系统配置文件值确定)
  124. var sslleList = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByStuNo(entity.StuNo);
  125. var sslleListOfNow = sslleList.Where(x => x.AcademicYearNo == olpeEntity.AcademicYearNo && x.Semester == olpeEntity.Semester);
  126. var sslleListOfNow1 = sslleListOfNow.Where(x => x.Status == 1 || x.Status == 2);
  127. var sslleListOfNow2 = sslleListOfNow.Where(x => x.Status == 3);
  128. if (sslleListOfNow1.Count() >= Config.GetValue("OnlineElectiveLessonApplyMax").ToInt())
  129. {
  130. //return Fail("每学期最多选择两门选修课!");
  131. return;
  132. }
  133. else
  134. {
  135. var m = sslleListOfNow1.FirstOrDefault(x => x.LIOEOId == olpeEntity.Id);
  136. if (m != null)
  137. {
  138. if (m.Status == 1)
  139. {
  140. //return Fail("当前课程报名审核中,请耐心等待!");
  141. return;
  142. }
  143. else if (m.Status == 2)
  144. {
  145. //return Fail("当前课程已报名成功!");
  146. return;
  147. }
  148. }
  149. }
  150. if (sslleListOfNow2.Count() > 0)
  151. {
  152. foreach (var item in sslleListOfNow2)
  153. {
  154. stuSelectLessonListOfElectiveOnlineIBLL.DeleteEntity(item.Id);
  155. }
  156. }
  157. //相同时间不能报名
  158. if (!string.IsNullOrEmpty(olpeEntity.LessonSection) && sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any())
  159. {
  160. //相同时间不能报名
  161. return;
  162. }
  163. //相同课程不能报名
  164. if (sslleListOfNow1.Where(x => x.LessonNo == olpeEntity.LessonNo).Any())
  165. {
  166. //相同课程不能报名
  167. return;
  168. }
  169. //新增报名数据
  170. var model = new StuSelectLessonListOfElectiveOnlineEntity()
  171. {
  172. LIOEOId = olpeEntity.Id,
  173. NoticeBookNo = stuInfoBasicEntity.NoticeNo,
  174. StuNo = stuInfoBasicEntity.StuNo,
  175. DeptNo = stuInfoBasicEntity.DeptNo,
  176. MajorNo = stuInfoBasicEntity.MajorNo,
  177. ClassNo = stuInfoBasicEntity.ClassNo,
  178. MajorDetailNo = stuInfoBasicEntity.MajorDetailNo,
  179. MajorDetailName = stuInfoBasicEntity.MajorDetailName,
  180. StuName = stuInfoBasicEntity.StuName,
  181. GenderNo = stuInfoBasicEntity.GenderNo,
  182. Grade = stuInfoBasicEntity.Grade,
  183. AcademicYearNo = olpeEntity.AcademicYearNo,
  184. Semester = olpeEntity.Semester,
  185. LessonNo = olpeEntity.LessonNo,
  186. LessonName = olpeEntity.LessonName,
  187. LessonSortNo = olpeEntity.LessonSortNo,
  188. LessonSection = olpeEntity.LessonSection,
  189. LessonTime = olpeEntity.LessonTime,
  190. EmpNo = olpeEntity.EmpNo,
  191. EmpName = olpeEntity.EmpName,
  192. ClassRoomNo = olpeEntity.ClassRoomNo,
  193. ClassRoomName = olpeEntity.ClassRoomName,
  194. StudyScore = olpeEntity.StudyScore,
  195. StartWeek = olpeEntity.StartWeek,
  196. EndWeek = olpeEntity.EndWeek,
  197. StartDate = olpeEntity.StartDate,
  198. EndDate = olpeEntity.EndDate,
  199. CreateTime = DateTime.Now,
  200. Status = 1,
  201. OrdinaryScoreScale = 1,
  202. TermInScoreScale = 1,
  203. TermEndScoreScale = 1,
  204. OtherScoreScale = 1,
  205. F_SchoolId = olpeEntity.F_SchoolId
  206. };
  207. stuSelectLessonListOfElectiveOnlineIBLL.SaveEntity("", model);
  208. }
  209. catch (Exception ex)
  210. {
  211. throw;
  212. }
  213. }
  214. }
  215. }
  216. }