using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; using EMIS.ViewModel; using EMIS.DataLogic.ScoreManage; using EMIS.ViewModel.Cultureplan; using EMIS.Utility; namespace EMIS.CommonLogic.ScoreManage { public class MisconductServices : BaseWorkflowServices, IMisconductServices { public ExaminationSuspensionDAL ExaminationSuspensionDAL { get; set; } public MisconductDAL MisconductDAL { get; set; } public FinalExaminationDAL FinalExaminationDAL { get; set; } public ExamsStateSettingDAL ExamsStateSettingDAL { get; set; } public Lazy ScoreServices { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetMisconductGridView(ViewModel.ConfiguretView conditions, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? examsStateID, int? recordStatus, int? learningformID, int? education, string LearnSystem, int? pageIndex = null, int? pageSize = null) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var statusList = this.GetStatusViewList(); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (year.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID); } if (examsCatagoryID.HasValue) { exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID); } if (examsStateID.HasValue) { exp = exp.And(x => x.ExamsStateID == examsStateID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } if (learningformID.HasValue) exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } var query = this.MisconductDAL.GetMisconductViewQueryable(exp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } query = this.GetQueryByDataRangeByCollege(query); var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public List GetMisconductViewList(ViewModel.ConfiguretView conditions, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? examsStateID, int? recordStatus, int? learningformID, int? education, string LearnSystem) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var statusList = this.GetStatusViewList(); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (year.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID); } if (examsCatagoryID.HasValue) { exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID); } if (examsStateID.HasValue) { exp = exp.And(x => x.ExamsStateID == examsStateID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } if (learningformID.HasValue) exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } var query = this.MisconductDAL.GetMisconductViewQueryable(exp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } query = this.GetQueryByDataRangeByCollege(query); var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList(); result.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public void Save(ViewModel.ScoreManage.MisconductView misconductView) { var dupMisconduct = this.MisconductDAL.MisconductRepository .GetSingle(x => x.UserID == misconductView.UserID && x.SchoolyearID == misconductView.SchoolyearID && x.CoursematerialID == misconductView.CoursematerialID && x.ExamsCategoryID == misconductView.ExamsCategoryID); ER_Misconduct misconduct = this.MisconductDAL.MisconductRepository .GetSingle(x => x.MisconductID == misconductView.MisconductID); ER_ExaminationSuspension examinationSuspension = this.ExaminationSuspensionDAL.ExaminationSuspensionRepository .GetSingle(x => x.SchoolyearID == misconductView.SchoolyearID &&x.UserID==misconductView.UserID &&x.ExamsCategoryID==misconductView.ExamsCategoryID &&x.CoursematerialID==misconductView.CoursematerialID &&x.RecordStatus==3); if (examinationSuspension!=null) { throw new Exception("该学生有这门考试的缓考申请记录,如需添加违纪请先撤销缓考申请。"); } if (misconduct == null) { if (dupMisconduct != null) { throw new Exception("已经有相同的违纪名单,请勿重复申请。"); } misconduct = new ER_Misconduct(); misconduct.MisconductID = Guid.NewGuid(); this.SetNewStatus(misconduct); misconduct.RecordStatus = this.GetStartStatus(); this.UnitOfWork.Add(misconduct); } else { if (dupMisconduct != null && dupMisconduct.MisconductID != misconduct.MisconductID) { throw new Exception("已经有相同的违纪名单,请勿重复申请。"); } this.SetModifyStatus(misconduct); } misconduct.UserID = misconductView.UserID; misconduct.SchoolyearID = misconductView.SchoolyearID; misconduct.CoursematerialID = misconductView.CoursematerialID; misconduct.ExamsCategoryID = misconductView.ExamsCategoryID; misconduct.ExamsStateID = misconductView.ExamsStateID; misconduct.Reason = misconductView.Reason; this.UnitOfWork.Commit(); } public void Delete(IList misconductIDList) { this.UnitOfWork.Remove(x => misconductIDList.Contains(x.MisconductID)); this.UnitOfWork.Commit(); } public List GetMisconductExamsStateList() { var misconductIDList = this.ExamsStateSettingDAL.GetMisconductIDList().ToList(); return DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExamsState).Where(x => misconductIDList.Contains(x.Value)).ToList(); } public ViewModel.ScoreManage.MisconductView GetMisconductView(Guid misconductID) { var statusList = this.GetStatusViewList(); var misconductView = this.MisconductDAL.GetMisconductViewQueryable(x => x.MisconductID == misconductID) .FirstOrDefault(); if (misconductView != null) { var recordStatus = statusList.FirstOrDefault(x => x.ID == misconductView.RecordStatus); if (recordStatus != null) { misconductView.RecordStatusName = recordStatus.Name; } } return misconductView; } public IGridResultSet GetMisconductCoursematerialGridView( ConfiguretView conditions, Guid? schoolyearID, Guid? userID, int? pageIndex = null, int? pageSize = null) { Expression> schoolyearExp = (x => x.SchoolyearID == schoolyearID); Expression> studentExp = (x => x.UserID == userID); var query = this.MisconductDAL.GetMisconductCoursematerialViewQueryable(schoolyearExp, studentExp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize); return result; } public void OnApproveEnd(IList misconductIDList, Guid? userID) { ScoreServices.Value.RefreshMisconductState(misconductIDList); } public void OnApproveEnds(IList misconductIDList, Guid? userID) { ScoreServices.Value.RefreshCancelMisconductState(misconductIDList); } public List GetMisconductViewListByFinalExamination(Guid? finalExaminationID) { var endStatus = this.GetCorrectEndStatus(); var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault(); if (finalExaminationView == null) { return new List(); } Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SchoolyearID == finalExaminationView.SchoolyearID && x.CoursematerialID == finalExaminationView.CoursematerialID && x.ExamsCategoryID == finalExaminationView.ExamsCategoryID && x.RecordStatus == 3); var statusList = this.GetStatusViewList(); var query = this.MisconductDAL.GetMisconductViewQueryable(exp); var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList(); result.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public void Cancel(List misconductIDList, Guid userID, string comment) { var endStatusID = GetEndStatusID(); var misconductList = MisconductDAL.MisconductRepository.GetList(x => misconductIDList.Contains(x.MisconductID)).ToList(); if (misconductList.Any(x => x.RecordStatus != endStatusID)) { throw new Exception("只能撤回已通过状态的记录。"); } var actionViewList = this.GetActionView(misconductIDList[0], userID); var actionView = actionViewList.FirstOrDefault(); this.Approve(misconductIDList, userID, actionView.ActionID, comment); } public int? GetEndStatusID() { var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description.Contains("[End]")); if (endStatus != null) { return endStatus.ID; } else { return null; } } } }