123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- 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<ER_ScoreConvertByReplace>, IScoreConvertByReplaceServices
- {
- public StudentScoreDAL StudentScoreDAL { get; set; }
- public ScoreConvertByReplaceDAL ScoreConvertByReplaceDAL { get; set; }
- public ExecutablePlanDAL ExecutablePlanDAL { get; set; }
- public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
- public Lazy<IParameterServices> ParameterServices { get; set; }
- public Lazy<IStudentScoreServices> StudentScoreServices { get; set; }
- public IGridResultSet<ScoreConvertByReplaceView> 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<Func<ER_ScoreConvertByReplace, bool>> exp = (x => true);
- Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
- Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
- Expression<Func<CF_Classmajor, bool>> 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<ScoreConvertByReplaceView> GetScoreConvertByReplaceViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
- int? yearID, int? standardID, Guid? classmajorID, Guid? targetCoursematerialID, int? recordStatus)
- {
- var statusViewList = this.GetStatusViewList();
- Expression<Func<ER_ScoreConvertByReplace, bool>> exp = (x => true);
- Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
- Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
- Expression<Func<CF_Classmajor, bool>> 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<Guid?> scoreConvertByReplaceIDList)
- {
- if (scoreConvertByReplaceIDList.Count > 0)
- {
- var canDeleteStatus = new List<int?>();
-
- 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<ER_ScoreConvertByReplace>(x => scoreConvertByReplaceIDList.Contains(x.ScoreConvertByReplaceID));
- }
- }
- public void OnApproveEnd(List<Guid> scoreConvertByReplaceIDList, Guid? userID)
- {
- int? retakeExamsCategoryID = ParameterServices.Value.GetParameterValue<int>(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<ER_ScoreConvertedSubmitedScore>();
- var insertSubmitedScoreDetailBackupList = new List<ER_ScoreConvertedSubmitedScoreDetail>();
- var insertSubmitedScoreList = new List<ER_SubmitedScore>();
- var insertSubmitedScoreDetailList = new List<ER_SubmitedScoreDetail>();
- 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<ER_SubmitedScoreDetail>(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
- UnitOfWork.Delete<ER_SubmitedScore>(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
- UnitOfWork.Delete<ER_FinallyScoreDetail>(x => finallyScoreIDList.Contains(x.FinallyScoreID));
- UnitOfWork.Delete<ER_FinallyScore>(x => finallyScoreIDList.Contains(x.FinallyScoreID));
- UnitOfWork.BulkInsert(insertSubmitedScoreList);
- UnitOfWork.BulkInsert(insertSubmitedScoreDetailList);
- StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(insertSubmitedScoreIDList);
- scope.Complete();
- }
- }
- }
- }
|