using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using EMIS.Entities; using EMIS.CommonLogic.SystemServices; using EMIS.DataLogic.Common.Students; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.DifferentDynamic; using EMIS.ViewModel; using EMIS.Utility.FormValidate; using EMIS.ViewModel.WorkflowManage; using EMIS.CommonLogic.CalendarManage; namespace EMIS.CommonLogic.Students { public class BatchRepeatServices : BaseWorkflowServices, IBatchRepeatServices { public Lazy DifferentDynamicServices { get; set; } public Lazy SchoolYearServices { get; set; } public BatchRepeatDAL BatchRepeatDAL { get; set; } public IGridResultSet GetDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? education, int? year, int? standard, int? learningform, int? differentDynamicStatus, int pageIndex, int pageSize) { var statusList = this.GetStatusViewList(); Expression> filter = (x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.BatchRepeat); Expression> collegeFilter = (x => true); Expression> facultyFilter = (x => true); Expression> gradeFilter = (x => true); if (schoolyearID.HasValue) { filter = filter.And(x => x.SchoolyearID == schoolyearID); } if (campusID.HasValue) { collegeFilter = collegeFilter.And(x => x.CampusID == campusID); } if (collegeID.HasValue) { collegeFilter = collegeFilter.And(x => x.CollegeID == collegeID); } if (year.HasValue) { gradeFilter = gradeFilter.And(x => x.GradeID == year); } if (standard.HasValue) { facultyFilter = facultyFilter.And(x => x.StandardID == standard); } if (education.HasValue) { facultyFilter = facultyFilter.And(x => x.EducationID == education); } if (learningform.HasValue) { facultyFilter = facultyFilter.And(x => x.LearningformID == learningform); } if (differentDynamicStatus.HasValue) { filter = filter.And(x => x.ApprovalStatus == differentDynamicStatus); } var query = BatchRepeatDAL.GetDifferentDynamicQueryable(filter, gradeFilter, facultyFilter, collegeFilter); query = GetQueryByDataRangeByCollege(query); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = query.OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID); var result = query.ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public List GetDifferentDynamicViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? education, int? year, int? standard, int? learningform, int? differentDynamicStatus) { var statusList = this.GetStatusViewList(); Expression> filter = (x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.BatchRepeat); Expression> collegeFilter = (x => true); Expression> facultyFilter = (x => true); Expression> gradeFilter = (x => true); if (schoolyearID.HasValue) { filter = filter.And(x => x.SchoolyearID == schoolyearID); } if (campusID.HasValue) { collegeFilter = collegeFilter.And(x => x.CampusID == campusID); } if (collegeID.HasValue) { collegeFilter = collegeFilter.And(x => x.CollegeID == collegeID); } if (year.HasValue) { gradeFilter = gradeFilter.And(x => x.GradeID == year); } if (standard.HasValue) { facultyFilter = facultyFilter.And(x => x.StandardID == standard); } if (education.HasValue) { facultyFilter = facultyFilter.And(x => x.EducationID == education); } if (learningform.HasValue) { facultyFilter = facultyFilter.And(x => x.LearningformID == learningform); } if (differentDynamicStatus.HasValue) { filter = filter.And(x => x.ApprovalStatus == differentDynamicStatus); } var query = BatchRepeatDAL.GetDifferentDynamicQueryable(filter, gradeFilter, facultyFilter, collegeFilter); query = GetQueryByDataRangeByCollege(query); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = query.OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID); var result = query.ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public void BatchAddStudents(IList studentIDList) { var studentList = StudentDAL.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor)).ToList(); var schoolyear = SchoolYearServices.Value.GetCurrentSchoolYear(); studentList.ForEach(student => { var differentDynamicView = new DifferentDynamicView() { EntityID = Guid.Empty, SchoolyearID = schoolyear.SchoolYearID, UserID = student.UserID, DifferentDynamicType = (int)CF_ChangeType.Repeat, Reason = (int)CF_ChangeReason.PoorPerformance, InSchoolStatusID = student.InSchoolStatusID, StudentStatus = student.StudentStatus, StandardID = student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID, ClassmajorID = student.ClassmajorID, ApplyTypeID = (int)CF_ChangeApplyType.BatchRepeat, ApplyRemark = "成绩太差,超过4门成绩不及格", Remark = "成绩太差,超过4门成绩不及格" }; DifferentDynamicServices.Value.AddOrUpdateDifferentDynamic(differentDynamicView); }); } public void Process(IList idList) { var startStatus = this.GetStartStatus(); var endStatusList = this.GetBackpointStatus(); var correctEndStatus = this.GetCorrectEndStatus(); var differentDynamicList = this.BatchRepeatDAL .GetBatchRepeatProcessView(x => idList.Contains(x.StudentChangeID) && x.AfterClassmajorID == null).ToList(); ActionView actionView = null; if (differentDynamicList.Any(x => x.EntityApprovalStatus == startStatus || x.EntityApprovalStatus == correctEndStatus || endStatusList.Contains(x.EntityApprovalStatus)) || idList.Any(x => !differentDynamicList.Any(w => w.EntityID == x))) { throw new Exception("只能审核已提交的数据,所选的记录中有其他状态的数据,无法审核。"); } if (differentDynamicList.Any(x => x.AfterClassmajorID == null)) { throw new Exception("学生" + string.Join("、", differentDynamicList.Where(x => x.AfterClassmajorID == null).Select(x => x.Name)) + "找不到可留级的班,请检查班级设置。"); } if (differentDynamicList.Count > 0) { actionView = this.GetActionView(differentDynamicList.First().EntityID, CustomPrincipal.Current.UserID) .OrderBy(x => x.Sort).FirstOrDefault(); } else { return; } foreach (var differentDynamic in differentDynamicList) { this.DifferentDynamicServices.Value.AddOrUpdateDifferentDynamic(differentDynamic); } var approveIDList = differentDynamicList.Select(x => x.EntityID).Distinct().ToList(); this.Approve(approveIDList, CustomPrincipal.Current.UserID, actionView.ActionID); } public void Approve(IList idList) { var startStatus = this.GetStartStatus(); var endStatusList = this.GetBackpointStatus(); var correctEndStatus = this.GetCorrectEndStatus(); var differentDynamicList = this.BatchRepeatDAL .GetBatchRepeatProcessView(x => idList.Contains(x.StudentChangeID) && x.AfterClassmajorID != null).ToList(); ActionView actionView = null; if (differentDynamicList.Any(x => x.EntityApprovalStatus == startStatus || x.EntityApprovalStatus == correctEndStatus || endStatusList.Contains(x.EntityApprovalStatus)) || idList.Any(x => !differentDynamicList.Any(w => w.EntityID == x))) { throw new Exception("只能审核已处理的数据,所选的记录中有其他状态的数据,无法审核。"); } if (differentDynamicList.Count > 0) { actionView = this.GetActionView(differentDynamicList.First().EntityID, CustomPrincipal.Current.UserID) .OrderBy(x => x.Sort).FirstOrDefault(); } else { return; } var approveIDList = differentDynamicList.Select(x => x.EntityID).Distinct().ToList(); this.Approve(approveIDList, CustomPrincipal.Current.UserID, actionView.ActionID); } } }