|
- 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 SignUpHelper
- {
-
- public readonly static SignUpHelper Instance = new SignUpHelper();
- public SignUpHelper()
- { }
- public static Queue<StuSelectLessonListOfElectiveEntity> ListQueue = new Queue<StuSelectLessonListOfElectiveEntity>();
- private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
- private OpenLessonPlanOfElectiveIBLL openLessonPlanOfElectiveIBLL = new OpenLessonPlanOfElectiveBLL();
- private StuSelectLessonListOfElectiveIBLL stuSelectLessonListOfElectiveIBLL = new StuSelectLessonListOfElectiveBLL();
- private Thread t;
-
- public static void AddQueue(string stuNo, string olpeId) //入列
- {
- StuSelectLessonListOfElectiveEntity entity = new StuSelectLessonListOfElectiveEntity();
- entity.StuNo = stuNo;
- entity.OLPEId = olpeId;
- 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();
- }
- }
-
- //Thread thread = new Thread(threadStart);
- //thread.IsBackground = true;
- //if (!thread.IsAlive)
- //{
- // thread.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
- {
- //从队列中取出
- StuSelectLessonListOfElectiveEntity entity = ListQueue.Dequeue();
- //处理数据:
-
- //学员信息
- var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(entity.StuNo);
- if (stuInfoBasicEntity == null)
- {
- //return Fail("当前学员不存在!");
- return;
- }
- //课程信息
- var olpeEntity = openLessonPlanOfElectiveIBLL.GetOpenLessonPlanOfElectiveEntity(entity.OLPEId);
- if (olpeEntity == null)
- {
- //return Fail("当前课程不存在!");
- return;
- }
- //所选课程的报名人数是否已满
- var aa = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveListByOLPEId(olpeEntity.Id);
- var aaa = aa.Where(x => x.Status == 1 || x.Status == 2).Count();
- if (aaa >= olpeEntity.StuNumMax)
- {
- //return Fail("当前课程报名人数已满,请选择其他课程!");
- return;
- }
-
- //当前学员本学期是否有报名课程:每学期一门
- //var sslleEntity = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveEntityByStuNo(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)//移除报名失败的数据
- // {
- // stuSelectLessonListOfElectiveIBLL.DeleteEntity(sslleEntity.Id);
- // }
-
- //}
-
-
- //每学期两门
- var sslleList = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveListByStuNo(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("ElectiveLessonApplyMax").ToInt())
- {
- //return Fail("每学期最多选择两门选修课!");
- return;
- }
- else
- {
- var m = sslleListOfNow1.FirstOrDefault(x => x.OLPEId == 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)
- {
- stuSelectLessonListOfElectiveIBLL.DeleteEntity(item.Id);
- }
- }
- //相同时间不能报名
- if (sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any())
- {
- //相同时间不能报名
- return;
- }
- //相同课程不能报名
- if (sslleListOfNow1.Where(x => x.LessonNo == olpeEntity.LessonNo).Any())
- {
- //相同课程不能报名
- return;
- }
- //新增报名数据
- var model = new StuSelectLessonListOfElectiveEntity()
- {
- OLPEId = 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
- };
- stuSelectLessonListOfElectiveIBLL.SaveEntity("", model);
-
-
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- }
-
- }
-
-
-
- }
|