using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; using Bowin.Common.Utility; using EMIS.ViewModel.DifferentDynamic; using Bowin.Common.Mapping; using Bowin.Common.Linq.Entity; using EMIS.ViewModel; using System.Linq.Expressions; using Bowin.Common.Linq; using EMIS.Utility; using EMIS.CommonLogic.CalendarManage; using EMIS.CommonLogic.EvaluationManage; using EMIS.Utility.FormValidate; using EMIS.ViewModel.Students; using EMIS.DataLogic.Common.Students; using EMIS.ViewModel.WorkflowManage; namespace EMIS.CommonLogic.Students { public class DifferentDynamicServices : BaseWorkflowServices, IDifferentDynamicServices { public DifferentDynamicDAL DifferentDynamicDAL { get; set; } public Lazy StudentsServices { get; set; } public Lazy SchoolYearServices { get; set; } public Lazy StudentsDAL { get; set; } public void AddOrUpdateDifferentDynamic(DifferentDynamicView model) { //TODO;调整验证逻辑、当前用户存在系统待办没有处理完、不能新增相同数据 2016年10月25日12:06:19 var startStatusID = this.GetStartStatus(); var status = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); status.Add(startStatusID); bool IsNext = false; var hasApprovalEntity = DifferentDynamicDAL.DifferentDynamicRepository .GetList(w => w.UserID == (Guid)model.UserID && status.Contains(w.ApprovalStatus) && model.EntityID != w.StudentChangeID).Any(); if (model.EntityID == Guid.Empty) { if (hasApprovalEntity) { IsNext = true; } } else { CF_DifferentDynamic differentDynamicEntity = DifferentDynamicDAL.DifferentDynamicRepository.Entities.Where(x => x.StudentChangeID == model.EntityID).FirstOrDefault(); //if (hasApprovalEntity && differentDynamicEntity.ApprovalStatus == startStatusID)//防止在一条情况下误判断 //{ // IsNext = true; //} //if (model.Action == "update")//防止编辑是误操作 //{ // if (DifferentDynamicDAL.DifferentDynamicRepository.GetList(x => x.UserID == model.UserID // && status.Contains(x.ApprovalStatus) && x.ID != model.EntityID).Count() > 0) // { // IsNext = true; // } // else // { // IsNext = false; // } //} } if (IsNext) { //throw new Exception("提交申请的学生中已有异动申请在审核中,请不要多次提交异动申请!"); throw new Exception("该学生有未处理的申请记录,请不要重复申请!"); } CF_DifferentDynamic entity; if (model.EntityID == Guid.Empty) { entity = new CF_DifferentDynamic(); model.DynamicCloneTo(entity); entity.StudentChangeID = Function.NewPKGuid(); SetNewStatus(entity); entity.ApprovalStatus = startStatusID.Value; UnitOfWork.Add(entity); } else { entity = DifferentDynamicDAL.DifferentDynamicRepository.GetSingle(w => w.StudentChangeID == model.EntityID); model.DynamicCloneTo(entity); SetModifyStatus(entity); //UnitOfWork.Update(entity); } UnitOfWork.Commit(); } public void DeleteDifferentDynamic(List ids) { var startStatusID = this.GetStartStatus(); var statusList = this.GetStatusViewList(); var status = statusList.Where(x => x.Description.Contains("[CanDelete]")).Select(x => x.ID).ToList(); status.Add(startStatusID); var DifferentDynamicList = DifferentDynamicDAL.DifferentDynamicRepository.GetList(x => ids.Contains(x.StudentChangeID) && !(status.Contains(x.ApprovalStatus))).ToList(); if (DifferentDynamicList.Count > 0) { throw new Exception("只能删除未提交的记录,所选的部分记录已提交,无法删除。"); } UnitOfWork.Delete(w => ids.Contains(w.StudentChangeID)); } public void Submit(List ids, Guid userID, string comment = "") { StartUp(ids, userID, comment); } public void Submit(Guid id, Guid userId, string comment = "") { var userIds = DifferentDynamicDAL.DifferentDynamicRepository.GetList(w => w.StudentChangeID == id).Select(s => s.UserID); var status = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); var hasApprovalEntity = DifferentDynamicDAL.DifferentDynamicRepository.GetList(w => userIds.Contains(w.UserID) && status.Contains(w.ApprovalStatus)).Any(); if (hasApprovalEntity) { throw new Exception("该学生已有异动申请在审核中,请不要多次提交异动申请!"); } StartUp(new List{ id }, userId, comment); } /// /// /// /// /// 校区 /// 院系所 /// 年级 /// 专业名称 /// 培养层次 /// 学习形式 /// 班级名称 /// 异动学期 /// 异动类型 /// 审批状态 /// /// /// public IGridResultSet GetDifferentDynamicViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, int? differentDynamicStatus, string LearnSystem, int pageIndex, int pageSize, int atype) { var endStatusID = this.GetCorrectEndStatus(); var statusList = this.GetStatusViewList(); var filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, differentDynamicStatus, LearnSystem); //atype=1 代表是申请列表 if (atype == 1) { filter = filter.And(x => x.ApprovalStatus != endStatusID); //根据老师要求,流程通过的数据不要显示在申请列表 20161011 czf filter = filter.And(x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.Normal); } var query = GetDifferentDynamicViewGrid(configuretView, filter); query = query.OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID);//.OrderBy(w => w.EntityApprovalStatus).ThenByDescending(w => w.SchoolyearCode); 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 IGridResultSet GetApplyDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, int? differentDynamicStatus, int pageIndex, int pageSize) { Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null,null); var statusList = this.GetStatusViewList(); if (differentDynamicStatus.HasValue) { filter = filter.And(w => w.ApprovalStatus == differentDynamicStatus); } else { var approvalStatus = this.GetBackpointStatus(); approvalStatus.Add(this.GetStartStatus()); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); } var result = GetDifferentDynamicViewGrid(configuretView, filter).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public IGridResultSet GetApprovalDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType,string LearnSystem, int pageIndex, int pageSize) { Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null, LearnSystem); filter = filter.And(x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.Normal); var statusList = this.GetStatusViewList(); var approvalStatus = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); var query = GetDifferentDynamicViewGrid(configuretView, filter); 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 IGridResultSet GetCollegeApprovalDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, string LearnSystem, int pageIndex, int pageSize) { Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null, LearnSystem); filter = filter.And(x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.Normal); var statusList = this.GetStatusViewList(); var approvalStatus = this.GetApproveStatusViewList() .Where(x => x.Description.Contains(Const.CF_STUDENTCHANGE_COLLEGEAPPROVE_FLAG)) .Select(x => x.ID).ToList(); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); var query = GetDifferentDynamicViewGrid(configuretView, filter); 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 IGridResultSet GetAdminApprovalDifferentDynamicViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, string LearnSystem, int pageIndex, int pageSize) { Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null, LearnSystem); var statusList = this.GetStatusViewList(); var approvalStatus = this.GetApproveStatusViewList() .Where(x => x.Description.Contains(Const.CF_STUDENTCHANGE_ADMINAPPROVE_FLAG)) .Select(x => x.ID).ToList(); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); var query = GetDifferentDynamicViewGrid(configuretView, filter); 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; } private static Expression> GetFilter(Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, int? differentDynamicStatus, string LearnSystem) { Expression> filter = w => true; if (campusID.HasValue && campusID != Guid.Empty) { filter = filter.And(w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID); } if (collegeID.HasValue && collegeID != Guid.Empty) { filter = filter.And(w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (education.HasValue) { filter = filter.And(w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education); } if (year.HasValue) { filter = filter.And(w => w.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year); } if (learningform.HasValue) { filter = filter.And(w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningform); } if (standard.HasValue) { //filter = filter.And(w => w.StandardID == standard); } if (classmajorID.HasValue && classmajorID != Guid.Empty) { filter = filter.And(w => w.BeforeClassmajorID == classmajorID); } if (schoolYearID.HasValue && schoolYearID != Guid.Empty) { filter = filter.And(w => w.SchoolyearID == schoolYearID); } if (differentDynamicType.HasValue) { filter = filter.And(w => w.ChangeTypeID == differentDynamicType); } if (differentDynamicStatus.HasValue) { filter = filter.And(w => w.ApprovalStatus == differentDynamicStatus); } var user = EMIS.Utility.FormValidate.CustomPrincipal.Current; if (user != null && user.IsStudent) { filter = filter.And(w => w.UserID == user.UserID); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); filter = filter.And(x => x.BeforeClassmajorID_Nav.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } return filter; } public ICollection GetDifferentDynamicStatistics(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolYearID) { var filter = GetFilter(campusID, collegeID, null, null, null, null, null, schoolYearID, null, this.GetCorrectEndStatus(),null); var query = DifferentDynamicDAL.GetDifferentDynamicStatisticsQueryable(filter); query = GetQueryByDataRangeByCollege(query); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = query.OrderBy(o => o.CampusID).ThenBy(o => o.CollegeID); return query.ToList(); } public ICollection GetDifferentDynamicViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, int? differentDynamicStatus, string LearnSystem, int atype, List UserIDList = null) { var endStatusID = this.GetCorrectEndStatus(); var statusList = this.GetStatusViewList(); var filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, differentDynamicStatus, LearnSystem); //filter = filter.And(x => x.ApplyTypeID == (int)CF_DifferentDynamicApplyType.Normal); if (atype == 1) filter = filter.And(x => x.ApprovalStatus != endStatusID); if (UserIDList != null && UserIDList.Count() > 0) { filter = filter.And(x => UserIDList.Contains(x.UserID)); } var result = GetDifferentDynamicViewGrid(configuretView, filter).OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID).ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public ICollection GetDifferentDynamicViewListNotDataRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, int? differentDynamicStatus, string LearnSystem, int atype, List UserIDList = null) { var endStatusID = this.GetCorrectEndStatus(); var statusList = this.GetStatusViewList(); var filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, differentDynamicStatus, LearnSystem); //filter = filter.And(x => x.ApplyTypeID == (int)CF_DifferentDynamicApplyType.Normal); if (atype == 1) filter = filter.And(x => x.ApprovalStatus != endStatusID); if (UserIDList != null && UserIDList.Count() > 0) { filter = filter.And(x => UserIDList.Contains(x.UserID)); } var query = DifferentDynamicDAL.GetDifferentDynamicQueryable(filter); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var result = query.OrderByDescending(o => o.EntityCreateTime).ThenByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID).ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public ICollection GetApprovalDifferentDynamicViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType,string LearnSystem) { var statusList = this.GetStatusViewList(); Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null, LearnSystem); filter = filter.And(x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.Normal); var approvalStatus = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); var result = GetDifferentDynamicViewGrid(configuretView, filter).OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID).ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public ICollection GetCollegeApprovalDifferentDynamicViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, string LearnSystem) { var statusList = this.GetStatusViewList(); Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null, LearnSystem); filter = filter.And(x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.Normal); var approvalStatus = this.GetApproveStatusViewList() .Where(x => x.Description.Contains(Const.CF_STUDENTCHANGE_COLLEGEAPPROVE_FLAG)) .Select(x => x.ID).ToList(); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); var result = GetDifferentDynamicViewGrid(configuretView, filter).OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID).ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public ICollection GetAdminApprovalDifferentDynamicViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, string LearnSystem) { var statusList = this.GetStatusViewList(); Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null, LearnSystem); filter = filter.And(x => x.ChangeApplyTypeID == (int)CF_ChangeApplyType.Normal); var approvalStatus = this.GetApproveStatusViewList() .Where(x => x.Description.Contains(Const.CF_STUDENTCHANGE_ADMINAPPROVE_FLAG)) .Select(x => x.ID).ToList(); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); var result = GetDifferentDynamicViewGrid(configuretView, filter).OrderByDescending(w => w.SchoolyearCode).ThenByDescending(w => w.EntityCreateTime).ThenBy(w => w.LoginID).ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public ICollection GetApplyDifferentDynamicViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? year, int? standard, int? education, int? learningform, Guid? classmajorID, Guid? schoolYearID, int? differentDynamicType, int? differentDynamicStatus) { Expression> filter = GetFilter(campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, null,null); var statusList = this.GetStatusViewList(); if (differentDynamicStatus.HasValue) { filter = filter.And(w => w.ApprovalStatus == differentDynamicStatus); } else { var approvalStatus = this.GetBackpointStatus(); approvalStatus.Add(this.GetStartStatus()); filter = filter.And(w => approvalStatus.Contains(w.ApprovalStatus)); } var result = GetDifferentDynamicViewGrid(configuretView, filter).ToList(); result.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } public DifferentDynamicView GetDifferentDynamicView(Guid? id) { var result = new DifferentDynamicView(); if (id.HasValue && id != Guid.Empty) result = DifferentDynamicDAL.GetDifferentDynamicQueryable(w => w.StudentChangeID == id).FirstOrDefault(); result.ApprovalStatusName = this.GetStatusViewList().Where(x => x.ID == result.EntityApprovalStatus).Select(x => x.Name).FirstOrDefault(); return result; } public void Approve(DifferentDynamicView model, Guid userID, ActionView actionView, string comment = "") { AddOrUpdateDifferentDynamic(model); //保存审核过程中的修改操作。 Approve(new List{ model.EntityID }, userID, actionView.ActionID, comment); } private IQueryable GetDifferentDynamicViewGrid(ConfiguretView configuretView, Expression> filter) { var query = DifferentDynamicDAL.GetDifferentDynamicQueryable(filter); query = GetQueryByDataRangeByCollege(query); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = query.OrderByDescending(o => o.EntityCreateTime); return query; } /// /// 查询学生异动信息 /// /// /// public IGridResultSet GetStudentDifferentInfoViewGrid(Guid? userID) { var endStatusID = this.GetCorrectEndStatus(); var statusList = this.GetStatusViewList(); Expression> filter = w => true; filter = filter.And(x => x.ApprovalStatus == endStatusID); //根据老师要求,流程通过的数据不要显示在申请列表 20161011 czf filter = filter.And(x => x.UserID == userID); var query = DifferentDynamicDAL.GetDifferentDynamicQueryable(filter); query = GetQueryByDataRangeByCollege(query); query = query.OrderByDescending(w => w.EntityCreateTime);//.OrderBy(w => w.EntityApprovalStatus).ThenByDescending(w => w.SchoolyearCode); var result = query.ToGridResultSet(); result.rows.ForEach(x => x.ApprovalStatusName = statusList.Where(w => w.ID == x.EntityApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } /// /// 查询异动报表下拉(已弃用) /// /// /// //public IGridResultSet GetDifferentDynamicViewGrid(ConfiguretView configuretView) //{ // var query = DifferentDynamicDAL.GetSelectReport(); // return query.OrderBy(x=>x.ReportUrl).ToGridResultSet(); //} public void OnApproveEnd(List differentDynamicIDList, Guid? userID) { var differentDynamicList = this.DifferentDynamicDAL.DifferentDynamicRepository.GetList(x => differentDynamicIDList.Contains(x.StudentChangeID)).ToList(); this.DifferentDynamicEnd(differentDynamicList); } private void DifferentDynamicEnd(List entityViewList) { var schoolYear = SchoolYearServices.Value.GetCurrentSchoolYear(); int? schoolYearValue = schoolYear.Value;//获取当前学年学期Value值 var differentDynamicIDList = entityViewList.Select(x => x.StudentChangeID).ToList(); Expression> exp = x => differentDynamicIDList.Contains(x.StudentChangeID); var studentIDList = entityViewList.Select(x => x.UserID).Distinct().ToList(); var studentEntityList = StudentsDAL.Value.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.CF_Classmajor.CF_Grademajor)).ToList();//要转班的学生 var afterClassmajorIDList = entityViewList.Where(x => x.AfterClassmajorID.HasValue).Select(x => x.AfterClassmajorID).ToList(); var afterClassMajorList = DifferentDynamicDAL.ClassmajorRepository.GetList(w => afterClassmajorIDList.Contains(w.ClassmajorID), i => i.CF_Grademajor.CF_Schoolyear).ToList(); #region 1.0 教学任务删除异动学生代码段...... var educationSchedulingClassStudent = DifferentDynamicDAL.GetEducationSchedulingClassStudent(exp).ToList(); var educationSchedulingIDList = educationSchedulingClassStudent.Select(u => u.TepTableID).ToList(); var edustudentList = DifferentDynamicDAL.EducationSchedulingClassRepository.GetList(x => educationSchedulingIDList.Contains(x.EducationSchedulingClassID), (x => x.CF_Student)); educationSchedulingClassStudent.ForEach(e => { var educationScheduleClass = edustudentList.FirstOrDefault(x => x.EducationSchedulingClassID == e.TepTableID); var studentEntity = studentEntityList.FirstOrDefault(x => x.UserID == e.UserID); educationScheduleClass.CF_Student.Remove(studentEntity); }); #endregion #region 2.0 考场安排删除异动学生代码段...... var examinationRoomStudent = DifferentDynamicDAL.GetExaminationRoomStudent(exp).ToList(); var examinationPlanStudent = DifferentDynamicDAL.GetExaminationPlanStudent(exp).ToList(); var examinationPlanIDList = examinationPlanStudent.Select(u => u.TepTableID).ToList(); var examinationPlanList = DifferentDynamicDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID), (x => x.CF_Student)).ToList(); var examinationRoomStudentIDList = examinationRoomStudent.Select(u => u.TepTableID).ToList(); //EX_ExaminationPlan_CF_Student考试计划相关学生表原先没删除成功掉,又往EX_ExaminationPlan_CF_Student插数据,一直没发现这个问题,但如果是同一个ExaminationPlanID时就会报重复错误 UnitOfWork.Remove(x => examinationRoomStudentIDList.Contains(x.ExaminationRoomStudentID)); examinationPlanStudent.ForEach(e => { var examinationPlan = examinationPlanList.FirstOrDefault(x => x.ExaminationPlanID == e.TepTableID); var studentEntity = studentEntityList.FirstOrDefault(x => x.UserID == e.UserID); examinationPlan.CF_Student.Remove(studentEntity); }); #endregion #region 3.0 成绩管理删除异动学生代码段...... var scoreStudent = DifferentDynamicDAL.GetScoreStudent(exp).ToList(); var finalExaminationIDList = scoreStudent.Select(u => u.TepTableID).ToList(); var finalExaminationList = DifferentDynamicDAL.FinalExaminationRepository.GetList(x => finalExaminationIDList.Contains(x.FinalExaminationID), (x => x.ER_FinalExaminationStudent), (x => x.ER_Score)).ToList(); var finalExaminationStudentIDList = ( from ss in scoreStudent join fe in finalExaminationList on ss.TepTableID equals fe.FinalExaminationID from fes in fe.ER_FinalExaminationStudent where ss.UserID == fes.UserID select fes.FinalExaminationStudentID ).ToList(); var scoreIDList = ( from ss in scoreStudent join fe in finalExaminationList on ss.TepTableID equals fe.FinalExaminationID from s in fe.ER_Score where ss.UserID == s.UserID select s.ScoreID ).ToList(); UnitOfWork.Remove(x => scoreIDList.Contains(x.ScoreID.Value)); UnitOfWork.Remove(x => scoreIDList.Contains(x.ScoreID)); UnitOfWork.Remove(x => finalExaminationStudentIDList.Contains(x.FinalExaminationStudentID)); #endregion #region 4.0 教学评价删除异动学生代码段...... var evaluationSettingStudent = DifferentDynamicDAL.GetEvaluationSettingStudent(exp).ToList(); var evaluationSettingIDList = evaluationSettingStudent.Select(u => u.TepTableID).ToList(); var evaluationSettingStudentList = DifferentDynamicDAL.EvaluationSettingRepository.GetList(x => evaluationSettingIDList.Contains(x.EvaluationSettingID), (x => x.CF_Student)); evaluationSettingStudent.ForEach(e => { var evaluationSetting = evaluationSettingStudentList.FirstOrDefault(x => x.EvaluationSettingID == e.TepTableID); var studentEntity = studentEntityList.FirstOrDefault(x => x.UserID == e.UserID); evaluationSetting.CF_Student.Remove(studentEntity); }); #endregion //这堆查询太慢了,不涉及班级转换的异动就不要跑了 if (entityViewList.Where(x => x.AfterClassmajorID != null).Count() > 0) { #region 5.0 教学任务插入异动学生代码段...... var studentSchedulingClassList = DifferentDynamicDAL.GetStudentRelateCourseViewQueryable(exp).ToList(); List educationSchedulingClassStudentInsert = new List(); foreach (var studentSchedulingClass in studentSchedulingClassList) { //情况1:找到同班同学,并且自己学号最小,塞同班同学的第一个班 var classmateSchdulingList = studentSchedulingClass .StudentRelateSchedulingClassViewList .Where(x => x.ClassmajorIDList.Contains(studentSchedulingClass.ClassmajorID)) .OrderBy(x => x.EducationMissionClassName) .ToList(); if (classmateSchdulingList.Count > 0 && studentSchedulingClass.LoginID.CompareTo(classmateSchdulingList.Max(x => x.MinLoginID)) < 0) { var minMissionClassName = classmateSchdulingList.Min(x => x.EducationMissionClassName); var minSchedulingClassID = classmateSchdulingList.Where(x => x.EducationMissionClassName == minMissionClassName).Select(x => x.EducationSchedulingClassID).FirstOrDefault(); if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == minSchedulingClassID)) { educationSchedulingClassStudentInsert.Add(new StudentsView { UserID = studentSchedulingClass.UserID ?? Guid.Empty, TepTableID = minSchedulingClassID }); } } //情况2:找到同班同学,并且自己学号不是最小,塞第一个自己不是最大的班,如果没有,塞最后一个班 else if (classmateSchdulingList.Count > 0 && studentSchedulingClass.LoginID.CompareTo(classmateSchdulingList.Max(x => x.MinLoginID)) >= 0) { foreach (var classmateScheduling in classmateSchdulingList) { if (studentSchedulingClass.LoginID.CompareTo(classmateScheduling.MaxLoginID) <= 0) { if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == classmateScheduling.EducationSchedulingClassID)) { educationSchedulingClassStudentInsert.Add(new StudentsView { UserID = studentSchedulingClass.UserID ?? Guid.Empty, TepTableID = classmateScheduling.EducationSchedulingClassID }); break; } } if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == classmateScheduling.EducationSchedulingClassID)) { educationSchedulingClassStudentInsert.Add(new StudentsView { UserID = studentSchedulingClass.UserID ?? Guid.Empty, TepTableID = classmateScheduling.EducationSchedulingClassID }); } } } //情况3:找不到同班同学,但排课班已经有人,塞顺序下来人最少的班 else if (classmateSchdulingList.Count == 0 && studentSchedulingClass.StudentRelateSchedulingClassViewList.Any(x => x.StudentCount > 0)) { var minStudentCount = studentSchedulingClass.StudentRelateSchedulingClassViewList.Min(x => x.StudentCount); var minSchedulingClassID = studentSchedulingClass.StudentRelateSchedulingClassViewList.Where(x => x.StudentCount == minStudentCount) .OrderBy(x => x.EducationMissionClassName) .Select(x => x.EducationSchedulingClassID).FirstOrDefault(); if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == minSchedulingClassID)) { educationSchedulingClassStudentInsert.Add(new StudentsView { UserID = studentSchedulingClass.UserID ?? Guid.Empty, TepTableID = minSchedulingClassID }); } } //情况4:找不到同班同学,而且排课班没人,塞第一个班 else if (classmateSchdulingList.Count == 0 && !studentSchedulingClass.StudentRelateSchedulingClassViewList.Any(x => x.StudentCount > 0)) { var minSchedulingClassID = studentSchedulingClass.StudentRelateSchedulingClassViewList .OrderBy(x => x.EducationMissionClassName) .Select(x => x.EducationSchedulingClassID).FirstOrDefault(); if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == minSchedulingClassID)) { educationSchedulingClassStudentInsert.Add(new StudentsView { UserID = studentSchedulingClass.UserID ?? Guid.Empty, TepTableID = minSchedulingClassID }); } } } var educationSchedulingClassIDInsertList = educationSchedulingClassStudentInsert.Select(x => x.TepTableID).Distinct().ToList(); var educationSchedulingClassInsertList = DifferentDynamicDAL.EducationSchedulingClassRepository.GetList(x => educationSchedulingClassIDInsertList.Contains(x.EducationSchedulingClassID), x => x.CF_Student).ToList(); foreach (var educationScheduling in educationSchedulingClassStudentInsert) { Guid? educationSchedulingClassID = educationScheduling.TepTableID; EM_EducationSchedulingClass educationSchedulingClassEntity = educationSchedulingClassInsertList.FirstOrDefault(x => x.EducationSchedulingClassID == educationSchedulingClassID); if (educationSchedulingClassEntity != null && educationScheduling.UserID != null) { if (!educationSchedulingClassEntity.CF_Student.Where(x => x.UserID == educationScheduling.UserID).Any()) { var studentEntity = studentEntityList.FirstOrDefault(x => x.UserID == educationScheduling.UserID); educationSchedulingClassEntity.CF_Student.Add(studentEntity); UnitOfWork.Update(educationSchedulingClassEntity); } } } #endregion #region 6.0 考场安排插入异动学生代码段...... var educationPlanInsertList = DifferentDynamicDAL.GetExaminationPlanStudentInsert(exp, (x => x.EM_EducationSchedulingClass .Any(w => educationSchedulingClassIDInsertList.Contains(w.EducationSchedulingClassID)))).ToList(); var educationPlanIDList = educationPlanInsertList.Select(x => x.TepTableID).ToList(); var educationPlanList = DifferentDynamicDAL.ExaminationPlanRepository.GetList(x => educationPlanIDList.Contains(x.ExaminationPlanID), (x => x.CF_Student)).ToList(); educationPlanInsertList.ForEach(x => { var educationPlan = educationPlanList.FirstOrDefault(w => w.ExaminationPlanID == x.TepTableID); var studentEntity = studentEntityList.FirstOrDefault(w => w.UserID == x.UserID); educationPlan.CF_Student.Add(studentEntity); }); //2016年11月8日11:32:50 zhanghl //TODO: 由于考场安排涉及座位安排、暂时不做插入数据处理...... #endregion #region 7.0 成绩管理插入异动学生代码段...... var scoreStudentInsert = DifferentDynamicDAL.GetScoreStudentInsert(exp, (x => x.EM_EducationSchedulingClass .Any(w => educationSchedulingClassIDInsertList.Contains(w.EducationSchedulingClassID))) ).Distinct().ToList(); var finalExaminationInsertIDList = scoreStudentInsert.Select(x => x.TepTableID).ToList(); var finalExaminationEntityList = DifferentDynamicDAL.FinalExaminationRepository.GetList(x => finalExaminationInsertIDList.Contains(x.FinalExaminationID), (x => x.CF_Schoolyear)).ToList(); foreach (var score in scoreStudentInsert) { Guid? finalExaminationID = score.TepTableID; var studentEntity = studentEntityList.FirstOrDefault(w => w.UserID == score.UserID); var finalExaminationEntity = finalExaminationEntityList.FirstOrDefault(x => x.FinalExaminationID == score.TepTableID); var afterClassMajor = (from c in afterClassMajorList join dd in entityViewList on c.ClassmajorID equals dd.AfterClassmajorID where dd.UserID == score.UserID select c ).LastOrDefault(); if (finalExaminationEntity != null && afterClassMajor != null) { if (!finalExaminationEntity.ER_FinalExaminationStudent.Where(x => x.UserID == score.UserID).Any()) { finalExaminationEntity.ER_FinalExaminationStudent.Add(new ER_FinalExaminationStudent { FinalExaminationStudentID = Guid.NewGuid(), FinalExaminationID = finalExaminationEntity.FinalExaminationID, SchoolyearNumID = (finalExaminationEntity.CF_Schoolyear.Value - ((afterClassMajor.CF_Grademajor.GradeID * 2) - 1 + (afterClassMajor.CF_Grademajor.SemesterID - 1)) - (finalExaminationEntity.CF_Schoolyear.SchoolcodeID == afterClassMajor.CF_Grademajor.SemesterID ? 0 : 1)) / 2 + 1, StarttermID = finalExaminationEntity.CF_Schoolyear.Value - ((afterClassMajor.CF_Grademajor.GradeID * 2) - 1 + (afterClassMajor.CF_Grademajor.SemesterID - 1)) + 1, UserID = studentEntity.UserID, RecordStatus = (int)SYS_STATUS.USABLE, CreateUserID = CustomPrincipal.Current.UserID, CreateTime = DateTime.Now, ModifyUserID = CustomPrincipal.Current.UserID, ModifyTime = DateTime.Now }); } } } #endregion #region 8.0 教学评价插入异动学生代码段...... var evaluationSettingStudentInsert = DifferentDynamicDAL.GetEvaluationSettingStudentInsert(exp).Distinct().ToList(); var evaluationSettingStudentInsertIDList = evaluationSettingStudentInsert.Select(x => x.TepTableID).ToList(); var evaluationSettingStudentInsertList = DifferentDynamicDAL.EvaluationSettingRepository.GetList(x => evaluationSettingStudentInsertIDList.Contains(x.EvaluationSettingID) && x.OpenStatus == (int)CF_YesOrNoStatus.No, (x => x.CF_Student)).ToList(); foreach (var evaluationSetting in evaluationSettingStudentInsert) { Guid? evaluationSettingID = evaluationSetting.TepTableID; EM_EvaluationSetting evaluationSettingEntity = evaluationSettingStudentInsertList.FirstOrDefault(x => x.EvaluationSettingID == evaluationSettingID); if (evaluationSettingEntity != null) { if (!evaluationSettingEntity.CF_Student.Where(x => x.UserID == evaluationSetting.UserID).Any()) { var studentEntity = studentEntityList.FirstOrDefault(w => w.UserID == evaluationSetting.UserID); evaluationSettingEntity.CF_Student.Add(studentEntity); UnitOfWork.Update(evaluationSettingEntity); } } } #endregion } #region 9.0学生征订 var studentOrderAddList = DifferentDynamicDAL.GetAddStudentsOrder(exp).ToList(); studentOrderAddList.ForEach(x => x.OrderQty++); var studentOrderDecreaseList = DifferentDynamicDAL.GetDecreaseStudentsOrder(exp).ToList(); studentOrderDecreaseList.ForEach(x => x.OrderQty--); #endregion #region 10.0学生发放 var studentDistributeAddList = DifferentDynamicDAL.GetAddStudentDistribute(exp).ToList(); studentDistributeAddList.ForEach(x => x.DistributeQty++); var studentDistributeDecreaseList = DifferentDynamicDAL.GetDecreaseStudentDistribute(exp).ToList(); studentDistributeDecreaseList.ForEach(x => x.DistributeQty--); #endregion foreach (var entityView in entityViewList) { var studentEntity = studentEntityList.FirstOrDefault(w => w.UserID == entityView.UserID); var afterClassMajor = afterClassMajorList.FirstOrDefault(w => w.ClassmajorID == entityView.AfterClassmajorID); if (entityView.AfterClassmajorID.HasValue && entityView.AfterClassmajorID != Guid.Empty) //班级 { studentEntity.ClassmajorID = entityView.AfterClassmajorID; // student.PlanningGraduateDate = PlanningGraduateDateHelper.GetPlanningGraduateDate(classMajor.CF_Grademajor.CF_Schoolyear); var PlanningGraduateDate = StudentsServices.Value.GetPlanningGraduate((Guid)afterClassMajor.GrademajorID); if (PlanningGraduateDate != "") { studentEntity.PlanningGraduateDate = Convert.ToDateTime(PlanningGraduateDate); } } if (entityView.AfterInSchoolStatusID.HasValue && entityView.AfterInSchoolStatusID != -1) //在校状态 { studentEntity.InSchoolStatusID = entityView.AfterInSchoolStatusID; } if (entityView.AfterStudentStatus.HasValue && entityView.AfterStudentStatus != -1) //学籍状态 { studentEntity.StudentStatus = entityView.AfterStudentStatus; } //异动后修改异动时间 entityView.ChangeDate = DateTime.Now; } UnitOfWork.Commit(); } } }