using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Utility; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.EnrollManage.SpecialtyManage; using EMIS.DataLogic.EnrollManage.SpecialtyManage; namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage { public class SpecialtyClassSettingServices : BaseServices, ISpecialtyClassSettingServices { public SpecialtyClassSettingDAL SpecialtyClassSettingDAL { get; set; } /// /// 查询对应的专业分班信息View /// /// /// /// /// /// /// /// /// public IGridResultSet GetSpecialtyClassSettingViewGrid(ConfiguretView configuretView, int? standardID, int? educationID, int? learningformID, string learnSystem, int pageIndex, int pageSize) { //专业分班 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = SpecialtyClassSettingDAL.GetSpecialtyClassSettingViewQueryable(exp); if (standardID.HasValue) { //专业ID(Value) 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()); } return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的专业分班信息List /// /// /// /// /// /// /// public IList GetSpecialtyClassSettingViewList(ConfiguretView configuretView, int? standardID, int? educationID, int? learningformID, string learnSystem) { //专业分班 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = SpecialtyClassSettingDAL.GetSpecialtyClassSettingViewQueryable(exp); if (standardID.HasValue) { //专业ID(Value) 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()); } return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToList(); } /// /// 根据专业分班ID查询对应的专业分班信息SpecialtyClassSettingView /// /// /// public SpecialtyClassSettingView GetSpecialtyClassSettingView(Guid? specialtyClassSettingID) { try { var query = SpecialtyClassSettingDAL.GetSpecialtyClassSettingViewQueryable(x => x.SpecialtyClassSettingID == specialtyClassSettingID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 专业分班批量新增(业务主键:专业信息ID) /// /// /// /// public string SpecialtyClassSettingBatchAdd(List specialtyIDList, SpecialtyClassSettingView specialtyClassSettingView) { try { //专业分班 Expression> expSpecialtyClassSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expSpecialtyClassSetting = expSpecialtyClassSetting.And(x => specialtyIDList.Contains(x.SpecialtyID)); //查询对应的专业分班信息List var specialtyClassSettingList = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository.GetList(expSpecialtyClassSetting).ToList(); int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 List specialtyClassSettingInList = new List(); foreach (var specialtyID in specialtyIDList) { var specialtyClassSettingVerify = specialtyClassSettingList.Where(x => x.SpecialtyID == specialtyID).SingleOrDefault(); if (specialtyClassSettingVerify == null) { //新增 var specialtyClassSetting = new CF_SpecialtyClassSetting(); specialtyClassSetting.SpecialtyClassSettingID = Guid.NewGuid(); specialtyClassSetting.SpecialtyID = specialtyID; specialtyClassSetting.PlanRecruitStudentCount = 0; specialtyClassSetting.ClassArrangeStudentCount = 0; specialtyClassSetting.ClassMaxStudentCount = 0; specialtyClassSetting.ClassNumber = 1; SetNewStatus(specialtyClassSetting); specialtyClassSettingInList.Add(specialtyClassSetting); success++; } else { //表示已存在相同的专业分班信息 fail++; } } //批量插入 UnitOfWork.BulkInsert(specialtyClassSettingInList); if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:已存在相同的专业分班信息,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询专业分班中未新增的专业信息SpecialtyView /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSpecialtyViewNoAdd(ConfiguretView configuretView, 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> expSpecialtyClassSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = SpecialtyClassSettingDAL.GetSpecialtyViewNoAddQueryable(expSpecialty, expSpecialtyClassSetting); //查询条件 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); } /// /// 编辑(新增、修改,业务主键:专业信息ID) /// /// public void SpecialtyClassSettingEdit(SpecialtyClassSettingView specialtyClassSettingView) { try { //查询数据库进行验证 var specialtyClassSettingVerification = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository.GetList(x => x.SpecialtyClassSettingID != specialtyClassSettingView.SpecialtyClassSettingID && x.SpecialtyID == specialtyClassSettingView.SpecialtyID).SingleOrDefault(); if (specialtyClassSettingVerification == null) { //数据有误验证 if (specialtyClassSettingView.SpecialtyClassSettingID != Guid.Empty) { var specialtyClassSetting = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository .GetList(x => x.SpecialtyClassSettingID == specialtyClassSettingView.SpecialtyClassSettingID).SingleOrDefault(); if (specialtyClassSetting == null) { throw new Exception("数据有误,请核查"); } else { //表示修改 specialtyClassSetting.SpecialtyID = specialtyClassSettingView.SpecialtyID; specialtyClassSetting.PlanRecruitStudentCount = specialtyClassSettingView.PlanRecruitStudentCount; specialtyClassSetting.ClassArrangeStudentCount = specialtyClassSettingView.ClassArrangeStudentCount; specialtyClassSetting.ClassMaxStudentCount = specialtyClassSettingView.ClassMaxStudentCount; specialtyClassSetting.ClassNumber = specialtyClassSettingView.ClassNumber; SetModifyStatus(specialtyClassSetting); } } else { //表示新增 CF_SpecialtyClassSetting specialtyClassSetting = new CF_SpecialtyClassSetting(); specialtyClassSetting.SpecialtyClassSettingID = Guid.NewGuid(); specialtyClassSetting.SpecialtyID = specialtyClassSettingView.SpecialtyID; specialtyClassSetting.PlanRecruitStudentCount = specialtyClassSettingView.PlanRecruitStudentCount; specialtyClassSetting.ClassArrangeStudentCount = specialtyClassSettingView.ClassArrangeStudentCount; specialtyClassSetting.ClassMaxStudentCount = specialtyClassSettingView.ClassMaxStudentCount; specialtyClassSetting.ClassNumber = specialtyClassSettingView.ClassNumber; SetNewStatus(specialtyClassSetting); UnitOfWork.Add(specialtyClassSetting); } } else { throw new Exception("已存在相同的专业分班信息,请核查"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 批量修改(计划招生人数、每班预招人数、每班最大人数) /// /// /// /// /// /// public string BatchModify(List specialtyClassSettingIDList, int? planRecruitStudentCount, int? classArrangeStudentCount, int? classMaxStudentCount) { try { //查询对应的专业分班信息 var specialtyClassSettingList = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository.GetList(x => specialtyClassSettingIDList.Contains(x.SpecialtyClassSettingID)).ToList(); int fail = 0; int success = 0; string tipMessage = null; //提示消息 List specialtyClassSettingUpList = new List(); foreach (var specialtyClassSetting in specialtyClassSettingList) { if (planRecruitStudentCount != null) { if (specialtyClassSetting.ClassArrangeStudentCount > specialtyClassSetting.ClassMaxStudentCount) { fail++; continue; } else if (planRecruitStudentCount <= 0) { specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount; specialtyClassSetting.ClassNumber = 1; } else if (specialtyClassSetting.ClassArrangeStudentCount <= 0) { specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount; specialtyClassSetting.ClassNumber = 1; } else if (specialtyClassSetting.ClassMaxStudentCount <= 0) { specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount; specialtyClassSetting.ClassNumber = 1; } else { specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount; var classNumber = planRecruitStudentCount.Value / specialtyClassSetting.ClassArrangeStudentCount.Value; var total = classNumber * specialtyClassSetting.ClassMaxStudentCount; if (total >= planRecruitStudentCount) { specialtyClassSetting.ClassNumber = classNumber; } else { specialtyClassSetting.ClassNumber = classNumber + 1; } } SetModifyStatus(specialtyClassSetting); } if (classArrangeStudentCount != null) { if (classArrangeStudentCount > specialtyClassSetting.ClassMaxStudentCount) { fail++; continue; } else if (classArrangeStudentCount <= 0) { specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount; specialtyClassSetting.ClassNumber = 1; } else if (specialtyClassSetting.PlanRecruitStudentCount <= 0) { specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount; specialtyClassSetting.ClassNumber = 1; } else if (specialtyClassSetting.ClassMaxStudentCount <= 0) { specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount; specialtyClassSetting.ClassNumber = 1; } else { specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount; var classNumber = specialtyClassSetting.PlanRecruitStudentCount.Value / classArrangeStudentCount.Value; var total = classNumber * specialtyClassSetting.ClassMaxStudentCount; if (total >= specialtyClassSetting.PlanRecruitStudentCount) { specialtyClassSetting.ClassNumber = classNumber; } else { specialtyClassSetting.ClassNumber = classNumber + 1; } } SetModifyStatus(specialtyClassSetting); } if (classMaxStudentCount != null) { if (specialtyClassSetting.ClassArrangeStudentCount > classMaxStudentCount) { fail++; continue; } else if (classMaxStudentCount <= 0) { specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount; specialtyClassSetting.ClassNumber = 1; } else if (specialtyClassSetting.PlanRecruitStudentCount <= 0) { specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount; specialtyClassSetting.ClassNumber = 1; } else if (specialtyClassSetting.ClassArrangeStudentCount <= 0) { specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount; specialtyClassSetting.ClassNumber = 1; } else { specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount; var classNumber = specialtyClassSetting.PlanRecruitStudentCount.Value / specialtyClassSetting.ClassArrangeStudentCount.Value; var total = classNumber * classMaxStudentCount; if (total >= specialtyClassSetting.PlanRecruitStudentCount) { specialtyClassSetting.ClassNumber = classNumber; } else { specialtyClassSetting.ClassNumber = classNumber + 1; } } SetModifyStatus(specialtyClassSetting); } specialtyClassSettingUpList.Add(specialtyClassSetting); success++; } //批量统一提交更新 if (specialtyClassSettingUpList != null && specialtyClassSettingUpList.Count() > 0) { UnitOfWork.BatchUpdate(specialtyClassSettingUpList); } if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:每班预招人数不能大于每班最大人数"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool SpecialtyClassSettingDelete(List specialtyClassSettingIDList) { try { UnitOfWork.Delete(x => specialtyClassSettingIDList.Contains(x.SpecialtyClassSettingID)); return true; } catch (Exception) { throw; } } } }