123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.StudentSystem.MyGrade;
- using EMIS.ViewModel.Students;
- using Bowin.Common.Linq.Entity;
- using EMIS.DataLogic.StudentSystem.ExamineApply;
- using EMIS.ViewModel.ExaminationApply;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.Entities;
- using EMIS.DataLogic.Repositories;
- using EMIS.DataLogic.ExaminationApply;
- using EMIS.CommonLogic.CalendarManage;
- using EMIS.ViewModel;
- using EMIS.DataLogic.ScoreManage;
- using System.Transactions;
- using EMIS.DataLogic.SelectCourse;
- using EMIS.ViewModel.ScoreManage;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using EMIS.DataLogic.StudentSystem.StudentMaterial;
- namespace EMIS.CommonLogic.Students
- {
- public class ExamineApplyServices : BaseWorkflowServices<EX_ExaminationRegistration>, IExamineApplyServices
- {
- public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
- public ExamineApplyDAL ExamineApplyDAL { get; set; }
- public StudentRecordDAL studentRecordDAL { get; set; }
- public ExaminationRegistrationRepository RegistrationRepository { get; set; }
- public SubjectCountLimitDAL SubjectCountLimitDAL { get; set; }
- public OpenControlDAL OpenControlDAL { get; set; }
- public GrademajorRepository gradeRepository { get; set; }
- public LevelScoreDAL levelScoreDAL { get; set; }
- public LevelSettingDAL levelSettingDAL { get; set; }
- public ExaminationSubjectCollegeControlDAL examinationSubjectCollegeControlDAL { get; set; }
- public DictionaryItemRepository dictionaryItemRepository { get; set; }
- public IGridResultSet<ExaminationApplyView> GetExaminationSubjectList(Guid UserID)
- {
- return ExamineApplyDAL.GetExaminationSubjectList(UserID).Where(x=>x.EndDate.Value.AddDays(1)>=DateTime.Now).OrderBy(x => x.EndDate).ThenBy(x => x.StartDate).ThenBy(x => x.ExaminationDate).AsQueryable<ExaminationApplyView>().ToGridResultSet();
- }
- public void ApplySubmit(Guid examinationSubjectID, Guid UserID)
- {
- var student = studentRecordDAL.GetStudentByStudentNo(UserID);
- if (student.PhotoUrl == null)
- {
- throw new Exception("您没有照片,请先上传照片后再报名");
- }
- var currentSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- //学生报名限制加上已报考且成绩“合格”以上禁止重复报考的限制
- var TotalScore = levelScoreDAL.levelScoreRepository.Entities.Where(x => x.UserID == UserID && x.ExaminationSubjectID == examinationSubjectID).OrderByDescending(x => x.TotalScore).FirstOrDefault();
- if (TotalScore != null)
- {
- //以合格、及格为关键字查询过级等级分数
- var passLevel = levelSettingDAL.levelSettingRepository.Entities.Where(x => x.ExaminationSubjectID == examinationSubjectID && (x.LevelName == "合格" || x.LevelName == "及格")).FirstOrDefault();
- if (passLevel != null && passLevel.MinScore <= TotalScore.TotalScore)
- throw new Exception("已报考过该科目,并且成绩合格,不能重复报考");
- }
- //找到该学生的年级
- int? gradeYear = gradeRepository.Entities.Where(x => x.Code == student.GradeCode).FirstOrDefault().GradeID;
- var subject = ExamineApplyDAL.SubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationSubjectID,
- x => x.EX_ExaminationRegistration.Select(w => w.CF_Student.CF_Classmajor.CF_Grademajor));
- //,x => x.ER_LevelScore);//.Where(q => q.UserID == UserID)
- var schoolyearNum = (currentSchoolyear.Value - student.StartSchoolyearValue - (currentSchoolyear.SchoolcodeID == student.StartSchoolcodeID ? 0 : 1)) / 2 + 1;
- var subjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.GetSingle(x => x.Years == schoolyearNum
- && x.EX_ExaminationType.EX_ExaminationSubject.Any(w => w.ExaminationSubjectID == examinationSubjectID)
- && x.FacultymajorID == student.FacultymajorID && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- int? sameSchoolNumRegistCount = 0;
- //if (subjectCountLimit == null)
- //{
- // sameSchoolNumRegistCount = RegistrationRepository.GetList(x => x.UserID == UserID && x.SchoolyearID == currentSchoolyear.SchoolYearID)
- // .Count();
- //}
- if (subjectCountLimit != null)//else
- {
- sameSchoolNumRegistCount = RegistrationRepository.GetList(x => x.UserID == UserID && x.SchoolyearID == currentSchoolyear.SchoolYearID && x.EX_ExaminationSubject.ExaminationTypeID == subjectCountLimit.ExaminationTypeID)
- .Count();
- }
- var openControl = OpenControlDAL.ExaminationOpenControlRepository.GetSingle(x => x.SchoolyearNumID == schoolyearNum
- && x.ExaminationSubjectID == examinationSubjectID
- && x.StudentType == student.StudentType && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- //当该考试科目存在要求通过的科目时,要判断该学生要求通过的科目成绩是否达到最低通过分,如英语六级要求英语四级达到60分时
- if (subject.PreposeSubjectID != null && subject.PreposeSubjectID != Guid.Empty)
- { //先判断是否有要求通过科目
- var preposeSubject = ExamineApplyDAL.SubjectRepository.Entities.Where(x => x.ExaminationSubjectID == subject.PreposeSubjectID).FirstOrDefault();
- if (preposeSubject == null)
- throw new Exception("找不到【" + subject.Name + "】所对应的要求通过科目。");
- //判断该学生的要求通过科目的成绩是否存在
- //var score = levelScoreDAL.levelScoreRepository.Entities.Where(x => x.ExaminationSubjectID == subject.PreposeSubjectID && x.UserID == UserID).FirstOrDefault();
- var score = levelScoreDAL.levelScoreRepository.Entities.Where(x => x.EX_ExaminationSubject.Name == preposeSubject.Name && x.UserID == UserID).OrderByDescending(x => x.TotalScore).FirstOrDefault();
- if (score == null)
- throw new Exception("找不到要求通过的科目【" + preposeSubject.Name + "】的成绩。");
- else
- { //找到该学生要求通过成绩后,判断分数是否达到通过的最低分
- if (score.TotalScore < subject.PreposeScoreLimit)
- throw new Exception("达不到要求通过科目【" + preposeSubject.Name + "】的最低分,不能报名");
- }
- }
- //var examinationSubjectCollegeControl = examinationSubjectCollegeControlDAL.GetExaminationSubjectCollegeControlView(x => x.ExaminationSubjectID == examinationSubjectID && x.FacultymajorID == student.FacultymajorID && x.SchoolyearNumID == schoolyearNum, x => true, x => true).FirstOrDefault();
- //if (examinationSubjectCollegeControl != null)
- //{
- // throw new Exception(examinationSubjectCollegeControl.FacultymajorName + "专业");
- //}
- using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
- {
- //统计出某科目除当前学生外,与其同级的学生报名数,也就是某科目某学年除当前学生外的报名数
- var studentCount = subject.EX_ExaminationRegistration.Where(x => x.CF_Student.UserID != UserID && x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == gradeYear && x.SchoolyearID == currentSchoolyear.SchoolYearID).Count();
- //同一个学生同一个考试科目考试学年学期相同则认为报名重复
- var isRegisted = subject.EX_ExaminationRegistration.Any(x => x.CF_Student.UserID == UserID && x.ExaminationSchoolyearID == subject.SchoolyearID);
- if (isRegisted)
- {
- throw new Exception("你已报名该科目,不能再报名。");
- }
- //该考试科目当前学年学期总报名人数
- int studentRegistCount = RegistrationRepository.GetList(x => x.SchoolyearID == currentSchoolyear.SchoolYearID && x.EX_ExaminationSubject.ExaminationSubjectID == subject.ExaminationSubjectID)
- .Count();
- if (subjectCountLimit != null && sameSchoolNumRegistCount >= subjectCountLimit.SubjectCountLimit && (subjectCountLimit.SubjectCountLimit ?? 0) != 0)
- {
- throw new Exception("你报考该类型的科目数量已经达到门数上限,本学年不能再报名。");
- }
- //if (openControl == null)
- //{
- // throw new Exception("没有开放控制,不能报名。");
- //}
- //开放控制某一年级人数限定判断
- if (openControl != null)
- {
- if (studentCount >= openControl.PeopleNumLimit && (openControl.PeopleNumLimit ?? 0) != 0)
- {
- throw new Exception("该科目同一年级报考人数已达上限,不能再报考");
- }
- }
- //科目最大报名人数
- if (studentRegistCount >= subject.PeopleNumLimit)
- {
- throw new Exception("该科目最大报名人数已达上限,不能再报考");
- }
- if (DateTime.Now.Date > openControl.EndDate || DateTime.Now.Date < openControl.StartDate)
- {
- throw new Exception("不在报名时间内,不能报名。");
- }
- EX_ExaminationRegistration regist = new EX_ExaminationRegistration();
- regist.ExaminationRegistrationID = Guid.NewGuid();
- regist.ExaminationSubjectID = examinationSubjectID;
- regist.CertificatesType = student.CertificatesType;
- regist.IDNumber = student.IDNumber;
- regist.UserID = student.UserID;
- regist.RecordStatus = 1;
- regist.ExaminationSchoolyearID = subject.SchoolyearID;//报名时加入科目考试学年学期
- regist.SchoolyearID = currentSchoolyear.SchoolYearID;
- regist.CreateUserID = UserID;
- regist.CreateTime = DateTime.Now;
- RegistrationRepository.UnitOfWork.Add(regist);
- RegistrationRepository.UnitOfWork.Commit();
- ts.Complete();
- }
-
- }
- public void ApplyCancel(List<Guid> examinationRegistrationIDList)
- {
- try
- {
- var currentSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- foreach (var id in examinationRegistrationIDList)
- {
- var examinationRegistration = RegistrationRepository.Entities.Where(x => x.ExaminationRegistrationID == id).FirstOrDefault();
- if (examinationRegistration != null)
- {
- var subject = ExamineApplyDAL.SubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationRegistration.ExaminationSubjectID, (x => x.EX_ExaminationOpenControl));
- if (subject != null)
- {
- var student = studentRecordDAL.GetStudentByStudentNo(examinationRegistration.UserID.Value);
- var schoolyearNum = (currentSchoolyear.Value - student.StartSchoolyearValue - (currentSchoolyear.SchoolcodeID == student.StartSchoolcodeID ? 0 : 1)) / 2 + 1;
- if (schoolyearNum <= 0)
- throw new Exception("撤销失败,找不到该学生对应年级数。");
- var examinationOpenControl = subject.EX_ExaminationOpenControl.Where(x => x.SchoolyearNumID == schoolyearNum).FirstOrDefault();
- if(examinationOpenControl!=null)
- {
- if (examinationOpenControl.EndDate < DateTime.Now.Date)
- {
- throw new Exception("已过报名截止时间,不能进行撤销操作。");
- }
- else
- //UnitOfWork.Delete<EX_ExaminationRegistration>(x => x.ExaminationRegistrationID==id);
- UnitOfWork.Remove<EX_ExaminationRegistration>(x => x.ExaminationRegistrationID == id);
- }
- else
- throw new Exception("撤销失败,找不到该学生对应年级的开放控制。");
- }
- }
- }
- //UnitOfWork.Delete<EX_ExaminationRegistration>(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID));
- UnitOfWork.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- public IGridResultSet<ExaminationRegisView> GetExaminationRegisterList(Guid UserID)
- {
- var result = ExamineApplyDAL.GetExaminationRegisterList(UserID).OrderByDescending(x => x.SchoolYearCode).ThenBy(x => x.Name).ThenBy(x => x.ExaminationDate).AsQueryable<ExaminationRegisView>().ToGridResultSet();
- return result;
- }
- public ExaminationApplyView GetExaminationApplyViewByExaminationSubjectID(Guid? ExaminationSubjectID)
- {
- var result = ExamineApplyDAL.GetExaminationApplyView(ExaminationSubjectID);
- if (result.Count > 0)
- {
- return result.FirstOrDefault();
- }
- else {
- return null;
- }
- }
- public IGridResultSet<LevelScoreView> GetLevelScoreViewAndRegisterList(Guid? UserID, Guid? SchoolYearID, int pageIndex, int pageSize)
- {
- Expression<Func<ER_LevelScore, bool>> lelexp = x => true;
- Expression<Func<EX_ExaminationRegistration, bool>> erexp = x => true;
- if(UserID.HasValue)
- {
- lelexp = lelexp.And(x => x.UserID == UserID);
- erexp = erexp.And(x => x.UserID == UserID);
- }
- if(SchoolYearID.HasValue)
- {
- lelexp = lelexp.And(x => x.SchoolyearID == SchoolYearID);
- erexp = erexp.And(x => x.SchoolyearID == SchoolYearID);
- }
- var query = ExamineApplyDAL.GetLevelScoreViewAndRegisterList(lelexp, erexp);
- var queryLevelName = levelSettingDAL.GetLevelSettingViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
- var result = query.OrderByDescending(x => x.SchoolyearCode).ToGridResultSet<LevelScoreView>(pageIndex, pageSize);
- result.rows.ForEach(x =>
- x.LevelName = x.TotalScore == null ? "":(queryLevelName.Where(t =>
- t.MaxScore >= x.TotalScore &&
- t.MinScore <= x.TotalScore &&
- t.ExaminationSubjectName == x.ExaminationSubjectName).OrderByDescending(o => o.MaxScore).ThenByDescending(o => o.MinScore).Select(w => w.LevelName).FirstOrDefault()));
- return result;
- }
- public Dictionary<int, string> GetPolitics()
- {
- Dictionary<int, string> Politics = new Dictionary<int, string>();
- var query = from dic in dictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_Politics")
- select new
- {
- dic.Value,
- dic.Code,
- dic.Name
- };
- query.ToList().ForEach(x =>
- {
- Politics.Add(x.Value.Value, x.Name);
- });
- return Politics;
- }
- public Dictionary<int, string> GetHealthState()
- {
- Dictionary<int, string> HealthState = new Dictionary<int, string>();
- var query = from dic in dictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_HealthState")
- select new
- {
- dic.Value,
- dic.Code,
- dic.Name
- };
- query.ToList().ForEach(x =>
- {
- HealthState.Add(x.Value.Value, x.Name);
- });
- return HealthState;
- }
- }
- }
|