123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- 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
- {
- /// <summary>
- /// 流水号生成Services
- /// </summary>
- public Lazy<ISerialNumberServices> SerialNumberServices { get; set; }
- /// <summary>
- /// 手动分配班级和生成学号(广东松山)
- /// 注:暂不支持院系专业分方向、年级专业分方向分班、分学号
- /// </summary>
- /// <param name="newStudentIDList"></param>
- /// <param name="classmajorID"></param>
- /// <returns></returns>
- public override string NewStudentEnterAssignClass(List<Guid?> 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<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
- 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);
- }
- }
- /// <summary>
- /// 自动分配班级和生成学号(广东松山)
- /// 注:暂不支持院系专业分方向、年级专业分方向分班、分学号
- /// </summary>
- /// <param name="newStudentIDList"></param>
- /// <returns></returns>
- public override string NewStudentEnterAutoAssignClass(List<Guid?> 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<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
- 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);
- }
- }
- }
- }
|