using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Data; using Bowin.Common.JSON; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.EvaluationManage.StudentEvaluation; using EMIS.DataLogic.EvaluationManage.StudentEvaluation; using EMIS.CommonLogic.EvaluationManage.EvaluationSetting; using EMIS.CommonLogic.EvaluationManage.EvaluationManage; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.StudentWeb.Evaluation { public class StudentEvaluationEnterServices : BaseServices, IStudentEvaluationEnterServices { public EvaluationStudentDAL EvaluationStudentDAL { get; set; } public Lazy EvaluationControlServices { get; set; } public Lazy EvaluationStudentScoreServices { get; set; } public Lazy ParameterServices { get; set; } /// /// 查询对应的学生评价信息View /// /// /// /// /// /// public IGridResultSet GetStudentEvaluationEnterViewGrid(ConfiguretView configuretView, Guid? userID, int pageIndex, int pageSize) { Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudent = expStudent.And(x => x.UserID == userID); Expression> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true); var query = EvaluationStudentDAL.GetStudentEvaluationEnterViewQueryable(expStudent, expEvaluationStudentSetting); var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { query = query.Where(x => false); } else { query = query.Where(x => x.SchoolyearValue <= evaluationControlView.SchoolyearValue); query = query.Where(x => x.StartTime <= DateTime.Now); query = query.Where(x => x.EndTime >= DateTime.Now); query = query.Where(x => x.Number > x.Numbered); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.SchoolyearValue).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.Numbered).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的学生评价信息List /// /// /// /// public IList GetStudentEvaluationEnterViewList(ConfiguretView configuretView, Guid? userID) { Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudent = expStudent.And(x => x.UserID == userID); Expression> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true); var query = EvaluationStudentDAL.GetStudentEvaluationEnterViewQueryable(expStudent, expEvaluationStudentSetting); var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { query = query.Where(x => false); } else { query = query.Where(x => x.SchoolyearValue <= evaluationControlView.SchoolyearValue); query = query.Where(x => x.StartTime <= DateTime.Now); query = query.Where(x => x.EndTime >= DateTime.Now); query = query.Where(x => x.Number > x.Numbered); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.SchoolyearValue).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.Numbered).ToList(); } /// /// 查询对应的学生未评价信息List /// /// /// public IList GetStudentNoEvaluationViewList(Guid? userID) { Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudent = expStudent.And(x => x.UserID == userID); Expression> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true); var query = EvaluationStudentDAL.GetStudentEvaluationEnterViewQueryable(expStudent, expEvaluationStudentSetting); var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { query = query.Where(x => false); } else { query = query.Where(x => x.SchoolyearValue <= evaluationControlView.SchoolyearValue); query = query.Where(x => x.StartTime <= DateTime.Now); query = query.Where(x => x.EndTime >= DateTime.Now); query = query.Where(x => x.Numbered == 0); query = query.Where(x => x.Number > 0); } return query.OrderBy(x => x.SchoolyearValue).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.Numbered).ToList(); } /// /// 查询对应的学生评价信息EvaluationStudentView /// /// /// /// public EvaluationStudentView GetStudentEvaluationEnterView(Guid? userID, Guid? evaluationStudentSettingID) { try { Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudent = expStudent.And(x => x.UserID == userID); Expression> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.EvaluationStudentSettingID == evaluationStudentSettingID); var query = EvaluationStudentDAL.GetStudentEvaluationEnterViewQueryable(expStudent, expEvaluationStudentSetting).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑 /// /// public void StudentEvaluationEnterEdit(EvaluationStudentView evaluationStudentView) { try { var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { throw new Exception("当前教学质量评价活动对应的评价学年学期已结束。"); } else { if (evaluationStudentView.SchoolyearValue > evaluationControlView.SchoolyearValue) { throw new Exception("当前教学质量评价活动对应的评价学年学期已结束。"); } } var evaluationParticipateType = EvaluationStudentDAL.EvaluationParticipateTypeRepository.GetList(x => x.ParticipateTypeID == (int)EM_ParticipateType.Student).SingleOrDefault(); if (evaluationParticipateType == null) { throw new Exception("当前教学质量评价活动对应的评价时间已结束。"); } else { if (evaluationParticipateType.StartTime == null || evaluationParticipateType.EndTime == null) { throw new Exception("当前教学质量评价活动对应的评价时间未开始。"); } if (DateTime.Now < evaluationParticipateType.StartTime) { throw new Exception("当前教学质量评价活动对应的评价时间未开始。"); } if (DateTime.Now > evaluationParticipateType.EndTime) { throw new Exception("当前教学质量评价活动对应的评价时间已结束。"); } } if (((evaluationStudentView.Numbered ?? 0) + 1) > (evaluationParticipateType.Number ?? 0)) { throw new Exception("当前教学质量评价活动对应的已评次数已评完。"); } if (!evaluationStudentView.EvaluationStudentSettingID.HasValue || evaluationStudentView.EvaluationStudentSettingID == Guid.Empty) { throw new Exception("评价超时,请刷新页面再次尝试。"); } Expression> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true); expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.EvaluationStudentSettingID == evaluationStudentView.EvaluationStudentSettingID); var evaluationStudentSetting = EvaluationStudentDAL.EvaluationStudentSettingRepository.GetList(expEvaluationStudentSetting, (x => x.CF_Student)).SingleOrDefault(); if (evaluationStudentSetting == null) { throw new Exception("当前教学质量评价活动已关闭,请刷新页面再次尝试。"); } else { var evaluationStudentSettingStudent = evaluationStudentSetting.CF_Student.Where(x => x.UserID == evaluationStudentView.UserID).SingleOrDefault(); if (evaluationStudentSettingStudent == null) { throw new Exception("当前教学质量评价活动已关闭,请刷新页面再次尝试。"); } } Expression> expEvaluationStudent = (x => x.EvaluationStudentID != evaluationStudentView.EvaluationStudentID); expEvaluationStudent = expEvaluationStudent.And(x => x.UserID == evaluationStudentView.UserID); expEvaluationStudent = expEvaluationStudent.And(x => x.EvaluationStudentSettingID == evaluationStudentView.EvaluationStudentSettingID); var evaluationStudentVerify = EvaluationStudentDAL.EvaluationStudentRepository.GetList(expEvaluationStudent).SingleOrDefault(); if (evaluationStudentVerify == null) { Expression> expEvaluationStudentScore = (x => x.SchoolyearID == evaluationStudentView.SchoolyearID); expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.UserID == evaluationStudentView.UserID); expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.CoursematerialID == evaluationStudentView.CoursematerialID); expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.DepartmentID == evaluationStudentView.DepartmentID); var evaluationStudentScore = EvaluationStudentDAL.EvaluationStudentScoreRepository.GetList(expEvaluationStudentScore).SingleOrDefault(); var isEvaluationControlForSchoolyear = ParameterServices.Value.GetParameterValue(CF_ParameterType.IsEvaluationControlForSchoolyear); if (evaluationStudentScore == null) { if (evaluationStudentView.SchoolyearValue < evaluationControlView.SchoolyearValue) { evaluationStudentView.IsValidity = isEvaluationControlForSchoolyear ?? false; } else { evaluationStudentView.IsValidity = true; } } else { var startStatusID = EvaluationStudentScoreServices.Value.GetStartStatus(); if (startStatusID == null) { throw new Exception("评价数据有误,请联系辅导员或教学评价负责老师。"); } if (evaluationStudentScore.ApprovalStatus == startStatusID) { if (evaluationStudentView.SchoolyearValue < evaluationControlView.SchoolyearValue) { evaluationStudentView.IsValidity = isEvaluationControlForSchoolyear ?? false; } else { evaluationStudentView.IsValidity = true; } } else { evaluationStudentView.IsValidity = false; } } var evaluationProjectJsonDataList = evaluationStudentView.JsonDataStr.ToString().JsonToObject>(); if (evaluationProjectJsonDataList == null || evaluationProjectJsonDataList.Count() < 0) { throw new Exception("当前教学质量评价活动,评价项目中对应的评分标准未评分,请进行评分。"); } var evaluationStudentInList = new List(); var evaluationStudentUpList = new List(); var evaluationStudentDetailInList = new List(); var evaluationStudentIDDelList = new List(); if (evaluationStudentView.EvaluationStudentID != Guid.Empty) { var evaluationStudent = EvaluationStudentDAL.EvaluationStudentRepository.GetList(x => x.EvaluationStudentID == evaluationStudentView.EvaluationStudentID).SingleOrDefault(); if (evaluationStudent == null) { throw new Exception("评价超时,请刷新页面再次尝试。"); } else { //表示修改 if (evaluationStudentView.IsValidity) { evaluationStudent.Numbered = (evaluationStudentView.Numbered ?? 0) + 1; evaluationStudent.IsValidity = evaluationStudentView.IsValidity; evaluationStudent.TotalScore = evaluationStudentView.TotalScore; evaluationStudent.Advice = evaluationStudentView.Advice; SetModifyStatus(evaluationStudent); evaluationStudentUpList.Add(evaluationStudent); evaluationStudentIDDelList.Add(evaluationStudent.EvaluationStudentID); foreach (var evaluationProjectJsonData in evaluationProjectJsonDataList) { var newEvaluationStudentDetail = new EM_EvaluationStudentDetail(); newEvaluationStudentDetail.EvaluationStudentDetailID = Guid.NewGuid(); newEvaluationStudentDetail.EvaluationStudentID = evaluationStudent.EvaluationStudentID; newEvaluationStudentDetail.EvaluationProjectID = evaluationProjectJsonData.EvaluationProjectID; newEvaluationStudentDetail.Score = evaluationProjectJsonData.Score; newEvaluationStudentDetail.Remark = null; SetNewStatus(newEvaluationStudentDetail); evaluationStudentDetailInList.Add(newEvaluationStudentDetail); } } else { throw new Exception("当前教学质量评价活动已结束。"); } } } else { //表示新增 var newEvaluationStudent = new EM_EvaluationStudent(); newEvaluationStudent.EvaluationStudentID = Guid.NewGuid(); newEvaluationStudent.UserID = evaluationStudentView.UserID; newEvaluationStudent.EvaluationStudentSettingID = evaluationStudentView.EvaluationStudentSettingID; newEvaluationStudent.Numbered = (evaluationStudentView.Numbered ?? 0) + 1; newEvaluationStudent.IsValidity = evaluationStudentView.IsValidity; newEvaluationStudent.TotalScore = evaluationStudentView.TotalScore; newEvaluationStudent.Advice = evaluationStudentView.Advice; newEvaluationStudent.Remark = evaluationStudentView.Remark; SetNewStatus(newEvaluationStudent); evaluationStudentInList.Add(newEvaluationStudent); foreach (var evaluationProjectJsonData in evaluationProjectJsonDataList) { var newEvaluationStudentDetail = new EM_EvaluationStudentDetail(); newEvaluationStudentDetail.EvaluationStudentDetailID = Guid.NewGuid(); newEvaluationStudentDetail.EvaluationStudentID = newEvaluationStudent.EvaluationStudentID; newEvaluationStudentDetail.EvaluationProjectID = evaluationProjectJsonData.EvaluationProjectID; newEvaluationStudentDetail.Score = evaluationProjectJsonData.Score; newEvaluationStudentDetail.Remark = null; SetNewStatus(newEvaluationStudentDetail); evaluationStudentDetailInList.Add(newEvaluationStudentDetail); } } using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable })) { UnitOfWork.Delete(x => evaluationStudentIDDelList.Contains(x.EvaluationStudentID)); UnitOfWork.BulkInsert(evaluationStudentInList); UnitOfWork.BulkInsert(evaluationStudentDetailInList); if (evaluationStudentUpList != null && evaluationStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(evaluationStudentUpList); } ts.Complete(); } } else { throw new Exception("同学,您当前参与的教学质量评价活动,评价信息已存在,如需再次评价,请刷新页面再次尝试,感谢您的参与。"); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的学评学生明细信息List /// /// /// public IList GetEvaluationStudentDetailList(Guid? evaluationStudentID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.EvaluationStudentID == evaluationStudentID); var query = EvaluationStudentDAL.EvaluationStudentDetailRepository.GetList(exp); return query.OrderBy(x => x.EvaluationStudentID).ThenBy(x => x.Score).ToList(); } /// /// 教学评价登录控制 /// /// /// public bool LoginControl(Guid? userID) { var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { return true; } else { if (evaluationControlView.IsLoginLock) { var evaluationStudentViewList = this.GetStudentNoEvaluationViewList(userID).ToList(); if (evaluationStudentViewList == null || evaluationStudentViewList.Count() <= 0) { return true; } else { if (evaluationStudentViewList.Count() <= (evaluationControlView.NoNumber ?? 0)) { return true; } else { return false; } } } else { return true; } } } /// /// 教学评价网上选课控制 /// /// /// public bool SelectCourseControl(Guid? userID) { var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { return true; } else { if (evaluationControlView.IsSelectCourseLock) { var evaluationStudentViewList = this.GetStudentNoEvaluationViewList(userID).ToList(); if (evaluationStudentViewList == null || evaluationStudentViewList.Count() <= 0) { return true; } else { if (evaluationStudentViewList.Count() <= (evaluationControlView.NoNumber ?? 0)) { return true; } else { return false; } } } else { return true; } } } /// /// 教学评价考试报名控制 /// /// /// public bool ExaminationApplyControl(Guid? userID) { var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { return true; } else { if (evaluationControlView.IsExaminationApplyLock) { var evaluationStudentViewList = this.GetStudentNoEvaluationViewList(userID).ToList(); if (evaluationStudentViewList == null || evaluationStudentViewList.Count() <= 0) { return true; } else { if (evaluationStudentViewList.Count() <= (evaluationControlView.NoNumber ?? 0)) { return true; } else { return false; } } } else { return true; } } } /// /// 教学评价课程成绩查询控制 /// /// /// public bool CourseScoreControl(Guid? userID) { var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { return true; } else { if (evaluationControlView.IsCourseScoreLock) { var evaluationStudentViewList = this.GetStudentNoEvaluationViewList(userID).ToList(); if (evaluationStudentViewList == null || evaluationStudentViewList.Count() <= 0) { return true; } else { if (evaluationStudentViewList.Count() <= (evaluationControlView.NoNumber ?? 0)) { return true; } else { return false; } } } else { return true; } } } /// /// 教学评价等级成绩查询控制 /// /// /// public bool LevelScoreControl(Guid? userID) { var evaluationControlView = EvaluationControlServices.Value.GetEvaluationControlView(); if (evaluationControlView == null) { return true; } else { if (evaluationControlView.IsLevelScoreLock) { var evaluationStudentViewList = this.GetStudentNoEvaluationViewList(userID).ToList(); if (evaluationStudentViewList == null || evaluationStudentViewList.Count() <= 0) { return true; } else { if (evaluationStudentViewList.Count() <= (evaluationControlView.NoNumber ?? 0)) { return true; } else { return false; } } } else { return true; } } } } }