using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Transactions; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.CacheManage; using EMIS.CommonLogic.SystemServices; namespace EMIS.ExtensionLogic.ServiceLogic.EnrollManage { public class RecruitSpecialtyServices : EMIS.CommonLogic.EnrollManage.SpecialtyManage.RecruitSpecialtyServices { /// /// 流水号生成Services /// public ISerialNumberServices SerialNumberServices { get; set; } /// /// 东莞理工专业班级生成规则(此版本生成规则,暂时这么处理,专业分方向不支持生成) /// /// /// public override string GenerateClass(List recruitSpecialtyIDs) { //生成规则如下: //院系编码:院系所编号+学习形式Value+培养层次Value+6位专业代码,拼出来,如:0112030101 //院系名称:院系所简称+"-"+专业名称+学习形式+培养层次,如:莞城-法学业余专升本 //年级专业编码:年级后两位+院系所编号+学习形式Value+培养层次Value+6位专业代码,拼出来,如:170112030101 //年级专业名称:年级+院系所简称+"-"+专业名称+学习形式+培养层次,如:2017莞城-法学业余专升本 //班级编码:年级+3位流水号,拼出来,如:2017001 //班级名称(区分本专科): //本科:年级后两位+专业名称+"本科"+学习形式+"班"+"("+院系所简称+")" //专科:年级后两位+专业名称+学习形式+"班"+"("+院系所简称+")" try { //查询招生专业信息 var recruitSpecialtyList = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => recruitSpecialtyIDs.Contains(x.RecruitSpecialtyID)).ToList(); //年级ID var gradeIDList = recruitSpecialtyList.Where(x => !string.IsNullOrEmpty(x.GradeID.ToString())).Select(x => x.GradeID).ToList(); //专业信息ID var specialtyIDList = recruitSpecialtyList.Where(x => !string.IsNullOrEmpty(x.SpecialtyID.ToString())).Select(x => x.SpecialtyID).ToList(); //院系所ID var collegeIDList = recruitSpecialtyList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).ToList(); //查询专业信息 var specialtyList = recruitSpecialtyDAL.specialtyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList(); //查询院系所信息 var collegeList = recruitSpecialtyDAL.collegeRepository.Entities.Where(x => collegeIDList.Contains(x.CollegeID)).ToList(); //年级 var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList(); //专业代码、专业名称、专业ID(Value) var standardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard).ToList(); //培养层次(所修学历) var educationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Education).ToList(); //学习形式 var learningFormList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningform).ToList(); //查询对应的院系专业信息 var facultyMajorList = recruitSpecialtyDAL.GetFacultymajorByRecruitSpecialty(x => recruitSpecialtyIDs.Contains(x.RecruitSpecialtyID)).ToList(); //院系专业ID var facultyMajorIDList = facultyMajorList.Where(x => !string.IsNullOrEmpty(x.FacultymajorID.ToString())).Select(x => x.FacultymajorID).ToList(); //查询对应的年级专业信息 var gradeMajorList = recruitSpecialtyDAL.GetGrademajorByRecruitSpecialty(x => recruitSpecialtyIDs.Contains(x.RecruitSpecialtyID), x => facultyMajorIDList.Contains(x.FacultymajorID)).ToList(); //年级专业ID var gradeMajorIDList = gradeMajorList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())).Select(x => x.GrademajorID).ToList(); //查询对应的班级信息 var classMajorList = recruitSpecialtyDAL.GetClassmajorByRecruitSpecialty(x => recruitSpecialtyIDs.Contains(x.RecruitSpecialtyID), x => facultyMajorIDList.Contains(x.FacultymajorID), x => gradeMajorIDList.Contains(x.GrademajorID)).ToList(); //班级信息ID var classMajorIDList = classMajorList.Where(x => !string.IsNullOrEmpty(x.ClassmajorID.ToString())).Select(x => x.ClassmajorID).ToList(); //查询学年学期信息 var schoolyearList = recruitSpecialtyDAL.schoolyearRepository.GetList(x => true).ToList(); //培养层次类型(区分本科、专科) var educationTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationType).ToList(); //查询培养类型设置信息 var educationTypeSettingList = recruitSpecialtyDAL.educationTypeSettingRepository.GetList(x => true).ToList(); //判断培养类型设置信息 if (educationTypeSettingList == null || educationTypeSettingList.Count() <= 0) { throw new Exception("培养类型设置信息未配置,请检查。"); } var facultymajorCode = ""; var facultymajorName = ""; var grademajorCode = ""; var grademajorName = ""; var classmajorCode = ""; var classmajorName = ""; int facultyMajorfail = 0; int gradeMajorfail = 0; int classMajorfail = 0; int fail = 0; int success = 0; string classNoSerialNumber = null; string tipMessage = null; List recruitSpecialtyUpList = new List(); List facultymajorInList = new List(); List grademajorInList = new List(); List classmajorInList = new List(); foreach (var recruitSpecialty in recruitSpecialtyList) { //目前只处理招生专业与专业班级一对一的情况(已存在的情况下,不做处理) //由于存在专业分方向、同一年级专业有多个班的情况(后期可在此处进行扩展:普教版本存在此类情况) //查询对应的院系所信息 var college = collegeList.Where(x => x.CollegeID == recruitSpecialty.CollegeID).SingleOrDefault(); //查询对应的专业信息 var specialty = specialtyList.Where(x => x.SpecialtyID == recruitSpecialty.SpecialtyID).SingleOrDefault(); //专业名称数据字典 var standard = standardList.Where(x => x.Value == specialty.StandardID).SingleOrDefault(); //培养层次(所修学历) var education = educationList.Where(x => x.Value == specialty.EducationID).SingleOrDefault(); //学习形式 var learningForm = learningFormList.Where(x => x.Value == specialty.LearningformID).SingleOrDefault(); //查询培养类型设置对应的信息 var educationTypeSetting = educationTypeSettingList.Where(x => x.EducationID == specialty.EducationID).SingleOrDefault(); //查询对应的培养层次类型 var educationType = educationTypeList.Where(x => x.Value == educationTypeSetting.EducationTypeID).SingleOrDefault(); //计算毕业学年学期Value var graduateSchoolyearValue = (recruitSpecialty.GradeID * 2) - 1 + (recruitSpecialty.SemesterID - 1) + Convert.ToInt32(Math.Ceiling(specialty.LearnSystem.Value * 2 - 1)); //查询对应的学年学期信息 var graduateSchoolyear = schoolyearList.Where(x => x.Value == graduateSchoolyearValue).SingleOrDefault(); //院系专业编号(处理6位专业代码的问题) if (standard.Code.Length > 6) { //院系所编号+学习形式Value+培养层次Value+6位专业代码 facultymajorCode = college.No.Trim() + specialty.LearningformID.ToString().Trim() + specialty.EducationID.ToString().Trim() + standard.Code.Substring(0, 6); } else { //院系所编号+学习形式Value+培养层次Value+6位专业代码 facultymajorCode = college.No.Trim() + specialty.LearningformID.ToString().Trim() + specialty.EducationID.ToString().Trim() + standard.Code.PadLeft(6, '0'); } //院系专业名称(院系所简称+"-"+专业名称+学习形式+培养层次) if (string.IsNullOrEmpty(college.SimpleName)) { facultymajorName = college.Name.Trim() + "-" + standard.Name.Trim() + learningForm.Name.Trim() + education.Name.Trim(); } else { facultymajorName = college.SimpleName.Trim() + "-" + standard.Name.Trim() + learningForm.Name.Trim() + education.Name.Trim(); } //年级专业编号(年级后两位+院系所编号+学习形式Value+培养层次Value+6位专业代码) grademajorCode = recruitSpecialty.GradeID.ToString().Substring(recruitSpecialty.GradeID.ToString().Length - 2) + facultymajorCode; //年级专业名称(年级+院系所简称+"-"+专业名称+学习形式+培养层次) grademajorName = recruitSpecialty.GradeID.ToString() + facultymajorName; //班级编号(年级+3位流水号,注:先获取,再存储) classNoSerialNumber = SerialNumberServices.GetSN("Const.CF_CLASSMAJOR_NO_PREFIX" + recruitSpecialty.GradeID.ToString(), 3); classmajorCode = classNoSerialNumber.Replace("Const.CF_CLASSMAJOR_NO_PREFIX", " ").Trim(); //班级名称(区分本专科): //本科:年级后两位+专业名称+"本科"+学习形式+"班"+"("+院系所简称+")" //专科:年级后两位+专业名称+学习形式+"班"+"("+院系所简称+")" if (educationType.Value == (int)CF_EducationType.UnderGraduate) { //表示本科 if (string.IsNullOrEmpty(college.SimpleName.Trim())) { classmajorName = recruitSpecialty.GradeID.ToString().Substring(recruitSpecialty.GradeID.ToString().Length - 2) + standard.Name.Trim() + educationType.Name.Trim() + learningForm.Name.Trim() + "班" + "(" + college.Name + ")"; } else { classmajorName = recruitSpecialty.GradeID.ToString().Substring(recruitSpecialty.GradeID.ToString().Length - 2) + standard.Name.Trim() + educationType.Name.Trim() + learningForm.Name.Trim() + "班" + "(" + college.SimpleName + ")"; } } else if (educationType.Value == (int)CF_EducationType.Special) { //表示专科 if (string.IsNullOrEmpty(college.SimpleName.Trim())) { classmajorName = recruitSpecialty.GradeID.ToString().Substring(recruitSpecialty.GradeID.ToString().Length - 2) + standard.Name.Trim() + learningForm.Name.Trim() + "班" + "(" + college.Name + ")"; } else { classmajorName = recruitSpecialty.GradeID.ToString().Substring(recruitSpecialty.GradeID.ToString().Length - 2) + standard.Name.Trim() + learningForm.Name.Trim() + "班" + "(" + college.SimpleName + ")"; } } else { //表示无法根据培养层次类型表定位时,默认此规则(由于是基础数据配置暂时不考虑抛出错误) classmajorName = recruitSpecialty.GradeID.ToString().Substring(recruitSpecialty.GradeID.ToString().Length - 2) + standard.Name.Trim() + learningForm.Name.Trim() + education.Name.Trim() + "班" + "(" + college.SimpleName + ")"; } var facultymajor = new CF_Facultymajor(); var grademajor = new CF_Grademajor(); var classmajor = new CF_Classmajor(); //查询院系专业 var facultyMajorVerify = facultyMajorList.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).ToList(); //判断对应的院系专业 if (facultyMajorVerify != null && facultyMajorVerify.Count() > 0) { //表示对应的院系专业信息已存在(可在此处,做更新处理:需准确定位院系专业) if (facultyMajorVerify.Count() == 1) { //查询对应的院系专业(只有一条院系专业可在此处做更新处理) var facultyMajorEntity = facultyMajorVerify.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).SingleOrDefault(); //查询年级专业 var gradeMajorVerify = gradeMajorList.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).ToList(); //判断对应的年级专业 if (gradeMajorVerify != null && gradeMajorVerify.Count() > 0) { //表示对应的年级专业信息已存在(可在此处,做更新处理:需准确定位院系专业) if (gradeMajorVerify.Count() == 1) { //查询对应的年级专业(只有一条年级专业可在此处做更新处理) var gradeMajorEntity = gradeMajorVerify.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).SingleOrDefault(); //查询班级信息 var classMajorVerify = classMajorList.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).ToList(); //判断对应的班级信息 if (classMajorVerify != null && classMajorVerify.Count() > 0) { //表示对应的班级信息已存在(可在此处,做更新处理:需准确定位院系专业) if (classMajorVerify.Count() == 1) { //查询对应的班级信息(只有一条班级信息可在此处做更新处理) var classMajorEntity = classMajorVerify.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).SingleOrDefault(); //(暂时不做更新处理) //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } else { //在此处进行处理特殊情况(存在专业分方向、同一年级专业有多个班的情况) classMajorfail++; continue; } } else { //表示对应的班级信息不存在 classmajor.ClassmajorID = Guid.NewGuid(); classmajor.GrademajorID = gradeMajorEntity.GrademajorID; classmajor.No = classmajorCode; classmajor.Name = classmajorName; classmajor.Abbreviation = classmajor.Name; classmajor.ClassNum = 1; SetNewStatus(classmajor, (int)SYS_STATUS.USABLE); classmajorInList.Add(classmajor); //存储序列号 SerialNumberServices.SetSN("Const.CF_CLASSMAJOR_NO_PREFIX" + recruitSpecialty.GradeID.ToString(), 3); //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } } else { //在此处进行处理特殊情况(存在专业分方向、同一年级专业有多个班的情况) gradeMajorfail++; continue; } } else { //表示对应的年级专业信息不存在 grademajor.GrademajorID = Guid.NewGuid(); grademajor.Code = grademajorCode; grademajor.Name = grademajorName; grademajor.Abbreviation = grademajor.Name; grademajor.GradeID = recruitSpecialty.GradeID; grademajor.SemesterID = recruitSpecialty.SemesterID; grademajor.FacultymajorID = facultyMajorEntity.FacultymajorID; if (graduateSchoolyear == null) { //表示年级专业对应的毕业学期,在学年学期信息中不存在 fail++; continue; } else { grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID; } SetNewStatus(grademajor, (int)SYS_STATUS.USABLE); //表示对应的班级信息不存在 classmajor.ClassmajorID = Guid.NewGuid(); classmajor.GrademajorID = grademajor.GrademajorID; classmajor.No = classmajorCode; classmajor.Name = classmajorName; classmajor.Abbreviation = classmajor.Name; classmajor.ClassNum = 1; SetNewStatus(classmajor, (int)SYS_STATUS.USABLE); grademajorInList.Add(grademajor); classmajorInList.Add(classmajor); //存储序列号 SerialNumberServices.SetSN("Const.CF_CLASSMAJOR_NO_PREFIX" + recruitSpecialty.GradeID.ToString(), 3); //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } } else { //在此处进行处理特殊情况(存在专业分方向、同一年级专业有多个班的情况) facultyMajorfail++; continue; } } else { //表示对应的院系专业信息不存在 facultymajor.FacultymajorID = Guid.NewGuid(); facultymajor.CollegeID = recruitSpecialty.CollegeID; facultymajor.Code = facultymajorCode; facultymajor.Name = facultymajorName; facultymajor.Abbreviation = facultymajor.Name; facultymajor.StandardID = specialty.StandardID; facultymajor.EducationID = specialty.EducationID; facultymajor.LearningformID = specialty.LearningformID; facultymajor.LearnSystem = specialty.LearnSystem; SetNewStatus(facultymajor, (int)SYS_STATUS.USABLE); //表示对应的年级专业信息不存在 grademajor.GrademajorID = Guid.NewGuid(); grademajor.Code = grademajorCode; grademajor.Name = grademajorName; grademajor.Abbreviation = grademajor.Name; grademajor.GradeID = recruitSpecialty.GradeID; grademajor.SemesterID = recruitSpecialty.SemesterID; grademajor.FacultymajorID = facultymajor.FacultymajorID; if (graduateSchoolyear == null) { //表示年级专业对应的毕业学期,在学年学期信息中不存在 fail++; continue; } else { grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID; } SetNewStatus(grademajor, (int)SYS_STATUS.USABLE); //表示对应的班级信息不存在 classmajor.ClassmajorID = Guid.NewGuid(); classmajor.GrademajorID = grademajor.GrademajorID; classmajor.No = classmajorCode; classmajor.Name = classmajorName; classmajor.Abbreviation = classmajor.Name; classmajor.ClassNum = 1; SetNewStatus(classmajor, (int)SYS_STATUS.USABLE); facultymajorInList.Add(facultymajor); grademajorInList.Add(grademajor); classmajorInList.Add(classmajor); //存储序列号 SerialNumberServices.SetSN("Const.CF_CLASSMAJOR_NO_PREFIX" + recruitSpecialty.GradeID.ToString(), 3); //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } } using (TransactionScope ts = new TransactionScope()) { if (facultymajorInList != null && facultymajorInList.Count() > 0) { UnitOfWork.BulkInsert(facultymajorInList); } if (grademajorInList != null && grademajorInList.Count() > 0) { UnitOfWork.BulkInsert(grademajorInList); } if (classmajorInList != null && classmajorInList.Count() > 0) { UnitOfWork.BulkInsert(classmajorInList); } if (recruitSpecialtyUpList != null && recruitSpecialtyUpList.Count() > 0) { UnitOfWork.BatchUpdate(recruitSpecialtyUpList); } ts.Complete(); } if (facultyMajorfail <= 0 && gradeMajorfail <= 0 && classMajorfail <= 0 && fail <= 0) { tipMessage = success + "条专业班级的信息"; } else { if (facultyMajorfail <= 0 && gradeMajorfail <= 0 && classMajorfail <= 0 && fail > 0) { tipMessage = success + "条专业班级的信息,失败" + fail + "条,原因:年级专业对应的毕业学期不存在,请核查"; } else if (facultyMajorfail > 0 && gradeMajorfail <= 0 && classMajorfail <= 0 && fail <= 0) { tipMessage = success + "条专业班级的信息," + facultyMajorfail + "条由于院系专业信息的原因无法生成,请核查"; } else if (facultyMajorfail <= 0 && gradeMajorfail > 0 && classMajorfail <= 0 && fail <= 0) { tipMessage = success + "条专业班级的信息," + gradeMajorfail + "条由于年级专业信息的原因无法生成,请核查"; } else if (facultyMajorfail <= 0 && gradeMajorfail <= 0 && classMajorfail > 0 && fail <= 0) { tipMessage = success + "条专业班级的信息," + classMajorfail + "条由于班级信息的原因无法生成,请核查"; } else { tipMessage = success + "条专业班级的信息," + fail + "条由于年级专业对应的毕业学期不存在的原因无法生成," + facultyMajorfail + "条由于院系专业信息的原因无法生成," + gradeMajorfail + "条由于年级专业信息的原因无法生成," + classMajorfail + "条由于班级信息的原因无法生成,请核查"; } } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } } }