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.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.EvaluationManage.EvaluationResult; using EMIS.DataLogic.EvaluationManage.EvaluationResult; using EMIS.DataLogic.EvaluationManage.StudentEvaluation; using EMIS.CommonLogic.EvaluationManage.EvaluationManage; namespace EMIS.CommonLogic.EvaluationManage.EvaluationResult { public class EvaluationStaffScoreServices : BaseServices, IEvaluationStaffScoreServices { public Lazy EvaluationStaffScoreDAL { get; set; } public Lazy EvaluationStudentSettingDAL { get; set; } public Lazy EvaluationStudentScoreServices { get; set; } public Lazy EvaluationCollegeScoreServices { get; set; } /// /// 查询对应的教师评分信息View /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetEvaluationStaffScoreViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? userID, int? incumbencyState, Guid? coursematerialID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } if (userID.HasValue) { exp = exp.And(x => x.UserID == userID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } var query = EvaluationStaffScoreDAL.Value.GetEvaluationStaffScoreViewQueryable(exp); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (incumbencyState.HasValue) { query = query.Where(x => x.IncumbencyState == incumbencyState); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRange(query, x => x.UserID).OrderByDescending(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length) .ThenBy(x => x.DepartmentNo).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.StaffCode).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的教师评分信息List /// /// /// /// /// /// /// /// /// /// public IList GetEvaluationStaffScoreViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? userID, int? incumbencyState, Guid? coursematerialID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } if (userID.HasValue) { exp = exp.And(x => x.UserID == userID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } var query = EvaluationStaffScoreDAL.Value.GetEvaluationStaffScoreViewQueryable(exp); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (incumbencyState.HasValue) { query = query.Where(x => x.IncumbencyState == incumbencyState); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRange(query, x => x.UserID).OrderByDescending(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length) .ThenBy(x => x.DepartmentNo).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.StaffCode).ToList(); } /// /// 查询对应的教师评分信息EvaluationStaffScoreView /// /// /// public EvaluationStaffScoreView GetEvaluationStaffScoreView(Guid? evaluationStaffScoreID) { try { Expression> exp = (x => x.EvaluationStaffScoreID == evaluationStaffScoreID); var query = EvaluationStaffScoreDAL.Value.GetEvaluationStaffScoreViewQueryable(exp).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 评分生成 /// /// /// /// /// /// /// /// public string EvaluationStaffScoreCreate(Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? coursematerialID, Guid? userID, Guid? schoolyearID) { try { var schoolyear = EvaluationStaffScoreDAL.Value.SchoolyearRepository.GetList(x => x.SchoolyearID == schoolyearID).SingleOrDefault(); if (schoolyear == null) { throw new Exception("选择的学年学期有误,请核查。"); } var stuPassNoEndStatusID = EvaluationStudentScoreServices.Value.GetPassNoEndStatus(); if (stuPassNoEndStatusID == null) { throw new Exception("工作流平台中,学生评分流程通过环节未配置,请核查。"); } var colPassNoEndStatusID = EvaluationCollegeScoreServices.Value.GetPassNoEndStatus(); if (colPassNoEndStatusID == null) { throw new Exception("工作流平台中,院系评分流程通过环节未配置,请核查。"); } Expression> expEducationMissionClass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expEducationMissionClass = expEducationMissionClass.And(x => x.RecordStatus == (int)EM_EducationMissionClassStatus.Submitted || x.RecordStatus == (int)EM_EducationMissionClassStatus.Scheduled); if (coursematerialID.HasValue) { expEducationMissionClass = expEducationMissionClass.And(x => x.CoursematerialID == coursematerialID); } var query = EvaluationStudentSettingDAL.Value.GetEvaluationMissionStaffViewQueryable(expEducationMissionClass).Distinct().AsQueryable(); if (schoolyearID.HasValue) { query = query.Where(x => x.SchoolyearID == schoolyearID); } if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { query = query.Where(x => x.DepartmentID == departmentID); } if (userID.HasValue) { query = query.Where(x => x.UserID == userID); } var evaluationMissionStaffViewList = this.GetQueryByDataRangeByDepartment(query).ToList(); if (evaluationMissionStaffViewList == null || evaluationMissionStaffViewList.Count() <= 0) { throw new Exception("对应的教学任务信息为空,请核查(如:任务状态为未提交)。"); } var schoolyearIDList = evaluationMissionStaffViewList.Select(x => x.SchoolyearID).Distinct().ToList(); var evaluationStaffScoreList = EvaluationStaffScoreDAL.Value.EvaluationStaffScoreRepository.GetList(x => schoolyearIDList.Contains(x.SchoolyearID), (x => x.EM_EvaluationStaffScoreDetail)).ToList(); var evaluationStudentScoreList = EvaluationStaffScoreDAL.Value.EvaluationStudentScoreRepository.GetList(x => schoolyearIDList.Contains(x.SchoolyearID)).ToList(); var evaluationCollegeScoreList = EvaluationStaffScoreDAL.Value.EvaluationCollegeScoreRepository.GetList(x => schoolyearIDList.Contains(x.SchoolyearID)).ToList(); int inSuccess = 0; int upSuccess = 0; string tipMessage = null; var evaluationStaffScoreInList = new List(); var evaluationStaffScoreUpList = new List(); var evaluationStaffScoreDetailInList = new List(); List evaluationStaffScoreIDDelList = new List(); foreach (var evaluationMissionStaffView in evaluationMissionStaffViewList) { var evaluationStaffScore = evaluationStaffScoreList.Where(x => x.SchoolyearID == evaluationMissionStaffView.SchoolyearID && x.UserID == evaluationMissionStaffView.UserID && x.CoursematerialID == evaluationMissionStaffView.CoursematerialID && x.DepartmentID == evaluationMissionStaffView.DepartmentID).SingleOrDefault(); var evaluationStudentScore = evaluationStudentScoreList.Where(x => x.SchoolyearID == evaluationMissionStaffView.SchoolyearID && x.UserID == evaluationMissionStaffView.UserID && x.CoursematerialID == evaluationMissionStaffView.CoursematerialID && x.DepartmentID == evaluationMissionStaffView.DepartmentID && x.ApprovalStatus == stuPassNoEndStatusID).SingleOrDefault(); var evaluationCollegeScore = evaluationCollegeScoreList.Where(x => x.SchoolyearID == evaluationMissionStaffView.SchoolyearID && x.UserID == evaluationMissionStaffView.UserID && x.CoursematerialID == evaluationMissionStaffView.CoursematerialID && x.DepartmentID == evaluationMissionStaffView.DepartmentID && x.ApprovalStatus == colPassNoEndStatusID).SingleOrDefault(); if (evaluationStaffScore == null) { var newEvaluationStaffScore = new EM_EvaluationStaffScore(); newEvaluationStaffScore.EvaluationStaffScoreID = Guid.NewGuid(); newEvaluationStaffScore.SchoolyearID = evaluationMissionStaffView.SchoolyearID; newEvaluationStaffScore.UserID = evaluationMissionStaffView.UserID; newEvaluationStaffScore.CoursematerialID = evaluationMissionStaffView.CoursematerialID; newEvaluationStaffScore.DepartmentID = evaluationMissionStaffView.DepartmentID; if (evaluationStudentScore != null) { if (evaluationCollegeScore != null) { newEvaluationStaffScore.TotalScore = Math.Round(((evaluationStudentScore.TotalScore ?? 0) * (decimal)0.7) + ((evaluationCollegeScore.TotalScore ?? 0) * (decimal)0.3), 2, MidpointRounding.AwayFromZero); } else { newEvaluationStaffScore.TotalScore = Math.Round(((evaluationStudentScore.TotalScore ?? 0) * (decimal)0.7), 2, MidpointRounding.AwayFromZero); } } else { if (evaluationCollegeScore != null) { newEvaluationStaffScore.TotalScore = Math.Round(((evaluationCollegeScore.TotalScore ?? 0) * (decimal)0.3), 2, MidpointRounding.AwayFromZero); } else { newEvaluationStaffScore.TotalScore = 0; } } newEvaluationStaffScore.Remark = null; SetNewStatus(newEvaluationStaffScore); evaluationStaffScoreInList.Add(newEvaluationStaffScore); var newEvaStuStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaStuStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaStuStaffScoreDetail.EvaluationStaffScoreID = newEvaluationStaffScore.EvaluationStaffScoreID; newEvaStuStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.StudentScore; if (evaluationStudentScore != null) { newEvaStuStaffScoreDetail.Score = evaluationStudentScore.TotalScore; } else { newEvaStuStaffScoreDetail.Score = 0; } SetNewStatus(newEvaStuStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaStuStaffScoreDetail); var newEvaColStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaColStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaColStaffScoreDetail.EvaluationStaffScoreID = newEvaluationStaffScore.EvaluationStaffScoreID; newEvaColStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.CollegeScore; if (evaluationCollegeScore != null) { newEvaColStaffScoreDetail.Score = evaluationCollegeScore.TotalScore; } else { newEvaColStaffScoreDetail.Score = 0; } SetNewStatus(newEvaColStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaColStaffScoreDetail); inSuccess++; } else { if (evaluationStudentScore != null) { if (evaluationCollegeScore != null) { evaluationStaffScore.TotalScore = Math.Round(((evaluationStudentScore.TotalScore ?? 0) * (decimal)0.7) + ((evaluationCollegeScore.TotalScore ?? 0) * (decimal)0.3), 2, MidpointRounding.AwayFromZero); } else { evaluationStaffScore.TotalScore = Math.Round(((evaluationStudentScore.TotalScore ?? 0) * (decimal)0.7), 2, MidpointRounding.AwayFromZero); } } else { if (evaluationCollegeScore != null) { evaluationStaffScore.TotalScore = Math.Round(((evaluationCollegeScore.TotalScore ?? 0) * (decimal)0.3), 2, MidpointRounding.AwayFromZero); } else { evaluationStaffScore.TotalScore = 0; } } SetModifyStatus(evaluationStaffScore); evaluationStaffScoreUpList.Add(evaluationStaffScore); if (evaluationStaffScore.EM_EvaluationStaffScoreDetail.Count() > 0) { evaluationStaffScoreIDDelList.Add(evaluationStaffScore.EvaluationStaffScoreID); } var newEvaStuStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaStuStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaStuStaffScoreDetail.EvaluationStaffScoreID = evaluationStaffScore.EvaluationStaffScoreID; newEvaStuStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.StudentScore; if (evaluationStudentScore != null) { newEvaStuStaffScoreDetail.Score = evaluationStudentScore.TotalScore; } else { newEvaStuStaffScoreDetail.Score = 0; } SetNewStatus(newEvaStuStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaStuStaffScoreDetail); var newEvaColStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaColStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaColStaffScoreDetail.EvaluationStaffScoreID = evaluationStaffScore.EvaluationStaffScoreID; newEvaColStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.CollegeScore; if (evaluationCollegeScore != null) { newEvaColStaffScoreDetail.Score = evaluationCollegeScore.TotalScore; } else { newEvaColStaffScoreDetail.Score = 0; } SetNewStatus(newEvaColStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaColStaffScoreDetail); upSuccess++; } } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => evaluationStaffScoreIDDelList.Contains(x.EvaluationStaffScoreID)); UnitOfWork.BulkInsert(evaluationStaffScoreInList); if (evaluationStaffScoreUpList != null && evaluationStaffScoreUpList.Count() > 0) { UnitOfWork.BatchUpdate(evaluationStaffScoreUpList); } UnitOfWork.BulkInsert(evaluationStaffScoreDetailInList); ts.Complete(); } if (inSuccess > 0 && upSuccess <= 0) { tipMessage = inSuccess + "条"; } else { tipMessage = inSuccess + "条,更新成功" + upSuccess + "条"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑 /// /// public void EvaluationStaffScoreEdit(EvaluationStaffScoreView evaluationStaffScoreView) { try { var evaluationStaffScoreVerify = EvaluationStaffScoreDAL.Value.EvaluationStaffScoreRepository.GetList(x => x.EvaluationStaffScoreID != evaluationStaffScoreView.EvaluationStaffScoreID && x.SchoolyearID == evaluationStaffScoreView.SchoolyearID && x.UserID == evaluationStaffScoreView.UserID && x.CoursematerialID == evaluationStaffScoreView.CoursematerialID && x.DepartmentID == evaluationStaffScoreView.DepartmentID).SingleOrDefault(); if (evaluationStaffScoreVerify == null) { var evaluationStaffScoreInList = new List(); var evaluationStaffScoreUpList = new List(); var evaluationStaffScoreDetailInList = new List(); List evaluationStaffScoreIDDelList = new List(); if (evaluationStaffScoreView.EvaluationStaffScoreID != Guid.Empty) { var evaluationStaffScore = EvaluationStaffScoreDAL.Value.EvaluationStaffScoreRepository.GetList(x => x.EvaluationStaffScoreID == evaluationStaffScoreView.EvaluationStaffScoreID).SingleOrDefault(); if (evaluationStaffScore == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 evaluationStaffScore.SchoolyearID = evaluationStaffScoreView.SchoolyearID; evaluationStaffScore.UserID = evaluationStaffScoreView.UserID; evaluationStaffScore.CoursematerialID = evaluationStaffScoreView.CoursematerialID; evaluationStaffScore.DepartmentID = evaluationStaffScoreView.DepartmentID; evaluationStaffScore.TotalScore = evaluationStaffScoreView.TotalScore; evaluationStaffScore.Remark = evaluationStaffScoreView.Remark; SetModifyStatus(evaluationStaffScore); evaluationStaffScoreUpList.Add(evaluationStaffScore); evaluationStaffScoreIDDelList.Add(evaluationStaffScore.EvaluationStaffScoreID); var newEvaStuStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaStuStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaStuStaffScoreDetail.EvaluationStaffScoreID = evaluationStaffScore.EvaluationStaffScoreID; newEvaStuStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.StudentScore; newEvaStuStaffScoreDetail.Score = evaluationStaffScoreView.StudentScore; SetNewStatus(newEvaStuStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaStuStaffScoreDetail); var newEvaColStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaColStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaColStaffScoreDetail.EvaluationStaffScoreID = evaluationStaffScore.EvaluationStaffScoreID; newEvaColStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.CollegeScore; newEvaColStaffScoreDetail.Score = evaluationStaffScoreView.CollegeScore; SetNewStatus(newEvaColStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaColStaffScoreDetail); } } else { //表示新增 var newEvaluationStaffScore = new EM_EvaluationStaffScore(); newEvaluationStaffScore.EvaluationStaffScoreID = Guid.NewGuid(); newEvaluationStaffScore.SchoolyearID = evaluationStaffScoreView.SchoolyearID; newEvaluationStaffScore.UserID = evaluationStaffScoreView.UserID; newEvaluationStaffScore.CoursematerialID = evaluationStaffScoreView.CoursematerialID; newEvaluationStaffScore.DepartmentID = evaluationStaffScoreView.DepartmentID; newEvaluationStaffScore.TotalScore = evaluationStaffScoreView.TotalScore; newEvaluationStaffScore.Remark = evaluationStaffScoreView.Remark; SetNewStatus(newEvaluationStaffScore); evaluationStaffScoreInList.Add(newEvaluationStaffScore); var newEvaStuStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaStuStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaStuStaffScoreDetail.EvaluationStaffScoreID = newEvaluationStaffScore.EvaluationStaffScoreID; newEvaStuStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.StudentScore; newEvaStuStaffScoreDetail.Score = evaluationStaffScoreView.StudentScore; SetNewStatus(newEvaStuStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaStuStaffScoreDetail); var newEvaColStaffScoreDetail = new EM_EvaluationStaffScoreDetail(); newEvaColStaffScoreDetail.EvaluationStaffScoreDetailID = Guid.NewGuid(); newEvaColStaffScoreDetail.EvaluationStaffScoreID = newEvaluationStaffScore.EvaluationStaffScoreID; newEvaColStaffScoreDetail.EvaluationScoreTypeID = (int)EMIS.ViewModel.EM_EvaluationScoreType.CollegeScore; newEvaColStaffScoreDetail.Score = evaluationStaffScoreView.CollegeScore; SetNewStatus(newEvaColStaffScoreDetail); evaluationStaffScoreDetailInList.Add(newEvaColStaffScoreDetail); } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => evaluationStaffScoreIDDelList.Contains(x.EvaluationStaffScoreID)); UnitOfWork.BulkInsert(evaluationStaffScoreInList); if (evaluationStaffScoreUpList != null && evaluationStaffScoreUpList.Count() > 0) { UnitOfWork.BatchUpdate(evaluationStaffScoreUpList); } UnitOfWork.BulkInsert(evaluationStaffScoreDetailInList); ts.Complete(); } } else { throw new Exception("已存在相同的教师评分信息(学年学期、学生信息、课程信息唯一),请核查。"); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool EvaluationStaffScoreDelete(List evaluationStaffScoreIDs) { try { using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => evaluationStaffScoreIDs.Contains(x.EvaluationStaffScoreID)); UnitOfWork.Delete(x => evaluationStaffScoreIDs.Contains(x.EvaluationStaffScoreID)); ts.Complete(); return true; } } catch (Exception) { throw; } } } }