using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; using EMIS.ViewModel.ScoreManage; using EMIS.ViewModel; using EMIS.DataLogic.ScoreManage; using System.Linq.Expressions; using EMIS.CommonLogic.CalendarManage; using System.Transactions; using EMIS.DataLogic.EducationManage; using EMIS.Utility; namespace EMIS.CommonLogic.ScoreManage { public partial class ScoreConvertByReplaceServices : BaseWorkflowServices, IScoreConvertByReplaceServices { public StudentScoreDAL StudentScoreDAL { get; set; } public ScoreConvertByReplaceDAL ScoreConvertByReplaceDAL { get; set; } public ExecutablePlanDAL ExecutablePlanDAL { get; set; } public Lazy SchoolYearServices { get; set; } public Lazy ParameterServices { get; set; } public Lazy StudentScoreServices { get; set; } public IGridResultSet GetScoreConvertByReplaceViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, Guid? targetCoursematerialID, int? recordStatus, int? pageIndex, int? pageSize) { var statusViewList = this.GetStatusViewList(); Expression> exp = (x => true); Expression> facultyExp = (x => true); Expression> gradeExp = (x => true); Expression> classExp = (x => true); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { facultyExp = facultyExp.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { gradeExp = gradeExp.And(x => x.GradeID == yearID); } if (standardID.HasValue) { facultyExp = facultyExp.And(x => x.StandardID == standardID); } if (classmajorID.HasValue) { classExp = classExp.And(x => x.ClassmajorID == classmajorID.Value); } if (targetCoursematerialID.HasValue) { exp = exp.And(x => x.TargetCoursematerialID == targetCoursematerialID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } var query = ScoreConvertByReplaceDAL.GetScoreConvertByReplaceViewQueryable(exp, facultyExp, gradeExp, classExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim()); query = this.GetQueryByDataRangeByCollege(query); query = query.OrderByDescending(x => x.SchoolyearCode) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.YearID) .ThenBy(x => x.StandardID) .ThenBy(x => x.ClassmajorNo) .ThenBy(x => x.LoginID); var result = query.ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.RecordStatusDesc = statusViewList.Where(w => w.ID == x.RecordStatus).Select(w => w.Name).FirstOrDefault()); return result; } public List GetScoreConvertByReplaceViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, Guid? targetCoursematerialID, int? recordStatus) { var statusViewList = this.GetStatusViewList(); Expression> exp = (x => true); Expression> facultyExp = (x => true); Expression> gradeExp = (x => true); Expression> classExp = (x => true); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { facultyExp = facultyExp.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { gradeExp = gradeExp.And(x => x.GradeID == yearID); } if (standardID.HasValue) { facultyExp = facultyExp.And(x => x.StandardID == standardID); } if (classmajorID.HasValue) { classExp = classExp.And(x => x.ClassmajorID == classmajorID.Value); } if (targetCoursematerialID.HasValue) { exp = exp.And(x => x.TargetCoursematerialID == targetCoursematerialID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } var query = ScoreConvertByReplaceDAL.GetScoreConvertByReplaceViewQueryable(exp, facultyExp, gradeExp, classExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim()); query = this.GetQueryByDataRangeByCollege(query); query = query.OrderByDescending(x => x.SchoolyearCode) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.YearID) .ThenBy(x => x.StandardID) .ThenBy(x => x.ClassmajorNo) .ThenBy(x => x.LoginID); var result = query.ToList(); result.ForEach(x => x.RecordStatusDesc = statusViewList.Where(w => w.ID == x.RecordStatus).Select(w => w.Name).FirstOrDefault()); return result; } public ScoreConvertByReplaceView GetScoreConvertByReplaceView(Guid? scoreConvertByReplaceID) { var statusViewList = this.GetStatusViewList(); var scoreConvertByReplaceView = this.ScoreConvertByReplaceDAL.GetScoreConvertByReplaceViewQueryable(x => x.ScoreConvertByReplaceID == scoreConvertByReplaceID, (x => true), (x => true), (x => true)).FirstOrDefault(); if (scoreConvertByReplaceView != null) { scoreConvertByReplaceView.RecordStatusDesc = statusViewList.Where(x => x.ID == scoreConvertByReplaceView.RecordStatus).Select(x => x.Name).FirstOrDefault(); } return scoreConvertByReplaceView; } public void Save(ScoreConvertByReplaceView scoreConvertByReplaceView) { try { var schoolyear = SchoolYearServices.Value.GetCurrentSchoolYear(); ER_ScoreConvertByReplace dupScoreConvert = ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository.Entities.Where(x => x.SourceCoursematerialID == scoreConvertByReplaceView.SourceCoursematerialID && x.UserID == scoreConvertByReplaceView.UserID && x.ScoreConvertByReplaceID != scoreConvertByReplaceView.ScoreConvertByReplaceID).FirstOrDefault(); if (dupScoreConvert != null) { throw new Exception("该课程已经申请过认定,不能重复申请。"); } ER_ScoreConvertByReplace scoreConvert = null; if (scoreConvertByReplaceView.ScoreConvertByReplaceID == null || scoreConvertByReplaceView.ScoreConvertByReplaceID == Guid.Empty) { scoreConvert = new ER_ScoreConvertByReplace(); scoreConvert.ScoreConvertByReplaceID = Guid.NewGuid(); SetNewStatus(scoreConvert); UnitOfWork.Add(scoreConvert); } else { scoreConvert = this.ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository .GetSingle(x => x.ScoreConvertByReplaceID == scoreConvertByReplaceView.ScoreConvertByReplaceID); if (scoreConvert == null) { throw new Exception("当前编辑的认定记录可能已被其他人删除。"); } SetModifyStatus(scoreConvert); } scoreConvert.SchoolyearID = schoolyear.SchoolYearID; scoreConvert.UserID = scoreConvertByReplaceView.UserID; scoreConvert.SourceCoursematerialID = scoreConvertByReplaceView.SourceCoursematerialID; scoreConvert.TotalScore = scoreConvertByReplaceView.TotalScore; scoreConvert.TargetCoursematerialID = scoreConvertByReplaceView.TargetCoursematerialID; scoreConvert.Reason = scoreConvertByReplaceView.Reason; UnitOfWork.Commit(); } catch (Exception) { throw; } } public void Delete(IList scoreConvertByReplaceIDList) { if (scoreConvertByReplaceIDList.Count > 0) { var canDeleteStatus = new List(); canDeleteStatus.Add(this.GetStartStatus()); canDeleteStatus.AddRange(this.GetBackpointStatus()); var canDeleteStatusDesc = this.GetStatusViewList().Where(x => canDeleteStatus.Contains(x.ID)).Select(x => x.Name); var scoreConvertByReplaceList = ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository.GetList(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID)).ToList(); if (scoreConvertByReplaceList.Any(x => !canDeleteStatus.Contains(x.RecordStatus))) { throw new Exception("只能删除状态为" + string.Join("、", canDeleteStatusDesc) + "的记录。"); } UnitOfWork.Delete(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID)); } } public void OnApproveEnd(List scoreConvertByReplaceIDList, Guid? userID) { int? retakeExamsCategoryID = ParameterServices.Value.GetParameterValue(CF_ParameterType.RetakeExamsCatagoryID); var scoreConvertByReplaceList = this.ScoreConvertByReplaceDAL.ScoreConvertByReplaceRepository .GetList(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID)).ToList(); var selectKeyList = scoreConvertByReplaceList.Select(x => new { x.UserID, CoursematerialID = x.SourceCoursematerialID }).ToList(); var targetSelectKeyList = scoreConvertByReplaceList.Select(x => new { x.UserID, CoursematerialID = x.TargetCoursematerialID }).ToList(); var submitedScoreList = StudentScoreDAL.submitedScoreRepository.Entities.SelectByKeys(selectKeyList); var submitedScoreIDList = submitedScoreList.Select(x => (Guid?)x.SubmitedScoreID); var submitedScoreDetailList = StudentScoreDAL.SubmitedScoreDetailRepository.GetList(x => submitedScoreIDList.Contains(x.SubmitedScoreID)).ToList(); var finallyScoreList = StudentScoreDAL.FinallyScoreRepository.Entities.SelectByKeys(selectKeyList); var finallyScoreIDList = finallyScoreList.Select(x => (Guid?)x.FinallyScoreID); var finallyScoreDetailList = StudentScoreDAL.FinallyScoreDetailRepository.GetList(x => finallyScoreIDList.Contains(x.FinallyScoreID)).ToList(); //这个方法比较可疑,不知道技术上能否实现(主要是EF产生的语句有自动命名的问题,端点调) var lastCourseStarttermViewList = ExecutablePlanDAL.GetLastCourseStarttermViewQueryable().SelectByKeys(targetSelectKeyList); var insertSubmitedScoreBackupList = new List(); var insertSubmitedScoreDetailBackupList = new List(); var insertSubmitedScoreList = new List(); var insertSubmitedScoreDetailList = new List(); foreach (var submitedScore in submitedScoreList) { var scoreConvertByReplace = scoreConvertByReplaceList.FirstOrDefault(x => x.UserID == submitedScore.UserID && x.SourceCoursematerialID == submitedScore.CoursematerialID); #region 备份已提交成绩主表 var scoreConvertedSubmitedScore = new ER_ScoreConvertedSubmitedScore { ScoreConvertedSubmitedScoreID = Guid.NewGuid(), ScoreConvertByReplaceID = scoreConvertByReplace.ScoreConvertByReplaceID, SchoolyearID = submitedScore.SchoolyearID, SchoolyearNumID = submitedScore.SchoolyearNumID, FinalExaminationID = submitedScore.FinalExaminationID, DepartmentID = submitedScore.DepartmentID, ClassName = submitedScore.ClassName, CoursematerialID = submitedScore.CoursematerialID, CourseTypeID = submitedScore.CourseTypeID, ExamsCategoryID = submitedScore.ExamsCategoryID, ExaminationModeID = submitedScore.ExaminationModeID, HandleModeID = submitedScore.HandleModeID, Credit = submitedScore.Credit, Totalhours = submitedScore.TotalHours, ExamsDatetime = submitedScore.ExamsDatetime, ResultTypeID = submitedScore.ResultTypeID, CreatorUserID = submitedScore.CreatorUserID, EntryDeadlineTime = submitedScore.EntryDeadlineTime, IsEntry = submitedScore.IsEntry, ExaminationType = submitedScore.ExaminationType, StarttermID = submitedScore.StarttermID, UserID = submitedScore.UserID, ExamsStateID = submitedScore.ExamsStateID, TotalScore = submitedScore.TotalScore, ScoreCredit = submitedScore.ScoreCredit, GradePoint = submitedScore.GradePoint, Remark = submitedScore.Remark, RecordStatus = submitedScore.RecordStatus, CreateTime = submitedScore.CreateTime, CreateUserID = submitedScore.CreateUserID, ModifyUserID = submitedScore.ModifyUserID, ModifyTime = submitedScore.ModifyTime }; insertSubmitedScoreBackupList.Add(scoreConvertedSubmitedScore); #endregion #region 备份已提交成绩明细 var curSubmitedScoreDetailList = submitedScoreDetailList.Where(x => x.SubmitedScoreID == submitedScore.SubmitedScoreID).ToList(); foreach (var detail in curSubmitedScoreDetailList) { insertSubmitedScoreDetailBackupList.Add(new ER_ScoreConvertedSubmitedScoreDetail { ScoreConvertedSubmitedScoreDetailID = Guid.NewGuid(), ScoreConvertedSubmitedScoreID = scoreConvertedSubmitedScore.ScoreConvertedSubmitedScoreID, ScoreTypeID = detail.ScoreTypeID, Score = detail.Score, RecordStatus = detail.RecordStatus, CreateTime = detail.CreateTime, CreateUserID = detail.CreateUserID, ModifyUserID = detail.ModifyUserID, ModifyTime = detail.ModifyTime }); } #endregion } foreach (var finallyScore in finallyScoreList) { var scoreConvertByReplace = scoreConvertByReplaceList.FirstOrDefault(x => x.UserID == finallyScore.UserID && x.SourceCoursematerialID == finallyScore.CoursematerialID); var lastCourseStarttermView = lastCourseStarttermViewList.FirstOrDefault(x => x.UserID == finallyScore.UserID && x.CoursematerialID == scoreConvertByReplace.TargetCoursematerialID); #region 添加新的已提交成绩 var insertSubmitedScore = new ER_SubmitedScore { SubmitedScoreID = Guid.NewGuid(), SchoolyearID = finallyScore.SchoolyearID, SchoolyearNumID = lastCourseStarttermView.SchoolyearNumID, DepartmentID = lastCourseStarttermView.DepartmentID, ClassName = lastCourseStarttermView.ClassName, CoursematerialID = lastCourseStarttermView.CoursematerialID, CourseTypeID = lastCourseStarttermView.CourseTypeID, ExamsCategoryID = (int)EMIS.ViewModel.CF_ExamsCategory.FinalExam, ExaminationModeID = lastCourseStarttermView.ExaminationModeID, HandleModeID = lastCourseStarttermView.HandleModeID, Credit = lastCourseStarttermView.Credit, TotalHours = lastCourseStarttermView.TotalHours, ResultTypeID = lastCourseStarttermView.ResultTypeID, CreatorUserID = userID, IsEntry = true, ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination, StarttermID = lastCourseStarttermView.StarttermID, UserID = lastCourseStarttermView.UserID, ExamsStateID = (int)CF_ExamsState.NormalExams, TotalScore = finallyScore.TotalScore, ScoreCredit = finallyScore.ScoreCredit > 0 ? lastCourseStarttermView.Credit : 0, GradePoint = finallyScore.GradePoint, Remark = Const.ER_SCORECONVERT_BYREPLACE_SCOREREMARK, RecordStatus = (int)SYS_STATUS.USABLE, CreateUserID = userID, CreateTime = DateTime.Now, ModifyUserID = userID, ModifyTime = DateTime.Now }; #endregion #region 添加新的已提交成绩明细 var curFinallyScoreDetailList = finallyScoreDetailList.Where(x => x.FinallyScoreID == finallyScore.FinallyScoreID).ToList(); foreach (var detail in curFinallyScoreDetailList) { insertSubmitedScoreDetailList.Add(new ER_SubmitedScoreDetail { SubmitedScoreDetailID = Guid.NewGuid(), SubmitedScoreID = insertSubmitedScore.SubmitedScoreID, ScoreTypeID = detail.ScoreTypeID, Score = detail.Score, RecordStatus = detail.RecordStatus, CreateTime = detail.CreateTime, CreateUserID = detail.CreateUserID, ModifyUserID = detail.ModifyUserID, ModifyTime = detail.ModifyTime }); } #endregion insertSubmitedScoreList.Add(insertSubmitedScore); } var insertSubmitedScoreIDList = insertSubmitedScoreList.Select(x => x.SubmitedScoreID).ToList(); using (var scope = new TransactionScope(TransactionScopeOption.Required)) { UnitOfWork.BulkInsert(insertSubmitedScoreBackupList); UnitOfWork.BulkInsert(insertSubmitedScoreDetailBackupList); UnitOfWork.Delete(x => submitedScoreIDList.Contains(x.SubmitedScoreID)); UnitOfWork.Delete(x => submitedScoreIDList.Contains(x.SubmitedScoreID)); UnitOfWork.Delete(x => finallyScoreIDList.Contains(x.FinallyScoreID)); UnitOfWork.Delete(x => finallyScoreIDList.Contains(x.FinallyScoreID)); UnitOfWork.BulkInsert(insertSubmitedScoreList); UnitOfWork.BulkInsert(insertSubmitedScoreDetailList); StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(insertSubmitedScoreIDList); scope.Complete(); } } } }