using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.MinorManage.MinorApply; using EMIS.ViewModel; using EMIS.DataLogic.MinorManage.MinorApply; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.CommonLogic.SystemServices; using EMIS.DataLogic.MinorManage.MinorClass; namespace EMIS.CommonLogic.MinorManage.MinorApply { public class MinorApplyServices : BaseWorkflowServices, IMinorApplyServices { public MinorApplyDAL minorApplyDAL { get; set; } public MinorClassDAL minorClassDAL { get; set; } /// /// 辅修报名审核 /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet MinorApplyViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, int? minorStandardID, int? approvalStatus, int pageIndex, int pageSize) { //结束流程环节ID var endStatusID = this.GetCorrectEndStatus(); //审核流程状态IDList 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> exp = x => true; Expression> expcla = x => true; Expression> expcol = x => true; if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { expcol = expcol.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { expcla = expcla.And(x => x.CF_Grademajor.GradeID == yearID); } if (standardID.HasValue) { expcla = expcla.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { expcla = expcla.And(x => x.ClassmajorID == classmajorID); } if (minorStandardID.HasValue) { exp = exp.And(x => x.CF_Grademinor.StandardID == minorStandardID); } if (approvalStatus.HasValue && approvalStatus > (int)SYS_STATUS.UNUSABLE) { exp = exp.And(x => x.RecordStatus == approvalStatus); } var query = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.GrademajorCode).ThenBy(x => x.GrademinorCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.RecordStatusStr = applyStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } /// /// 辅修报名(Excel) /// /// /// /// /// /// /// /// /// /// public List GetMinorApplyViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, int? minorStandardID, int? approvalStatus, List idList) { //结束流程环节ID var endStatusID = this.GetCorrectEndStatus(); //审核流程状态IDList 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> exp = x => true; Expression> expcla = x => true; Expression> expcol = x => true; if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { expcol = expcol.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { expcla = expcla.And(x => x.CF_Grademajor.GradeID == yearID); } if (standardID.HasValue) { expcla = expcla.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { expcla = expcla.And(x => x.ClassmajorID == classmajorID); } if (minorStandardID.HasValue) { exp = exp.And(x => x.CF_Grademinor.StandardID == minorStandardID); } if (approvalStatus.HasValue && approvalStatus > (int)SYS_STATUS.UNUSABLE) { exp = exp.And(x => x.RecordStatus == approvalStatus); } if (idList.Count > 0 && idList != null) { exp = exp.And(x => idList.Contains(x.StudentMinorRegistID)); } var query = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.GrademajorCode).ThenBy(x => x.GrademinorCode).ThenBy(x => x.LoginID).ToList(); result.ForEach(x => x.RecordStatusStr = applyStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } public void MinorApplyEdit(MinorApplyView minorApplyView) { try { EM_StudentMinorRegist studentMinorRegist = new EM_StudentMinorRegist(); if (minorApplyView.StudentMinorRegistID == null || minorApplyView.StudentMinorRegistID == Guid.Empty) { //新增、复制新增 studentMinorRegist = minorApplyDAL.studentMinorRegistRepository .GetSingle(x => x.SchoolyearID == minorApplyView.SchoolyearID && x.UserID == minorApplyView.CollegeID && x.GrademinorID == minorApplyView.GrademinorID); if (studentMinorRegist != null) { throw new Exception("该学生已存在相同学年学期的辅修报名信息。"); } studentMinorRegist = new EM_StudentMinorRegist(); studentMinorRegist.StudentMinorRegistID = Guid.NewGuid(); studentMinorRegist.GrademinorID = minorApplyView.GrademinorID; studentMinorRegist.SchoolyearID = minorApplyView.SchoolyearID; studentMinorRegist.UserID = minorApplyView.UserID; studentMinorRegist.CreateTime = DateTime.Now; studentMinorRegist.CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; studentMinorRegist.ModifyTime = DateTime.Now; studentMinorRegist.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; UnitOfWork.Add(studentMinorRegist); } else { //修改 studentMinorRegist = minorApplyDAL.studentMinorRegistRepository .GetSingle(x => x.StudentMinorRegistID != minorApplyView.StudentMinorRegistID && x.SchoolyearID == minorApplyView.SchoolyearID && x.UserID == minorApplyView.CollegeID && x.GrademinorID == minorApplyView.GrademinorID); if (studentMinorRegist != null) { throw new Exception("该学生已存在相同学年学期的辅修报名信息。"); } studentMinorRegist = minorApplyDAL.studentMinorRegistRepository .GetSingle(x => x.StudentMinorRegistID == minorApplyView.StudentMinorRegistID); if (studentMinorRegist == null) { throw new Exception("数据有误,请核查。"); } studentMinorRegist = new EM_StudentMinorRegist(); studentMinorRegist.StudentMinorRegistID = Guid.NewGuid(); studentMinorRegist.GrademinorID = minorApplyView.GrademinorID; studentMinorRegist.SchoolyearID = minorApplyView.SchoolyearID; studentMinorRegist.UserID = minorApplyView.UserID; studentMinorRegist.ModifyTime = DateTime.Now; studentMinorRegist.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// public void MinorApplyDelete(IList minorApplyIDList) { try { if (minorApplyIDList.Count > 0) { UnitOfWork.Delete(x => minorApplyIDList.Contains(x.StudentMinorRegistID)); } } catch (Exception ex) { throw new Exception(ex.Message); } } public MinorApplyView GetMinorApplyView(Guid? minorApplyID) { try { var minorApplyView = minorApplyDAL.GetMinorApplyViewQueryable(x => x.StudentMinorRegistID == minorApplyID, x => true, x => true) .SingleOrDefault(); return minorApplyView; } catch (Exception ex) { throw new Exception(ex.Message); } } public void MinorApproveConfirm(List minorApplyIDs, Guid userID, Guid actionID, string comment) { try { //查询对应的审核信息List var minorApplyList = minorApplyDAL.studentMinorRegistRepository .GetList(x => minorApplyIDs.Contains(x.StudentMinorRegistID)).ToList(); var endStatusID = this.GetCorrectEndStatus(); foreach (var minorApplyID in minorApplyIDs) { //查询对应的审核信息 var minorApply = minorApplyList.Where(x => x.StudentMinorRegistID == minorApplyID).SingleOrDefault(); if (minorApply == null) { throw new Exception("数据有误,请核查"); } } //审核 this.Approve(minorApplyIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询辅修专业,下拉框用 /// /// /// public IGridResultSet GetGrademinorGrid(ConfiguretView configuretView) { return null; } public void OnApproveEnd(IList studentMinorRegistIDList, Guid? userID) { try { Expression> exp = x => true; Expression> expcla = x => true; Expression> expcol = x => true; if (studentMinorRegistIDList.Count > 0) { exp = exp.And(x => studentMinorRegistIDList.Contains(x.StudentMinorRegistID)); } var query = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol).ToList(); foreach (var studentMinor in query) { var classMinor = minorClassDAL.classminorRepository.GetSingle(x => x.GrademinorID == studentMinor.GrademinorID && x.RecordStatus == (int)SYS_STATUS.USABLE, (x => x.CF_ClassminorStudent)); if (classMinor == null) { return; } var classmionrStudent = new CF_ClassminorStudent(); classmionrStudent.ClassminorStudentID = Guid.NewGuid(); classmionrStudent.ClassminorID = classMinor.ClassminorID; classmionrStudent.UserID = studentMinor.UserID.Value; SetNewStatus(classmionrStudent); classMinor.CF_ClassminorStudent.Add(classmionrStudent); } UnitOfWork.Commit(); } catch (Exception) { throw; } } } }