123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.ScoreManage;
- using EMIS.ViewModel;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.Entities;
- using System.Linq.Expressions;
- using EMIS.DataLogic.ScoreManage;
- using EMIS.CommonLogic.CalendarManage;
- using System.Transactions;
- using EMIS.DataLogic.EducationManage;
- using EMIS.Utility;
- namespace EMIS.CommonLogic.ScoreManage
- {
- public class ScoreConvertByApplyServices : BaseWorkflowServices<ER_ScoreConvertByApply>, IScoreConvertByApplyServices, IFileUploadServices
- {
- public StudentScoreDAL studentScoreDAL { get; set; }
- public ScoreConvertByApplyDAL scoreConvertByApplyDAL { get; set; }
- public ISchoolYearServices schoolYearServices { get; set; }
- public IParameterServices parameterServices { get; set; }
- public ExecutablePlanDAL ExecutablePlanDAL { get; set; }
- public IStudentScoreServices studentScoreServices { get; set; }
- public IGridResultSet<ScoreConvertByApplyView> GetScoreConvertByApplyViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
- int? yearID, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus, int? pageIndex, int? pageSize)
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var statusViewList = this.GetStatusViewList();
- Expression<Func<ER_ScoreConvertByApply, 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 (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (recordStatus.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == recordStatus);
- }
- //学生登录只看到自己的信息
- if (curUser.IsStudent)
- {
- exp = exp.And(x => x.UserID == curUser.UserID);
- }
- var query = scoreConvertByApplyDAL.GetScoreConvertByApplyViewQueryable(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.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<ScoreConvertByApplyView> GetScoreConvertByApplyViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
- int? yearID, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus, List<Guid?> idList)
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var statusViewList = this.GetStatusViewList();
- Expression<Func<ER_ScoreConvertByApply, 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 (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (recordStatus.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == recordStatus);
- }
- if (idList != null && idList.Count > 0)
- {
- exp = exp.And(x => idList.Contains(x.ScoreConvertByApplyID));
- }
- //学生登录只看到自己的信息
- if (curUser.IsStudent)
- {
- exp = exp.And(x => x.UserID == curUser.UserID);
- }
- var query = scoreConvertByApplyDAL.GetScoreConvertByApplyViewQueryable(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.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 ScoreConvertByApplyView GetScoreConvertByApplyView(Guid? scoreConvertByApplyID)
- {
- var statusViewList = this.GetStatusViewList();
- var scoreConvertByApplyView = this.scoreConvertByApplyDAL.GetScoreConvertByApplyViewQueryable(x => x.ScoreConvertByApplyID == scoreConvertByApplyID,
- (x => true), (x => true), (x => true)).FirstOrDefault();
- if (scoreConvertByApplyView != null)
- {
- scoreConvertByApplyView.RecordStatusDesc = statusViewList.Where(x => x.ID == scoreConvertByApplyView.RecordStatus).Select(x => x.Name).FirstOrDefault();
- }
- return scoreConvertByApplyView;
- }
- public void Save(ScoreConvertByApplyView scoreConvertByApplyView, List<FileUploadView> fileList)
- {
- try
- {
- var statusViewList = this.GetStatusViewList();
- var status = this.GetStartStatus();
- var returnStatus = this.GetBackpointStatus();
- var schoolyear = schoolYearServices.GetCurrentSchoolYear();
- ER_ScoreConvertByApply dbScoreConvert = scoreConvertByApplyDAL.scoreConvertByApplyRepository.Entities.Where(x =>
- x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID
- && x.UserID == scoreConvertByApplyView.UserID
- && x.ScoreConvertByApplyID != scoreConvertByApplyView.ScoreConvertByApplyID).FirstOrDefault();
- if (dbScoreConvert != null)
- {
- throw new Exception("该课程已经申请过认定,不能重复申请。");
- }
- ER_ScoreConvertByApply scoreConvert = null;
- List<ER_ScoreConvertByApplyAttachment> addAttachmentList = new List<ER_ScoreConvertByApplyAttachment>();
- var dbScoreConvertByApply = scoreConvertByApplyDAL.scoreConvertByApplyRepository.GetSingle(x => x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID);
- if (dbScoreConvertByApply == null)
- {
- scoreConvert = new ER_ScoreConvertByApply();
- scoreConvert.ScoreConvertByApplyID = Guid.NewGuid();
- SetNewStatus(scoreConvert);
- UnitOfWork.Add(scoreConvert);
- if (fileList != null && fileList.Count > 0)
- {
- foreach (var file in fileList)
- {
- ER_ScoreConvertByApplyAttachment attachment = new ER_ScoreConvertByApplyAttachment();
- attachment.ScoreConvertByApplyAttachmentID = Guid.NewGuid();
- attachment.ScoreConvertByApplyID = scoreConvert.ScoreConvertByApplyID;
- attachment.Name = file.FileName;
- attachment.Url = file.FileUrl;
- this.SetNewStatus(attachment);
- scoreConvert.ER_ScoreConvertByApplyAttachment.Add(attachment);
- }
- }
- }
- else
- {
- scoreConvert = this.scoreConvertByApplyDAL.scoreConvertByApplyRepository
- .GetSingle(x => x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID);
- if (scoreConvert.RecordStatus != status && !returnStatus.Contains(scoreConvert.RecordStatus))
- {
- throw new Exception("该信息处于待审核或已通过状态,不能修改");
- }
- if (scoreConvert == null)
- {
- throw new Exception("当前编辑的记录可能已被其他人删除。");
- }
- SetModifyStatus(scoreConvert);
- if (scoreConvertByApplyView.IsChangeAttachment == 1)
- {
- UnitOfWork.Remove<ER_ScoreConvertByApplyAttachment>(x => x.ScoreConvertByApplyID == scoreConvertByApplyView.ScoreConvertByApplyID);
- if (fileList != null && fileList.Count > 0)
- {
- foreach (var file in fileList)
- {
- ER_ScoreConvertByApplyAttachment attachment = new ER_ScoreConvertByApplyAttachment();
- attachment.ScoreConvertByApplyAttachmentID = Guid.NewGuid();
- attachment.ScoreConvertByApplyID = scoreConvert.ScoreConvertByApplyID;
- attachment.Name = file.FileName;
- attachment.Url = file.FileUrl;
- this.SetNewStatus(attachment);
- scoreConvert.ER_ScoreConvertByApplyAttachment.Add(attachment);
- //addAttachmentList.Add(attachment);
- }
- }
- }
- }
- scoreConvert.SchoolyearID = schoolyear.SchoolYearID;
- scoreConvert.UserID = scoreConvertByApplyView.UserID;
- scoreConvert.CoursematerialID = scoreConvertByApplyView.CoursematerialID;
- scoreConvert.TotalScore = scoreConvertByApplyView.TotalScore;
- scoreConvert.Reason = scoreConvertByApplyView.Reason;
- UnitOfWork.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- public void Delete(IList<Guid?> scoreConvertByApplyIDList)
- {
- if (scoreConvertByApplyIDList.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 scoreConvertByApplyList = scoreConvertByApplyDAL.scoreConvertByApplyRepository.GetList(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID)).ToList();
- if (scoreConvertByApplyList.Any(x => !canDeleteStatus.Contains(x.RecordStatus)))
- {
- throw new Exception("只能删除状态为" + string.Join("、", canDeleteStatusDesc) + "的记录。");
- }
- UnitOfWork.Delete<ER_ScoreConvertByApplyAttachment>(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID));
- UnitOfWork.Delete<ER_ScoreConvertByApply>(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID));
- }
- }
- public List<FileUploadView> GetFileList(Guid? formID)
- {
- //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID);
- var fileList = scoreConvertByApplyDAL.GetScoreConvertByApplyAttachmentView(x => x.ScoreConvertByApplyID == formID).ToList();
- return fileList;
- }
- public void Submit(List<Guid> scoreConvertByReplaceIDList, Guid? userID)
- {
- try
- {
- this.StartUp(scoreConvertByReplaceIDList, userID.Value);
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- public void ScoreConvertByApplyApprove(List<Guid> idList, Guid userID, Guid actionID, string comment)
- {
- try
- {
- this.Approve(idList, userID, actionID, comment);
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- public IGridResultSet<FileUploadView> GetAttachment(Guid? scoreConvertByApplyID, int? pageIndex, int? pageSize)
- {
- var attachment = scoreConvertByApplyDAL.GetScoreConvertByApplyAttachmentView(x => x.ScoreConvertByApplyID == scoreConvertByApplyID);
- return attachment.ToGridResultSet(pageIndex, pageSize);
- }
- public void OnApproveEnd(List<Guid> scoreConvertByApplyIDList, Guid? userID)
- {
- //获取默认绩点公式
- var gradePointFormula = scoreConvertByApplyDAL.GetDefaultGradePointFormula().FirstOrDefault();
- //ER_GradePointFormula
- var scoreConvertByApplyList = scoreConvertByApplyDAL.scoreConvertByApplyRepository.GetList(x => scoreConvertByApplyIDList.Contains(x.ScoreConvertByApplyID)).ToList();
- var selectKeyList = scoreConvertByApplyList.Select(x => new { x.UserID, CoursematerialID = x.CoursematerialID }).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();
- var lastCourseStarttermViewList = ExecutablePlanDAL.GetLastCourseStarttermViewQueryable().SelectByKeys(selectKeyList);
- //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 scoreConvertByApply in scoreConvertByApplyList)
- {
- var submitedScore = lastCourseStarttermViewList.FirstOrDefault(x => x.UserID == scoreConvertByApply.UserID && x.CoursematerialID == scoreConvertByApply.CoursematerialID);
- var insertSubmitedScore = new ER_SubmitedScore
- {
- SubmitedScoreID = Guid.NewGuid(),
- SchoolyearID = submitedScore.SchoolyearID,
- SchoolyearNumID = submitedScore.SchoolyearNumID,
- DepartmentID = submitedScore.DepartmentID,
- ClassName = submitedScore.ClassName,
- CoursematerialID = submitedScore.CoursematerialID,
- CourseTypeID = submitedScore.CourseTypeID,
- ExamsCategoryID = (int)EMIS.ViewModel.CF_ExamsCategory.FinalExam,
- ExaminationModeID = submitedScore.ExaminationModeID,
- HandleModeID = submitedScore.HandleModeID,
- Credit = submitedScore.Credit,
- TotalHours = submitedScore.TotalHours,
- ResultTypeID = submitedScore.ResultTypeID,
- CreatorUserID = userID,
- IsEntry = true,
- ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination,
- StarttermID = submitedScore.StarttermID,
- UserID = submitedScore.UserID,
- ExamsStateID = (int)CF_ExamsState.NormalExams,
- TotalScore = scoreConvertByApply.TotalScore,
- ScoreCredit = scoreConvertByApply.TotalScore >= 60 ? submitedScore.Credit : 0,
- GradePoint = gradePointFormula == null ? 0 : (scoreConvertByApply.TotalScore >= gradePointFormula.GradePointlimit ? (1 + gradePointFormula.GradePointFloor * (scoreConvertByApply.TotalScore - gradePointFormula.GradePointlimit)) : 0),
- Remark = Const.ER_SCORECONVERT_BYREPLACE_SCOREREMARK,
- RecordStatus = (int)SYS_STATUS.USABLE,
- CreateUserID = userID,
- CreateTime = DateTime.Now,
- ModifyUserID = userID,
- ModifyTime = DateTime.Now
- };
- insertSubmitedScoreList.Add(insertSubmitedScore);
- }
- var insertSubmitedScoreIDList = insertSubmitedScoreList.Select(x => x.SubmitedScoreID).ToList();
- using (var scope = new TransactionScope(TransactionScopeOption.Required))
- {
- UnitOfWork.BulkInsert(insertSubmitedScoreList);
- studentScoreServices.RefreshFinallyScoreBySubmitedScoreID(insertSubmitedScoreIDList);
- scope.Complete();
- }
- }
- }
- }
|