123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- 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;
- using EMIS.CommonLogic.StudentManage.StudentStatistics;
- namespace EMIS.CommonLogic.StudentManage.StudentChange
- {
- public class ChangeApplyServices : BaseWorkflowServices<CF_DifferentDynamic>, IChangeApplyServices
- {
- public Lazy<StudentChangeDAL> StudentChangeDAL { get; set; }
- public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
- /// <summary>
- /// 数据范围
- /// </summary>
- public ChangeApplyServices()
- {
- DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege<CF_DifferentDynamic>(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID)));
- }
- /// <summary>
- /// 查询学籍异动申请信息View
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="classmajorID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="changeTypeID"></param>
- /// <param name="inSchoolStatus"></param>
- /// <param name="approvalStatus"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<StudentChangeView> GetChangeApplyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? schoolyearID, int? changeTypeID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize)
- {
- var endStatusID = this.GetCorrectEndStatus();
- var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
- var applyStatusList = this.GetStatusViewList();
- var applyStatusIDList = applyStatusList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
- Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expStudentChange = expStudentChange.And(x => applyStatusIDList.Contains(x.ApprovalStatus));
- if (schoolyearID.HasValue)
- {
- expStudentChange = expStudentChange.And(x => x.SchoolyearID == schoolyearID);
- }
- if (changeTypeID.HasValue)
- {
- expStudentChange = expStudentChange.And(x => x.ChangeTypeID == changeTypeID);
- }
- if (approvalStatus.HasValue)
- {
- expStudentChange = expStudentChange.And(x => x.ApprovalStatus == approvalStatus);
- }
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (classmajorID.HasValue)
- {
- expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
- }
- 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 = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange, 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.SchoolyearValue).ThenBy(x => x.ChangeTypeID).ThenBy(x => x.GradeID).ThenBy(x => x.StandardID)
- .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.StudentNo)
- .ThenByDescending(x => x.ChangeDate).ToGridResultSet<StudentChangeView>(pageIndex, pageSize);
- result.rows.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault());
- return result;
- }
- /// <summary>
- /// 查询学籍异动申请信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="classmajorID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="changeTypeID"></param>
- /// <param name="inSchoolStatus"></param>
- /// <param name="approvalStatus"></param>
- /// <returns></returns>
- public IList<StudentChangeView> GetChangeApplyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? schoolyearID, int? changeTypeID, int? inSchoolStatus, int? approvalStatus)
- {
- var endStatusID = this.GetCorrectEndStatus();
- var approveStatusIDList = this.GetApproveStatusViewList().Select(x => x.ID).ToList();
- var applyStatusList = this.GetStatusViewList();
- var applyStatusIDList = applyStatusList.Where(x => x.ID != endStatusID && !approveStatusIDList.Contains(x.ID)).Select(x => x.ID).ToList();
- Expression<Func<CF_DifferentDynamic, bool>> expStudentChange = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expStudentChange = expStudentChange.And(x => applyStatusIDList.Contains(x.ApprovalStatus));
- if (schoolyearID.HasValue)
- {
- expStudentChange = expStudentChange.And(x => x.SchoolyearID == schoolyearID);
- }
- if (changeTypeID.HasValue)
- {
- expStudentChange = expStudentChange.And(x => x.ChangeTypeID == changeTypeID);
- }
- if (approvalStatus.HasValue)
- {
- expStudentChange = expStudentChange.And(x => x.ApprovalStatus == approvalStatus);
- }
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (classmajorID.HasValue)
- {
- expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
- }
- 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 = StudentChangeDAL.Value.GetStudentChangeViewQueryable(expStudentChange, 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.SchoolyearValue).ThenBy(x => x.ChangeTypeID).ThenBy(x => x.GradeID).ThenBy(x => x.StandardID)
- .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.StudentNo)
- .ThenByDescending(x => x.ChangeDate).ToList();
- result.ForEach(x => x.ApprovalStatusName = applyStatusList.Where(w => w.ID == x.ApprovalStatus).Select(w => w.Name).FirstOrDefault());
- return result;
- }
- /// <summary>
- /// 查询对应的学籍异动信息View
- /// </summary>
- /// <param name="studentChangeID"></param>
- /// <returns></returns>
- public StudentChangeView GetStudentChangeView(Guid? studentChangeID)
- {
- try
- {
- Expression<Func<CF_DifferentDynamic, bool>> 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);
- }
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="studentChangeView"></param>
- public void ChangeApplyEdit(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);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="studentChangeIDs"></param>
- /// <returns></returns>
- public bool ChangeApplyDelete(List<Guid?> 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<CF_DifferentDynamic>(x => studentChangeIDs.Contains(x.StudentChangeID));
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="studentChangeIDs"></param>
- /// <param name="userID"></param>
- /// <param name="comment"></param>
- /// <returns></returns>
- public string ChangeApplySubmit(List<Guid> 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<Guid>();
- var approveIDList = new List<Guid>();
- 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);
- }
- }
- }
- }
|