using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using Bowin.Common.Utility; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.StudentProfile; using EMIS.DataLogic.StudentManage.StudentProfile; using EMIS.CommonLogic.StudentManage.StudentStatistics; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.StudentManage.StudentProfile { public class StudentPunishServices : BaseWorkflowServices, IStudentPunishServices { public Lazy StudentPunishDAL { get; set; } public Lazy InSchoolSettingServices { get; set; } /// /// 数据范围 /// public StudentPunishServices() { DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID))); } /// /// 查询对应的学生处分信息StudentPunishView /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetStudentPunishViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? punishTypeID, int? punishLevelID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize) { var approveStatusList = this.GetStatusViewList(); Expression> expStudentPunish = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { expStudentPunish = expStudentPunish.And(x => x.SchoolyearID == schoolyearID); } if (punishTypeID.HasValue) { expStudentPunish = expStudentPunish.And(x => x.PunishTypeID == punishTypeID); } if (punishLevelID.HasValue) { expStudentPunish = expStudentPunish.And(x => x.PunishLevelID == punishLevelID); } if (approvalStatus.HasValue) { expStudentPunish = expStudentPunish.And(x => x.ApprovalStatus == approvalStatus); } 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 = StudentPunishDAL.Value.GetStudentPunishViewQueryable(expStudentPunish, expStudent); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length) .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的学生处分信息List /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IList GetStudentPunishViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? punishTypeID, int? punishLevelID, int? inSchoolStatus, int? approvalStatus) { var approveStatusList = this.GetStatusViewList(); Expression> expStudentPunish = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { expStudentPunish = expStudentPunish.And(x => x.SchoolyearID == schoolyearID); } if (punishTypeID.HasValue) { expStudentPunish = expStudentPunish.And(x => x.PunishTypeID == punishTypeID); } if (punishLevelID.HasValue) { expStudentPunish = expStudentPunish.And(x => x.PunishLevelID == punishLevelID); } if (approvalStatus.HasValue) { expStudentPunish = expStudentPunish.And(x => x.ApprovalStatus == approvalStatus); } 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 = StudentPunishDAL.Value.GetStudentPunishViewQueryable(expStudentPunish, expStudent); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length) .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToList(); result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的学生处分信息View /// /// /// public StudentPunishView GetStudentPunishView(Guid? studentPunishID) { try { var query = StudentPunishDAL.Value.GetStudentPunishViewQueryable(x => x.StudentPunishID == studentPunishID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑 /// /// public void StudentPunishEdit(StudentPunishView studentPunishView) { try { var approveStatusList = this.GetStatusViewList(); if (approveStatusList == null || approveStatusList.Count() <= 0) { throw new Exception("工作流平台中,学生处分流程未配置,请核查。"); } var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,学生处分流程开始环节未配置,请核查。"); } var studentPunishVerify = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => x.StudentPunishID != studentPunishView.StudentPunishID && x.SchoolyearID == studentPunishView.SchoolyearID && x.UserID == studentPunishView.UserID && x.PunishTypeID == studentPunishView.PunishTypeID).SingleOrDefault(); if (studentPunishVerify == null) { if (studentPunishView.StudentPunishID != Guid.Empty) { var studentPunish = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => x.StudentPunishID == studentPunishView.StudentPunishID).SingleOrDefault(); if (studentPunish == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 studentPunish.PunishLevelID = studentPunishView.PunishLevelID; studentPunish.DocNo = studentPunishView.DocNo; studentPunish.PunishDate = studentPunishView.PunishDate; studentPunish.Reason = studentPunishView.Reason; studentPunish.CancelDocNo = studentPunishView.CancelDocNo; studentPunish.CancelDate = studentPunishView.CancelDate; SetModifyStatus(studentPunish); } } else { //表示新增 var newStudentPunish = new EM_StudentPunish(); newStudentPunish.StudentPunishID = Guid.NewGuid(); newStudentPunish.SchoolyearID = studentPunishView.SchoolyearID; newStudentPunish.UserID = studentPunishView.UserID; newStudentPunish.PunishTypeID = studentPunishView.PunishTypeID; newStudentPunish.PunishLevelID = studentPunishView.PunishLevelID; newStudentPunish.DocNo = studentPunishView.DocNo; newStudentPunish.PunishDate = studentPunishView.PunishDate; newStudentPunish.Reason = studentPunishView.Reason; newStudentPunish.CancelDocNo = studentPunishView.CancelDocNo; newStudentPunish.CancelDate = studentPunishView.CancelDate; newStudentPunish.ApprovalStatus = startStatusID; SetNewStatus(newStudentPunish); UnitOfWork.Add(newStudentPunish); } } else { throw new Exception("已存在相同的学生处分信息,请核查。"); } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool StudentPunishDelete(List studentPunishIDs) { try { var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,学生处分流程开始环节流程未配置,请核查"); } var approvalStatusList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).Select(x => x.ApprovalStatus).ToList(); foreach (var approvalStatus in approvalStatusList) { if (approvalStatus != startStatusID) { throw new Exception("只能对未提交状态的信息进行删除"); } } UnitOfWork.Delete(x => studentPunishIDs.Contains(x.StudentPunishID)); return true; } catch (Exception) { throw; } } /// /// 提交 /// /// /// /// /// public string StudentPunishSubmit(List studentPunishIDs, Guid userID, string comment = "") { try { var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,学生处分流程开始环节流程未配置,请核查。"); } var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList(); int success = 0; string tipMessage = null; var submitIDList = new List(); var approveIDList = new List(); foreach (var studentPunish in studentPunishList) { if (studentPunish.ApprovalStatus == startStatusID) { submitIDList.Add(studentPunish.StudentPunishID); } else { approveIDList.Add(studentPunish.StudentPunishID); } success++; } if (submitIDList.Count > 0) { this.StartUp(submitIDList, userID, comment); } if (approveIDList.Count > 0) { this.Approve(approveIDList, userID, Guid.Empty, comment); } tipMessage = success + "条"; return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 审核确定(批量) /// /// /// /// /// public void StudentPunishApproveConfirm(List studentPunishIDs, Guid userID, Guid actionID, string comment) { try { var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList(); foreach (var studentPunishID in studentPunishIDs) { var studentPunish = studentPunishList.Where(x => x.StudentPunishID == studentPunishID).SingleOrDefault(); if (studentPunish == null) { throw new Exception("数据有误,请核查。"); } } this.Approve(studentPunishIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 撤销确定(批量) /// /// /// /// public void StudentPunishCancelConfirm(List studentPunishIDs, Guid userID, string comment) { try { var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList(); foreach (var studentPunishID in studentPunishIDs) { var studentPunish = studentPunishList.Where(x => x.StudentPunishID == studentPunishID).SingleOrDefault(); if (studentPunish == null) { throw new Exception("数据有误,请核查。"); } } var actionID = this.GetActionView(studentPunishIDs[0].Value, userID).Where(x => (x.Description ?? "").Contains("[CANCEL]")).Select(x => x.ActionID).SingleOrDefault(); this.Approve(studentPunishIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 撤销确定(批量) /// /// /// /// /// /// public void StudentPunishCancelConfirm(List studentPunishIDs, Guid userID, string cancelDocNo, DateTime? cancelDate, string comment) { try { var newStudentPunishUpList = new List(); var studentPunishList = StudentPunishDAL.Value.StudentPunishRepository.GetList(x => studentPunishIDs.Contains(x.StudentPunishID)).ToList(); foreach (var studentPunishID in studentPunishIDs) { var studentPunish = studentPunishList.Where(x => x.StudentPunishID == studentPunishID).SingleOrDefault(); if (studentPunish == null) { throw new Exception("数据有误,请核查。"); } studentPunish.CancelDocNo = cancelDocNo; studentPunish.CancelDate = cancelDate; this.SetModifyStatus(studentPunish); newStudentPunishUpList.Add(studentPunish); } var actionID = this.GetActionView(studentPunishIDs[0].Value, userID).Where(x => (x.Description ?? "").Contains("[CANCEL]")).Select(x => x.ActionID).SingleOrDefault(); using (TransactionScope ts = new TransactionScope()) { this.Approve(studentPunishIDs.Select(x => x.Value).ToList(), userID, actionID, comment); this.UnitOfWork.BatchUpdate(newStudentPunishUpList); ts.Complete(); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 流程结束跳转函数(工作流平台中配置) /// /// /// public void OnApproveEnd(List studentPunishIDList, Guid? userID) { throw new NotImplementedException(); } } }