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.

SignUpHelper.cs 9.8 KiB

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