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.StudentEvaluation; using EMIS.DataLogic.EvaluationManage.StudentEvaluation; using EMIS.CommonLogic.StudentManage.StudentStatistics; namespace EMIS.CommonLogic.EvaluationManage.StudentEvaluation { public class EvaluationStudentServices : BaseServices, IEvaluationStudentServices { public EvaluationStudentDAL EvaluationStudentDAL { get; set; } public Lazy InSchoolSettingServices { get; set; } /// /// 查询对应的学评学生信息View /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetEvaluationStudentViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? coursematerialID, int? courseTypeID, int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? evaluationTableID, int? isValidity, int? inSchoolStatus, int pageIndex, int pageSize) { Expression> expEvaluationStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (isValidity.HasValue) { if (isValidity.Value == (int)CF_GeneralPurpose.IsYes) { expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity == true); } if (isValidity.Value == (int)CF_GeneralPurpose.IsNo) { expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity != true); } } Expression> expEducationMission = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { expEducationMission = expEducationMission.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { expEducationMission = expEducationMission.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { expEducationMission = expEducationMission.And(x => x.DepartmentID == departmentID); } Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = EvaluationStudentDAL.GetEvaluationStudentViewQueryable(expEvaluationStudent, expEducationMission, expStudent); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (coursematerialID.HasValue) { query = query.Where(x => x.CoursematerialID == coursematerialID); } if (courseTypeID.HasValue) { query = query.Where(x => x.CourseTypeID == courseTypeID); } if (teachingModeID.HasValue) { query = query.Where(x => x.TeachingModeID == teachingModeID); } if (staffID.HasValue) { query = query.Where(x => x.StaffUserID == staffID); } if (teachingMethodID.HasValue) { query = query.Where(x => x.TeachingMethodID == teachingMethodID); } if (evaluationTableID.HasValue) { query = query.Where(x => x.EvaluationTableID == evaluationTableID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByDepartment(query, x => x.DepartmentID).OrderBy(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length).ThenBy(x => x.DepartmentNo) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.TeachingModeID).ThenBy(x => x.StudentNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的学评学生信息List /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IList GetEvaluationStudentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? coursematerialID, int? courseTypeID, int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? evaluationTableID, int? isValidity, int? inSchoolStatus) { Expression> expEvaluationStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (isValidity.HasValue) { if (isValidity.Value == (int)CF_GeneralPurpose.IsYes) { expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity == true); } if (isValidity.Value == (int)CF_GeneralPurpose.IsNo) { expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity != true); } } Expression> expEducationMission = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { expEducationMission = expEducationMission.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { expEducationMission = expEducationMission.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { expEducationMission = expEducationMission.And(x => x.DepartmentID == departmentID); } Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = EvaluationStudentDAL.GetEvaluationStudentViewQueryable(expEvaluationStudent, expEducationMission, expStudent); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (coursematerialID.HasValue) { query = query.Where(x => x.CoursematerialID == coursematerialID); } if (courseTypeID.HasValue) { query = query.Where(x => x.CourseTypeID == courseTypeID); } if (teachingModeID.HasValue) { query = query.Where(x => x.TeachingModeID == teachingModeID); } if (staffID.HasValue) { query = query.Where(x => x.StaffUserID == staffID); } if (teachingMethodID.HasValue) { query = query.Where(x => x.TeachingMethodID == teachingMethodID); } if (evaluationTableID.HasValue) { query = query.Where(x => x.EvaluationTableID == evaluationTableID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByDepartment(query, x => x.DepartmentID).OrderBy(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length).ThenBy(x => x.DepartmentNo) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.TeachingModeID).ThenBy(x => x.StudentNo).ToList(); } /// /// 查询对应的学评学生信息EvaluationStudentView /// /// /// public EvaluationStudentView GetEvaluationStudentView(Guid? evaluationStudentID) { try { Expression> exp = (x => x.EvaluationStudentID == evaluationStudentID); var query = EvaluationStudentDAL.GetEvaluationStudentViewQueryable(exp).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑 /// /// public void EvaluationStudentEdit(EvaluationStudentView evaluationStudentView) { try { if (!evaluationStudentView.EvaluationStudentSettingID.HasValue || evaluationStudentView.EvaluationStudentSettingID == Guid.Empty) { throw new Exception("对应的学评设定信息数据有误,请核查。"); } var evaluationStudentVerify = EvaluationStudentDAL.EvaluationStudentRepository.GetList(x => x.EvaluationStudentID != evaluationStudentView.EvaluationStudentID && x.UserID == evaluationStudentView.UserID && x.EvaluationStudentSettingID == evaluationStudentView.EvaluationStudentSettingID).SingleOrDefault(); if (evaluationStudentVerify == null) { var evaluationStudentInList = new List(); var evaluationStudentUpList = 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 { //表示修改 evaluationStudent.Numbered = (evaluationStudent.Numbered ?? 0) + 1; evaluationStudent.IsValidity = evaluationStudentView.IsValidity; evaluationStudent.TotalScore = evaluationStudentView.TotalScore; evaluationStudent.Advice = evaluationStudentView.Advice; evaluationStudent.Remark = evaluationStudentView.Remark; SetModifyStatus(evaluationStudent); evaluationStudentUpList.Add(evaluationStudent); } } else { //表示新增 var newEvaluationStudent = new EM_EvaluationStudent(); newEvaluationStudent.EvaluationStudentID = Guid.NewGuid(); newEvaluationStudent.UserID = evaluationStudentView.UserID; newEvaluationStudent.EvaluationStudentSettingID = evaluationStudentView.EvaluationStudentSettingID; newEvaluationStudent.Numbered = evaluationStudentView.Numbered; newEvaluationStudent.IsValidity = evaluationStudentView.IsValidity; newEvaluationStudent.TotalScore = evaluationStudentView.TotalScore; newEvaluationStudent.Advice = evaluationStudentView.Remark; newEvaluationStudent.Remark = evaluationStudentView.Remark; SetNewStatus(newEvaluationStudent); evaluationStudentInList.Add(newEvaluationStudent); } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.BulkInsert(evaluationStudentInList); if (evaluationStudentInList != null && evaluationStudentInList.Count() > 0) { UnitOfWork.BatchUpdate(evaluationStudentInList); } ts.Complete(); } } else { throw new Exception("已存在相同的学评明细信息(学生信息、学评设定信息唯一),请核查。"); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool EvaluationStudentDelete(List evaluationStudentIDs) { try { Expression> expEvaluationStudent = (x => evaluationStudentIDs.Contains(x.EvaluationStudentID)); var evaluationStudentList = EvaluationStudentDAL.EvaluationStudentRepository.GetList(expEvaluationStudent).ToList(); var evaluationStudentSettingIDList = evaluationStudentList.Select(x => x.EvaluationStudentSettingID).Distinct().ToList(); var evaluationStudentSettingScoreList = EvaluationStudentDAL.EvaluationStudentSettingScoreRepository.GetList(x => evaluationStudentSettingIDList.Contains(x.EvaluationStudentSettingID)).ToList(); if (evaluationStudentSettingScoreList != null && evaluationStudentSettingScoreList.Count() > 0) { throw new Exception("选择删除的信息中存在对应的学评评分信息,无法删除,请核查。"); } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => evaluationStudentIDs.Contains(x.EvaluationStudentID)); UnitOfWork.Delete(x => evaluationStudentIDs.Contains(x.EvaluationStudentID)); ts.Complete(); } return true; } catch (Exception) { throw; } } } }