using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Transactions; using Bowin.Common.Utility; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.SystemView; using EMIS.ViewModel.EnrollManage.SpecialtyManage; using EMIS.DataLogic.EnrollManage.SpecialtyManage; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage { public class SpecialtyApplyServices : BaseWorkflowServices, ISpecialtyApplyServices { public SpecialtyApplyDAL specialtyApplyDAL { get; set; } /// /// 数据范围 /// public SpecialtyApplyServices() { DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege(x, y, (w => w.CollegeID))); } /// /// 查询对应的专业申请信息View /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSpecialtyApplyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, 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> expSpecialtyApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expSpecialtyApply = expSpecialtyApply.And(x => applyStatusIDList.Contains(x.ApprovalStatus)); if (collegeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.GradeID == gradeID); } if (approvalStatus.HasValue) { //审批状态 expSpecialtyApply = expSpecialtyApply.And(x => x.ApprovalStatus == approvalStatus); } var query = specialtyApplyDAL.GetSpecialtyApplyViewQueryable(expSpecialtyApply); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } 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.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode).ThenByDescending(x => x.GradeID).ThenBy(x => x.StandardName) .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem) .ThenBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = applyStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的专业申请信息List /// /// /// /// /// /// /// /// /// /// /// public List GetSpecialtyApplyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? approvalStatus) { //结束流程环节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> expSpecialtyApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expSpecialtyApply = expSpecialtyApply.And(x => applyStatusIDList.Contains(x.ApprovalStatus)); if (collegeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.GradeID == gradeID); } if (approvalStatus.HasValue) { //审批状态 expSpecialtyApply = expSpecialtyApply.And(x => x.ApprovalStatus == approvalStatus); } var query = specialtyApplyDAL.GetSpecialtyApplyViewQueryable(expSpecialtyApply); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } 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.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode).ThenByDescending(x => x.GradeID).ThenBy(x => x.StandardName) .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.CreateTime).ToList(); result.ForEach(x => x.ApprovalStatusName = applyStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的专业审核信息View /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSpecialtyAuditingViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? approvalStatus, int pageIndex, int pageSize) { var approveStatusList = this.GetApproveStatusViewList(); var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); //专业申请 Expression> expSpecialtyApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expSpecialtyApply = expSpecialtyApply.And(x => approveStatusIDList.Contains(x.ApprovalStatus)); if (collegeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.GradeID == gradeID); } if (approvalStatus.HasValue) { //审批状态 expSpecialtyApply = expSpecialtyApply.And(x => x.ApprovalStatus == approvalStatus); } var query = specialtyApplyDAL.GetSpecialtyApplyViewQueryable(expSpecialtyApply); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } 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.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode).ThenByDescending(x => x.GradeID).ThenBy(x => x.StandardName) .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的专业审核信息List /// /// /// /// /// /// /// /// /// /// /// public IList GetSpecialtyAuditingViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? approvalStatus) { var approveStatusList = this.GetApproveStatusViewList(); var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); //专业申请 Expression> expSpecialtyApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expSpecialtyApply = expSpecialtyApply.And(x => approveStatusIDList.Contains(x.ApprovalStatus)); if (collegeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.GradeID == gradeID); } if (approvalStatus.HasValue) { //审批状态 expSpecialtyApply = expSpecialtyApply.And(x => x.ApprovalStatus == approvalStatus); } var query = specialtyApplyDAL.GetSpecialtyApplyViewQueryable(expSpecialtyApply); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } 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.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode).ThenByDescending(x => x.GradeID).ThenBy(x => x.StandardName) .ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ThenBy(x => x.CreateTime).ToList(); result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询专业审核信息CF_SpecialtyApply(只查询审核状态信息,根据业务主键:专业信息ID、院系所、年级、学期) /// /// /// /// /// /// public CF_SpecialtyApply GetSpecialtyApply(Guid? specialtyID, Guid? collegeID, int? gradeID, int? semesterID) { try { var approveStatusList = this.GetApproveStatusViewList(); var aprroveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); Expression> exp = (x => aprroveStatusIDList.Contains(x.ApprovalStatus)); if (specialtyID.HasValue) { exp = exp.And(x => x.SpecialtyID == specialtyID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { exp = exp.And(x => x.GradeID == gradeID); } if (semesterID.HasValue) { exp = exp.And(x => x.SemesterID == semesterID); } return specialtyApplyDAL.specialtyApplyRepository.GetSingle(exp); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询专业申请信息SpecialtyApplyView /// /// /// public SpecialtyApplyView GetSpecialtyApplyView(Guid? specialtyApplyID) { try { var query = specialtyApplyDAL.GetSpecialtyApplyViewQueryable(x => x.SpecialtyApplyID == specialtyApplyID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 申请(批量新增,业务主键:专业信息ID、年级、学期、院系所) /// /// /// /// public string SpecialtyApplyBatchAdd(List specialtyIDList, SpecialtyApplyView specialtyApplyView) { try { //查询对应的工作流程环节状态信息View var approveStatusList = this.GetStatusViewList(); if (approveStatusList == null || approveStatusList.Count() <= 0) { throw new Exception("工作流平台中,招生专业流程未配置,请核查。"); } //查询工作流程开始环节状态 var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,招生专业流程开始环节未配置,请核查。"); } //专业申请 Expression> expSpecialtyApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expSpecialtyApply = expSpecialtyApply.And(x => specialtyIDList.Contains(x.SpecialtyID)); //查询对应的专业申请信息List var specialtyApplyList = specialtyApplyDAL.specialtyApplyRepository.GetList(expSpecialtyApply).ToList(); int success = 0; int fail = 0; string tipMessage = null; List specialtyApplyInList = new List(); foreach (var specialtyID in specialtyIDList) { var specialtyApplyVerify = specialtyApplyList.Where(x => x.SpecialtyID == specialtyID && x.CollegeID == specialtyApplyView.CollegeID && x.GradeID == specialtyApplyView.GradeID && x.SemesterID == specialtyApplyView.SemesterID).SingleOrDefault(); if (specialtyApplyVerify == null) { //新增 var specialtyApply = new CF_SpecialtyApply(); specialtyApply.SpecialtyApplyID = Guid.NewGuid(); specialtyApply.SpecialtyID = specialtyID; specialtyApply.CollegeID = specialtyApplyView.CollegeID; specialtyApply.GradeID = specialtyApplyView.GradeID; specialtyApply.SemesterID = specialtyApplyView.SemesterID; specialtyApply.ApprovalStatus = startStatusID; specialtyApply.Remark = specialtyApplyView.Remark; SetNewStatus(specialtyApply); specialtyApplyInList.Add(specialtyApply); success++; } else { //表示已存在相同的专业申请信息 fail++; } } UnitOfWork.BulkInsert(specialtyApplyInList); if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:已存在相同的专业申请信息,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询专业申请中的未申请专业信息SpecialtyView /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSpecialtyViewNoApply(ConfiguretView configuretView, Guid? collegeID, int? gradeID, int? semesterID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? scienceclassID, int pageIndex, int pageSize) { //专业信息(只查询启用状态的专业信息) Expression> expSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (standardID.HasValue) { expSpecialty = expSpecialty.And(x => x.StandardID == standardID); } if (educationID.HasValue) { expSpecialty = expSpecialty.And(x => x.EducationID == educationID); } if (learningformID.HasValue) { expSpecialty = expSpecialty.And(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); expSpecialty = expSpecialty.And(x => x.LearnSystem == LearnSystems); } if (scienceclassID.HasValue) { expSpecialty = expSpecialty.And(x => x.ScienceclassID == scienceclassID); } //专业申请 Expression> expSpecialtyApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.GradeID == gradeID); } if (semesterID.HasValue) { expSpecialtyApply = expSpecialtyApply.And(x => x.SemesterID == semesterID); } //招生专业 Expression> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID); } if (semesterID.HasValue) { expRecruitSpecialty = expRecruitSpecialty.And(x => x.SemesterID == semesterID); } var query = specialtyApplyDAL.GetSpecialtyViewNoApplyQueryable(expSpecialty, expSpecialtyApply, expRecruitSpecialty); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet(pageIndex, pageSize); } /// /// 删除 /// /// /// public bool SpecialtyApplyDelete(List specialtyApplyIDs) { try { //var startStatusID = this.GetStartStatus(); //if (startStatusID == null) //{ // throw new Exception("工作流平台中,招生专业流程开始环节流程未配置,请核查"); //} //var approvalStatusList = specialtyApplyDAL.specialtyApplyRepository.GetList(x => specialtyApplyIDs.Contains(x.SpecialtyApplyID)).Select(x => x.ApprovalStatus).ToList(); //foreach (var approvalStatus in approvalStatusList) //{ // if (approvalStatus != startStatusID) // { // throw new Exception("只能对未提交状态的信息进行删除"); // } //} UnitOfWork.Delete(x => specialtyApplyIDs.Contains(x.SpecialtyApplyID)); return true; } catch (Exception) { throw; } } /// /// 提交 /// /// /// /// /// public string SpecialtyApplySubmit(List specialtyApplyIDs, Guid userID, string comment = "") { try { //查询招生专业工作流程开始环节状态 var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,招生专业流程开始环节流程未配置,请核查"); } //查询对应的专业申请信息List var specialtyApplyList = specialtyApplyDAL.specialtyApplyRepository.GetList(x => specialtyApplyIDs.Contains(x.SpecialtyApplyID)).ToList(); int success = 0; //成功 string tipMessage = null; //提示消息 var submitIDList = new List(); var approveIDList = new List(); foreach (var specialtyApply in specialtyApplyList) { if (specialtyApply.ApprovalStatus == startStatusID) { submitIDList.Add(specialtyApply.SpecialtyApplyID); } else { approveIDList.Add(specialtyApply.SpecialtyApplyID); } 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 SpecialtyApproveConfirm(List specialtyApplyIDs, Guid userID, Guid actionID, string comment) { try { //查询对应的专业审核信息List var specialtyApplyList = specialtyApplyDAL.specialtyApplyRepository.GetList(x => specialtyApplyIDs.Contains(x.SpecialtyApplyID)).ToList(); foreach (var specialtyApplyID in specialtyApplyIDs) { //查询对应的专业审核信息 var specialtyApply = specialtyApplyList.Where(x => x.SpecialtyApplyID == specialtyApplyID).SingleOrDefault(); if (specialtyApply == null) { throw new Exception("数据有误,请核查。"); } } //审核 this.Approve(specialtyApplyIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的流程审批步骤详细信息(暂时不用) /// /// /// public IGridResultSet GetWorkflowApproveHistoryView(Guid? specialtyApplyID) { try { var query = this.GetApproveHistoryViewList((Guid)specialtyApplyID).ToList(); return query.AsQueryable().ToGridResultSet(0, 100); } catch (Exception) { throw; } } /// /// 流程结束跳转函数(工作流平台中配置) /// 注:需对招生专业信息进行处理(根据业务主键处理,专业信息ID、院系所、年级、学期) /// /// /// public void OnApproveEnd(List specialtyApplyIDList, Guid? userID) { try { //查询对应的专业申请信息List var specialtyApplyList = specialtyApplyDAL.specialtyApplyRepository.GetList(x => specialtyApplyIDList.Contains(x.SpecialtyApplyID)).ToList(); //招生专业 Expression> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //查询招生专业信息 var recruitSpecialtyList = specialtyApplyDAL.recruitSpecialtyRepository.GetList(expRecruitSpecialty).ToList(); //流程审核通过结束状态 var endApproveStatusID = this.GetCorrectEndStatus(); List recruitSpecialtyInList = new List(); List recruitSpecialtyUpList = new List(); foreach (var specialtyApply in specialtyApplyList) { //对招生专业信息进行验证(专业信息ID、院系所ID、年级、学期) var recruitSpecialtyEntity = recruitSpecialtyList.Where(x => x.SpecialtyID == specialtyApply.SpecialtyID && x.CollegeID == specialtyApply.CollegeID && x.GradeID == specialtyApply.GradeID && x.SemesterID == specialtyApply.SemesterID).SingleOrDefault(); if (recruitSpecialtyEntity == null) { //新增 var recruitSpecialty = new CF_RecruitSpecialty(); recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid(); recruitSpecialty.SpecialtyApplyID = specialtyApply.SpecialtyApplyID; recruitSpecialty.SpecialtyID = specialtyApply.SpecialtyID; recruitSpecialty.CollegeID = specialtyApply.CollegeID; recruitSpecialty.GradeID = specialtyApply.GradeID; recruitSpecialty.SemesterID = specialtyApply.SemesterID; recruitSpecialty.ApprovalStatus = endApproveStatusID; recruitSpecialty.isGenerated = false; recruitSpecialty.Remark = specialtyApply.Remark; SetNewStatus(recruitSpecialty); recruitSpecialtyInList.Add(recruitSpecialty); } else { //修改 recruitSpecialtyEntity.SpecialtyApplyID = specialtyApply.SpecialtyApplyID; recruitSpecialtyEntity.ApprovalStatus = endApproveStatusID; SetModifyStatus(recruitSpecialtyEntity); recruitSpecialtyUpList.Add(recruitSpecialtyEntity); } } using (TransactionScope ts = new TransactionScope()) { //批量统一提交更新 if (recruitSpecialtyInList != null && recruitSpecialtyInList.Count() > 0) { this.UnitOfWork.BulkInsert(recruitSpecialtyInList); } //批量统一提交更新 if (recruitSpecialtyUpList != null && recruitSpecialtyUpList.Count() > 0) { this.UnitOfWork.BatchUpdate(recruitSpecialtyUpList); } ts.Complete(); } } catch (Exception) { throw; } } } }