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 Lazy SerialNumberServices { get; set; } /// /// 河北工大专业班级生成规则(由于院系专业、年级专业编码规则的问题,暂时不支持院系专业、年级专业分方向的生成) /// 注:班级信息的生成,存在多个班时,默认在班级编码后加流水号1位,否则不加流水号1位(暂时这么处理) /// /// /// public override string GenerateClass(List recruitSpecialtyIDs) { //生成规则如下: //院系编码:院系所编号+培养层次Value+学习形式Value+6位专业代码,拼出来,如:0112030101 //院系名称:院系所简称+"-"+专业名称+学习形式+培养层次,如:河北城乡-法学业余专升本 //年级专业编码:年级后两位+院系所编号+培养层次Value+学习形式Value+6位专业代码,拼出来,如:140112030101 //年级专业名称:年级+院系所简称+"-"+专业名称+学习形式+培养层次 //如:2014河北城乡-法学业余专升本 //班级编码:年级后两位+院系所编号+培养层次Value+学习形式Value+6位专业代码,拼出来,如:140112030101 //班级名称:年级+院系所简称+"-"+专业名称+学习形式+培养层次+"班" //如:2014河北城乡-法学业余专升本班 try { //查询招生专业信息 var recruitSpecialtyList = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => recruitSpecialtyIDs.Contains(x.RecruitSpecialtyID), x => x.CF_College, x => x.CF_Specialty).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 specialtyClassSettingList = recruitSpecialtyDAL.SpecialtyClassSettingRepository.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(); //根据年级专业信息查询对应的班级信息MaxCode(年级专业分组查询) var clMaxCodeList = recruitSpecialtyDAL.GetClassmajorMaxCodeByGrademajor(x => grademajorIDList.Contains(x.GrademajorID)).ToList(); //查询学年学期信息 var schoolyearList = recruitSpecialtyDAL.schoolyearRepository.GetList(x => true).ToList(); var facultymajorCode = ""; var facultymajorName = ""; var grademajorCode = ""; var grademajorName = ""; var classmajorCode = ""; var classmajorName = ""; int facultymajorfail = 0; int grademajorfail = 0; int fail = 0; int success = 0; string tipMessage = null; List recruitSpecialtyUpList = new List(); List facultymajorInList = new List(); List grademajorInList = new List(); List classmajorInList = new List(); foreach (var recruitSpecialty in recruitSpecialtyList) { //目前只处理招生专业与专业班级对应关系的情况(已存在的情况下,暂时不做处理) //专业分方向的情况处理有以下3种,按以下方式进行处理: //院系专业分方向(暂不支持) //年级专业分方向(暂不支持) //班级信息分方向(以专业分班设置来处理) //查询对应的院系所信息 var college = collegeList.Where(x => x.CollegeID == recruitSpecialty.CollegeID).SingleOrDefault(); //查询对应的专业信息 var specialty = specialtyList.Where(x => x.SpecialtyID == recruitSpecialty.SpecialtyID).SingleOrDefault(); //查询对应的专业分班信息 var specialtyClassSetting = specialtyClassSettingList.Where(x => x.SpecialtyID == recruitSpecialty.SpecialtyID).SingleOrDefault(); //对应的班级个数 int classNum = 1; if (specialtyClassSetting != null) { if (specialtyClassSetting.ClassNumber != null) { if (specialtyClassSetting.ClassNumber.Value > 1) { classNum = specialtyClassSetting.ClassNumber.Value; } } } //专业名称数据字典 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(); //计算毕业学年学期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(); if (graduateSchoolyear == null) { //表示年级专业对应的毕业学期,在学年学期信息中不存在(此时不生成) fail++; continue; } //院系专业编号(处理6位专业代码的问题) if (standard.Code.Length > 6) { //院系所编号+培养层次Value+学习形式Value+6位专业代码 facultymajorCode = college.No.Trim() + specialty.EducationID.ToString().Trim() + specialty.LearningformID.ToString().Trim() + standard.Code.Substring(0, 6); } else { //院系所编号+培养层次Value+学习形式Value+6位专业代码 facultymajorCode = college.No.Trim() + specialty.EducationID.ToString().Trim() + specialty.LearningformID.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; //注:暂时只取部分命名规则 //班级编号(年级后两位+院系所编号+培养层次Value+学习形式Value+6位专业代码) classmajorCode = grademajorCode; //班级名称(年级+院系所简称+"-"+专业名称+学习形式+培养层次+"班") classmajorName = grademajorName; //查询对应的院系专业信息 var facultymajorVerifyList = facultymajorList.Where(x => x.RecruitSpecialtyID == recruitSpecialty.RecruitSpecialtyID).ToList(); //判断院系专业 if (facultymajorVerifyList != null && facultymajorVerifyList.Count() > 0) { //表示存在对应的院系专业信息且只有一条(一一对应,可在此处,做更新处理:需准确定位院系专业) if (facultymajorVerifyList.Count() == 1) { //表示存在对应的院系专业信息 foreach (var facultymajorVerify in facultymajorVerifyList) { //查询对应的年级专业信息 var grademajorVerifyList = grademajorList.Where(x => x.FacultymajorID == facultymajorVerify.FacultymajorID).ToList(); //判断年级专业 if (grademajorVerifyList != null && grademajorVerifyList.Count() > 0) { //表示存在对应的年级专业信息且只有一条(一一对应,可在此处,做更新处理:需准确定位年级专业) if (grademajorVerifyList.Count() == 1) { //表示存在对应的年级专业信息 foreach (var grademajorVerify in grademajorVerifyList) { //查询对应的班级信息 var classmajorVerifyList = classmajorList.Where(x => x.GrademajorID == grademajorVerify.GrademajorID).ToList(); //判断班级信息 if (classmajorVerifyList != null && classmajorVerifyList.Count() > 0) { //表示存在对应的班级信息(需处理专业分班信息中班级个数的问题) //表示存在的班级个数大于专业分班的班级个数 if (classmajorVerifyList.Count() >= classNum) { if (classmajorVerifyList.Count() == 1) { //查询对应的班级信息(只有一条班级信息可在此处做更新处理) var classmajorEntity = classmajorVerifyList.Where(x => x.GrademajorID == grademajorVerify.GrademajorID).SingleOrDefault(); //(暂时不做更新处理) } else { //表示存在多个班级个数(可在此做其它处理) } //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } else { //表示存在的班级个数不足 //查询对应的班级信息Max编号(年级专业分组查询) //注:由于班级编码可能没有流水号1位,暂时这么取 var clMaxCode = clMaxCodeList.Where(x => x.GrademajorID == grademajorVerify.GrademajorID).SingleOrDefault(); var clNum = Convert.ToInt32(clMaxCode.No.Trim().Substring(clMaxCode.No.Trim().Length - 1)); //生成剩余的班级个数(暂时以MaxCode+1形式生成) for (int i = 1; i <= classNum - classmajorVerifyList.Count(); i++) { CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = grademajorVerify.GrademajorID; newClassmajor.No = classmajorCode + (clNum + i).ToString(); newClassmajor.Name = classmajorName + (clNum + i).ToString() + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = (clNum + i); newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } } else { //表示对应的班级信息不存在(需根据专业分班信息生成对应的班级个数) if (classNum > 1) { for (int i = 1; i <= classNum; i++) { CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = grademajorVerify.GrademajorID; newClassmajor.No = classmajorCode + i.ToString(); newClassmajor.Name = classmajorName + i.ToString() + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = i; newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } } else { //表示只生成一个对应的班级信息(默认) CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = grademajorVerify.GrademajorID; newClassmajor.No = classmajorCode; newClassmajor.Name = classmajorName + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = 1; newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } } } else { //表示存在多个年级专业信息的情况 grademajorfail++; continue; } } else { //表示对应的年级专业信息不存在 //注:根据院系专业信息生成年级专业信息、专业分班信息生成对应的班级个数 CF_Grademajor newGrademajor = new CF_Grademajor(); newGrademajor.GrademajorID = Guid.NewGuid(); newGrademajor.FacultymajorID = facultymajorVerify.FacultymajorID; newGrademajor.Code = grademajorCode; newGrademajor.Name = grademajorName; newGrademajor.Abbreviation = newGrademajor.Name; newGrademajor.GradeID = recruitSpecialty.GradeID; newGrademajor.SemesterID = recruitSpecialty.SemesterID; newGrademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID; newGrademajor.Professional = null; newGrademajor.Remark = null; SetNewStatus(newGrademajor); grademajorInList.Add(newGrademajor); //表示对应的班级信息不存在(需根据专业分班信息生成对应的班级信息) if (classNum > 1) { for (int i = 1; i <= classNum; i++) { CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = newGrademajor.GrademajorID; newClassmajor.No = classmajorCode + i.ToString(); newClassmajor.Name = classmajorName + i.ToString() + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = i; newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } } else { //表示只生成一个对应的班级信息(默认) CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = newGrademajor.GrademajorID; newClassmajor.No = classmajorCode; newClassmajor.Name = classmajorName + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = 1; newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } //更新招生专业信息生成状态 recruitSpecialty.isGenerated = true; recruitSpecialtyUpList.Add(recruitSpecialty); success++; } } } else { //表示存在多个院系专业信息的情况 facultymajorfail++; continue; } } else { //表示对应的院系专业信息不存在 //注:默认生成一条院系专业信息、一条年级专业信息、专业分班信息生成对应的班级个数 CF_Facultymajor newFacultymajor = new CF_Facultymajor(); newFacultymajor.FacultymajorID = Guid.NewGuid(); newFacultymajor.CollegeID = recruitSpecialty.CollegeID; newFacultymajor.Code = facultymajorCode; newFacultymajor.Name = facultymajorName; newFacultymajor.Abbreviation = newFacultymajor.Name; newFacultymajor.EnglishName = null; newFacultymajor.StandardID = specialty.StandardID; newFacultymajor.EducationID = specialty.EducationID; newFacultymajor.LearningformID = specialty.LearningformID; newFacultymajor.LearnSystem = specialty.LearnSystem; newFacultymajor.ScienceclassID = specialty.ScienceclassID; newFacultymajor.SetTime = DateTime.Now; newFacultymajor.Remark = null; SetNewStatus(newFacultymajor); facultymajorInList.Add(newFacultymajor); //表示对应的年级专业信息不存在 CF_Grademajor newGrademajor = new CF_Grademajor(); newGrademajor.GrademajorID = Guid.NewGuid(); newGrademajor.FacultymajorID = newFacultymajor.FacultymajorID; newGrademajor.Code = grademajorCode; newGrademajor.Name = grademajorName; newGrademajor.Abbreviation = newGrademajor.Name; newGrademajor.GradeID = recruitSpecialty.GradeID; newGrademajor.SemesterID = recruitSpecialty.SemesterID; newGrademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID; newGrademajor.Professional = null; newGrademajor.Remark = null; SetNewStatus(newGrademajor); grademajorInList.Add(newGrademajor); //表示对应的班级信息不存在(需根据专业分班信息生成对应的班级信息) if (classNum > 1) { for (int i = 1; i <= classNum; i++) { CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = newGrademajor.GrademajorID; newClassmajor.No = classmajorCode + i.ToString(); newClassmajor.Name = classmajorName + i.ToString() + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = i; newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } } else { //表示只生成一个对应的班级信息(默认) CF_Classmajor newClassmajor = new CF_Classmajor(); newClassmajor.ClassmajorID = Guid.NewGuid(); newClassmajor.GrademajorID = newGrademajor.GrademajorID; newClassmajor.No = classmajorCode; newClassmajor.Name = classmajorName + "班"; newClassmajor.Abbreviation = newClassmajor.Name; newClassmajor.EnglishName = null; newClassmajor.ClassNum = 1; newClassmajor.UserID = null; newClassmajor.AssistantUserID = null; newClassmajor.Fixedclassroom = null; newClassmajor.Remark = null; SetNewStatus(newClassmajor); classmajorInList.Add(newClassmajor); } //更新招生专业信息生成状态 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 (success > 0 && facultymajorfail <= 0 && grademajorfail <= 0 && fail <= 0) { tipMessage = success + "条"; } else { if (facultymajorfail <= 0 && grademajorfail <= 0 && fail > 0) { tipMessage = success + "条," + fail + "条失败,原因:年级专业对应的毕业学期不存在,请核查"; } else if (facultymajorfail > 0 && grademajorfail <= 0 && fail <= 0) { tipMessage = success + "条," + facultymajorfail + "条由于院系专业信息的原因无法生成,请核查"; } else if (facultymajorfail <= 0 && grademajorfail > 0 && fail <= 0) { tipMessage = success + "条," + grademajorfail + "条由于年级专业信息的原因无法生成,请核查"; } else if (facultymajorfail > 0 && grademajorfail > 0 && fail <= 0) { tipMessage = success + "条," + facultymajorfail + "条由于院系专业信息的原因无法生成," + grademajorfail + "条由于年级专业信息的原因无法生成"; } else { tipMessage = success + "条," + fail + "条由于年级专业对应的毕业学期不存在的原因无法生成," + facultymajorfail + "条由于院系专业信息的原因无法生成," + grademajorfail + "条由于年级专业信息的原因无法生成"; } } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } } }