using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.StudentChange; using EMIS.DataLogic.StudentManage.StudentChange; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.StudentWeb.Change { public class StudentChangeServices : BaseWorkflowServices, IStudentChangeServices { public Lazy StudentChangeDAL { get; set; } /// /// /// public StudentChangeServices() { } /// /// 查询学生异动申请信息View /// /// /// /// /// /// public IGridResultSet GetStudentChangeViewGrid(ConfiguretView configuretView, Guid? userID, int pageIndex, int pageSize) { var applyStatusList = this.GetStatusViewList(); Expression> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentChange = expStudentChange.And(x => x.UserID == userID); var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query.OrderByDescending(x => x.SchoolyearValue).ThenByDescending(x => x.ChangeDate).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } /// /// 查询学生异动申请信息List /// /// /// /// public IList GetStudentChangeViewList(ConfiguretView configuretView, Guid? userID) { var applyStatusList = this.GetStatusViewList(); Expression> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentChange = expStudentChange.And(x => x.UserID == userID); var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query.OrderByDescending(x => x.SchoolyearValue).ThenByDescending(x => x.ChangeDate).ToList(); result.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault()); return result; } /// /// 查询对应的学生异动信息View /// /// /// public StudentChangeView GetStudentChangeView(Guid? studentChangeID) { try { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.StudentChangeID == studentChangeID); var query = StudentChangeDAL.Value.GetStudentChangeViewQueryable(exp).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑 /// /// public void StudentChangeEdit(StudentChangeView studentChangeView) { try { var workflowStatusViewList = this.GetStatusViewList(); if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } var endStatusID = this.GetCorrectEndStatus(); if (endStatusID == null) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); var applyStatusIDList = workflowStatusViewList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList(); var studentChangeVerify = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => x.StudentChangeID != studentChangeView.StudentChangeID && x.UserID == studentChangeView.UserID && x.SchoolyearID == studentChangeView.SchoolyearID && x.ChangeTypeID == studentChangeView.ChangeTypeID).SingleOrDefault(); if (studentChangeVerify == null) { if (studentChangeView.StudentChangeID != Guid.Empty) { var studentChange = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => x.StudentChangeID == studentChangeView.StudentChangeID).SingleOrDefault(); if (studentChange == null) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } else { if (applyStatusIDList.Any(x => x == studentChange.ApprovalStatus)) { studentChange.UserID = studentChangeView.UserID; studentChange.SchoolyearID = studentChangeView.SchoolyearID; studentChange.ChangeTypeID = studentChangeView.ChangeTypeID; studentChange.BeforeClassmajorID = studentChangeView.BeforeClassmajorID; studentChange.BeforeInSchoolStatusID = studentChangeView.BeforeInSchoolStatusID; studentChange.BeforeStudentStatus = studentChangeView.BeforeStudentStatus; studentChange.AfterClassmajorID = studentChangeView.AfterClassmajorID; studentChange.AfterInSchoolStatusID = studentChangeView.AfterInSchoolStatusID; studentChange.AfterStudentStatus = studentChangeView.AfterStudentStatus; studentChange.ReturnSchoolyearID = studentChangeView.ReturnSchoolyearID; studentChange.ChangeReasonID = studentChangeView.ChangeReasonID; studentChange.ChangeDate = studentChangeView.ChangeDate; studentChange.Description = studentChangeView.Description; studentChange.Remark = studentChangeView.Remark; SetModifyStatus(studentChange); } else { throw new Exception("只能修改未提交、已退回状态的信息,请核查。"); } } } else { var newStudentChange = new CF_DifferentDynamic(); newStudentChange.StudentChangeID = Guid.NewGuid(); newStudentChange.UserID = studentChangeView.UserID; newStudentChange.SchoolyearID = studentChangeView.SchoolyearID; newStudentChange.ChangeTypeID = studentChangeView.ChangeTypeID; newStudentChange.BeforeClassmajorID = studentChangeView.BeforeClassmajorID; newStudentChange.BeforeInSchoolStatusID = studentChangeView.BeforeInSchoolStatusID; newStudentChange.BeforeStudentStatus = studentChangeView.BeforeStudentStatus; newStudentChange.AfterClassmajorID = studentChangeView.AfterClassmajorID; newStudentChange.AfterInSchoolStatusID = studentChangeView.AfterInSchoolStatusID; newStudentChange.AfterStudentStatus = studentChangeView.AfterStudentStatus; newStudentChange.ReturnSchoolyearID = studentChangeView.ReturnSchoolyearID; newStudentChange.ChangeApplyTypeID = (int)CF_ChangeApplyType.Normal; newStudentChange.ChangeReasonID = studentChangeView.ChangeReasonID; newStudentChange.ChangeDate = studentChangeView.ChangeDate; newStudentChange.Description = studentChangeView.Description; newStudentChange.ApprovalStatus = startStatusID; newStudentChange.Remark = studentChangeView.Remark; SetNewStatus(newStudentChange); UnitOfWork.Add(newStudentChange); } } else { throw new Exception("已存在相同的异动申请信息,请核查。"); } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool StudentChangeDelete(List studentChangeIDs) { try { var workflowStatusViewList = this.GetStatusViewList(); if (workflowStatusViewList == null || workflowStatusViewList.Count() <= 0) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } var endStatusID = this.GetCorrectEndStatus(); if (endStatusID == null) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); var applyStatusIDList = workflowStatusViewList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList(); var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList(); foreach (var studentChange in studentChangeList) { if (!applyStatusIDList.Any(x => x == studentChange.ApprovalStatus)) { throw new Exception("只能删除未提交、已退回状态的信息,请刷新页面再次尝试。"); } } UnitOfWork.Delete(x => studentChangeIDs.Contains(x.StudentChangeID)); return true; } catch (Exception) { throw; } } /// /// 提交 /// /// /// /// /// public string StudentChangeSubmit(List studentChangeIDs, Guid userID, string comment = "") { try { var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("数据有误,请联系辅导员或学籍异动负责老师。"); } int success = 0; string tipMessage = null; var submitIDList = new List(); var approveIDList = new List(); var studentChangeList = StudentChangeDAL.Value.StudentChangeRepository.GetList(x => studentChangeIDs.Contains(x.StudentChangeID)).ToList(); foreach (var studentChange in studentChangeList) { if (!studentChange.SchoolyearID.HasValue) { throw new Exception("选择提交的数据存在异常(如:学年学期为空),请核查。"); } if (!studentChange.ChangeTypeID.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动类型为空),请核查。"); } if (!studentChange.BeforeClassmajorID.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动前班级为空),请核查。"); } if (!studentChange.BeforeInSchoolStatusID.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动前在校状态为空),请核查。"); } if (!studentChange.AfterClassmajorID.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动后班级为空),请核查。"); } if (!studentChange.AfterInSchoolStatusID.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动后在校状态为空),请核查。"); } if (!studentChange.ChangeReasonID.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动原因为空),请核查。"); } if (!studentChange.ChangeDate.HasValue) { throw new Exception("选择提交的数据存在异常(如:异动日期为空),请核查。"); } if (studentChange.ApprovalStatus == startStatusID) { submitIDList.Add(studentChange.StudentChangeID); } else { approveIDList.Add(studentChange.StudentChangeID); } 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); } } } }