using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Text.RegularExpressions; using System.Data; using System.IO; using System.Transactions; using Bowin.Common.Utility; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Utility; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.CacheManage; using EMIS.ViewModel.EnrollManage.NewStudentManage; using EMIS.DataLogic.EnrollManage.NewStudentManage; namespace EMIS.CommonLogic.EnrollManage.NewStudentManage { public class NewStudentCollegeServices : BaseServices, INewStudentCollegeServices { public NewStudentDAL NewStudentDAL { get; set; } /// /// 查询新生分配信息View /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetNewStudentCollegeViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned); if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { exp = exp.And(x => x.GradeID == gradeID); } if (isPhoto.HasValue) { if (isPhoto.Value == (int)CF_GeneralExist.Have) { exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != ""); } if (isPhoto.Value == (int)CF_GeneralExist.No) { exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == ""); } } var query = NewStudentDAL.GetNewStudentCollegeViewQueryable(exp); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (standardID.HasValue) { 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 this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeID) .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).OrderBy(x => x.OrderNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询新生分配信息List /// /// /// /// /// /// /// /// /// /// /// public IList GetNewStudentCollegeViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned); if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { exp = exp.And(x => x.GradeID == gradeID); } if (isPhoto.HasValue) { if (isPhoto.Value == (int)CF_GeneralExist.Have) { exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != ""); } if (isPhoto.Value == (int)CF_GeneralExist.No) { exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == ""); } } var query = NewStudentDAL.GetNewStudentCollegeViewQueryable(exp); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (standardID.HasValue) { 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 this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeID) .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).OrderBy(x => x.OrderNo).ToList(); } /// /// 查询未分配新生名单信息View /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetUnAssignNewStudentViewGrid(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned); if (gradeID.HasValue) { exp = exp.And(x => x.GradeID == gradeID); } var query = NewStudentDAL.GetNewStudentViewQueryable(exp); if (standardID.HasValue) { 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.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID) .ThenBy(x => x.LearnSystem).ToGridResultSet(pageIndex, pageSize); } /// /// 查询未分配新生名单信息List /// /// /// /// /// /// /// /// public IList GetUnAssignNewStudentViewList(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned); if (gradeID.HasValue) { exp = exp.And(x => x.GradeID == gradeID); } var query = NewStudentDAL.GetNewStudentViewQueryable(exp); if (standardID.HasValue) { 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.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID) .ThenBy(x => x.LearnSystem).ToList(); } /// /// 查询对应的新生分配信息NewStudentView /// /// /// public NewStudentView GetNewStudentCollegeView(Guid? newStudentID) { try { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned); exp = exp.And(x => x.NewStudentID == newStudentID); var query = NewStudentDAL.GetNewStudentCollegeViewQueryable(exp).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 导入分配 /// /// /// /// /// /// /// public void NewStudentAssignCollegeImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { try { StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); // 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage) List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "未导入原因"); //对List集合进行有效性校验 if (enlist.Count() <= 0) { throw new Exception("Excel文件数据为空,请检查。"); } Regex reg = null; //正则表达式 inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 List newStudentInList = new List(); List newStudentUpList = new List(); //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询) //年级 var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList(); //院系所代码 var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeNo)).Select(x => x.CollegeNo).ToList(); //院系所 var collegeList = NewStudentDAL.CollegeRepository.GetList(x => true, x => x.CF_CollegeProfile).ToList(); //姓名 var nameList = enlist.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList(); //身份证号 var iDNumberList = enlist.Where(x => !string.IsNullOrEmpty(x.IDNumber)).Select(x => x.IDNumber).ToList(); //年级 var gradeIDList = enlist.Where(x => !string.IsNullOrEmpty(x.GradeStr)).Select(x => x.GradeStr).ToList(); //新生名单(由于需要和Excel中数据进行比对,数据太多就会报异常,所以需要先查询出来) var newStudentAllList = NewStudentDAL.NewStudentRepository.GetList(x => true).ToList(); //对比后的newStudentList var newStudentList = newStudentAllList.Where(x => nameList.Contains(x.Name) && iDNumberList.Contains(x.IDNumber) && gradeIDList.Contains(x.GradeID.ToString())).ToList(); //招生专业(用于检测是否开设相对应的专业:专业信息、年级、院系所) var recruitSpecialtyList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => gradeIDList.Contains(x.GradeID.ToString())).ToList(); //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { NewStudentView en = enlist[i]; //Excel表数据视图 CF_NewStudent newStudent = new CF_NewStudent(); //新生信息实体 //序号 if (string.IsNullOrEmpty(en.OrderNoStr)) { errCount++; errorMsgStr = "序号不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^[1-9]\d*|0$"); //序号字段正则表达式() if (!reg.IsMatch(en.OrderNoStr)) { errCount++; errorMsgStr = "序号格式不正确,请检查(自然数)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //序号 newStudent.OrderNo = Convert.ToInt32(en.OrderNoStr); } } //身份证号 if (string.IsNullOrEmpty(en.IDNumber)) { errCount++; errorMsgStr = "身份证号不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //身份证号正则表达式 //if (!reg.IsMatch(en.IDNumber)) //{ // errCount++; // errorMsgStr = "身份证号格式不正确,请检查"; // en.ErrorMessage = errorMsgStr; // errList.Add(en); // errorMsg.AppendLine(errorMsgStr); // continue; //} //else //{ // //身份证号 // newStudent.IDNumber = en.IDNumber.Trim(); //} newStudent.IDNumber = en.IDNumber.Trim(); } //姓名 if (string.IsNullOrEmpty(en.Name)) { errCount++; errorMsgStr = "姓名不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //姓名 newStudent.Name = en.Name.Trim(); } //年级 if (string.IsNullOrEmpty(en.GradeStr)) { errCount++; errorMsgStr = "年级不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var grade = gradeList.Where(x => x.Name == en.GradeStr.Trim()).SingleOrDefault(); if (grade == null) { errCount++; errorMsgStr = "年级不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //年级ID newStudent.GradeID = grade.Value; } } //院系所代码 if (string.IsNullOrEmpty(en.CollegeNo)) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var college = collegeList.Where(x => x.No == en.CollegeNo.Trim()).SingleOrDefault(); if (college == null) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { if (college.CF_CollegeProfile == null) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else if (college.CF_CollegeProfile.UnitCategoryID != (int)CF_UnitCategory.College) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } //院系所ID newStudent.CollegeID = college.CollegeID; } } ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉) //for (int j = i + 1; j < enlist.Count; j++) //{ // NewStudentView enA = enlist[j]; // //根据Excel表中的业务主键进行去重(身份证号、姓名、年级唯一) // if (en.IDNumber == enA.IDNumber && en.Name == enA.Name && en.YearID == enA.YearID) // { // //用于标识Excel表中的重复记录(由于是批量进行插入数据表) // } //} //由于新生管理模块中存在新生分配的业务,在进行新生信息新增时, //需要对新生分配、录取名单中的信息进行提示性验证(业务主键:身份证号、姓名、年级唯一) //处理方法:进行Excel导入时,对新生分配、录取名单中的信息提示性验证(当错误信息抛出) //注:(未分配-1,预分配-2,已分配-3) //数据表重复性验证,此为名单归站功能(身份证号、姓名、年级唯一) CF_NewStudent newStudentEnetey = newStudentList.Where(x => x.IDNumber == newStudent.IDNumber && x.Name == newStudent.Name && x.GradeID == newStudent.GradeID).FirstOrDefault(); if (newStudentEnetey == null) { errCount++; errorMsgStr = "此归站名单不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var recruitSpecialty = recruitSpecialtyList.Where(x => x.GradeID == newStudent.GradeID && x.SpecialtyID == newStudentEnetey.SpecialtyID && x.CollegeID == newStudent.CollegeID).FirstOrDefault(); //名单归站时,需对招生专业进行验证 if (recruitSpecialty == null) { errCount++; errorMsgStr = "归站失败,此归站名单未开设相关的招生专业,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //由于新生管理模块中存在新生分配的业务,只更新分配状态为:未分配-1、预分配-2 //分配状态为:未分配-1,预分配-2,已分配-3 if (newStudentEnetey.AssignStatus == (int)CF_AssignStatus.Assigned) { errCount++; errorMsgStr = "归站失败,录取名单信息中已存在此归站名单"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //(Excel有重复时,以最后一条记录的更新为准) if (newStudentEnetey.CollegeID.HasValue) { //更新 newStudentEnetey.OrderNo = newStudent.OrderNo; newStudentEnetey.CollegeID = newStudent.CollegeID; newStudentEnetey.AssignStatus = (int)CF_AssignStatus.PreAssigned; //预分配 SetModifyStatus(newStudentEnetey); newStudentUpList.Add(newStudentEnetey); upCount++; } else { //归站 newStudentEnetey.OrderNo = newStudent.OrderNo; newStudentEnetey.CollegeID = newStudent.CollegeID; newStudentEnetey.AssignStatus = (int)CF_AssignStatus.PreAssigned; //预分配 SetModifyStatus(newStudentEnetey); newStudentUpList.Add(newStudentEnetey); inCount++; } } } } } //批量统一提交更新 if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); //批量更新 } errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception) { throw; } } /// /// 名单分配确定 /// 注:需对招生专业进行验证 /// /// /// /// public string NewStudentAssignCollegeConfirm(Guid? collegeID, List newStudentIDList) { try { //查询新生信息 var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).ToList(); //查询招生专业信息 var recruitSpecialtyList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => x.CollegeID == collegeID).ToList(); int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 List newStudentUpList = new List(); foreach (var newStudentID in newStudentIDList) { var newStudent = newStudentList.Where(x => x.NewStudentID == newStudentID).SingleOrDefault(); if (newStudent == null) { throw new Exception("数据有误,请检查。"); } else { var recruitSpecialty = recruitSpecialtyList.Where(x => x.SpecialtyID == newStudent.SpecialtyID && x.GradeID == newStudent.GradeID && x.CollegeID == collegeID).SingleOrDefault(); if (recruitSpecialty == null) { fail++; } else { newStudent.CollegeID = collegeID; newStudent.AssignStatus = (int)CF_AssignStatus.PreAssigned; SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); success++; } } } //批量统一提交更新 if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:选择分配的" + RSL.Get("College") + ",未开设相应的招生专业,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除照片(批量删除) /// /// /// public bool PicDelete(List newStudentIDs) { try { List photoUrlList = new List(); List newStudentUpList = new List(); var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDs.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.PreAssigned).ToList(); foreach (var newStudent in newStudentList) { if (newStudent != null) { if (!string.IsNullOrEmpty(newStudent.RecruitPictureUrl)) { photoUrlList.Add(newStudent.RecruitPictureUrl); newStudent.RecruitPictureUrl = null; newStudentUpList.Add(newStudent); } } } using (TransactionScope ts = new TransactionScope()) { foreach (var photoUrl in photoUrlList) { FileUploadHelper.DeleteFile(photoUrl); } if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } ts.Complete(); } return true; } catch (Exception) { throw; } } /// /// 取消分配 /// /// /// public string NewStudentCollegeCancleAssign(List NewStudentIDList) { try { var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => NewStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.PreAssigned).ToList(); int success = 0; //成功 string tipMessage = null; //提示消息 List newStudentUpList = new List(); foreach (var newStudent in newStudentList) { //newStudent.RecruitPictureUrl = null; newStudent.CollegeID = null; newStudent.AssignStatus = (int)CF_AssignStatus.NotAssigned; SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); success++; } //批量统一提交更新 if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } tipMessage = success + "条"; return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 提交(需对招生专业进行验证,再提交,同时生成录取通知书编号(默认:年级+院系所代码+5位流水号)) /// 注:个性化生成录取通知书编号(暂不考虑) /// /// /// public string NewStudentCollegeSubmitAssign(List NewStudentIDList) { try { //查询新生信息(注意排序) var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => NewStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.PreAssigned).OrderByDescending(x => x.GradeID).ThenBy(x => x.CollegeID) .ThenBy(x => x.ExamineeNum.Length).ThenBy(x => x.ExamineeNum); //查询对应的院系所IDList var collegeIDList = newStudentList.Where(x => !string.IsNullOrEmpty(x.CollegeID.ToString())).Select(x => x.CollegeID).Distinct().ToList(); //查询院系所信息 var collegeList = NewStudentDAL.CollegeRepository.GetList(x => true).ToList(); //查询招生专业信息 var recruitSpecialtyList = NewStudentDAL.RecruitSpecialtyRepository.GetList(x => collegeIDList.Contains(x.CollegeID)).ToList(); //查询各院系所最大的录取通知编号(只查询已分配状态的信息--录取名单) var maxCollegeEnrollmentList = NewStudentDAL.GetEnrollmentNo(x => collegeIDList.Contains(x.CollegeID) && x.AssignStatus == (int)CF_AssignStatus.Assigned).ToList(); long startEnrollmentNo = 0; //初始录取通知书编号 long newEnrollmentNo = 0; //新生成的录取通知书编号 int total = 0; //年级+院系所长度 int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 //新生信息提交List var newStudentUpList = new List(); foreach (var newStudent in newStudentList) { var recruitSpecialty = recruitSpecialtyList.Where(x => x.SpecialtyID == newStudent.SpecialtyID && x.GradeID == newStudent.GradeID && x.CollegeID == newStudent.CollegeID).SingleOrDefault(); if (recruitSpecialty == null) { fail++; } else { //查询对应院系的最大的录取通知编号(根据年级、院系所查询) var maxCollegeEnrollment = maxCollegeEnrollmentList.Where(x => x.GradeID == newStudent.GradeID && x.CollegeID == newStudent.CollegeID).SingleOrDefault(); //查询新生信息提交List中是否有重复的信息(业务主键:年级、院系所) var newStudentRepeatList = newStudentUpList.Where(x => x.GradeID == newStudent.GradeID && x.CollegeID == newStudent.CollegeID).ToList(); //表示当前院系所无对应的录取通知书编号,此时应为初始编号(年级+院系所代码+5位流水号) if (maxCollegeEnrollment == null) { //查询院系所代码 var college = collegeList.Where(x => x.CollegeID == newStudent.CollegeID).SingleOrDefault(); //生成初始录取通知书编号 total = (newStudent.GradeID.ToString() + college.No).Length; startEnrollmentNo = Convert.ToInt64((newStudent.GradeID.ToString() + college.No).PadRight(total + 4, '0') + "1"); //表示提交的信息中无重复信息(业务主键:年级、院系所) if (newStudentRepeatList.Count() <= 0) { //初始录取通知书编号 newEnrollmentNo = startEnrollmentNo; } else { //提交信息中重复数据的最大录取通知书编号+1,作为下一个录取通知书编号 newEnrollmentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.EnrollmentNo)).FirstOrDefault().EnrollmentNo) + 1; } } else { //表示提交的信息中无重复信息(业务主键:年级、院系所) if (newStudentRepeatList.Count() <= 0) { //数据表中的最大录取通知书编号+1,作为下一个录取通知书编号 newEnrollmentNo = Convert.ToInt64(maxCollegeEnrollment.EnrollmentNo) + 1; } else { //提交信息中重复数据的最大录取通知书编号+1,作为下一个录取通知书编号 newEnrollmentNo = Convert.ToInt64(newStudentRepeatList.OrderByDescending(x => Convert.ToInt64(x.EnrollmentNo)).FirstOrDefault().EnrollmentNo) + 1; } } //录取通知书编号 newStudent.EnrollmentNo = newEnrollmentNo.ToString(); newStudent.AssignStatus = (int)CF_AssignStatus.Assigned; //已分配 SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); success++; } } //批量统一提交更新 if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:提交的信息中存在," + RSL.Get("College") + "未开设相应的招生专业信息,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 导入照片 /// /// /// /// /// /// public void NewStudentCollegePicImport(IList photoPaths, string importPicType, out int? inCount, out int? errCount, out DataTable errDataTable) { try { var mapList = photoPaths.Select(s => new { PhotoInfo = Path.GetFileName(s).Trim(), PhotoName = Path.GetFileNameWithoutExtension(s).Trim(), PhotoPath = s, }).ToArray(); var photoNameList = mapList.Select(s => s.PhotoName).Distinct().ToList(); inCount = 0; errCount = 0; errDataTable = new DataTable(); List newStudentUpList = new List(); if (importPicType.Equals("ExamineeNum")) { var newPhotoNameList = new List(); foreach (var photoName in photoNameList) { var photoNameStart = photoName.Substring(0, 1); if (photoNameStart.Equals("F") || photoNameStart.Equals("Z")) { newPhotoNameList.Add(photoName.Substring(1)); } } errDataTable.Columns.Add("PhotoInfo", typeof(string)); errDataTable.Columns.Add("ExamineeNum", typeof(string)); errDataTable.Columns.Add("ErrorMessage", typeof(string)); var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned && (photoNameList.Contains(x.ExamineeNum) || newPhotoNameList.Contains(x.ExamineeNum))).ToList(); foreach (var map in mapList) { var photoNameStart = map.PhotoName.Substring(0, 1); if (photoNameStart.Equals("F") || photoNameStart.Equals("Z")) { var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName || x.ExamineeNum == map.PhotoName.Substring(1)).SingleOrDefault(); if (newStudent == null) { DataRow errDataRow = errDataTable.NewRow(); errDataRow["PhotoInfo"] = map.PhotoInfo; errDataRow["ExamineeNum"] = map.PhotoName; errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")"; errDataTable.Rows.Add(errDataRow); errCount++; } else { newStudent.RecruitPictureUrl = map.PhotoPath; this.SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); inCount++; } } else { var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName).SingleOrDefault(); if (newStudent == null) { DataRow errDataRow = errDataTable.NewRow(); errDataRow["PhotoInfo"] = map.PhotoInfo; errDataRow["ExamineeNum"] = map.PhotoName; errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")"; errDataTable.Rows.Add(errDataRow); errCount++; } else { newStudent.RecruitPictureUrl = map.PhotoPath; this.SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); inCount++; } } } } else if (importPicType.Equals("IDNumber")) { errDataTable.Columns.Add("PhotoInfo", typeof(string)); errDataTable.Columns.Add("IDNumber", typeof(string)); errDataTable.Columns.Add("ErrorMessage", typeof(string)); var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.PreAssigned && photoNameList.Contains(x.IDNumber)).ToList(); foreach (var map in mapList) { var newStudentVerifyList = newStudentList.Where(x => x.IDNumber == map.PhotoName).ToList(); if (newStudentVerifyList != null && newStudentVerifyList.Count() > 1) { DataRow errDataRow = errDataTable.NewRow(); errDataRow["PhotoInfo"] = map.PhotoInfo; errDataRow["IDNumber"] = map.PhotoName; errDataRow["ErrorMessage"] = "存在多个对应的证件号码(" + map.PhotoName + ")"; errDataTable.Rows.Add(errDataRow); errCount++; } else { if (newStudentVerifyList != null && newStudentVerifyList.Count() == 1) { var newStudent = newStudentVerifyList.Where(x => x.IDNumber == map.PhotoName).SingleOrDefault(); if (newStudent == null) { DataRow errDataRow = errDataTable.NewRow(); errDataRow["PhotoInfo"] = map.PhotoInfo; errDataRow["IDNumber"] = map.PhotoName; errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")"; errDataTable.Rows.Add(errDataRow); errCount++; } else { newStudent.RecruitPictureUrl = map.PhotoPath; this.SetModifyStatus(newStudent); newStudentUpList.Add(newStudent); inCount++; } } else { DataRow errDataRow = errDataTable.NewRow(); errDataRow["PhotoInfo"] = map.PhotoInfo; errDataRow["IDNumber"] = map.PhotoName; errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")"; errDataTable.Rows.Add(errDataRow); errCount++; } } } } if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } } catch (Exception) { throw; } } /// /// 招生信息Excel导入(预分配,需根据省招专业相关信息进行匹配--个性化) /// /// /// /// /// /// /// public virtual void NewStudentCollegeImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { //根据各高校个性化要求进行配置 throw new Exception("招生信息导入配置有误(根据个性化要求进行配置),请检查"); } } }