using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using System.Linq.Expressions; using EMIS.Entities; using EMIS.ViewModel.EvaluationManage; using EMIS.DataLogic.SystemDAL; using EMIS.ViewModel; using EMIS.ViewModel.EducationManage; using Bowin.Common.Linq; using EMIS.ViewModel.EvaluationManage.EvaluationEnter; using EMIS.Utility; using EMIS.DataLogic.StudentManage.StudentStatistics; namespace EMIS.DataLogic.Common.EvaluationManage { public class EvaluationEnterDAL { public DataRangeDAL DataRangeDAL { get; set; } public InSchoolSettingDAL InSchoolSettingDAL { get; set; } public EvaluationSettingRepository EvaluationSettingRepository { get; set; } public EducationMissionRepository EducationMissionRepository { get; set; } public MissionClassTeacherRepository MissionClassTeacherRepository { get; set; } public EvaluationTableRepository EvaluationTableRepository { get; set; } public EducationSchedulingClassRepository EducationSchedulingClassRepository { get; set; } public DictionaryDAL DictionaryDAL { get; set; } public UserRepository UserRepository { get; set; } public StaffRepository StaffRepository { get; set; } public StudentRepository StudentRepository { get; set; } public EducationMissionClassRepository EducationMissionClassRepository { get; set; } public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; } public EvaluationTypeRepository evaluationTypeRepository { get; set; } public EvaluationControlRepository EvaluationControlRepository { get; set; } public EvaluationEnterRepository EvaluationEnterRepository { get; set; } public EvaluationProjectRepository EvaluationProjectRepository { get; set; } public EvaluationTargetRepository EvaluationTargetRepository { get; set; } public EvaluationNormRepository EvaluationNormRepository { get; set; } public EvaluationNormDetailRepository EvaluationNormDetailRepository { get; set; } //public EvaluationNeedDAL evaluationNeedDAL { get; set; } public EvaluationGradeControlRepository EvaluationGradeControlRepository { get; set; } public GrademajorRepository GrademajorRepository { get; set; } public EvaluationEnter_EM_EvaluationProjectRepository EvaluationEnter_EM_EvaluationProjectRepository { get; set; } // 加载进入评价信息 public IQueryable GetEvaluationEnterQuery(Expression> expEvaluationSetting = null, Expression> expEvaluationEnter = null, Expression> expEvaluationTable = null) { if (expEvaluationSetting == null) { expEvaluationSetting = (x => true); } if (expEvaluationEnter == null) { expEvaluationEnter = (x => true); } if (expEvaluationTable == null) { expEvaluationTable = (x => true); } var query = from c in EvaluationSettingRepository.GetList(expEvaluationSetting) from stcontrol in EvaluationTableRepository.Entities.Where(expEvaluationTable) .Where(x => x.EM_EvaluationIntType.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID) .Contains(c.EM_EducationMissionClass.TeachingModeID ?? (int)CF_TeachingMode.Theory)).DefaultIfEmpty() //into tcontrol//评价表评价类型变动、转变成一对多关系、一种评价类型对应多个授课类型 //from stcontrol in tcontrol.DefaultIfEmpty() join even in EvaluationEnterRepository.GetList(expEvaluationEnter) on new { c.EducationMissionClassID, TableID = (Guid)stcontrol.EvaluationTableID } equals new { even.EducationMissionClassID, TableID = (Guid)even.EvaluationTableID } into teven from cteven in teven.DefaultIfEmpty() join evcontrol in EvaluationControlRepository.Entities on c.EM_EducationMissionClass.EM_EducationMission.SchoolyearID equals evcontrol.SchoolyearID into Temevcontrol from evcontroltab in Temevcontrol.DefaultIfEmpty() select new EvaluationEnterView { EntityCreateTime = cteven.ModifyTime, CollegeID = c.EM_EducationMissionClass.EM_EducationMission.CollegeID, DepartmentName = c.EM_EducationMissionClass.EM_EducationMission.CF_Department.Name, EvaluationTableID = stcontrol.EvaluationTableID, EvaluationTableName = stcontrol.Name, EvaluationEnterID = cteven.EvaluationEnterID, EvaluationSettingID = c.EvaluationSettingID,//评价设置ID EvaluationIntTypeID = stcontrol.EM_EvaluationIntType.EvaluationIntTypeID, EvaluationTableTypeName = stcontrol.EM_EvaluationIntType.Name, EvaluationTypeID = stcontrol.EM_EvaluationType.EvaluationTypeID,//参评类型 EvaluationTypeName = stcontrol.EM_EvaluationType.Name, EducationMissionClassName = c.EM_EducationMissionClass.Name, EducationMissionClassID = c.EM_EducationMissionClass.EducationMissionClassID, EvaluationSettingCode = c.EvaluationSettingCode, DepartmentID = c.EM_EducationMissionClass.EM_EducationMission.DepartmentID, SchoolyearID = c.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID, SchoolyearCode = c.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.Code, CourseName = c.EM_EducationMissionClass.EM_Coursematerial.CourseName, CourseCode = c.EM_EducationMissionClass.EM_Coursematerial.CourseCode, LimitMore = stcontrol.EM_EvaluationType.Number, PhotoUrl = c.EM_EducationMissionClass.EM_MissionClassTeacher.Where(x => x.TeachType == (int)EM_TeachingMethod.Lecturer).FirstOrDefault().CF_Staff.PhotoUrl, Sys_User = c.EM_EducationMissionClass.EM_MissionClassTeacher.Select(s => s.CF_Staff.Sys_User), StaffDepartmentID = c.EM_EducationMissionClass.EM_MissionClassTeacher.Select(s => s.CF_Staff.DepartmentID), IsEvaluation = DateTime.Now > stcontrol.EM_EvaluationType.StartTime && DateTime.Now < stcontrol.EM_EvaluationType.EndTime ? true : false, EvaluationCount = cteven.EvaluationEnterID == null ? 0 : cteven.EM_EvaluationEnter_EM_EvaluationProject.GroupBy(x => x.ModifyTime).Select(y => y).Count(), Remark = cteven.Remark, }; return query; } //学生加载进入评价信息 public IQueryable GetStudentEvaluationEnterQuery(Expression> expEvaluationSetting = null, Expression> expEvaluationEnter = null, Expression> expEvaluationTable = null, Expression> expEvaluationGradeControl = null, Expression> expStudent = null) { if (expEvaluationSetting == null) { expEvaluationSetting = (x => true); } if (expEvaluationEnter == null) { expEvaluationEnter = (x => true); } if (expEvaluationTable == null) { expEvaluationTable = (x => true); } if (expEvaluationGradeControl == null) { expEvaluationGradeControl = (x => true); } if (expStudent == null) { expStudent = (x => true); } var query = from c in EvaluationSettingRepository.GetList(expEvaluationSetting) from stcontrol in EvaluationTableRepository.Entities.Where(expEvaluationTable) .Where(x => x.EM_EvaluationIntType.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID) .Contains(c.EM_EducationMissionClass.TeachingModeID ?? (int)CF_TeachingMode.Theory)).DefaultIfEmpty() //into tcontrol//评价表评价类型变动、转变成一对多关系、一种评价类型对应多个授课类型 //from stcontrol in tcontrol.DefaultIfEmpty() join even in EvaluationEnterRepository.GetList(expEvaluationEnter) on new { c.EducationMissionClassID, TableID = (Guid)stcontrol.EvaluationTableID } equals new { even.EducationMissionClassID, TableID = (Guid)even.EvaluationTableID } into teven from cteven in teven.DefaultIfEmpty() join evcontrol in EvaluationControlRepository.Entities on c.EM_EducationMissionClass.EM_EducationMission.SchoolyearID equals evcontrol.SchoolyearID into Temevcontrol from evcontroltab in Temevcontrol.DefaultIfEmpty() from student in StudentRepository.Entities.Where(expStudent).DefaultIfEmpty() join grade in GrademajorRepository.Entities on student.CF_Classmajor.CF_Grademajor.GrademajorID equals grade.GrademajorID join egcontrol in EvaluationGradeControlRepository.Entities on new { c.EM_EducationMissionClass.EM_EducationMission.SchoolyearID, GrademajorID = grade.GrademajorID } equals new { egcontrol.SchoolyearID, GrademajorID = (Guid)egcontrol.GrademajorID } into eg from e in eg.DefaultIfEmpty() select new EvaluationEnterView { EntityCreateTime = cteven.ModifyTime, CollegeID = c.EM_EducationMissionClass.EM_EducationMission.CollegeID, DepartmentName = c.EM_EducationMissionClass.EM_EducationMission.CF_Department.Name, EvaluationTableID = stcontrol.EvaluationTableID, EvaluationTableName = stcontrol.Name, EvaluationEnterID = cteven.EvaluationEnterID, EvaluationSettingID = c.EvaluationSettingID,//评价设置ID EvaluationIntTypeID = stcontrol.EM_EvaluationIntType.EvaluationIntTypeID, EvaluationTableTypeName = stcontrol.EM_EvaluationIntType.Name, EvaluationTypeID = stcontrol.EM_EvaluationType.EvaluationTypeID,//参评类型 EvaluationTypeName = stcontrol.EM_EvaluationType.Name, EducationMissionClassName = c.EM_EducationMissionClass.Name, EducationMissionClassID = c.EM_EducationMissionClass.EducationMissionClassID, EvaluationSettingCode = c.EvaluationSettingCode, DepartmentID = c.EM_EducationMissionClass.EM_EducationMission.DepartmentID, SchoolyearID = c.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID, SchoolyearCode = c.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.Code, CourseName = c.EM_EducationMissionClass.EM_Coursematerial.CourseName, CourseCode = c.EM_EducationMissionClass.EM_Coursematerial.CourseCode, LimitMore = (e.EvaluationGradeControlID == null ? stcontrol.EM_EvaluationType.Number : e.Number), PhotoUrl = c.EM_EducationMissionClass.EM_MissionClassTeacher.Where(x => x.TeachType == (int)EM_TeachingMethod.Lecturer).FirstOrDefault().CF_Staff.PhotoUrl, Sys_User = c.EM_EducationMissionClass.EM_MissionClassTeacher.Select(s => s.CF_Staff.Sys_User), StaffDepartmentID = c.EM_EducationMissionClass.EM_MissionClassTeacher.Select(s => s.CF_Staff.DepartmentID), IsEvaluation = DateTime.Now > stcontrol.EM_EvaluationType.StartTime && DateTime.Now < stcontrol.EM_EvaluationType.EndTime ? true : false, IsStudentEvaluation = (e.EvaluationGradeControlID == null ? (DateTime.Now > stcontrol.EM_EvaluationType.StartTime && DateTime.Now < stcontrol.EM_EvaluationType.EndTime ? true : false) : (DateTime.Now > e.StartTime && DateTime.Now < e.EndTime ? true : false)), EvaluationCount = cteven.EvaluationEnterID == null ? 0 : cteven.EM_EvaluationEnter_EM_EvaluationProject.GroupBy(x => x.ModifyTime).Select(y => y).Count(), Remark = cteven.Remark, }; return query; } // 加载进入评价表头相关信息 public EvaluationEnterView GetEvaluationEnterTitleView(Guid? educationMissionClassID, Guid? evaluationTableID) { var Query = from c in EvaluationSettingRepository.GetList(x => x.OpenStatus == (int)CF_YesOrNoStatus.Yes && x.EvaluationTableID == evaluationTableID) //join f in DictionaryDAL.GetDictionaryItemQuery(typeof(CF_TeachingMode).Name) on c.EM_EvaluationTable.IntType equals f.Value join emc in EducationMissionClassRepository.GetList(x => x.EducationMissionClassID == educationMissionClassID) on c.EducationMissionClassID equals emc.EducationMissionClassID into temc from stemc in temc.DefaultIfEmpty() join control in EvaluationControlRepository.Entities on stemc.EM_EducationMission.CF_Schoolyear.SchoolyearID equals control.SchoolyearID into tcontrol from stcontrol in tcontrol.DefaultIfEmpty() // join entype in evaluationTypeRepository.Entities on c.EM_EvaluationType.TypeID equals entype.TypeID // join user in UserRepository.Entities on stcourse.UserID equals user.UserID select new EvaluationEnterView { EvaluationTableID = c.EvaluationTableID, //EvaluationTableTypeName = f.Name, EvaluationTypeName = c.EM_EvaluationType.Name, EducationMissionClassName = c.EM_EducationMissionClass.Name, EducationMissionClassID = c.EM_EducationMissionClass.EducationMissionClassID, EvaluationSettingCode = c.EvaluationSettingCode, CourseName = stemc.EM_Coursematerial.CourseName, CourseCode = stemc.EM_Coursematerial.CourseCode, Remark = stemc.EM_EducationMission.CF_Department.Name, LimitMore = c.EM_EvaluationType.Number,//entype.Number, Sys_User = stemc.EM_MissionClassTeacher.Select(x => x.CF_Staff.Sys_User) }; return Query.FirstOrDefault(); } // 加载进入评价评价项目相关信息 public IQueryable GetEvaluationEnterView(Guid? evaluationEnterID, Guid? evaluationTableID) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; //取最大操作时间 var maxModifyTime = (from a in EvaluationEnter_EM_EvaluationProjectRepository.Entities.Where(x => x.EvaluationEnterID == evaluationEnterID) group new { a } by new { a.ModifyTime } into g select new { ModifyTime = g.Max(x => x.a.ModifyTime) }).OrderByDescending(x => x.ModifyTime).FirstOrDefault(); var Query = from c in EvaluationEnterRepository.Entities.Where(x => x.EvaluationTableID == evaluationTableID && x.EvaluationEnterID == evaluationEnterID) join b in EvaluationEnter_EM_EvaluationProjectRepository.Entities.Where(x => x.CreateUserID == curUser.UserID && x.ModifyTime == maxModifyTime.ModifyTime) on c.EvaluationEnterID equals b.EvaluationEnterID into tProject from ctProject in tProject.DefaultIfEmpty() group new { ctProject } by new { ctProject.ModifyTime, ctProject.EvaluationScore, ctProject.ProjectID } into g select new EvaluationEnterView { EvaluationScore = (decimal)g.Key.EvaluationScore, ProjectID = g.Key.ProjectID, ModifyTime = g.Max(x => x.ctProject.ModifyTime) }; return Query; } //这个部门对于的所有教师 public IQueryable GetDepartmentStaffViewQueryable(Expression> exp) { var query = from emc in EducationMissionClassRepository.GetList(exp) from emcTecher in emc.EM_MissionClassTeacher.DefaultIfEmpty() join staff in StaffRepository.Entities.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE) on emcTecher.CF_Staff.DepartmentID equals staff.DepartmentID select new DepartmentStaffView { EducationMissionClassID = emc.EducationMissionClassID, UserID = staff.UserID, Name = staff.Sys_User.Name, DepartmentID = staff.DepartmentID, StaffCode = staff.Sys_User.LoginID }; return query; } } }