using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.Entities; using EMIS.ViewModel; using EMIS.CommonLogic.SystemServices; namespace EMIS.ExtensionLogic.ServiceLogic.EnrollManage { public class NewStudentEnterServices : EMIS.CommonLogic.EnrollManage.NewStudentManage.NewStudentEnterServices { /// /// 流水号生成Services /// public Lazy SerialNumberServices { get; set; } /// /// 手动分配班级和生成学号(广东松山) /// 注:暂不支持院系专业分方向、年级专业分方向分班、分学号 /// /// /// /// public override string NewStudentEnterAssignClass(List newStudentIDList, Guid? classmajorID) { //分配规则如下(根据新生实际报到人数进行分班,每个专业设置多少个小班,以教务处数据为主): //1、男女比例均衡; //2、各地区人数比例均衡; //3、高考成绩各分数段比例均衡; //4、同一宿舍的序号能连续编排在一起; //5、女生少的班级建议女生排在前面,男生少的班级建议男生排在前面,男女生比例相差不悬殊的建议混排; //6、每个小班人数必须控制在60人以内,最好55人以下; //学号(11位)=班级编号+2位流水号(按学生录取通知书编号、宿舍编号排序后顺序取学号) try { var studentNoTotal = EMIS.Utility.Const.LOCAL_SETTING_LOGINIDTOTAL; if (studentNoTotal == null) { throw new Exception("学号总位数未配置,请检查。"); } //查询录取名单信息(已分配状态) var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.Assigned) .OrderBy(x => x.EnrollmentNo).ThenBy(x => x.Dormitory).OrderBy(x => x.OrderNo).ToList(); //年级ID var gradeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.GradeID.ToString())).Select(x => x.GradeID).ToList(); //专业信息ID var specialtyIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.SpecialtyID.ToString())).Select(x => x.SpecialtyID).ToList(); //院系所ID var collegeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).ToList(); //查询专业信息 var specialtyList = NewStudentDAL.SpecialtyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList(); //查询招生专业信息(暂时不需对招生专业进行验证) var recruitSpecialtyAllList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => true).ToList(); //查询招生专业 var recruitSpecialtyList = recruitSpecialtyAllList.Where(x => gradeIDList.Contains(x.GradeID) && specialtyIDList.Contains(x.SpecialtyID) && collegeIDList.Contains(x.CollegeID)).ToList(); //查询对应的院系专业信息 var facultymajorList = NewStudentDAL.GetFacultymajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID)).ToList(); //院系专业ID var facultymajorIDList = facultymajorList.Where(x => !string.IsNullOrEmpty(x.FacultymajorID.ToString())).Select(x => x.FacultymajorID).ToList(); //查询对应的年级专业信息 var grademajorList = NewStudentDAL.GetGrademajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), x => facultymajorIDList.Contains(x.FacultymajorID)).ToList(); //年级专业ID var grademajorIDList = grademajorList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())).Select(x => x.GrademajorID).ToList(); //查询对应的班级信息 var classmajorList = NewStudentDAL.GetClassmajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), 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 maxStudentNoList = NewStudentDAL.GetMaxStudentNoClass(x => classmajorIDList.Contains(x.ClassmajorID)).ToList(); int classmajorfail = 0; int fail = 0; int success = 0; string tipMessage = null; long startStudentNo = 0; long newStudentNo = 0; List newStudentUpList = new List(); foreach (var newStudent in newStudentList) { //需要对选择的班级信息分别进行验证(一一对应的情况下,才可分配班级及生成学号) //查询班级信息(根据新生ID、选择的班级信息ID查询) var classmajorVerify = classmajorList.Where(x => x.NewStudentID == newStudent.NewStudentID && x.ClassmajorID == classmajorID).SingleOrDefault(); //判断对应的班级信息 if (classmajorVerify != null) { //判断当选择的信息中存在班级信息或学号等情况(只要两者之中有一个存在,将不考虑生成) if (newStudent.ClassmajorID.HasValue || !string.IsNullOrEmpty(newStudent.StudentNo)) { //表示不生成 fail++; continue; } else { //查询对应班级信息中最大的学号(新生信息表、学生信息表) var maxStudentNo = maxStudentNoList.Where(x => x.ClassmajorID == classmajorID).SingleOrDefault(); //查询选择生成的录取名单List中是否有分配到同一班级的信息 var newStudentRepeatList = newStudentUpList.Where(x => x.ClassmajorID == classmajorID).ToList(); //初始学号(班级编号+流水号,不够学号总位数的用0填充,可在此处通过个性化配置来定义学号生成规则) startStudentNo = Convert.ToInt64(classmajorVerify.ClassmajorNo.PadRight(Convert.ToInt32(studentNoTotal) - 1, '0') + "1"); //表示当前班级无对应的学号,此时应为初始学号(班级编号+2位流水号,需匹配Web.config配置) if (maxStudentNo == null) { //表示无相同班级的信息 if (newStudentRepeatList.Count <= 0) { //初始学号 newStudentNo = startStudentNo; } else { //相同班级的信息中最大学号+1,作为下一个学号 newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1; } } else { //表示无相同班级的信息 if (newStudentRepeatList.Count <= 0) { //数据表中的最大学号+1,作为下一个学号(需考虑异动情况下产生的学号) var classmajorNo = maxStudentNo.StudentNo.Substring(0, maxStudentNo.StudentNo.Trim().Length - 2); if (classmajorNo == classmajorVerify.ClassmajorNo.Trim()) { //表示学号为相同班级编号下学号 newStudentNo = Convert.ToInt64(maxStudentNo.StudentNo) + 1; } else { //表示学号为不相同班级编号下学号,此时应为初始学号 newStudentNo = startStudentNo; } } else { //相同班级的信息中最大学号+1,作为下一个学号 newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1; } } newStudent.ClassmajorID = classmajorID; newStudent.StudentNo = newStudentNo.ToString(); SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); success++; } } else { //表示选择的班级信息不相符,无法分班及生成学号 classmajorfail++; continue; } } //批量更新 if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } if (classmajorfail <= 0 && fail <= 0) { tipMessage = success + "条录取名单的学号"; } else { if (classmajorfail <= 0 && fail > 0) { tipMessage = success + "个学号,失败" + fail + "条,原因:班级信息或学号已存在,如需生成请初始化后重新生成"; } else if (classmajorfail > 0 && fail <= 0) { tipMessage = success + "个学号," + classmajorfail + "条由于与选择的班级信息不相符,无法生成,请核查"; } else { tipMessage = success + "个学号," + fail + "条由于班级信息或学号已存在无法生成," + classmajorfail + "条由于与选择的班级信息不相符,无法生成,请核查"; } } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 自动分配班级和生成学号(广东松山) /// 注:暂不支持院系专业分方向、年级专业分方向分班、分学号 /// /// /// public override string NewStudentEnterAutoAssignClass(List newStudentIDList) { //分配规则如下(根据新生实际报到人数进行分班,每个专业设置多少个小班,以教务处数据为主): //1、男女比例均衡; //2、各地区人数比例均衡; //3、高考成绩各分数段比例均衡; //4、同一宿舍的序号能连续编排在一起; //5、女生少的班级建议女生排在前面,男生少的班级建议男生排在前面,男女生比例相差不悬殊的建议混排; //6、每个小班人数必须控制在60人以内,最好55人以下; //学号(11位)=班级编号+2位流水号(按学生录取通知书编号、宿舍编号排序后顺序取学号) try { var studentNoTotal = EMIS.Utility.Const.LOCAL_SETTING_LOGINIDTOTAL; if (studentNoTotal == null) { throw new Exception("学号总位数未配置,请检查。"); } //查询录取名单信息(已分配状态) var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.Assigned) .OrderBy(x => x.EnrollmentNo).ThenBy(x => x.Dormitory).OrderBy(x => x.OrderNo).ToList(); //年级ID var gradeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.GradeID.ToString())).Select(x => x.GradeID).ToList(); //专业信息ID var specialtyIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.SpecialtyID.ToString())).Select(x => x.SpecialtyID).ToList(); //院系所ID var collegeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).ToList(); //查询专业信息 var specialtyList = NewStudentDAL.SpecialtyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList(); //查询招生专业信息(暂时不需对招生专业进行验证) var recruitSpecialtyAllList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => true).ToList(); //查询招生专业 var recruitSpecialtyList = recruitSpecialtyAllList.Where(x => gradeIDList.Contains(x.GradeID) && specialtyIDList.Contains(x.SpecialtyID) && collegeIDList.Contains(x.CollegeID)).ToList(); //查询对应的院系专业信息 var facultymajorList = NewStudentDAL.GetFacultymajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID)).ToList(); //院系专业ID var facultymajorIDList = facultymajorList.Where(x => !string.IsNullOrEmpty(x.FacultymajorID.ToString())).Select(x => x.FacultymajorID).ToList(); //查询对应的年级专业信息 var grademajorList = NewStudentDAL.GetGrademajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), x => facultymajorIDList.Contains(x.FacultymajorID)).ToList(); //年级专业ID var grademajorIDList = grademajorList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())).Select(x => x.GrademajorID).ToList(); //查询对应的班级信息 var classmajorList = NewStudentDAL.GetClassmajorByNewStudent(x => newStudentIDList.Contains(x.NewStudentID), 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 maxStudentNoList = NewStudentDAL.GetMaxStudentNoClass(x => classmajorIDList.Contains(x.ClassmajorID)).ToList(); int facultymajorfail = 0; int grademajorfail = 0; int classmajorfail = 0; int fail = 0; int success = 0; string tipMessage = null; long startStudentNo = 0; long newStudentNo = 0; List newStudentUpList = new List(); foreach (var newStudent in newStudentList) { //需要对院系专业、年级专业、班级信息分别进行验证(一一对应的情况下,才可自动分配班级及生成学号) //查询院系专业 var facultymajorVerify = facultymajorList.Where(x => x.NewStudentID == newStudent.NewStudentID).ToList(); //判断对应的院系专业 if (facultymajorVerify != null && facultymajorVerify.Count() > 0) { if (facultymajorVerify.Count() == 1) { //查询年级专业 var grademajorVerify = grademajorList.Where(x => x.NewStudentID == newStudent.NewStudentID).ToList(); //判断对应的年级专业 if (grademajorVerify != null && grademajorVerify.Count() > 0) { if (grademajorVerify.Count() == 1) { //查询班级信息 var classmajorVerify = classmajorList.Where(x => x.NewStudentID == newStudent.NewStudentID).ToList(); //判断对应的班级信息 if (classmajorVerify != null && classmajorVerify.Count() > 0) { if (classmajorVerify.Count() == 1) { //判断当选择的信息中存在班级信息或学号等情况(只要两者之中有一个存在,将不考虑生成) if (newStudent.ClassmajorID.HasValue || !string.IsNullOrEmpty(newStudent.StudentNo)) { //表示不生成 fail++; continue; } else { //对可分配的班级信息及学号进行查询 //查询对应班级信息中最大的学号(新生信息表、学生信息表) var specialtyClass = classmajorVerify.Where(x => x.NewStudentID == newStudent.NewStudentID).SingleOrDefault(); var maxStudentNo = maxStudentNoList.Where(x => x.ClassmajorID == specialtyClass.ClassmajorID).SingleOrDefault(); //查询选择生成的录取名单List中是否有分配到同一班级的信息 var newStudentRepeatList = newStudentUpList.Where(x => x.ClassmajorID == specialtyClass.ClassmajorID).ToList(); //初始学号(班级编号+流水号,不够学号总位数的用0填充,可在此处通过个性化配置来定义学号生成规则) startStudentNo = Convert.ToInt64(specialtyClass.ClassmajorNo.PadRight(Convert.ToInt32(studentNoTotal) - 1, '0') + "1"); //表示当前班级无对应的学号,此时应为初始学号(班级编号+2位流水号,需匹配Web.config配置) if (maxStudentNo == null) { //表示无相同班级的信息 if (newStudentRepeatList.Count <= 0) { //初始学号 newStudentNo = startStudentNo; } else { //相同班级的信息中最大学号+1,作为下一个学号 newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1; } } else { //表示无相同班级的信息 if (newStudentRepeatList.Count <= 0) { //数据表中的最大学号+1,作为下一个学号(需考虑异动情况下产生的学号) var classmajorNo = maxStudentNo.StudentNo.Substring(0, maxStudentNo.StudentNo.Trim().Length - 2); if (classmajorNo == specialtyClass.ClassmajorNo.Trim()) { //表示学号为相同班级编号下学号 newStudentNo = Convert.ToInt64(maxStudentNo.StudentNo) + 1; } else { //表示学号为不相同班级编号下学号,此时应为初始学号 newStudentNo = startStudentNo; } } else { //相同班级的信息中最大学号+1,作为下一个学号 newStudentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.StudentNo)).FirstOrDefault().StudentNo) + 1; } } newStudent.ClassmajorID = specialtyClass.ClassmajorID; newStudent.StudentNo = newStudentNo.ToString(); SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); success++; } } else { //表示对应的班级信息存在多个,无法确定对应的班级信息(可在此处进行扩展,针对专业分方向的情况) classmajorfail++; continue; } } else { //表示对应的班级信息不存在,无法分班及生成学号 classmajorfail++; continue; } } else { //表示对应的年级专业信息存在多个,无法确定对应的年级专业(可在此处进行扩展,针对专业分方向的情况) grademajorfail++; continue; } } else { //表示对应的年级专业信息不存在,无法分班及生成学号 grademajorfail++; continue; } } else { //表示对应的院系专业信息存在多个,无法确定对应的院系专业(可在此处进行扩展,针对专业分方向的情况) facultymajorfail++; continue; } } else { //表示对应的院系专业信息不存在,无法分班及生成学号 facultymajorfail++; continue; } } //批量更新 if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } if (facultymajorfail <= 0 && grademajorfail <= 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); } } } }