using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Learun.Util; using Microsoft.AspNet.SignalR; namespace Learun.Application.TwoDevelopment.EducationalAdministration { public class SignUpOnlineHelper { public readonly static SignUpOnlineHelper Instance = new SignUpOnlineHelper(); public SignUpOnlineHelper() { } public static Queue ListQueue = new Queue(); private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL(); private LessonInfoOfElectiveOnlineIBLL lessonInfoOfElectiveOnlineIBLL = new LessonInfoOfElectiveOnlineBLL(); private StuSelectLessonListOfElectiveOnlineIBLL stuSelectLessonListOfElectiveOnlineIBLL = new StuSelectLessonListOfElectiveOnlineBLL(); private Thread t; public static void AddQueue(string stuNo, string lioeoId) //入列 { StuSelectLessonListOfElectiveOnlineEntity entity = new StuSelectLessonListOfElectiveOnlineEntity(); entity.StuNo = stuNo; entity.LIOEOId = lioeoId; ListQueue.Enqueue(entity); } public void Start()//启动 { if (t == null) { t = new Thread(threadStart); t.IsBackground = true; t.Start(); } else { if (!t.IsAlive) { t = new Thread(threadStart); t.IsBackground = true; t.Start(); } } } private void threadStart() { while (true) { if (ListQueue.Count > 0) { try { ScanQueue(); } catch (Exception ex) { } } else { //没有任务,休息3秒钟 Thread.Sleep(3000); } } } //要执行的方法 private void ScanQueue() { while (ListQueue.Count > 0) { try { //从队列中取出 StuSelectLessonListOfElectiveOnlineEntity entity = ListQueue.Dequeue(); //处理数据: //学员信息 var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(entity.StuNo); if (stuInfoBasicEntity == null) { //return Fail("当前学员不存在!"); return; } //课程信息 var olpeEntity = lessonInfoOfElectiveOnlineIBLL.GetLessonInfoOfElectiveOnlineEntity(entity.LIOEOId); if (olpeEntity == null) { //return Fail("当前课程不存在!"); return; } //所选课程的报名人数是否已满 var aa = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByOLPEId(olpeEntity.Id); var aaa = aa.Where(x => x.Status == 1 || x.Status == 2).Count(); if (aaa >= olpeEntity.StuNumMax) { //return Fail("当前课程报名人数已满,请选择其他课程!"); return; } //当前学员本学期是否有报名课程:每学期一门 //var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(entity.StuNo, ""); //if (sslleEntity != null) //{ // if (sslleEntity.OLPEId != entity.OLPEId && sslleEntity.Status != 3) // { // //return Fail("已存在报名课程,每学期只能选择一门选修课!如需报名其他课程请先取消。"); // return; // } // if (sslleEntity.Status == 1) // { // //return Fail("报名审核中,请耐心等待!"); // return; // } // else if (sslleEntity.Status == 2) // { // //return Fail("已存在报名成功的课程,只能选择一门选修课!"); // return; // } // else if (sslleEntity.Status == 3)//移除报名失败的数据 // { // stuSelectLessonListOfElectiveOnlineIBLL.DeleteEntity(sslleEntity.Id); // } //} //每学期两门(几门根据系统配置文件值确定) var sslleList = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByStuNo(entity.StuNo); var sslleListOfNow = sslleList.Where(x => x.AcademicYearNo == olpeEntity.AcademicYearNo && x.Semester == olpeEntity.Semester); var sslleListOfNow1 = sslleListOfNow.Where(x => x.Status == 1 || x.Status == 2); var sslleListOfNow2 = sslleListOfNow.Where(x => x.Status == 3); if (sslleListOfNow1.Count() >= Config.GetValue("OnlineElectiveLessonApplyMax").ToInt()) { //return Fail("每学期最多选择两门选修课!"); return; } else { var m = sslleListOfNow1.FirstOrDefault(x => x.LIOEOId == olpeEntity.Id); if (m != null) { if (m.Status == 1) { //return Fail("当前课程报名审核中,请耐心等待!"); return; } else if (m.Status == 2) { //return Fail("当前课程已报名成功!"); return; } } } if (sslleListOfNow2.Count() > 0) { foreach (var item in sslleListOfNow2) { stuSelectLessonListOfElectiveOnlineIBLL.DeleteEntity(item.Id); } } //相同时间不能报名 if (!string.IsNullOrEmpty(olpeEntity.LessonSection) && sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any()) { //相同时间不能报名 return; } //相同课程不能报名 if (sslleListOfNow1.Where(x => x.LessonNo == olpeEntity.LessonNo).Any()) { //相同课程不能报名 return; } //新增报名数据 var model = new StuSelectLessonListOfElectiveOnlineEntity() { LIOEOId = olpeEntity.Id, NoticeBookNo = stuInfoBasicEntity.NoticeNo, StuNo = stuInfoBasicEntity.StuNo, DeptNo = stuInfoBasicEntity.DeptNo, MajorNo = stuInfoBasicEntity.MajorNo, ClassNo = stuInfoBasicEntity.ClassNo, MajorDetailNo = stuInfoBasicEntity.MajorDetailNo, MajorDetailName = stuInfoBasicEntity.MajorDetailName, StuName = stuInfoBasicEntity.StuName, GenderNo = stuInfoBasicEntity.GenderNo, Grade = stuInfoBasicEntity.Grade, AcademicYearNo = olpeEntity.AcademicYearNo, Semester = olpeEntity.Semester, LessonNo = olpeEntity.LessonNo, LessonName = olpeEntity.LessonName, LessonSortNo = olpeEntity.LessonSortNo, LessonSection = olpeEntity.LessonSection, LessonTime = olpeEntity.LessonTime, EmpNo = olpeEntity.EmpNo, EmpName = olpeEntity.EmpName, ClassRoomNo = olpeEntity.ClassRoomNo, ClassRoomName = olpeEntity.ClassRoomName, StudyScore = olpeEntity.StudyScore, StartWeek = olpeEntity.StartWeek, EndWeek = olpeEntity.EndWeek, StartDate = olpeEntity.StartDate, EndDate = olpeEntity.EndDate, CreateTime = DateTime.Now, Status = 1, OrdinaryScoreScale = 1, TermInScoreScale = 1, TermEndScoreScale = 1, OtherScoreScale = 1, F_SchoolId = olpeEntity.F_SchoolId }; stuSelectLessonListOfElectiveOnlineIBLL.SaveEntity("", model); } catch (Exception ex) { throw; } } } } }