123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Text.RegularExpressions;
- 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.SpecialtyManage;
- using EMIS.DataLogic.EnrollManage.SpecialtyManage;
- namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage
- {
- public class RecruitSpecialtyServices : BaseServices, IRecruitSpecialtyServices
- {
- public RecruitSpecialtyDAL recruitSpecialtyDAL { get; set; }
- public Lazy<ISpecialtyApplyServices> SpecialtyApplyServices { get; set; }
- /// <summary>
- /// 查询对应的招生专业信息View
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="isGenerated"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<RecruitSpecialtyView> GetRecruitSpecialtyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, int? isGenerated, int pageIndex, int pageSize)
- {
- //招生专业
- Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID);
- }
- if (gradeID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID);
- }
- if (isGenerated.HasValue)
- {
- //生成状态
- if (isGenerated.Value == (int)CF_GeneralPurpose.IsYes)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated == true);
- }
- if (isGenerated.Value == (int)CF_GeneralPurpose.IsNo)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated != true);
- }
- }
- var query = recruitSpecialtyDAL.GetRecruitSpecialtyViewQueryable(expRecruitSpecialty);
- 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).ToGridResultSet<RecruitSpecialtyView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的招生专业信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="isGenerated"></param>
- /// <returns></returns>
- public IList<RecruitSpecialtyView> GetRecruitSpecialtyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, int? isGenerated)
- {
- //招生专业
- Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID);
- }
- if (gradeID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID);
- }
- if (isGenerated.HasValue)
- {
- //生成状态
- if (isGenerated.Value == (int)CF_GeneralPurpose.IsYes)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated == true);
- }
- if (isGenerated.Value == (int)CF_GeneralPurpose.IsNo)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.isGenerated != true);
- }
- }
- var query = recruitSpecialtyDAL.GetRecruitSpecialtyViewQueryable(expRecruitSpecialty);
- 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).ToList();
- }
- /// <summary>
- /// 查询对应的招生专业信息CF_RecruitSpecialty
- /// </summary>
- /// <param name="recruitSpecialtyID"></param>
- /// <returns></returns>
- public CF_RecruitSpecialty GetRecruitSpecialtyInfo(Guid? recruitSpecialtyID)
- {
- try
- {
- var query = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => x.RecruitSpecialtyID == recruitSpecialtyID).SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 查询对应的招生专业信息RecruitSpecialtyView
- /// </summary>
- /// <param name="recruitSpecialtyID"></param>
- /// <returns></returns>
- public RecruitSpecialtyView GetRecruitSpecialtyView(Guid? recruitSpecialtyID)
- {
- try
- {
- var query = recruitSpecialtyDAL.GetRecruitSpecialtyViewQueryable(x => x.RecruitSpecialtyID == recruitSpecialtyID).SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 招生专业批量新增(业务主键:专业信息ID、年级、学期、院系所)
- /// </summary>
- /// <param name="specialtyIDList"></param>
- /// <param name="recruitSpecialtyView"></param>
- /// <returns></returns>
- public string RecruitSpecialtyBatchAdd(List<Guid?> specialtyIDList, RecruitSpecialtyView recruitSpecialtyView)
- {
- try
- {
- var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
- if (endStatusID == null)
- {
- throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
- }
- //招生专业
- Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expRecruitSpecialty = expRecruitSpecialty.And(x => specialtyIDList.Contains(x.SpecialtyID));
- //查询对应的招生专业信息List
- var recruitSpecialtyList = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(expRecruitSpecialty).ToList();
- int success = 0;
- int fail = 0;
- string tipMessage = null;
- List<CF_RecruitSpecialty> recruitSpecialtyInList = new List<CF_RecruitSpecialty>();
- foreach (var specialtyID in specialtyIDList)
- {
- var recruitSpecialtyVerify = recruitSpecialtyList.Where(x => x.SpecialtyID == specialtyID && x.CollegeID == recruitSpecialtyView.CollegeID
- && x.GradeID == recruitSpecialtyView.GradeID && x.SemesterID == recruitSpecialtyView.SemesterID).SingleOrDefault();
- if (recruitSpecialtyVerify == null)
- {
- //新增
- var recruitSpecialty = new CF_RecruitSpecialty();
- recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid();
- recruitSpecialty.SpecialtyApplyID = null;
- recruitSpecialty.SpecialtyID = specialtyID;
- recruitSpecialty.CollegeID = recruitSpecialtyView.CollegeID;
- recruitSpecialty.GradeID = recruitSpecialtyView.GradeID;
- recruitSpecialty.SemesterID = recruitSpecialtyView.SemesterID;
- recruitSpecialty.ApprovalStatus = endStatusID;
- recruitSpecialty.isGenerated = false;
- recruitSpecialty.Remark = recruitSpecialtyView.Remark;
- SetNewStatus(recruitSpecialty);
- recruitSpecialtyInList.Add(recruitSpecialty);
- success++;
- }
- else
- {
- //表示已存在相同的招生专业信息
- fail++;
- }
- }
- //批量插入
- UnitOfWork.BulkInsert<CF_RecruitSpecialty>(recruitSpecialtyInList);
- if (success > 0 && fail <= 0)
- {
- tipMessage = success + "条";
- }
- else
- {
- tipMessage = success + "条," + fail + "条失败,原因:已存在相同的招生专业信息,请检查";
- }
- return tipMessage;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 查询招生专业中未新增的专业信息SpecialtyView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="semesterID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="scienceclassID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<SpecialtyView> GetSpecialtyViewNoAdd(ConfiguretView configuretView, Guid? collegeID, int? gradeID, int? semesterID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, int? scienceclassID, int pageIndex, int pageSize)
- {
- //专业信息(只查询启用状态的专业信息)
- Expression<Func<CF_Specialty, bool>> expSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (standardID.HasValue)
- {
- expSpecialty = expSpecialty.And(x => x.StandardID == standardID);
- }
- if (educationID.HasValue)
- {
- expSpecialty = expSpecialty.And(x => x.EducationID == educationID);
- }
- if (learningformID.HasValue)
- {
- expSpecialty = expSpecialty.And(x => x.LearningformID == learningformID);
- }
- if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(learnSystem);
- expSpecialty = expSpecialty.And(x => x.LearnSystem == LearnSystems);
- }
- if (scienceclassID.HasValue)
- {
- expSpecialty = expSpecialty.And(x => x.ScienceclassID == scienceclassID);
- }
- //招生专业
- Expression<Func<CF_RecruitSpecialty, bool>> expRecruitSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.CollegeID == collegeID);
- }
- if (gradeID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.GradeID == gradeID);
- }
- if (semesterID.HasValue)
- {
- expRecruitSpecialty = expRecruitSpecialty.And(x => x.SemesterID == semesterID);
- }
- var query = recruitSpecialtyDAL.GetSpecialtyViewNoAddQueryable(expSpecialty, expRecruitSpecialty);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<SpecialtyView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:专业信息ID、院系所、年级、学期)
- /// </summary>
- /// <param name="recruitSpecialtyView"></param>
- public void RecruitSpecialtyEdit(RecruitSpecialtyView recruitSpecialtyView)
- {
- try
- {
- var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
- if (endStatusID == null)
- {
- throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
- }
- //查询数据库进行验证
- var recruitSpecialtyVerification = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => x.RecruitSpecialtyID != recruitSpecialtyView.RecruitSpecialtyID
- && x.SpecialtyID == recruitSpecialtyView.SpecialtyID && x.CollegeID == recruitSpecialtyView.CollegeID
- && x.GradeID == recruitSpecialtyView.GradeID && x.SemesterID == recruitSpecialtyView.SemesterID).SingleOrDefault();
- if (recruitSpecialtyVerification == null)
- {
- //数据有误验证
- if (recruitSpecialtyView.RecruitSpecialtyID != Guid.Empty)
- {
- var recruitSpecialty = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => x.RecruitSpecialtyID == recruitSpecialtyView.RecruitSpecialtyID).SingleOrDefault();
- if (recruitSpecialty == null)
- {
- throw new Exception("数据有误,请核查");
- }
- else
- {
- //表示修改
- recruitSpecialty.Remark = recruitSpecialtyView.Remark;
- SetModifyStatus(recruitSpecialty);
- }
- }
- else
- {
- //表示新增
- var recruitSpecialty = new CF_RecruitSpecialty();
- recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid();
- recruitSpecialty.SpecialtyApplyID = null;
- recruitSpecialty.SpecialtyID = recruitSpecialtyView.SpecialtyID;
- recruitSpecialty.CollegeID = recruitSpecialtyView.CollegeID;
- recruitSpecialty.GradeID = recruitSpecialtyView.GradeID;
- recruitSpecialty.SemesterID = recruitSpecialtyView.SemesterID;
- recruitSpecialty.ApprovalStatus = endStatusID;
- recruitSpecialty.isGenerated = false;
- recruitSpecialty.Remark = recruitSpecialtyView.Remark;
- SetNewStatus(recruitSpecialty);
- UnitOfWork.Add(recruitSpecialty);
- }
- }
- else
- {
- throw new Exception("已存在相同的招生专业信息(专业信息、" + RSL.Get("College") + "、年级、学期唯一),请核查");
- }
- //事务提交
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 专业班级生成(由于各高校生成规则不同,需分版本—个性化配置)
- /// </summary>
- /// <param name="recruitSpecialtyIDs"></param>
- /// <returns></returns>
- public virtual string GenerateClass(List<Guid?> recruitSpecialtyIDs)
- {
- //根据各高校个性化要求进行配置
- throw new Exception("生成规则配置有误(根据个性化要求进行配置),请检查");
- }
- /// <summary>
- /// 删除(需根据业务主键删除对应的流程结束专业申请信息)
- /// </summary>
- /// <param name="recruitSpecialtyIDList"></param>
- /// <returns></returns>
- public bool RecruitSpecialtyDelete(List<Guid?> recruitSpecialtyIDList)
- {
- try
- {
- //查询招生专业工作流程线束环节状态
- var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
- if (endStatusID == null)
- {
- throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
- }
- //查询对应的招生专业信息List
- var recruitSpecialtyList = this.recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => recruitSpecialtyIDList.Contains(x.RecruitSpecialtyID)).ToList();
- //招生专业中对应的专业信息IDList
- var specialtyIDList = recruitSpecialtyList.Select(x => x.SpecialtyID).ToList();
- //查询对应的专业申请信息List
- var specialtyApplyList = recruitSpecialtyDAL.specialtyApplyRepository.GetList(x => specialtyIDList.Contains(x.SpecialtyID)).ToList();
- //查询专业申请信息List(流程结束)
- List<Guid> specialtyApplyIDList = new List<Guid>();
- foreach (var recruitSpecialty in recruitSpecialtyList)
- {
- //查询专业申请信息
- var specialtyApply = specialtyApplyList.Where(x => x.SpecialtyID == recruitSpecialty.SpecialtyID && x.CollegeID == recruitSpecialty.CollegeID
- && x.GradeID == recruitSpecialty.GradeID && x.SemesterID == recruitSpecialty.SemesterID && x.ApprovalStatus == endStatusID).SingleOrDefault();
- if (specialtyApply != null)
- {
- specialtyApplyIDList.Add(specialtyApply.SpecialtyApplyID);
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- if (recruitSpecialtyIDList != null && recruitSpecialtyIDList.Count() > 0)
- {
- UnitOfWork.Delete<CF_RecruitSpecialty>(x => recruitSpecialtyIDList.Contains(x.RecruitSpecialtyID));
- }
- if (specialtyApplyIDList != null && specialtyApplyIDList.Count() > 0)
- {
- UnitOfWork.Delete<CF_SpecialtyApply>(x => specialtyApplyIDList.Contains(x.SpecialtyApplyID));
- }
- ts.Complete();
- }
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// Excel导入
- /// </summary>
- /// <param name="cellheader"></param>
- /// <param name="inCount"></param>
- /// <param name="upCount"></param>
- /// <param name="errdataList"></param>
- /// <param name="errCount"></param>
- /// <param name="sourcePhysicalPath"></param>
- public void RecruitSpecialtyImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<RecruitSpecialtyView> errdataList, out int? errCount, string sourcePhysicalPath)
- {
- try
- {
- //查询招生专业工作流程结束环节状态
- var endStatusID = SpecialtyApplyServices.Value.GetCorrectEndStatus();
- if (endStatusID == null)
- {
- throw new Exception("工作流平台中,招生专业流程结束环节未配置,请核查");
- }
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- List<RecruitSpecialtyView> errList = new List<RecruitSpecialtyView>();
- // 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
- List<RecruitSpecialtyView> enlist = NpoiExcelHelper.ExcelToEntityList<RecruitSpecialtyView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
- cellheader.Add("ErrorMessage", "未导入原因");
- //对List集合进行有效性校验
- if (enlist.Count() <= 0)
- {
- throw new Exception("Excel文件数据为空,请检查。");
- }
- Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
- inCount = 0; //导入个数
- upCount = 0; //更新个数
- errCount = 0; //失败个数
- string errorMsgStr = ""; //错误信息
- List<CF_RecruitSpecialty> recruitSpecialtyInList = new List<CF_RecruitSpecialty>();
- List<CF_RecruitSpecialty> recruitSpecialtyUpList = new List<CF_RecruitSpecialty>();
- //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
- //专业代码、专业名称、专业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 collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeNo)).Select(x => x.CollegeNo).ToList();
- //对应的院系所信息
- var collegeList = recruitSpecialtyDAL.collegeRepository.GetList(x => collegeNoList.Contains(x.No), x => x.CF_CollegeProfile).ToList();
- //GradeStr
- var gradeStrList = enlist.Where(x => !string.IsNullOrEmpty(x.GradeStr)).Select(x => x.GradeStr).ToList();
- //年级
- var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
- //学期
- var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();
- //专业信息
- var specialtyList = recruitSpecialtyDAL.specialtyRepository.GetList(x => true).ToList();
- //招生专业
- var recruitSpecialtyList = recruitSpecialtyDAL.recruitSpecialtyRepository.GetList(x => gradeStrList.Contains(x.GradeID.ToString())).ToList();
- //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
- for (int i = 0; i < enlist.Count; i++)
- {
- RecruitSpecialtyView en = enlist[i]; //Excel表数据视图
- var recruitSpecialty = new CF_RecruitSpecialty(); //招生专业实体
- //专业代码
- if (string.IsNullOrEmpty(en.StandardCode))
- {
- errCount++;
- errorMsgStr = "专业代码不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var standardCode = standardList.Where(x => x.Code == en.StandardCode.Trim()).FirstOrDefault();
- if (standardCode == null)
- {
- errCount++;
- errorMsgStr = "专业代码不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //专业代码
- }
- }
- //专业名称
- if (string.IsNullOrEmpty(en.StandardName))
- {
- errCount++;
- errorMsgStr = "专业名称不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var standardName = standardList.Where(x => x.Name == en.StandardName.Trim()).FirstOrDefault();
- if (standardName == null)
- {
- errCount++;
- errorMsgStr = "专业名称不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //专业名称
- }
- }
- //专业代码与专业名称查询专业ID(Value)
- if (string.IsNullOrEmpty(en.StandardCode) || string.IsNullOrEmpty(en.StandardName))
- {
- errCount++;
- errorMsgStr = "专业代码或专业名称不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var standardID = standardList.Where(x => x.Code == en.StandardCode.Trim() && x.Name == en.StandardName.Trim()).SingleOrDefault();
- if (standardID == null)
- {
- errCount++;
- errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //专业ID(Value)
- en.StandardID = standardID.Value;
- }
- }
- //培养层次(所修学历)
- if (string.IsNullOrEmpty(en.EducationStr))
- {
- errCount++;
- errorMsgStr = RSL.Get("EducationID") + "不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var education = educationList.Where(x => x.Name == en.EducationStr.Trim()).SingleOrDefault();
- if (education == null)
- {
- errCount++;
- errorMsgStr = RSL.Get("EducationID") + "不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //培养层次
- en.EducationID = education.Value;
- }
- }
- //学习形式
- if (string.IsNullOrEmpty(en.LearningformStr))
- {
- errCount++;
- errorMsgStr = "学习形式不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var learningForm = learningFormList.Where(x => x.Name == en.LearningformStr.Trim()).SingleOrDefault();
- if (learningForm == null)
- {
- errCount++;
- errorMsgStr = "学习形式不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学习形式
- en.LearningformID = learningForm.Value;
- }
- }
- //学制
- if (string.IsNullOrEmpty(en.LearnSystemStr))
- {
- errCount++;
- errorMsgStr = "学制不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- if (!reg.IsMatch(en.LearnSystemStr))
- {
- errCount++;
- errorMsgStr = "学制格式不正确,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学制
- en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr);
- }
- }
- //专业信息查询
- var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.EducationID == en.EducationID && x.LearningformID == en.LearningformID && x.LearnSystem == en.LearnSystem).SingleOrDefault();
- //专业信息ID
- if (specialty == null)
- {
- errCount++;
- errorMsgStr = "专业信息不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //查询专业信息(启用、禁用状态)
- if (specialty.RecordStatus > (int)SYS_STATUS.UNUSABLE)
- {
- recruitSpecialty.SpecialtyID = specialty.SpecialtyID;
- }
- else
- {
- recruitSpecialty.SpecialtyID = specialty.SpecialtyID;
- errCount++;
- errorMsgStr = "专业信息为禁用状态,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- }
- //院系所代码
- 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
- recruitSpecialty.CollegeID = college.CollegeID;
- }
- }
- //年级
- 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
- {
- //年级
- recruitSpecialty.GradeID = grade.Value;
- }
- }
- //学期
- if (string.IsNullOrEmpty(en.SemesterStr))
- {
- errCount++;
- errorMsgStr = "学期不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var semester = semesterList.Where(x => x.Name == en.SemesterStr.Trim()).SingleOrDefault();
- if (semester == null)
- {
- errCount++;
- errorMsgStr = "学期不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学期
- recruitSpecialty.SemesterID = semester.Value;
- }
- }
- //备注
- recruitSpecialty.Remark = en.Remark;
- ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
- //for (int j = i + 1; j < enlist.Count; j++)
- //{
- // RecruitSpecialtyView enA = enlist[j];
- // //根据Excel表中的业务主键进行去重(专业代码、专业名称、学制、培养层次(所修学历)、学习形式、年级、学期、院系所代码唯一)
- // if (en.StandardCode == enA.StandardCode && en.StandardName == enA.StandardName
- // && en.LearnSystemStr == enA.LearnSystemStr
- // && en.EducationStr == enA.EducationStr
- // && en.LearningformStr == enA.LearningformStr
- // && en.GradeStr == enA.GradeStr
- // && en.SemesterStr == enA.SemesterStr
- // && en.CollegeNo == enA.CollegeNo)
- // {
- // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
- // }
- //}
- //由于招生专业表与专业申请表不同,招生专业新增时,需进行处理(目前采用方法一进行处理)
- //处理方法一:目前已在工作流审核处理通过时,进行了相关处理(采用更新的方式)
- //处理方法二:可在此处进行判断处理,以Excel错误数据方式进行抛出,提示信息:数据重复,工作流程中已存在此数据
- //数据表重复性验证(专业信息ID、年级、学期、院系所ID唯一)
- var recruitSpecialtyVerify = recruitSpecialtyList.Where(x => x.GradeID == recruitSpecialty.GradeID && x.SemesterID == recruitSpecialty.SemesterID
- && x.SpecialtyID == recruitSpecialty.SpecialtyID && x.CollegeID == recruitSpecialty.CollegeID).SingleOrDefault();
- if (recruitSpecialtyVerify == null)
- {
- //新增
- if (!recruitSpecialtyInList.Any(x => x.GradeID == recruitSpecialty.GradeID && x.SemesterID == recruitSpecialty.SemesterID
- && x.SpecialtyID == recruitSpecialty.SpecialtyID && x.CollegeID == recruitSpecialty.CollegeID))
- {
- recruitSpecialty.RecruitSpecialtyID = Guid.NewGuid();
- recruitSpecialty.SpecialtyApplyID = null;
- recruitSpecialty.ApprovalStatus = endStatusID;
- recruitSpecialty.isGenerated = false;
- SetNewStatus(recruitSpecialty);
- recruitSpecialtyInList.Add(recruitSpecialty);
- inCount++;
- }
- else
- {
- //Excel表重复性验证
- //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
- inCount++;
- }
- }
- else
- {
- //更新(Excel有重复时,以最后一条记录的更新为准)
- recruitSpecialtyVerify.Remark = recruitSpecialty.Remark;
- SetModifyStatus(recruitSpecialtyVerify);
- recruitSpecialtyUpList.Add(recruitSpecialtyVerify);
- upCount++;
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- if (recruitSpecialtyInList != null && recruitSpecialtyInList.Count() > 0)
- {
- UnitOfWork.BulkInsert(recruitSpecialtyInList);
- }
- if (recruitSpecialtyUpList != null && recruitSpecialtyUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate(recruitSpecialtyUpList);
- }
- ts.Complete();
- }
- errdataList = errList.Distinct().ToList();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|