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