using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.EvaluationManage; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.EvaluationManage.EvaluationEnter; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using Bowin.Common.Utility; using Bowin.Common.Mapping; using EMIS.CommonLogic.SystemServices; using Bowin.Common.JSON; using EMIS.Utility; using EMIS.DataLogic.SystemDAL; using EMIS.DataLogic.Repositories; namespace EMIS.CommonLogic.EvaluationManage { public class EvaluationEnterServices : BaseServices, IEvaluationEnterServices { public EvaluationTypeRepository EvaluationTypeRepository { get; set; } public DataRangeDAL DataRangeDAL { get; set; } public EvaluationEnterDAL EvaluationEnterDAL { get; set; } public Lazy EvaluationNormServices { get; set; } public Lazy EvaluationTargetServices { get; set; } public Lazy EvaluationProjectServices { get; set; } public IGridResultSet GetEvaluationEnterViewGrid(ConfiguretView configuretView, Guid? schoolYearID, Guid? userID, Guid? roleID, bool isStudent, int pageIndex, int pageSize) { Expression> expEvaluationSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.OpenStatus == (int)CF_YesOrNoStatus.Yes); Expression> expEvaluationTable = x => x.IsEnabled == true; Expression> expStudent = x => true; if (schoolYearID.HasValue) expEvaluationSetting = expEvaluationSetting.And(x => x.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID == schoolYearID); if (isStudent) { expStudent = expStudent.And(x => x.UserID == userID); var studentEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == true).FirstOrDefault(); if (studentEvaluationType == null) { throw new Exception("未找到对应的参评类型数据!"); } expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == studentEvaluationType.EvaluationTypeID); } else { var staffEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == false) .OrderByDescending(w => w.IsStudent).FirstOrDefault(); if (staffEvaluationType == null) { throw new Exception("未找到对应的参评类型数据!"); } expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == staffEvaluationType.EvaluationTypeID); } Expression> expEvaluationGradeControl = x => true; Expression> expEvaluationEnter = x => true;// 如果是超级管理员、那么默认显示全部数据 expEvaluationSetting = expEvaluationSetting.And(x => x.OpenStatus == (int)CF_YesOrNoStatus.Yes); var menuNo = HttpHelper.GetMenuNo(); if (isStudent)//过滤属于自己的评价信息 { expEvaluationEnter = expEvaluationEnter.And(x => x.StudentUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0); expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Student.Any(w => w.UserID == userID)); expEvaluationGradeControl = expEvaluationGradeControl.And(x => x.CF_Schoolyear.SchoolyearID == schoolYearID); } else { SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo); if (!dataRange.Equals(SYS_DataRange.All) && !isStudent)//过滤属于自己的评价信息 { expEvaluationEnter = expEvaluationEnter.And(x => x.StaffUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0); expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Staff.Any(w => w.UserID == userID)); } } var query = EvaluationEnterDAL.GetEvaluationEnterQuery(expEvaluationSetting, expEvaluationEnter, expEvaluationTable); if (isStudent) { query = EvaluationEnterDAL.GetStudentEvaluationEnterQuery(expEvaluationSetting, expEvaluationEnter, expEvaluationTable, expEvaluationGradeControl, expStudent); } if (!isStudent) { //query = GetQueryByDataRangeByCollege(query);//以院系 区分 } else { query = query.Where(x => x.IsStudentEvaluation == true && x.IsEvaluation == true); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); query = query.OrderByDescending(o => o.SchoolyearCode).ThenByDescending(o => o.EntityCreateTime); return query.ToGridResultSet(pageIndex, pageSize); } public IList GetEvaluationEnterViewList(ConfiguretView configuretView, Guid? schoolYearID, Guid? userID, Guid? roleID, bool isStudent) { Expression> expEvaluationSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expEvaluationTable = x => x.IsEnabled == true; if (schoolYearID.HasValue) expEvaluationSetting = expEvaluationSetting.And(x => x.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID == schoolYearID); if (isStudent) { var studentEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == true).FirstOrDefault(); if (studentEvaluationType == null) { throw new Exception("未找到对应的参评类型数据!"); } expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == studentEvaluationType.EvaluationTypeID); } else { var staffEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == false) .OrderByDescending(w => w.IsStudent).FirstOrDefault(); if (staffEvaluationType == null) { throw new Exception("未找到对应的参评类型数据!"); } expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == staffEvaluationType.EvaluationTypeID); } Expression> expEvaluationEnter = x => true;// 如果是超级管理员、那么默认显示全部数据 expEvaluationSetting = expEvaluationSetting.And(x => x.OpenStatus == (int)CF_YesOrNoStatus.Yes); var menuNo = HttpHelper.GetMenuNo(); if (isStudent)//过滤属于自己的评价信息 { expEvaluationEnter = expEvaluationEnter.And(x => x.StudentUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0); expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Student.Any(w => w.UserID == userID)); } else { SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo); if (!dataRange.Equals(SYS_DataRange.All) && !isStudent)//过滤属于自己的评价信息 { expEvaluationEnter = expEvaluationEnter.And(x => x.StaffUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0); expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Staff.Any(w => w.UserID == userID)); } } var query = EvaluationEnterDAL.GetEvaluationEnterQuery(expEvaluationSetting, expEvaluationEnter, expEvaluationTable); 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.ToList(); } public void Save(EvaluationEnterView model, bool isStudent) { var ProjectStrList = model.jsonDataStr.ToString().JsonToObject>();//将json转实体集合 EM_EvaluationEnter evaluationEnter = EvaluationEnterDAL.EvaluationEnterRepository.Entities.Where(x => x.EvaluationEnterID == model.EvaluationEnterID).FirstOrDefault(); if (evaluationEnter == null) { //新增进入评价信息 evaluationEnter = new EM_EvaluationEnter(); evaluationEnter.EvaluationEnterID = Guid.NewGuid(); evaluationEnter.EducationMissionClassID = model.EducationMissionClassID; evaluationEnter.EvaluationTableID = model.EvaluationTableID; evaluationEnter.Remark = model.Remark; evaluationEnter.TotalScore = model.TotalScore; if (isStudent) { evaluationEnter.StudentUserID = model.UserID; } else { evaluationEnter.StaffUserID = model.UserID; } this.SetNewStatus(evaluationEnter); foreach (var ProjectEntity in ProjectStrList) { EM_EvaluationEnter_EM_EvaluationProject evaluationEnterOrProject = new EM_EvaluationEnter_EM_EvaluationProject(); evaluationEnterOrProject.ID = Guid.NewGuid(); evaluationEnterOrProject.CreateUserID = model.UserID; evaluationEnterOrProject.CreateTime = DateTime.Now; evaluationEnterOrProject.ModifyUserID = model.UserID; evaluationEnterOrProject.ModifyTime = evaluationEnter.ModifyTime;// Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm")); evaluationEnterOrProject.ProjectID = (Guid)ProjectEntity.ProjectID; evaluationEnterOrProject.EvaluationScore = ProjectEntity.EvaluationScore; evaluationEnterOrProject.EvaluationEnterID = evaluationEnter.EvaluationEnterID; //SetNewStatus(evaluationEnterOrProject); //evaluationEnterOrProject. this.UnitOfWork.Add(evaluationEnterOrProject); } this.UnitOfWork.Add(evaluationEnter); } else { //更新进入评价信息 this.SetModifyStatus(evaluationEnter); evaluationEnter.EducationMissionClassID = model.EducationMissionClassID; evaluationEnter.EvaluationTableID = model.EvaluationTableID; evaluationEnter.Remark = model.Remark; evaluationEnter.TotalScore = model.TotalScore; if (isStudent) { evaluationEnter.StudentUserID = model.UserID; } else { evaluationEnter.StaffUserID = model.UserID; } foreach (var ProjectEntity in ProjectStrList) { EM_EvaluationEnter_EM_EvaluationProject evaluationEnterOrProject = new EM_EvaluationEnter_EM_EvaluationProject(); evaluationEnterOrProject.ID = Guid.NewGuid(); evaluationEnterOrProject.CreateUserID = model.UserID; evaluationEnterOrProject.ModifyUserID = model.UserID; evaluationEnterOrProject.ModifyTime = evaluationEnter.ModifyTime;//Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm")); evaluationEnterOrProject.ProjectID = (Guid)ProjectEntity.ProjectID; evaluationEnterOrProject.EvaluationScore = ProjectEntity.EvaluationScore; evaluationEnterOrProject.EvaluationEnterID = evaluationEnter.EvaluationEnterID; //SetModifyStatus(evaluationEnterOrProject); this.UnitOfWork.Add(evaluationEnterOrProject); } this.UnitOfWork.Update(evaluationEnter); } this.UnitOfWork.Commit(); } /// /// 查询进入评价基本信息 /// /// /// public EM_EvaluationEnter GetEvaluationEnterView(Guid? evaluationEnterID) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; //查询条件 Expression> expression = (x => x.EvaluationEnterID == evaluationEnterID && x.CreateUserID == curUser.UserID); return EvaluationEnterDAL.EvaluationEnterRepository.GetSingle(expression); } /// /// 获取创建评价表集合 /// /// /// public IList GetCreateEvaluationEnterTable(Guid? evaluationTableID, ConfiguretView configuretView) { List CreateTableList = new List(); //1.0 查询评价指标信息 var dataTargetList = EvaluationTargetServices.Value.GetEvaluationTargetViewList(configuretView, evaluationTableID, null).Select(x => new { x.TargetID, x.NormID, x.Name, x.Weight }).ToList(); CreateTable tables = null; foreach (var dataTarget in dataTargetList) { //2.0 查询评分标准明细 var NormNames = string.Join(" ", EvaluationNormServices.Value.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select(s => s.Name + s.Weight)); tables = new CreateTable(); tables.OrderID = dataTarget.Name; tables.Weight = dataTarget.Weight + ""; tables.NormNames = NormNames; //构建一级标题 CreateTableList.Add(tables); //3.0 查询评分项目信息 var dataProjectList = EvaluationProjectServices.Value.GetEvaluationProjectViewList(configuretView, dataTarget.TargetID, evaluationTableID, null).Select(x => new { x.ProjectID, x.OrderID, x.Name, x.Weight, x.Code }).ToList(); foreach (var dataProject in dataProjectList) { tables = new CreateTable(); //4.0 查询评分评分标准信息 //格式: 优,中,差 var NormNames1 = string.Join(",", EvaluationNormServices.Value.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select((s, index) => s.Name)); //构建一级标题下、标题 tables.OrderID = dataProject.OrderID + ""; tables.ProjectName = dataProject.Name; tables.Weight = dataProject.Weight + ""; tables.NormNames = NormNames; CreateTableList.Add(tables); } } return CreateTableList; } /// /// 查询进入评价教研室、课程名称、教师名称相关信息 /// /// 教学任务班ID /// 评价表ID /// public EvaluationEnterView GetEvaluationEnterByMissionClass(Guid? educationMissionClassID, Guid? evaluationTableID) { var queryView = EvaluationEnterDAL.GetEvaluationEnterTitleView(educationMissionClassID, evaluationTableID); return queryView; } //评价项目明细 public IList GetEvaluationEnterByNormDetail(Guid? evaluationEnterID, Guid? evaluationTableID, Guid? normID) { var queryView = EvaluationEnterDAL.GetEvaluationEnterView(evaluationEnterID, evaluationTableID); //if (normID.HasValue) //{ // queryView = queryView.Where(x => x.NormID == normID); //} return queryView.ToList(); } public IList GetEvaluationEnter_EM_EvaluationProjectList(Guid? evaluationEnterID) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var queryView = EvaluationEnterDAL.EvaluationEnter_EM_EvaluationProjectRepository.GetList(x => x.EvaluationEnterID == evaluationEnterID && x.CreateUserID == curUser.UserID); return queryView.ToList(); } public EvaluationEnterView GetEvaluationSettingOrEnterView(Guid? evaluationSettingID, Guid userID, Guid? roleID, bool isStudent) { EM_EvaluationSetting evaluationSetting = EvaluationEnterDAL.EvaluationSettingRepository.Entities.Where(x => x.EvaluationSettingID == evaluationSettingID).FirstOrDefault(); Expression> expEvaluationTable = x => x.IsEnabled == true; if (isStudent) { var studentEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == true).FirstOrDefault(); if (studentEvaluationType == null) { throw new Exception("未找到对应的参评类型数据!"); } expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == studentEvaluationType.EvaluationTypeID); } else { var staffEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == false) .OrderByDescending(w => w.IsStudent).FirstOrDefault(); if (staffEvaluationType == null) { throw new Exception("未找到对应的参评类型数据!"); } expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == staffEvaluationType.EvaluationTypeID); } Expression> expEvaluationEnter = x => true;// 如果是超级管理员、那么默认显示全部数据 var menuNo = HttpHelper.GetMenuNo(); if (isStudent)//过滤属于自己的评价信息 { expEvaluationEnter = expEvaluationEnter.And(x => x.StudentUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0); } else { SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo); if (!dataRange.Equals(SYS_DataRange.All) && !isStudent)//过滤属于自己的评价信息 { expEvaluationEnter = expEvaluationEnter.And(x => x.StaffUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0); } } var query = EvaluationEnterDAL.GetEvaluationEnterQuery(null, expEvaluationEnter, expEvaluationTable); if (isStudent) { Expression> expStudent = x => true; Expression> expEvaluationGradeControl = x => true; expStudent = expStudent.And(x => x.UserID == userID); //expEvaluationGradeControl = expEvaluationGradeControl.And(x => x.CF_Schoolyear.SchoolyearID == schoolYearID); query = EvaluationEnterDAL.GetStudentEvaluationEnterQuery(null, expEvaluationEnter, expEvaluationTable, expEvaluationGradeControl, expStudent); } //query = GetQueryByDataRangeByCollege(query); if (evaluationSettingID.HasValue && evaluationSettingID != Guid.Empty) { query = query.Where(w => w.EducationMissionClassID == evaluationSetting.EducationMissionClassID && w.EvaluationSettingID == evaluationSettingID); } return query.FirstOrDefault(); } public bool GteDataRange(Guid? roleID) { bool IsView = true; var menuNo = HttpHelper.GetMenuNo(); SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo); if (dataRange.Equals(SYS_DataRange.All)) { IsView = false; } if (dataRange.Equals(SYS_DataRange.Campus)) { IsView = true; } if (dataRange.Equals(SYS_DataRange.College)) { IsView = true; } return IsView; } } }