123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Transactions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.CommonLogic.CalendarManage;
- using EMIS.DataLogic.ExamManage;
- using EMIS.DataLogic.ScoreManage;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.ScoreManage;
- namespace EMIS.CommonLogic.ScoreManage
- {
- public class ProjectScoreServices : BaseServices, IProjectScoreServices
- {
- public LevelSettingSubjectDAL LevelSettingSubjectDAL { get; set; }
- public ExaminationScoreDAL ExaminationScoreDAL { get; set; }
- public ProjectScoreDAL ProjectScoreDAL { get; set; }
- public ResitDAL ResitDAL { get; set; }
- public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
- public IGridResultSet<ProjectScoreView> GetProjectScoreViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationTypeID,
- Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, bool? hasTrain, int? pageIndex, int? pageSize)
- {
- Expression<Func<ER_ProjectScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
- Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
- Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
- Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (examinationTypeID.HasValue)
- {
- projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID);
- }
- if (examinationProjectID.HasValue)
- {
- exp = exp.And(x => x.ExaminationProjectID == examinationProjectID);
- }
- if (schoolAreaID.HasValue)
- {
- grademajorExp = grademajorExp.And(x => x.SchoolAreaID == schoolAreaID);
- }
- if (collegeID.HasValue)
- {
- facultExp = facultExp.And(x => x.CollegeID == collegeID);
- }
- if (yearID.HasValue)
- {
- grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
- }
- if (standardID.HasValue)
- {
- facultExp = facultExp.And(x => x.StandardID == standardID);
- }
- if (classmajorID.HasValue)
- {
- classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
- }
- var query = ProjectScoreDAL.GetProjectScoreViewQueryable(exp, projectExp, facultExp, grademajorExp, classmajorExp);
- if (hasTrain.HasValue)
- {
- if (hasTrain.Value)
- {
- query = query.Where(x => x.TrainingClassID != null);
- }
- else
- {
- query = query.Where(x => x.TrainingClassID == null);
- }
- }
- if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
- {
- query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
- }
- //var result = GetQueryByDataRangeByCollege(query);
- return query.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationTypeName)
- .ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.ClassmajorName).ThenBy(x => x.UserName)
- .ToGridResultSet<ProjectScoreView>(pageIndex, pageSize);
- }
- public List<ProjectScoreView> GetProjectScoreViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationTypeID, Guid? examinationProjectID,
- int? schoolAreaID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, bool? hasTrain)
- {
- Expression<Func<ER_ProjectScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
- Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
- Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
- Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (examinationTypeID.HasValue)
- {
- projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID);
- }
- if (examinationProjectID.HasValue)
- {
- exp = exp.And(x => x.ExaminationProjectID == examinationProjectID);
- }
- if (schoolAreaID.HasValue)
- {
- grademajorExp = grademajorExp.And(x => x.SchoolAreaID == schoolAreaID);
- }
- if (collegeID.HasValue)
- {
- facultExp = facultExp.And(x => x.CollegeID == collegeID);
- }
- if (yearID.HasValue)
- {
- grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
- }
- if (standardID.HasValue)
- {
- facultExp = facultExp.And(x => x.StandardID == standardID);
- }
- if (classmajorID.HasValue)
- {
- classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
- }
- var query = ProjectScoreDAL.GetProjectScoreViewQueryable(exp, projectExp, facultExp, grademajorExp, classmajorExp);
- if (hasTrain.HasValue)
- {
- if (hasTrain.Value)
- {
- query = query.Where(x => x.TrainingClassID != null);
- }
- else
- {
- query = query.Where(x => x.TrainingClassID == null);
- }
- }
- if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
- {
- query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
- }
- //var result = GetQueryByDataRangeByCollege(query);
- return this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationTypeName)
- .ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.ClassmajorName).ThenBy(x => x.UserName)
- .ToList();
- }
- //对所有不及格而又没有产生过补考记录的科目成绩生成补考
- //不一定是不及格的科目,也包括完全匹配不上任何成绩等级的科目
- //生成补考记录必须保证在该科至少有一项有有效期的成绩,贞媚说第一科考试失败是没办法补考的2019-06-25
- //流程:先找出对应的及格线和当前范围考试的科目成绩,对比后看看哪个是不及格的,再找当前批次的补考记录,看看哪个是没有生成过补考名单的,
- //再找上次正常考试之后的所有补考成绩,看看次数够了没,
- //再找是否存在有效期内的成绩,最后生成补考
- private List<ER_Resit> GenerateResit(List<ER_LevelSetting> levelSettingList,
- List<EX_ExaminationProjectSubject> subjectList, List<ProjectScoreGenerateScoreView> allScoreList,
- List<ProjectScoreGenerateScoreView> curScoreList)
- {
- var nowTime = DateTime.Today;
- var passLevelSettingList = levelSettingList.Where(x => x.IsPassLine == true).ToList();
- var examinationScoreIDList = curScoreList.Select(x => x.ExaminationScoreID).Distinct().ToList();
- var curResitList = ResitDAL.ResitRepository.GetList(x => examinationScoreIDList.Contains(x.ResitID)).ToList();
- var insertResitList = new List<ER_Resit>();
- foreach (var score in curScoreList)
- {
- var subject = subjectList.FirstOrDefault(x => x.ExaminationProjectID == score.ExaminationProjectID && x.ExaminationSubjectID == score.ExaminationSubjectID);
- if (subject == null)
- {
- continue;
- }
- var passLevelSetting = passLevelSettingList.Where(x => x.ExaminationProjectID == score.ExaminationProjectID)
- .SelectMany(x => x.ER_LevelSettingSubject).FirstOrDefault(x => x.ExaminationSubjectID == score.ExaminationSubjectID);
- if (passLevelSetting == null)
- {
- continue;
- }
- if (score.Score >= passLevelSetting.PassScore)
- {
- continue;
- }
- if (curResitList.Any(x => x.ExaminationScoreID == score.ExaminationScoreID))
- {
- continue;
- }
- if (!allScoreList.Any(x => x.ExaminationProjectID == score.ExaminationProjectID && x.UserID == score.UserID && x.Score >= passLevelSetting.PassScore && (x.Expire >= nowTime || x.Expire == null)))
- {
- continue;
- }
- var subjectScoreList = allScoreList.Where(x => x.ExaminationProjectID == score.ExaminationProjectID && x.ExaminationSubjectID == score.ExaminationSubjectID);
- var lastNormalExamTime = subjectScoreList.Where(x => x.IsResit != true).Max(x => x.BatchStartDate);
- var resitCount = subjectScoreList.Where(x => x.IsResit == true && x.BatchStartDate > lastNormalExamTime).Count();
- if (subject.ResitCount <= resitCount)
- {
- continue;
- }
- var resit = new ER_Resit()
- {
- ResitID = Guid.NewGuid(),
- ExaminationScoreID = score.ExaminationScoreID
- };
- this.SetNewStatus(resit);
- insertResitList.Add(resit);
- }
- return insertResitList;
- }
- public void GenerateProjectScore(Guid schoolyearID, Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID)
- {
- var nowTime = DateTime.Today;
- Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => x.SchoolyearID == schoolyearID);
- Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
- if (examinationBatchID.HasValue)
- {
- batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
- }
- if (examinationTypeID.HasValue)
- {
- projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID);
- }
- if (examinationProjectID.HasValue)
- {
- projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
- }
- //读出和范围相关的所有考试成绩(这里不分有效期,因为不及格的成绩有效期是无效的)
- var allScore = ProjectScoreDAL.GetAllExaminationScoreViewByBatchStudent(batchExp, projectExp).ToList();
- var curScoreList = ProjectScoreDAL.GetExaminationScoreViewByBatchStudent(batchExp, projectExp).ToList();
- var projectIDList = allScore.Select(x => x.ExaminationProjectID).Distinct().ToList();
- var projectSubjectList = ProjectScoreDAL.ExaminationProjectRepository.GetList(x => projectIDList.Contains(x.ExaminationProjectID), (x => x.EX_ExaminationProjectSubject)).ToList();
- var projectUserIDLIst = allScore.GroupBy(x => new { ExaminationProjectID = x.ExaminationProjectID, UserID = x.UserID }).Select(x => x.Key).ToList();
- var dbProjectScoreList = ProjectScoreDAL.ProjectScoreRepository.Entities.SelectByKeys(projectUserIDLIst);
- var levelSettingList = LevelSettingSubjectDAL.levelSettingRepository.GetList(x => projectIDList.Contains(x.ExaminationProjectID) && x.RecordStatus > (int)SYS_STATUS.UNUSABLE,
- (x => x.ER_LevelSettingSubject)).ToList();
- var schoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- var dbcertisfierDistributeList = ProjectScoreDAL.CertisfierDistributeRepository.GetList(x => projectIDList.Contains(x.ExaminationProjectID)).ToList();
- var insertList = new List<ER_ProjectScore>();
- var certisfierDistributeList = new List<ER_CertisfierDistribute>();
- foreach (var projectUser in projectUserIDLIst)
- {
- var subjectList = projectSubjectList.Where(x => x.ExaminationProjectID == projectUser.ExaminationProjectID).SelectMany(x => x.EX_ExaminationProjectSubject).ToList();
- var projectLevelSettingList = levelSettingList.Where(x => x.ExaminationProjectID == projectUser.ExaminationProjectID)
- .OrderByDescending(x => subjectList
- .Join(x.ER_LevelSettingSubject, (w => w.ExaminationSubjectID), (w => w.ExaminationSubjectID), ((w,v) => v.PassScore))
- .DefaultIfEmpty()
- .Average(w => w == null ? 0 : w)).ToList();
- var passLevelSetting = projectLevelSettingList.FirstOrDefault(x => x.IsPassLine == true);
- var scoreList = allScore.Where(x => x.ExaminationProjectID == projectUser.ExaminationProjectID && x.UserID == projectUser.UserID).ToList();
- var userCurScoreList = curScoreList.Where(x => x.ExaminationProjectID == projectUser.ExaminationProjectID && x.UserID == projectUser.UserID).ToList();
- foreach (var levelSetting in projectLevelSettingList)
- {
- bool allMatch = true;
- var newProjectScore = new ER_ProjectScore();
- foreach (var levelSubject in levelSetting.ER_LevelSettingSubject)
- {
- var subjectMaxScore = scoreList.Where(x => x.ExaminationSubjectID == levelSubject.ExaminationSubjectID && (x.Expire == null || x.Expire >= nowTime)).Max(x => x.Score);
- if (subjectMaxScore == null || subjectMaxScore < levelSubject.PassScore)
- {
- allMatch = false;
- break;
- }
- var score = scoreList.Where(x => x.ExaminationSubjectID == levelSubject.ExaminationSubjectID && (x.Expire == null || x.Expire >= nowTime) && x.Score == subjectMaxScore).FirstOrDefault();
- newProjectScore.SchoolyearID = score.SchoolYearID;
- }
- if (allMatch)
- {
- newProjectScore.ProjectScoreID = Guid.NewGuid();
- newProjectScore.ExaminationProjectID = projectUser.ExaminationProjectID;
- newProjectScore.UserID = projectUser.UserID;
- newProjectScore.LevelSettingID = levelSetting.LevelSettingID;
- this.SetNewStatus(newProjectScore);
- insertList.Add(newProjectScore);
- break;
- }
- }
- }
- foreach (var proScore in insertList)
- {
- var ispass = levelSettingList.FirstOrDefault(x => x.LevelSettingID == proScore.LevelSettingID).IsPassed;
- if (ispass.Value && dbcertisfierDistributeList.FirstOrDefault(x => x.ExaminationProjectID == proScore.ExaminationProjectID && x.UserID == proScore.UserID) == null)
- {
- ER_CertisfierDistribute certisfierDistribute = new ER_CertisfierDistribute();
- certisfierDistribute.CertisfierDistributeID = Guid.NewGuid();
- certisfierDistribute.ExaminationProjectID = proScore.ExaminationProjectID;
- certisfierDistribute.UserID = proScore.UserID;
- certisfierDistribute.SchoolyearID = proScore.SchoolyearID;
- SetNewStatus<ER_CertisfierDistribute>(certisfierDistribute);
- SetModifyStatus<ER_CertisfierDistribute>(certisfierDistribute);
- certisfierDistributeList.Add(certisfierDistribute);
- }
- }
- var insertResitList = GenerateResit(levelSettingList, projectSubjectList.SelectMany(x => x.EX_ExaminationProjectSubject).ToList(), allScore, curScoreList);
- var deleteResitScoreIDList = curScoreList.Select(x => (Guid?)x.ExaminationScoreID).Distinct().ToList();
- using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
- {
- UnitOfWork.Delete(dbProjectScoreList);
- UnitOfWork.BulkInsert(insertList);
- UnitOfWork.Delete<ER_Resit>(x => deleteResitScoreIDList.Contains(x.ExaminationScoreID));
- UnitOfWork.BulkInsert(insertResitList);
- UnitOfWork.BulkInsert(certisfierDistributeList);
- scope.Complete();
- }
- }
- public IGridResultSet<ProjectScoreDetailView> GetProjectScoreDetailViewGrid(ConfiguretView conditionView, Guid projectScoreID, int? pageIndex, int? pageSize)
- {
- Expression<Func<ER_ProjectScore, bool>> exp = (x => x.ProjectScoreID == projectScoreID);
-
- var query = ProjectScoreDAL.GetProjectScoreDetailViewQueryable(exp);
- if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
- {
- query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
- }
- return query.OrderByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize);
- }
- }
- }
|