123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using System.Data.Entity;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.DataLogic.ExaminationManage;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.ExaminationManage;
- using EMIS.Utility.FormValidate;
- using EMIS.DataLogic.UniversityManage.TeacherManage;
- using EMIS.ViewModel.Students;
- using EMIS.DataLogic.UniversityManage.ClassroomManage;
- using EMIS.DataLogic.Common.Students;
- using EMIS.DataLogic.ScoreManage;
- using EMIS.CommonLogic.CalendarManage;
- using EMIS.ViewModel.UniversityManage.ClassroomManage;
- using Bowin.Common.DataTime;
- using Bowin.Common.Utility;
- using EMIS.Utility;
- using EMIS.DataLogic.Repositories;
- using AutoMapper;
- using System.Text.RegularExpressions;
- using System.IO;
- using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
- using EMIS.CommonLogic.EducationSchedule;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.ViewModel.EducationSchedule;
- using EMIS.ViewModel.CalendarManage;
- using System.Transactions;
- using EMIS.ViewModel.UniversityManage.TeacherManage;
- namespace EMIS.CommonLogic.ExaminationManage
- {
- public class ExaminationPlanServices : BaseWorkflowServices<ER_FinalExamination>, IExaminationPlanServices
- {
-
- public UserRepository UserRepository { get; set; }
- public ExaminationRoomSettingRepository ExaminationRoomSettingRepository { get; set; }
- public EducationSchedulingRepository EducationSchedulingRepository { get; set; }
- public ExaminationPlanRepository examinationPlanRepository { get; set; }
- public ExaminationPlanDAL ExaminationPlanDAL { get; set; }
- public ExaminationTeacherDAL ExaminationTeacherDAL { get; set; }
- public FinalExaminationDAL FinalExaminationDAL { get; set; }
- public RoomSettingDAL RoomSettingDAL { get; set; }
- public TimeSegmentDAL TimeSegmentDAL { get; set; }
- public StaffDAL StaffDAL { get; set; }
- public StudentsDAL StudentsDAL { get; set; }
- public ClassroomDAL ClassroomDAL { get; set; }
- public CollegeDAL CollegeDAL { get; set; }
- public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
- public Lazy<EMIS.CommonLogic.EducationSchedule.IScheduleServices> ScheduleServices { get; set; }
- public Lazy<IClassroomExcessiveUseServices> ClassroomExcessiveUseServices { get; set; }
- public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ExaminationManage.ExaminationPlanView> GetExaminationPlanViewList(
- ViewModel.ConfiguretView examinationPlanView,
- Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID,
- int pageIndex, int pageSize)
- {
- Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if(gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
- }
- if(standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (examsCategoryID.HasValue)
- {
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- }
- if (examinationModeID.HasValue)
- {
- exp = exp.And(x => x.ExaminationModeID == examinationModeID);
- }
- if (examinationStyleID.HasValue)
- {
- exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
- }
-
- if (statusID.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == statusID);
- }
- if (starWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
- }
- if(endWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
- }
- var q = ExaminationPlanDAL.GetExaminationPlanView(exp);
- if(courseEndWeek.HasValue)
- {
- q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
- }
- if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
- q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
- try
- {
- return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToGridResultSet<ExaminationPlanView>(pageIndex, pageSize);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public IGridResultSet<ExaminationPlanView> GetGdssExaminationPlanViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? classmajorID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? courseEndWeek, int? statusID, int pageIndex, int pageSize)
- {
- Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- //原先是用教学任务关联的由于补考记录没有对应的教学任务,所以改用专业课程关联,
- //学校那边说不会有多个教研室开同一门可的情况,即使有,那这些教研室同样可以查到,也没有问题
- exp = exp.And(x => x.EM_Coursematerial.EM_SpecialtyCourse.Any(w => w.CF_Department.CollegeID == collegeID && w.IsEnable == true));
- }
- if (gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (examsCategoryID.HasValue)
- {
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- }
- if (examinationModeID.HasValue)
- {
- exp = exp.And(x => x.ExaminationModeID == examinationModeID);
- }
- if (examinationStyleID.HasValue)
- {
- exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
- }
- if (classmajorID.HasValue)
- {
- var classmajor = ExaminationPlanDAL.ClassmajorRepository.GetList(x => x.ClassmajorID == classmajorID).FirstOrDefault();
- exp = exp.And(x => x.ClassName == classmajor.Name);
- }
- if (statusID.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == statusID);
- }
- var q = ExaminationPlanDAL.GetExaminationPlanView(exp);
- if (courseEndWeek.HasValue)
- {
- q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
- q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- try
- {
- var result = this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToGridResultSet<ExaminationPlanView>(pageIndex, pageSize);
- var ExaminationPlanID = result.rows.Select(x => x.ExaminationPlanID).ToList();
- var ExaminationPlanTeacherList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => ExaminationPlanID.Contains((Guid)x.ExaminationPlanID)).ToList();
- result.rows.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(ExaminationPlanTeacherList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
- return result;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public List<ViewModel.ExaminationManage.ExaminationPlanView> GetExaminationPlanViewList(ViewModel.ConfiguretView examinationPlanView,
- Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID, List<Guid?> selectIDlist)
- {
- Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if (gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (examsCategoryID.HasValue)
- {
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- }
- if (examinationModeID.HasValue)
- {
- exp = exp.And(x => x.ExaminationModeID == examinationModeID);
- }
- if (examinationStyleID.HasValue)
- {
- exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
- }
- if (starWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
- }
- if (endWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
- }
- if (statusID.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == statusID);
- }
- if (selectIDlist != null && selectIDlist.Count > 0)
- {
- exp = exp.And(x => selectIDlist.Contains(x.ExaminationPlanID));
- }
- var q = ExaminationPlanDAL.GetExaminationPlanView(exp);
- if (courseEndWeek.HasValue)
- {
- q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
- }
- if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
- q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
- return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToList();
- }
- public List<ViewModel.ExaminationManage.ExaminationPlanView> GetAdultExaminationPlanViewList(ViewModel.ConfiguretView examinationPlanView,
- Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID, List<Guid?> selectIDlist)
- {
- Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if (gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (examsCategoryID.HasValue)
- {
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- }
- if (examinationModeID.HasValue)
- {
- exp = exp.And(x => x.ExaminationModeID == examinationModeID);
- }
- if (examinationStyleID.HasValue)
- {
- exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
- }
- if (starWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
- }
- if (endWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
- }
- if (statusID.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == statusID);
- }
- if (selectIDlist != null && selectIDlist.Count > 0)
- {
- exp = exp.And(x => selectIDlist.Contains(x.ExaminationPlanID));
- }
- var q = ExaminationPlanDAL.GetExaminationPlanViewForAdult(exp);
- if (courseEndWeek.HasValue)
- {
- q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
- }
- if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
- q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
- return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToList();
- }
- public List<ViewModel.ExaminationManage.ExaminationPlanView> GetGdssExaminationPlanViewList(ViewModel.ConfiguretView examinationPlanView,
- Guid? schoolyearID, Guid? collegeID, Guid? classmajorID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? courseEndWeek, int? statusID, List<Guid?> selectIDlist)
- {
- Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- //原先是用教学任务关联的由于补考记录没有对应的教学任务,所以改用专业课程关联,
- //学校那边说不会有多个教研室开同一门可的情况,即使有,那这些教研室同样可以查到,也没有问题
- exp = exp.And(x => x.EM_Coursematerial.EM_SpecialtyCourse.Any(w => w.CF_Department.CollegeID == collegeID));
- }
- if (gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (examsCategoryID.HasValue)
- {
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- }
- if (examinationModeID.HasValue)
- {
- exp = exp.And(x => x.ExaminationModeID == examinationModeID);
- }
- if (examinationStyleID.HasValue)
- {
- exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
- }
- if(classmajorID.HasValue)
- {
- var classmajor = ExaminationPlanDAL.ClassmajorRepository.GetList(x => x.ClassmajorID == classmajorID).FirstOrDefault();
- exp = exp.And(x => x.ClassName == classmajor.Name);
- }
- if (statusID.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == statusID);
- }
- if (selectIDlist != null && selectIDlist.Count > 0)
- {
- exp = exp.And(x => selectIDlist.Contains(x.ExaminationPlanID));
- }
- var q = ExaminationPlanDAL.GetExaminationPlanViewForAdult(exp);
- if (courseEndWeek.HasValue)
- {
- q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
- }
- if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
- q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
- return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToList();
- }
- public IGridResultSet<StaffView> GetExaminationTeacherViewInfo(Guid? examinationRoomLayoutID)
- {
- return ExaminationPlanDAL.GetExaminationTeacherView(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID, (x => true)).ToGridResultSet();
- }
- public IGridResultSet<ExaminationRoomStudentView> GetExaminationStudentViewInfo(Guid? examinationRoomLayoutID)
- {
- var roomLayout = ExaminationPlanDAL.ExaminationRoomLayoutRepository.GetSingle(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID);
- var q = ExaminationPlanDAL.GetExaminationRoomStudentView(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID);
- if (roomLayout.StudentOrderType == (int)CF_StudentOrderType.StudentNo)
- {
- return q.OrderBy(x => x.LoginID).ToGridResultSet();
- }
- else
- {
- return q.ToGridResultSet();
- }
- }
- public ViewModel.ExaminationManage.ExaminationPlanView GetExaminationPlanViewInfo(Guid? examinationPlanID)
- {
- return ExaminationPlanDAL.GetExaminationPlanView(x => x.ExaminationPlanID == examinationPlanID).FirstOrDefault();
- }
- public ExaminationRoomLayoutView GetExaminationRoomLayoutViewInfo(Guid? examinationRoomLayoutID)
- {
- return ExaminationPlanDAL.GetExaminationRoomLayoutView(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID).FirstOrDefault();
- }
- public virtual void GenerateExaminationPlan(Guid? schoolyearID, Guid? collegeID, int? gradeID, int? standardID)
- {
- var nowDate = DateTime.Now;
- var recordStatusID = (int)CF_ApprovalStatus.NotSubmitted;
- var user = CustomPrincipal.Current;
- Expression<Func<EM_EducationMission, bool>> exp = x => true;
- Expression<Func<EM_EducationMissionClass, bool>> emcExp = x => true;
- //x.SchoolyearID == schoolyearID;
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if (gradeID.HasValue && gradeID != -1)
- {
- emcExp = emcExp.And(x => x.CF_Classmajor.Any(y => y.CF_Grademajor.GradeID == gradeID));
- }
- if (standardID.HasValue && standardID != -1)
- {
- emcExp = emcExp.And(x => x.CF_Classmajor.Any(y => y.CF_Grademajor.CF_Facultymajor.StandardID == standardID));
- }
- var examinationPlanQuery = ExaminationPlanDAL.GetExaminationPlanByEducationMission(exp, emcExp);
- List<ExaminationPlanView> examinationPlanViewList = this.GetQueryByDataRangeByCollege(examinationPlanQuery).ToList();
- var dbExaminationPlanList = ExaminationPlanDAL.ExaminationPlanRepository.Entities;
- int sameCount = 0;
- List<EX_ExaminationPlan> listExaminationPlan = new List<EX_ExaminationPlan>();
- foreach (var examinationPlan in examinationPlanViewList)
- {
- if (dbExaminationPlanList.Any(x => x.ClassName.Contains(examinationPlan.ClassName)))
- {
- sameCount = dbExaminationPlanList.Where(x => x.ClassName.Contains(examinationPlan.ClassName)).Count();
- }
- EX_ExaminationPlan newexaminationPlan = new EX_ExaminationPlan();
- newexaminationPlan.ExaminationPlanID = Guid.NewGuid();
- newexaminationPlan.SchoolyearID = examinationPlan.SchoolyearID;
- newexaminationPlan.CollegeID = examinationPlan.CollegeID;
- newexaminationPlan.CoursematerialID = examinationPlan.CoursematerialID;
- newexaminationPlan.ExaminationModeID = examinationPlan.ExaminationModeID;
- newexaminationPlan.ExaminationStyleID = examinationPlan.ExaminationStyleID;
- newexaminationPlan.ExamsCategoryID = (int)CF_ExamsCategory.FinalExam;
- newexaminationPlan.EducationMissionID = examinationPlan.EducationMissionID;
- newexaminationPlan.ClassmajorID = examinationPlan.ClassmajorID;
- //if (sameCount > 0)
- //{
- // examinationPlan.ClassName = examinationPlan.ClassName + sameCount.ToString();
- //}
- newexaminationPlan.ClassName = examinationPlan.ClassName;
- newexaminationPlan.ExaminationDate = examinationPlan.ExaminationDate;
- newexaminationPlan.StartTime = examinationPlan.StartTime;
- newexaminationPlan.EndTime = examinationPlan.EndTime;
- newexaminationPlan.CF_Student = new HashSet<CF_Student>(examinationPlan.Students);
- SetNewStatus(newexaminationPlan);
- newexaminationPlan.RecordStatus = recordStatusID;
- listExaminationPlan.Add(newexaminationPlan);
- }
- //var examinationPlanList = examinationPlanViewList.Select(x => new EX_ExaminationPlan
- //{
- // ExaminationPlanID = Guid.NewGuid(),
- // SchoolyearID = x.SchoolyearID,
- // CollegeID = x.CollegeID,
- // CoursematerialID = x.CoursematerialID,
- // ExaminationModeID = x.ExaminationModeID,
- // ExaminationStyleID = x.ExaminationStyleID,
- // ExamsCategoryID = (int)CF_ExamsCategory.FinalExam,
- // EducationMissionID = x.EducationMissionID,
- // ClassmajorID = x.ClassmajorID,
- // ClassName = x.ClassName,
- // ExaminationDate = x.ExaminationDate,
- // StartTime = x.StartTime,
- // EndTime = x.EndTime,
- // CF_Student = new HashSet<CF_Student>(x.Students),
- // RecordStatus = recordStatusID,
- // CreateUserID = user.UserID,
- // CreateTime = nowDate,
- // ModifyUserID = user.UserID,
- // ModifyTime = nowDate
- //}).ToList();
- this.UnitOfWork.BulkInsert(listExaminationPlan);
- this.UnitOfWork.BulkInsert(listExaminationPlan, (x => x.CF_Student));
- }
- public void GenerateResitPlan(Guid schoolyearID)
- {
- try
- {
- var statusList = this.GetStatusViewList();
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- List<EX_ExaminationPlan> listExaminationPlan = new List<EX_ExaminationPlan>();
- var dbExaminationPlanList = ExaminationPlanDAL.ExaminationPlanRepository.Entities;
- var resitExaminationPlanList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByResitStudent(schoolyearID, curSchoolyear.SchoolYearID)).ToList();
- var resitExaminationPlanByFinalExaminationList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByResitExamination(curSchoolyear.SchoolYearID)).ToList();
- resitExaminationPlanList = resitExaminationPlanList.Concat(resitExaminationPlanByFinalExaminationList).ToList();
- int sameCount = 0;
- foreach (var resitExaminationPlan in resitExaminationPlanList)
- {
- if (dbExaminationPlanList.Any(x => x.ClassName.Contains(resitExaminationPlan.ClassName)))
- {
- sameCount = dbExaminationPlanList.Where(x => x.ClassName.Contains(resitExaminationPlan.ClassName)).Count();
- }
- EX_ExaminationPlan examinationPlan = new EX_ExaminationPlan();
- examinationPlan.ExaminationPlanID = Guid.NewGuid();
- examinationPlan.SchoolyearID = resitExaminationPlan.SchoolyearID;
- examinationPlan.CollegeID = resitExaminationPlan.CollegeID;
- examinationPlan.CoursematerialID = resitExaminationPlan.CoursematerialID;
- examinationPlan.ExaminationModeID = resitExaminationPlan.ExaminationModeID;
- examinationPlan.ExaminationStyleID = resitExaminationPlan.ExaminationStyleID;
- examinationPlan.ExamsCategoryID = (int)CF_ExamsCategory.Resit;
- //if (sameCount > 0)
- //{
- // resitExaminationPlan.ClassName = resitExaminationPlan.ClassName + sameCount.ToString();
- //}
- examinationPlan.ClassName = resitExaminationPlan.ClassName;
- examinationPlan.CF_Student = new HashSet<CF_Student>(resitExaminationPlan.Students);
- SetNewStatus(examinationPlan);
- examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
- listExaminationPlan.Add(examinationPlan);
- }
- UnitOfWork.BulkInsert(listExaminationPlan);
- this.UnitOfWork.BulkInsert(listExaminationPlan, (x => x.CF_Student));
- }
- catch (Exception)
- {
- throw;
- }
- }
- public void GenerateGraduateExamPlan(int year, Guid? collegeID, int? standardID, decimal? learnSystem)
- {
- try
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- List<EX_ExaminationPlan> listExaminationPlan = new List<EX_ExaminationPlan>();
- var dbgraduateExamPlanList = ExaminationPlanDAL.ExaminationPlanRepository.Entities;
- var graduateExamPlanList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByGraduateExamStudent(year,collegeID,standardID,learnSystem, curSchoolyear.SchoolYearID)).ToList();
- var graduateExamPlanByFinalExaminationList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByGraduateExamination(curSchoolyear.SchoolYearID)).ToList();
- graduateExamPlanList = graduateExamPlanList.Concat(graduateExamPlanByFinalExaminationList).ToList();
- int sameCount = 0;
- foreach (var graduateExamPlan in graduateExamPlanList)
- {
- if (dbgraduateExamPlanList.Any(x => x.ClassName.Contains(graduateExamPlan.ClassName)))
- {
- sameCount = dbgraduateExamPlanList.Where(x => x.ClassName.Contains(graduateExamPlan.ClassName)).Count();
- }
- EX_ExaminationPlan examinationPlan = new EX_ExaminationPlan();
- examinationPlan.ExaminationPlanID = Guid.NewGuid();
- examinationPlan.SchoolyearID = graduateExamPlan.SchoolyearID;
- examinationPlan.CollegeID = graduateExamPlan.CollegeID;
- examinationPlan.CoursematerialID = graduateExamPlan.CoursematerialID;
- examinationPlan.ExaminationModeID = graduateExamPlan.ExaminationModeID;
- examinationPlan.ExaminationStyleID = graduateExamPlan.ExaminationStyleID;
- examinationPlan.ExamsCategoryID = (int)CF_ExamsCategory.GraduationExam;
- //if (sameCount > 0)
- //{
- // graduateExamPlan.ClassName = graduateExamPlan.ClassName + sameCount.ToString();
- //}
- examinationPlan.ClassName = graduateExamPlan.ClassName;
- examinationPlan.CF_Student = new HashSet<CF_Student>(graduateExamPlan.Students);
- SetNewStatus(examinationPlan);
- examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
- listExaminationPlan.Add(examinationPlan);
- }
- UnitOfWork.BulkInsert(listExaminationPlan);
- this.UnitOfWork.BulkInsert(listExaminationPlan, (x => x.CF_Student));
- }
- catch (Exception)
- {
- throw;
- }
- }
- public void Save(ExaminationPlanView examinationPlanView)
- {
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var examinationPlanScheduleView = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).FirstOrDefault();
- var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanScheduleView.ExaminationPlan.ExaminationDate
- && x.StartTime <= examinationPlanScheduleView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanScheduleView.ExaminationPlan.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
- && x.ExaminationPlanID != examinationPlanScheduleView.ExaminationPlan.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).ToList();
- var timeSegment = new TimeSegmentView { ExaminationDate = examinationPlanView.ExaminationDate.Value, StartTime = examinationPlanView.StartTime.Value, EndTime = examinationPlanView.EndTime.Value };
- var errorList = new List<string>();
- foreach (var classroomLayout in examinationPlanScheduleView.ExaminationPlan.EX_ExaminationRoomLayout)
- {
- var studentIDList = classroomLayout.EX_ExaminationRoomStudent.Select(x => x.UserID.Value).ToList();
- if (IsConflictForSetTime(examinationPlanScheduleView, studentIDList, timeSegment, classroomLayout.CF_Classroom, scheduledPlanViewList))
- {
- errorList.Add("考场" + classroomLayout.CF_Classroom.Name + "时间安排存在冲突,请重新核对后再进行设置。");
- }
- }
- if (errorList.Count > 0)
- {
- throw new Exception(string.Join(",", errorList));
- }
- if (examinationPlanScheduleView != null)
- {
- examinationPlanScheduleView.ExaminationPlan.ExaminationDate = examinationPlanView.ExaminationDate;
- examinationPlanScheduleView.ExaminationPlan.StartTime = examinationPlanView.StartTime;
- examinationPlanScheduleView.ExaminationPlan.EndTime = examinationPlanView.EndTime;
- this.SetModifyStatus(examinationPlanScheduleView.ExaminationPlan);
-
- }
- else
- {
- throw new Exception("指定的考试计划不存在。");
- }
-
- UnitOfWork.Commit();
-
- }
- public virtual void Submit(IList<Guid?> examinationPlanIDList)
- {
- var examinationPlanList = ExaminationPlanDAL.ExaminationPlanRepository
- .GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID),
- (x => x.EX_ExaminationRoomLayout)).ToList();
- var examinationPlanLayoutList = ExaminationPlanDAL.ExaminationRoomLayoutRepository
- .GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID),
- (x => x.CF_Staff),
- (x => x.EX_ExaminationRoomStudent),
- (x => x.CF_Classroom));
- var submitedPlan = examinationPlanList.Where(x => x.RecordStatus != (int)CF_ApprovalStatus.NotSubmitted).ToList();
- if (submitedPlan.Count > 0)
- {
- string submitedClassNames = string.Join(",", submitedPlan.Select(x => x.ClassName)) + "并不在未提交状态,请选择正确的记录进行提交。";
- throw new Exception(submitedClassNames);
- }
- var noLayoutPlanList = (from ep in examinationPlanList
- join epl in examinationPlanLayoutList on ep.ExaminationPlanID equals epl.ExaminationPlanID into depl
- from eepl in depl.DefaultIfEmpty()
- where eepl == null
- select ep).ToList();
- if (noLayoutPlanList.Count > 0)
- {
- string noLayoutPlanClassNames = string.Join(",", noLayoutPlanList.Select(x => x.ClassName)) + "没有设置对应的考场,请先设置再进行提交。";
- throw new Exception(noLayoutPlanClassNames);
- }
- var noTeacherPlanList = (from ep in examinationPlanList
- join epl in examinationPlanLayoutList on ep.ExaminationPlanID equals epl.ExaminationPlanID
- from s in epl.CF_Staff.DefaultIfEmpty()
- where s == null
- select new { Plan = ep, Classroom = epl.CF_Classroom }).ToList();
- if (noTeacherPlanList.Count > 0)
- {
- string noTeacherPlanClassNames = string.Join(";", noTeacherPlanList.Select(x => x.Plan.ClassName + ",考场" + x.Classroom.Name)) + "没有设置监考老师,请先设置再进行提交。";
- throw new Exception(noTeacherPlanClassNames);
- }
- var noStudentPlanList = (from ep in examinationPlanList
- join epl in examinationPlanLayoutList on ep.ExaminationPlanID equals epl.ExaminationPlanID
- from s in epl.EX_ExaminationRoomStudent.DefaultIfEmpty()
- where s == null
- select new { Plan = ep, Classroom = epl.CF_Classroom }).ToList();
- if (noStudentPlanList.Count > 0)
- {
- string noStudentPlanClassNames = string.Join(";", noStudentPlanList.Select(x => x.Plan.ClassName + ",考场" + x.Classroom.Name)) + "没有设置学生,请先设置再进行提交。";
- throw new Exception(noStudentPlanClassNames);
- }
- if (examinationPlanIDList.Count > 0)
- {
- UnitOfWork.Update<EX_ExaminationPlan>((x => new EX_ExaminationPlan { RecordStatus = (int)CF_ApprovalStatus.Submitted }), (x => examinationPlanIDList.Contains(x.ExaminationPlanID)));
- }
- }
- public void UnSubmit(IList<Guid?> examinationPlanIDList)
- {
- var examinationPlanList = ExaminationPlanDAL.ExaminationPlanRepository
- .GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID),
- (x => x.EX_ExaminationRoomLayout)).ToList();
- var submitedPlan = examinationPlanList.Where(x => x.RecordStatus != (int)CF_ApprovalStatus.Submitted).ToList();
- if (submitedPlan.Count > 0)
- {
- string submitedClassNames = string.Join(",", submitedPlan.Select(x => x.ClassName)) + "并不在已提交状态,请选择正确的记录进行撤回。";
- throw new Exception(submitedClassNames);
- }
- if (examinationPlanIDList.Count > 0)
- {
- UnitOfWork.Update<EX_ExaminationPlan>((x => new EX_ExaminationPlan { RecordStatus = (int)CF_ApprovalStatus.NotSubmitted }), (x => examinationPlanIDList.Contains(x.ExaminationPlanID)));
- }
- }
- public IGridResultSet<ExaminationRoomLayoutView> GetExaminationRoomLayoutViewList(Guid examinationPlanID)
- {
- return this.ExaminationPlanDAL.GetExaminationRoomLayoutView(x => x.ExaminationPlanID == examinationPlanID).ToGridResultSet();
- }
- protected List<EX_ExaminationRoomStudent> SetRoomStudentSeats(IList<ExaminationRoomStudentView> studentList, ClassroomView classroom,
- int rowSpacing, int columnSpacing, CF_StudentOrderType? orderType = null)
- {
- var result = new List<EX_ExaminationRoomStudent>();
- if (classroom == null) throw new Exception("指定的教室资源不存在。");
- int currentIndex = 0;
- var firstRowSeatCount = Math.Ceiling((double)classroom.ColumnCount / (double)(columnSpacing + 1));
- var rowCount = Math.Ceiling((double)classroom.RowCout / (double)(rowSpacing + 1));
- switch (orderType)
- {
- case CF_StudentOrderType.StudentNo:
- studentList = studentList.OrderBy(x => x.LoginID).ToList();
- break;
- case CF_StudentOrderType.Random:
- studentList = studentList.OrderBy(x => Guid.NewGuid()).ToList();
- break;
- }
- for (int i = 0; i < rowCount; i++)
- {
- for (int j = 0; j < firstRowSeatCount; j++)
- {
- if (currentIndex >= studentList.Count)
- {
- break;
- }
- var roomStudent = new EX_ExaminationRoomStudent();
- roomStudent.ExaminationRoomStudentID = Guid.NewGuid();
- roomStudent.ExaminationRoomLayoutID = studentList[currentIndex].ExaminationRoomLayoutID;
- roomStudent.UserID = studentList[currentIndex].UserID;
- roomStudent.Row = i * (rowSpacing + 1) + 1;
- roomStudent.Column = j * (columnSpacing + 1) + 1;
- roomStudent.Remark = studentList[currentIndex].Remark;
- result.Add(roomStudent);
- currentIndex++;
- }
- }
- return result;
- }
- public void SaveClassroomLayout(ViewModel.ExaminationManage.ExaminationRoomLayoutView examinationRoomLayoutView, IList<Guid?> staffIDList, IList<ExaminationRoomStudentView> studentList)
- {
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var examinationRoomLayoutEntity = ExaminationPlanDAL.ExaminationRoomLayoutRepository
- .GetSingle(x => x.ExaminationRoomLayoutID == examinationRoomLayoutView.ExaminationRoomLayoutID,
- (x => x.CF_Staff),
- (x => x.EX_ExaminationRoomStudent));
- var examinationPlanView = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationPlanID == examinationRoomLayoutView.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).FirstOrDefault();
- if (examinationPlanView == null)
- {
- throw new Exception("找不到对应的考试计划。");
- }
- if (examinationRoomLayoutEntity == null && examinationPlanView.ExaminationPlan.EX_ExaminationRoomLayout.Any(x => x.ClassroomID == examinationRoomLayoutView.ClassroomID))
- {
- throw new Exception("该考试计划已经设置该教室为考场!");
- }
- var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationPlan.ExaminationDate
- && x.StartTime <= examinationPlanView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanView.ExaminationPlan.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
- && x.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).ToList();
- var timeSegment = new TimeSegmentView { ExaminationDate = examinationPlanView.ExaminationPlan.ExaminationDate.Value, StartTime = examinationPlanView.ExaminationPlan.StartTime.Value, EndTime = examinationPlanView.ExaminationPlan.EndTime.Value };
- var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationRoomLayoutView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
- if (IsConflictForSetTime(examinationPlanView, studentList.Select(x => x.UserID.Value).ToList(), timeSegment, classroomEntity, scheduledPlanViewList))
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,请重新核对后再进行设置。");
- }
- if (examinationRoomLayoutEntity != null)
- {
- examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
- examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
- examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
- examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
- examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
- this.SetModifyStatus(examinationRoomLayoutEntity);
- }
- else
- {
- examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
- examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
- examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
- examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
- examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
- examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
- examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
- this.SetModifyStatus(examinationRoomLayoutEntity);
- this.UnitOfWork.Add(examinationRoomLayoutEntity);
- }
- var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
- examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>();
- examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
- UnitOfWork.Remove<EX_ExaminationRoomStudent>(x => x.ExaminationRoomLayoutID == examinationRoomLayoutEntity.ExaminationRoomLayoutID);
- var classroomID = (examinationRoomLayoutEntity.ClassroomID ?? Guid.Empty);
- var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomID).FirstOrDefault();
- var roomStudentList = this.SetRoomStudentSeats(studentList, classroom,
- examinationRoomLayoutEntity.RowSpacing ?? 0, examinationRoomLayoutEntity.ColumnSpacing ?? 0);
- roomStudentList.ForEach(x =>
- {
- x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
- this.SetNewStatus(x);
- this.UnitOfWork.Add(x);
- });
- UnitOfWork.Commit();
- }
- /// <summary>
- /// 新增保存
- /// </summary>
- /// <param name="examinationRoomLayoutView"></param>
- /// <param name="staffIDList"></param>
- /// <param name="studentList"></param>
- public void SaveAddClassroomLayout(ExaminationRoomLayoutView examinationRoomLayoutView, IList<Guid?> staffIDList, IList<ExaminationRoomStudentView> studentList)
- {
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var examinationRoomLayoutEntity = ExaminationPlanDAL.ExaminationRoomLayoutRepository
- .GetSingle(x => x.ExaminationRoomLayoutID == examinationRoomLayoutView.ExaminationRoomLayoutID,
- (x => x.CF_Staff),
- (x => x.EX_ExaminationRoomStudent));
- var examinationPlanView = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationPlanID == examinationRoomLayoutView.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).FirstOrDefault();
- if (examinationPlanView == null)
- {
- throw new Exception("找不到对应的考试计划。");
- }
- var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationPlan.ExaminationDate
- && x.StartTime <= examinationPlanView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanView.ExaminationPlan.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
- && x.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).ToList();
- var timeSegment = new TimeSegmentView { ExaminationDate = examinationPlanView.ExaminationPlan.ExaminationDate.Value, StartTime = examinationPlanView.ExaminationPlan.StartTime.Value, EndTime = examinationPlanView.ExaminationPlan.EndTime.Value };
- var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationRoomLayoutView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
- if (IsConflictForSetTime(examinationPlanView, studentList.Select(x => x.UserID.Value).ToList(), timeSegment, classroomEntity, scheduledPlanViewList))
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,请重新核对后再进行设置。");
- }
- if (examinationRoomLayoutEntity != null)
- {
- examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
- examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
- examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
- examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
- examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
- this.SetModifyStatus(examinationRoomLayoutEntity);
- }
- else
- {
- examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
- examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
- examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
- examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
- examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
- examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
- examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
- this.SetModifyStatus(examinationRoomLayoutEntity);
- this.UnitOfWork.Add(examinationRoomLayoutEntity);
- }
- var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
- examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>();
- examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
- UnitOfWork.Remove<EX_ExaminationRoomStudent>(x => x.ExaminationRoomLayoutID == examinationRoomLayoutEntity.ExaminationRoomLayoutID);
- var classroomID = (examinationRoomLayoutEntity.ClassroomID ?? Guid.Empty);
- var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomID).FirstOrDefault();
- var roomStudentList = this.SetRoomStudentSeats(studentList, classroom,
- examinationRoomLayoutEntity.RowSpacing ?? 0, examinationRoomLayoutEntity.ColumnSpacing ?? 0);
- roomStudentList.ForEach(x =>
- {
- x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
- this.SetNewStatus(x);
- this.UnitOfWork.Add(x);
- });
- UnitOfWork.Commit();
- }
- public Bowin.Common.Linq.Entity.IGridResultSet<StudentsView> GetAvailableStudentViewList(Guid examinationPlanID,
- Guid? collegeID, Guid? grademajorID, Guid? classmajorID, CF_StudentOrderType studentOrderType, int? pageIndex, int? pageSize)
- {
- var inschool = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x=>x.InSchoolStatusID).ToList();
- Expression<Func<CF_Student, bool>> studentExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && inschool.Contains(x.InSchoolStatusID));
- Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
- Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
- IQueryable<StudentsView> query;
-
- if (collegeID.HasValue || grademajorID.HasValue || classmajorID.HasValue)
- {
- if (collegeID.HasValue)
- {
- gradeExp = gradeExp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
- }
- if (grademajorID.HasValue)
- {
- classExp = classExp.And(x => x.GrademajorID == grademajorID);
- }
- if (classmajorID.HasValue)
- {
- studentExp = studentExp.And(x => x.ClassmajorID == classmajorID);
- }
- query = StudentsDAL.GetStudentQueryable(studentExp, classExp, gradeExp);
- }
- else
- {
- query = ExaminationPlanDAL.GetAvailableStudentView(x => x.ExaminationPlanID == examinationPlanID, studentExp);
- }
- if (studentOrderType == CF_StudentOrderType.Random)
- {
- query = query.OrderByNewId();
- }
- else if (studentOrderType == CF_StudentOrderType.StudentNo)
- {
- query = query.OrderBy(x => x.LoginID);
- }
-
- return query.ToGridResultSet(pageIndex, pageSize);
- }
- public IGridResultSet<StudentsView> GetAddAvailableStudentViewList(Guid? collegeID, Guid? grademajorID, Guid? classmajorID, CF_StudentOrderType studentOrderType, int? pageIndex, int? pageSize)
- {
- var inschool = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- Expression<Func<CF_Student, bool>> studentExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && inschool.Contains(x.InSchoolStatusID));
- Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
- Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
- IQueryable<StudentsView> query;
- if (collegeID.HasValue || grademajorID.HasValue || classmajorID.HasValue)
- {
- if (collegeID.HasValue)
- {
- gradeExp = gradeExp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
- }
- if (grademajorID.HasValue)
- {
- classExp = classExp.And(x => x.GrademajorID == grademajorID);
- }
- if (classmajorID.HasValue)
- {
- studentExp = studentExp.And(x => x.ClassmajorID == classmajorID);
- }
- query = StudentsDAL.GetStudentQueryable(studentExp, classExp, gradeExp);
- }
- else
- {
- query = ExaminationPlanDAL.GetAvailableStudentView(x => true, studentExp);
- }
- if (studentOrderType == CF_StudentOrderType.Random)
- {
- query = query.OrderByNewId();
- }
- else if (studentOrderType == CF_StudentOrderType.StudentNo)
- {
- query = query.OrderBy(x => x.LoginID);
- }
- return query.ToGridResultSet(pageIndex, pageSize);
- }
- public void DeleteExaminationClassroomLayout(IList<Guid> examinationRoomLayoutIDs)
- {
- var examinationLayoutList = this.ExaminationPlanDAL.ExaminationRoomLayoutRepository
- .GetList(x => examinationRoomLayoutIDs.Contains(x.ExaminationRoomLayoutID),
- (x => x.EX_ExaminationRoomStudent), (x => x.CF_Staff)).ToList();
- foreach (var examinationLayout in examinationLayoutList)
- {
- examinationLayout.CF_Staff = new HashSet<CF_Staff>();
- examinationLayout.EX_ExaminationRoomStudent.ToList().ForEach(x => this.UnitOfWork.Remove(x));
- this.UnitOfWork.Remove(examinationLayout);
- }
- this.UnitOfWork.Commit();
- }
- public void Delete(IList<Guid> examinationPlanIDs)
- {
- try
- {
- var nullableIDs = examinationPlanIDs.Select(x => (Guid?)x).ToList();
- List<EX_ExaminationPlan> ExaminationPlanList = examinationPlanRepository
- .GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID),
- (x => x.CF_Student), (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))).ToList();
- if (ExaminationPlanList.Any(x => x.RecordStatus != (int)CF_ApprovalStatus.NotSubmitted))
- {
- throw new Exception("要删除的信息只能是未提交的信息。");
- }
- var layoutList = ExaminationPlanList.SelectMany(x => x.EX_ExaminationRoomLayout).ToList();
- var layoutIDList = layoutList.Select(x => (Guid?)x.ExaminationRoomLayoutID).ToList();
- using (var scope = new TransactionScope())
- {
- UnitOfWork.Delete(ExaminationPlanList, (x => x.CF_Student));
- UnitOfWork.Delete(layoutList, (x => x.CF_Staff));
- UnitOfWork.Delete<EX_ExaminationRoomStudent>(x => layoutIDList.Contains(x.ExaminationRoomLayoutID));
- UnitOfWork.Delete<EX_ExaminationRoomLayout>(x => layoutIDList.Contains(x.ExaminationRoomLayoutID));
- UnitOfWork.Delete<EX_ExaminationPlan>(x => examinationPlanIDs.Contains(x.ExaminationPlanID));
- scope.Complete();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public virtual void AutoGenerateExaminationRoomLayout(IList<Guid?> examinationPlanIDList)
- {
- DateTime today = DateTime.Today;
- var userCollegeIDList = this.GetQueryByDataRangeByCollege(CollegeDAL.GetCollegeViewQueryable()).Select(x => x.CollegeID).ToList();
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- //获取可排时间
- var examinationDateList = this.TimeSegmentDAL.GetTimeSegmentView(x => x.ExaminationDate > today)
- .OrderByDescending(x => x.IsForResit).ThenBy(x => x.ExaminationDate).ThenBy(x => x.StartTime).ToList();
- //获取当前学年学期的考试计划(由于要检测冲突,所以不能只拿没排完的,也不要限制数据范围)
- var examinationPlanList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.SchoolyearID == curSchoolyear.SchoolYearID
- //&& (x.ExamsCategoryID == (int)CF_ExamsCategory.Resit || x.ExamsCategoryID == (int)CF_ExamsCategory.GraduationExam)
- )
- .Include(x => x.EM_Coursematerial)
- .Include(x => x.CF_Student.Select(w => w.Sys_User))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).ToList();
- //获取没排完的考试计划
- var notCompleteExaminationPlanList = examinationPlanList.Where(x => x.StudentCount < x.MissionStudentCount
- && userCollegeIDList.Contains(x.ExaminationPlan.CollegeID.Value)
- && x.ExaminationPlan.RecordStatus == (int)EX_ExaminationPlanStatus.NotSubmitted
- && (examinationPlanIDList.Count == 0 || examinationPlanIDList.Contains(x.ExaminationPlan.ExaminationPlanID))).ToList();
- if (examinationPlanIDList.Where(x => !notCompleteExaminationPlanList
- .Select(w => (Guid?)w.ExaminationPlan.ExaminationPlanID).Contains(x)).Count() > 0)
- {
- throw new Exception("当前选中的考试计划不包含当前学年学期需要排考的计划,请检查选择。");
- }
- //获取已经指定时间的未排考试计划(三部分组成:
- //1、已经指定了时间的未排计划;
- //2、未指定时间但有其他同科目的未排计划已经指定了时间;
- //3、未指定时间但有其他同科目的已派计划已经指定了时间)
- var notCompleteExaminationPlanWithDateList = notCompleteExaminationPlanList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue
- && x.ExaminationPlan.StartTime.HasValue && x.ExaminationPlan.EndTime.HasValue).ToList();
- notCompleteExaminationPlanWithDateList = notCompleteExaminationPlanWithDateList.Concat(
- notCompleteExaminationPlanList.Where(x =>
- !notCompleteExaminationPlanWithDateList.Select(w => w.ExaminationPlan.ExaminationPlanID).Contains(x.ExaminationPlan.ExaminationPlanID)
- && notCompleteExaminationPlanWithDateList.Select(w => w.ExaminationPlan.CoursematerialID).Contains(x.ExaminationPlan.CoursematerialID)
- )
- ).Concat(
- from notComplete in notCompleteExaminationPlanList
- join complete in examinationPlanList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue)
- on notComplete.ExaminationPlan.CoursematerialID equals complete.ExaminationPlan.CoursematerialID
- group notComplete by notComplete.ExaminationPlan.ExaminationPlanID into g
- select g.FirstOrDefault()
- ).ToList();
- //获取排课
- var scheduleDateTimeList = examinationDateList.Select(x => new StartEndTimeView { StartTime = x.ExaminationDate.Add(x.StartTime), EndTime = x.ExaminationDate.Add(x.EndTime) })
- .Concat(notCompleteExaminationPlanWithDateList
- .Where(x => x.ExaminationPlan.ExaminationDate.HasValue && x.ExaminationPlan.StartTime.HasValue && x.ExaminationPlan.EndTime.HasValue)
- .GroupBy(x => new
- {
- StartTime = x.ExaminationPlan.ExaminationDate.Value.Add(x.ExaminationPlan.StartTime.Value),
- EndTime = x.ExaminationPlan.ExaminationDate.Value.Add(x.ExaminationPlan.EndTime.Value)
- }).Select(x => new StartEndTimeView
- {
- StartTime = x.Key.StartTime,
- EndTime = x.Key.EndTime
- }))
- .ToList();
- var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var excessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
- curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var conflictStudentPlanWithDateList = (from plan in notCompleteExaminationPlanWithDateList
- from student in plan.ExaminationPlan.CF_Student
- from scheduling in schedulingList.Where(x => x.Date == plan.ExaminationPlan.ExaminationDate
- && x.StartTime <= plan.ExaminationPlan.EndTime && x.EndTime >= plan.ExaminationPlan.StartTime)
- from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student.UserID)
- group plan by plan.ExaminationPlan.ExaminationPlanID into g
- select g.FirstOrDefault()
- ).ToList();
- if (conflictStudentPlanWithDateList.Count > 0)
- {
- throw new Exception(string.Format("考试计划{0}由于指定了具体的考试时间,而学生需要上课无法安排,未免影响整体的考试安排,排考中止。",
- string.Join("、", conflictStudentPlanWithDateList.Select(x => x.ExaminationPlan.ClassName))));
- }
- //获取未指定时间的未排考试计划
- var notCompleteExaminationPlanWithOutDateList = notCompleteExaminationPlanList
- .Where(x =>
- !notCompleteExaminationPlanWithDateList.Select(w => w.ExaminationPlan.CoursematerialID).Contains(x.ExaminationPlan.CoursematerialID)
- ).ToList();
- //获取已排完的考试计划
- var scheduledStudentList = (from plan in examinationPlanList.Where(x => x.StudentCount > 0)
- from layout in plan.ExaminationPlan.EX_ExaminationRoomLayout
- from student in layout.EX_ExaminationRoomStudent
- select new StudentClassroomView
- {
- ExaminationDate = plan.ExaminationPlan.ExaminationDate,
- StartTime = plan.ExaminationPlan.StartTime,
- EndTime = plan.ExaminationPlan.EndTime,
- ClassroomID = layout.ClassroomID,
- UserID = student.UserID,
- TeacherIDList = layout.CF_Staff.Select(x => x.UserID).ToList(),
- ExaminationStyleID = plan.ExaminationPlan.ExaminationStyleID,
- ExaminationPlanID = plan.ExaminationPlan.ExaminationPlanID
- }).ToList();
- //获取足够的考室信息
- var examinationRoomList = this.RoomSettingDAL.ExaminationRoomSettingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE,
- (x => x.CF_Classroom.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
- (x => x.CF_Classroom.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)),
- (x => x.CF_Classroom.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent))).ToList();
- var classroomIDList = examinationRoomList.Select(x => x.ClassroomID).ToList();
- var classroomViewList = this.ClassroomDAL.GetClassroomViewQueryable(x => classroomIDList.Contains(x.ClassroomID)).ToList();
- //获取足够的监考员信息
- var examinationTeacherList = this.ExaminationTeacherDAL.ExaminationTeacherRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE,
- (x => x.CF_Staff))
- .ToList();
- var existsExaminationDateList = notCompleteExaminationPlanWithDateList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue)
- .Concat(
- from notComplete in notCompleteExaminationPlanWithDateList
- join complete in examinationPlanList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue)
- on notComplete.ExaminationPlan.CoursematerialID equals complete.ExaminationPlan.CoursematerialID
- group complete by new { complete.ExaminationPlan.ExaminationDate, complete.ExaminationPlan.StartTime, complete.ExaminationPlan.EndTime } into g
- select g.FirstOrDefault()
- )
- .GroupBy(x => new { x.ExaminationPlan.ExaminationDate, x.ExaminationPlan.StartTime, x.ExaminationPlan.EndTime })
- .Select(x => new TimeSegmentView
- {
- ExaminationDate = x.Key.ExaminationDate.Value,
- StartTime = x.Key.StartTime.Value,
- EndTime = x.Key.EndTime.Value
- }).OrderBy(x => x.ExaminationDate)
- .ThenBy(x => x.StartTime).ToList();
- //先排指定了日期的考试计划
- foreach (var examinationDate in existsExaminationDateList)
- {
- //先取出指定当前日期的考试计划和它们同科目的考试计划,在这个循环里面,必须排完这些内容,
- //如果排不完,直接抛出异常,结束整个排考
- var notCompleteExaminationPlanCorrectTypeWithDateList = notCompleteExaminationPlanWithDateList
- .Where(x => ((!examinationDate.IsForResit)
- ? x.ExaminationPlan.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam
- : x.ExaminationPlan.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam)).ToList();
- var fixedDateExaminationPlanList = notCompleteExaminationPlanCorrectTypeWithDateList
- .Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
- && x.ExaminationPlan.StartTime == examinationDate.StartTime && x.ExaminationPlan.EndTime == examinationDate.EndTime).ToList();
- fixedDateExaminationPlanList = fixedDateExaminationPlanList.Concat(
- notCompleteExaminationPlanCorrectTypeWithDateList.Where(x => fixedDateExaminationPlanList.Select(w => w.ExaminationPlan.CoursematerialID).Contains(x.ExaminationPlan.CoursematerialID)
- && (!x.ExaminationPlan.ExaminationDate.HasValue || !x.ExaminationPlan.StartTime.HasValue || !x.ExaminationPlan.EndTime.HasValue))
- ).Concat(
- from notComplete in notCompleteExaminationPlanCorrectTypeWithDateList
- join complete in examinationPlanList.Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
- && x.ExaminationPlan.StartTime == examinationDate.StartTime && x.ExaminationPlan.EndTime == examinationDate.EndTime)
- on notComplete.ExaminationPlan.CoursematerialID equals complete.ExaminationPlan.CoursematerialID
- group notComplete by notComplete.ExaminationPlan.ExaminationPlanID into g
- select g.FirstOrDefault()
- ).ToList();
- //按照剩余座位数从多到少排序,拿出可排的教室备用,排考时,目的是为了
- //(由于检查的是剩余座位数,这里已经解决了冲突的问题,没有剩余座位的考室不会被列出)
- var orderedExaminationRoomList = this.GetMaxSeatExaminationRoomList(examinationRoomList,
- examinationDate.ExaminationDate, examinationDate.StartTime, examinationDate.EndTime, scheduledStudentList);
- var result = this.AutoSchedule(fixedDateExaminationPlanList, orderedExaminationRoomList, classroomViewList, examinationDate,
- examinationTeacherList, scheduledStudentList, schedulingList, excessiveUseList);
- //如果排不完,直接抛出异常,结束整个排考
- if (!result)
- {
- throw new Exception("自动排考失败:" + examinationDate.ExaminationDateString
- + "(" + examinationDate.StartTimeString + "-" + examinationDate.EndTimeString + ")无法排完所有指定日期的考试计划以及其相同科目的考试计划,"
- + "排考过程中断,为了不影响后面的考试安排,请先调整好这些考试计划再进行排考。");
- }
- }
- //再排未指定日期的考试计划,这些计划需要一个个课程地排,每个课程必须排在同一时间点,否则失败。
- var courseList = notCompleteExaminationPlanWithOutDateList.GroupBy(x => new { x.ExaminationPlan.CoursematerialID, IsResit = x.ExaminationPlan.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam })
- .Select(x => new { Course = x.FirstOrDefault().ExaminationPlan.EM_Coursematerial, x.Key.IsResit }).ToList();
- foreach (var course in courseList)
- {
- var courseExaminationPlanList = notCompleteExaminationPlanWithOutDateList
- .Where(x => x.ExaminationPlan.CoursematerialID == course.Course.CoursematerialID
- && (course.IsResit ? (x.ExaminationPlan.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam) : (x.ExaminationPlan.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam)))
- .ToList();
- var courseExaminationDateList = examinationDateList.Where(x => x.IsForResit == course.IsResit)
- .OrderBy(x => x.ExaminationDate).ThenBy(x => x.StartTime);
- foreach (var examinationDate in courseExaminationDateList)
- {
- //先检查当时的学生冲突,有冲突的话需要移到下一个时段
- var conflictStudentPlanEnum = (from plan in courseExaminationPlanList
- from student in plan.ExaminationPlan.CF_Student
- from scheduling in schedulingList.Where(x => x.Date == plan.ExaminationPlan.ExaminationDate
- && x.StartTime <= plan.ExaminationPlan.EndTime && x.EndTime >= plan.ExaminationPlan.StartTime)
- from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student.UserID)
- select plan);
- if (conflictStudentPlanEnum.Any())
- {
- continue;
- }
- //按照剩余座位数从多到少排序,拿出可排的教室备用,排考时也先排人数多的考试计划,
- //目的是为了将同一场考试尽量安排在一个考场中
- //(由于检查的是剩余座位数,这里已经解决了冲突的问题,没有剩余座位的考室不会被列出)
- var orderedExaminationRoomList = this.GetMaxSeatExaminationRoomList(examinationRoomList,
- examinationDate.ExaminationDate, examinationDate.StartTime, examinationDate.EndTime, scheduledStudentList);
- var result = this.AutoSchedule(courseExaminationPlanList, orderedExaminationRoomList, classroomViewList, examinationDate,
- examinationTeacherList, scheduledStudentList, schedulingList, excessiveUseList);
- //如果失败,需要从scheduledStudentList撤销这次排的记录,选另一个时间点重新排
- if (!result)
- {
- //如果考试计划没指定日期,那初始状态下应该没有排到任何考场,可以清空排考信息再来过
- scheduledStudentList.RemoveAll(x => courseExaminationPlanList.Select(w => w.ExaminationPlan.ExaminationPlanID).Contains(x.ExaminationPlanID));
- courseExaminationPlanList.ForEach(x => x.StudentCount = 0);
- continue;
- }
- else
- {
- break;
- }
- }
- }
- //(需要增加逻辑显示具体排不进去的提示)
- var notSuccessList = notCompleteExaminationPlanWithOutDateList.Where(x => x.MissionStudentCount > x.StudentCount).ToList();
- var successCount = notCompleteExaminationPlanList.Count - notSuccessList.Count;
- this.UnitOfWork.Commit();
- if (successCount == 0)
- {
- throw new Exception("自动排课失败:" + string.Join("、", notSuccessList.Select(x => x.ExaminationPlan.ClassName)) + "由于时间冲突无法排入。");
- }
- else if (notSuccessList.Count > 0)
- {
- throw new Exception("成功排课" + successCount.ToString() + "条记录,失败" + notSuccessList.Count.ToString() + "条记录,其中"
- + string.Join("、", notSuccessList.Select(x => x.ExaminationPlan.ClassName)) + "由于时间冲突无法排入。");
- }
- }
- //一般情况下传输进来的未排考试必须是同一科目的考试
- protected virtual bool AutoSchedule(List<ExamiationPlanAutoScheduleView> notCompleteExaminationPlanList,
- List<EX_ExaminationRoomSetting> examinationRoomList, List<ClassroomView> classroomViewList, TimeSegmentView examinationDate,
- List<EX_ExaminationTeacher> examinationTeacherList, List<StudentClassroomView> scheduledStudentList,
- List<EducationSchedulingWeekNumView> schedulingList, List<ClassroomExcessiveUseWeekNumView> excessiveUseList)
- {
- var needScheduleCount = notCompleteExaminationPlanList.Count;
- var scheduledCount = 0;
- var needModifyRecordList = new List<AutoScheduleModifyView>();
- foreach (var examinationRoom in examinationRoomList)
- {
- //如果考场在当前时间有排课,跳过
- var schedule = schedulingList.FirstOrDefault(x => x.ClassroomID == examinationRoom.ClassroomID
- && x.Date == examinationDate.ExaminationDate && x.StartTime <= examinationDate.EndTime
- && x.EndTime >= examinationDate.StartTime);
- if (schedule != null)
- {
- continue;
- }
- var excessiveUse = excessiveUseList.FirstOrDefault(x => x.ClassroomID == examinationRoom.ClassroomID
- && x.Date == examinationDate.ExaminationDate && x.StartTime <= examinationDate.EndTime
- && x.EndTime >= examinationDate.StartTime);
- if (excessiveUse != null)
- {
- continue;
- }
- //按照排考人数从多到少排序,第一行拿出未排过的考试计划,然后从第二个计划开始,优先拿出排过考的考试计划,
- //这样做的目的是保证考试计划能排到最少的考场去,不至于学生太过分散
- var orderedExaminationPlanViewList = notCompleteExaminationPlanList
- .Where(x => (x.MissionStudentCount - x.StudentCount) > 0)
- .OrderBy(x => x.MissionStudentCount - x.StudentCount).Take(1).ToList();
- orderedExaminationPlanViewList = orderedExaminationPlanViewList
- .Concat(notCompleteExaminationPlanList.Where(x =>
- !orderedExaminationPlanViewList.Select(w => w.ExaminationPlan.ExaminationPlanID)
- .Contains(x.ExaminationPlan.ExaminationPlanID)
- && (x.MissionStudentCount - x.StudentCount) > 0)
- .OrderBy(x => x.StudentCount > 0 ? 0 : 1)
- .ThenByDescending(x => x.MissionStudentCount - x.StudentCount)).ToList();
- #region 获取目前有空的监考员,并随机抽出两个
- //先找出排课没有冲突的监考员
- var noScheduleTeacherList = (from allteacher in examinationTeacherList
- from scheduling in schedulingList.Where(x => x.TeacherList.Any(w => w.UserID == allteacher.UserID)
- && x.Date == examinationDate.ExaminationDate && x.StartTime <= examinationDate.EndTime
- && x.EndTime >= examinationDate.StartTime).DefaultIfEmpty()
- where scheduling == null
- select allteacher).ToList();
- var teacherList = this.GetAvailableExaminationTeacher(noScheduleTeacherList,
- examinationDate.ExaminationDate, examinationDate.StartTime, examinationDate.EndTime, scheduledStudentList);
- if (teacherList.Count < 2)
- {
- return false;
- }
- #endregion
- //这个循环需要把考室尽量塞满……
- foreach (var orderedExaminationPlanView in orderedExaminationPlanViewList)
- {
- //获取要排考的学生
- var needScheduleStudentList = this.GetNeedScheduleStudentList(orderedExaminationPlanView, scheduledStudentList);
- //首先判断是否指定了考试时间,但并不是当前时间,这些自动排考无法处理
- if (orderedExaminationPlanView.ExaminationPlan.ExaminationDate.HasValue
- && !(orderedExaminationPlanView.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
- && orderedExaminationPlanView.ExaminationPlan.StartTime == examinationDate.StartTime
- && orderedExaminationPlanView.ExaminationPlan.EndTime == examinationDate.EndTime))
- {
- continue;
- }
- //然后判断冲突
- if (IsConflict(orderedExaminationPlanView, needScheduleStudentList.Select(x => x.UserID).ToList(), examinationDate, examinationRoom.CF_Classroom, scheduledStudentList))
- {
- continue;
- }
- var roomRemainSeat = examinationRoom.CF_Classroom.Examinationseating - scheduledStudentList
- .Where(x => x.ExaminationDate == examinationDate.ExaminationDate
- && x.ClassroomID == examinationRoom.ClassroomID
- && x.StartTime <= examinationDate.EndTime
- && x.EndTime >= examinationDate.StartTime).Count();
- var actualScheduleStudentList = needScheduleStudentList.Take(roomRemainSeat ?? 0).ToList();
- //记录住这些数据需要修改,后面所有考场和考试任务都检查完后,再统一修改
- var result = new AutoScheduleModifyView
- {
- ExaminationPlan = orderedExaminationPlanView.ExaminationPlan,
- ExaminationDate = examinationDate.ExaminationDate,
- StartTime = examinationDate.StartTime,
- EndTime = examinationDate.EndTime,
- ExaminationRoom = examinationRoom,
- ScheduleStudentList = actualScheduleStudentList
- };
- var lastExaminationRoomLayout = scheduledStudentList.Where(x => x.ClassroomID == examinationRoom.ClassroomID).FirstOrDefault();
- if (lastExaminationRoomLayout != null)
- {
- result.CF_Staff = new HashSet<CF_Staff>(
- examinationTeacherList.Where(x => lastExaminationRoomLayout.TeacherIDList.Contains(x.UserID ?? Guid.NewGuid())).Select(x => x.CF_Staff)
- );
- }
- else
- {
- result.CF_Staff = new HashSet<CF_Staff>(teacherList);
- }
- needModifyRecordList.Add(result);
- //更新已排完的计划,这样后续的判断才会没问题
- scheduledStudentList.AddRange(actualScheduleStudentList.Select(x => new StudentClassroomView
- {
- UserID = x.UserID,
- ExaminationDate = examinationDate.ExaminationDate,
- StartTime = examinationDate.StartTime,
- EndTime = examinationDate.EndTime,
- ClassroomID = examinationRoom.ClassroomID,
- ExaminationStyleID = orderedExaminationPlanView.ExaminationPlan.ExaminationStyleID,
- TeacherIDList = result.CF_Staff.Select(w => w.UserID).ToList(),
- ExaminationPlanID = orderedExaminationPlanView.ExaminationPlan.ExaminationPlanID
- }));
- orderedExaminationPlanView.StudentCount += actualScheduleStudentList.Count();
- if (actualScheduleStudentList.Count == needScheduleStudentList.Count)
- {
- scheduledCount++;
- }
- //如果教室塞满了,那后面的考试计划也排不动了,需要结束循环并跳转到下一个教室,以防浪费资源
- if (actualScheduleStudentList.Count >= roomRemainSeat)
- {
- break;
- }
- }
- }
- //如果排不完,返回失败,让外部决定如何处理
- if (scheduledCount < needScheduleCount)
- {
- return false;
- }
- foreach (var needModifyRecord in needModifyRecordList)
- {
- #region 判断成功,开始更新数据
- needModifyRecord.ExaminationPlan.ExaminationDate = examinationDate.ExaminationDate;
- needModifyRecord.ExaminationPlan.StartTime = examinationDate.StartTime;
- needModifyRecord.ExaminationPlan.EndTime = examinationDate.EndTime;
- var examinationRoomLayout = new EX_ExaminationRoomLayout
- {
- ExaminationRoomLayoutID = Guid.NewGuid(),
- ExaminationPlanID = needModifyRecord.ExaminationPlan.ExaminationPlanID,
- EX_ExaminationPlan = needModifyRecord.ExaminationPlan,
- ClassroomID = needModifyRecord.ExaminationRoom.ClassroomID,
- RowSpacing = 0,
- ColumnSpacing = 0,
- StudentOrderType = (int)CF_StudentOrderType.StudentNo,
- CF_Staff = needModifyRecord.CF_Staff
- };
- this.SetNewStatus(examinationRoomLayout);
- //这块需要挪到上面检测的地方,在上面如何判断这个考场能容纳多少学生?
- var examinationRoomStudentViewList = needModifyRecord.ScheduleStudentList.Select(x => new ExaminationRoomStudentView
- {
- ExaminationRoomStudentID = Guid.NewGuid(),
- ExaminationRoomLayoutID = examinationRoomLayout.ExaminationRoomLayoutID,
- UserID = x.UserID,
- LoginID = x.Sys_User.LoginID,
- Remark = ""
- }).ToList();
- var classroomView = classroomViewList.FirstOrDefault(x => x.ClassroomID == needModifyRecord.ExaminationRoom.ClassroomID);
- var examinationRoomStudentList = this.SetRoomStudentSeats(examinationRoomStudentViewList, classroomView, 0, 0, CF_StudentOrderType.StudentNo);
- examinationRoomLayout.EX_ExaminationRoomStudent = new HashSet<EX_ExaminationRoomStudent>(examinationRoomStudentList);
- needModifyRecord.ExaminationPlan.EX_ExaminationRoomLayout.Add(examinationRoomLayout);
- needModifyRecord.ExaminationRoom.CF_Classroom.EX_ExaminationRoomLayout.Add(examinationRoomLayout);
- #endregion
- }
- return true;
- }
- protected List<CF_Student> GetNeedScheduleStudentList(ExamiationPlanAutoScheduleView examinationPlanView
- , List<StudentClassroomView> scheduledStudentList)
- {
- //这里只找出在当前考试计划里面排过的学生,这个功能是找需排的学生,如果是其他考试计划排过的话,算冲突
- var needScheduleStudentList = (from student in examinationPlanView.ExaminationPlan.CF_Student
- join roomStudent in scheduledStudentList.Where(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlan.ExaminationPlanID)
- on student.UserID equals roomStudent.UserID into dRoomStudent
- from eRoomStudent in dRoomStudent.DefaultIfEmpty()
- where eRoomStudent == null
- select student).ToList();
- return needScheduleStudentList;
- }
-
- //判断考试方式是否有冲突
- private bool IsExaminationStyleConflict(ExamiationPlanAutoScheduleView examinationPlanView, CF_Classroom examinationRoom,
- TimeSegmentView examinationDate)
- {
- if (examinationRoom.EX_ExaminationRoomLayout
- .Any(x => x.EX_ExaminationPlan.ExaminationStyleID != examinationPlanView.ExaminationPlan.ExaminationStyleID
- && x.EX_ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
- && x.EX_ExaminationPlan.StartTime <= examinationDate.EndTime
- && x.EX_ExaminationPlan.EndTime >= examinationDate.StartTime))
- {
- return true;
- }
- return false;
- }
- private bool IsExaminationStyleConflictForAuto(ExamiationPlanAutoScheduleView examinationPlanView, CF_Classroom examinationRoom,
- TimeSegmentView examinationDate, IList<StudentClassroomView> scheduledStudentList)
- {
- if (scheduledStudentList
- .Any(x => x.ExaminationStyleID != examinationPlanView.ExaminationPlan.ExaminationStyleID
- && x.ClassroomID == examinationRoom.ClassroomID
- && x.ExaminationDate == examinationDate.ExaminationDate
- && x.StartTime <= examinationDate.EndTime
- && x.EndTime >= examinationDate.StartTime))
- {
- return true;
- }
- return false;
- }
- //判断考生时间有没有冲突
- private bool IsStudentConflict(IList<Guid> needScheduleStudentIDList,
- IList<ExamiationPlanAutoScheduleView> scheduledPlanList, TimeSegmentView examinationDate)
- {
- var conflictStudentList = (from student in needScheduleStudentIDList
- join scheduled in
- (
- from scheduled in scheduledPlanList.Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
- && x.ExaminationPlan.StartTime <= examinationDate.EndTime
- && x.ExaminationPlan.EndTime >= examinationDate.StartTime)
- from layout in scheduled.ExaminationPlan.EX_ExaminationRoomLayout
- from student in layout.EX_ExaminationRoomStudent
- select student.UserID
- ) on student equals scheduled
- select student).ToList();
- if (conflictStudentList.Count > 0)
- {
- return true;
- }
- return false;
- }
- //判断考生时间有没有冲突
- private bool IsStudentConflictForAuto(IList<Guid> needScheduleStudentIDList,
- IList<StudentClassroomView> scheduledStudentList, TimeSegmentView examinationDate)
- {
- var conflictStudentList = (from student in needScheduleStudentIDList
- join scheduled in scheduledStudentList.Where(x => x.ExaminationDate == examinationDate.ExaminationDate
- && x.StartTime <= examinationDate.EndTime
- && x.EndTime >= examinationDate.StartTime) on student equals scheduled.UserID
- select student).ToList();
- if (conflictStudentList.Count > 0)
- {
- return true;
- }
- return false;
- }
- private bool IsClassroomConflictForAuto(CF_Classroom examinationRoom,
- TimeSegmentView examinationDate, IList<StudentClassroomView> scheduledStudentList)
- {
- var conflictRoomList = (from schedule in scheduledStudentList
- where schedule.ClassroomID == examinationRoom.ClassroomID
- && schedule.ExaminationDate == examinationDate.ExaminationDate
- && schedule.StartTime <= examinationDate.EndTime
- && schedule.EndTime >= examinationDate.StartTime
- select schedule).ToList();
- if (conflictRoomList.Count >= examinationRoom.Examinationseating)
- {
- return true;
- }
- return false;
- }
- protected bool IsConflict(ExamiationPlanAutoScheduleView examinationPlanView, IList<Guid> needScheduleStudentIDList,
- TimeSegmentView examinationDate, CF_Classroom examinationRoom, IList<StudentClassroomView> scheduledStudentList)
- {
- if (IsExaminationStyleConflictForAuto(examinationPlanView, examinationRoom, examinationDate, scheduledStudentList))
- {
- return true;
- }
- if (IsClassroomConflictForAuto(examinationRoom, examinationDate, scheduledStudentList))
- {
- return true;
- }
- if (IsStudentConflictForAuto(needScheduleStudentIDList, scheduledStudentList, examinationDate))
- {
- return true;
- }
- return false;
- }
- private bool IsClassroomConflict(ExamiationPlanAutoScheduleView examinationPlanView, TimeSegmentView examinationDate,
- IList<ExamiationPlanAutoScheduleView> scheduledPlanList)
- {
- var conflictRoomList = (from room in examinationPlanView.ExaminationPlan.EX_ExaminationRoomLayout
- join layout in scheduledPlanList.Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
- && x.ExaminationPlan.StartTime <= examinationDate.EndTime && x.ExaminationPlan.EndTime >= examinationDate.StartTime
- && x.ExaminationPlan.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID)
- .SelectMany(x => x.ExaminationPlan.EX_ExaminationRoomLayout) on room.ClassroomID equals layout.ClassroomID
- group new { ExaminationRoom = room, Layout = layout } by new { room.ClassroomID, room.CF_Classroom.Examinationseating } into g
- where (g.Key.Examinationseating ?? 0) < (g.Sum(x => (x.Layout == null) ? 0 : x.Layout.EX_ExaminationRoomStudent.Count())
- + g.Sum(x => x.ExaminationRoom.EX_ExaminationRoomStudent.Count()))
- select g.Select(x => x.ExaminationRoom).FirstOrDefault()).ToList();
- if (conflictRoomList.Count > 0)
- {
- return true;
- }
- return false;
- }
- private bool IsConflictForSetTime(ExamiationPlanAutoScheduleView examinationPlanView, IList<Guid> needScheduleStudentIDList,
- TimeSegmentView examinationDate, CF_Classroom examinationRoom, IList<ExamiationPlanAutoScheduleView> scheduledPlanList)
- {
- if (IsExaminationStyleConflict(examinationPlanView, examinationRoom, examinationDate))
- {
- return true;
- }
- if (IsClassroomConflict(examinationPlanView, examinationDate, scheduledPlanList))
- {
- return true;
- }
- if (IsStudentConflict(needScheduleStudentIDList, scheduledPlanList, examinationDate))
- {
- return true;
- }
- return false;
- }
- protected List<CF_Staff> GetAvailableExaminationTeacher(IList<EX_ExaminationTeacher> examinationTeacherList,
- DateTime examinationDate, TimeSpan startTime, TimeSpan endTime, IList<StudentClassroomView> scheduledStudentList)
- {
- var q = (from teacher in examinationTeacherList
- from plan in scheduledStudentList.Where(x => x.ExaminationDate == examinationDate
- && x.StartTime <= endTime && x.EndTime >= startTime
- && x.TeacherIDList.Contains(teacher.CF_Staff.UserID))
- .DefaultIfEmpty()
- where plan == null
- select teacher.CF_Staff).OrderBy(x => Guid.NewGuid()).ToList();
- return q.Take(2).ToList();
- }
- protected virtual List<EX_ExaminationRoomSetting> GetMaxSeatExaminationRoomList(IList<EX_ExaminationRoomSetting> examinationRoomList,
- DateTime examinationDate, TimeSpan startTime, TimeSpan endTime, IList<StudentClassroomView> scheduledStudentList)
- {
- var examinationRoom = (from room in examinationRoomList
- join layout in scheduledStudentList.Where(x => x.ExaminationDate == examinationDate
- && x.StartTime <= endTime && x.EndTime >= startTime)
- .GroupBy(x => x.ClassroomID) on room.ClassroomID equals layout.Key into dlayout
- from elayout in dlayout.DefaultIfEmpty()
- where (room.CF_Classroom.Examinationseating ?? 0) > (elayout == null ? 0 : elayout.Count())
- orderby ((room.CF_Classroom.Examinationseating ?? 0) - (elayout == null ? 0 : elayout.Count())) descending
- select room);
- return examinationRoom.ToList();
- }
- private List<ExamiationPlanAutoScheduleView> GetOrderedExaminationPlanViewList(IList<ExamiationPlanAutoScheduleView> source, IList<ExamiationPlanAutoScheduleView> scheduledPlanList,
- DateTime examinationDate)
- {
- //优先级顺序:有学生当天排过考的优先(OrderID)、需要排课的学生数大的优先(NeedScheduleCount)、同一课程优先级相同(CoursematerialID)
- var q = (from plan in source
- where plan.MissionStudentCount > plan.StudentCount
- select new {
- ExaminationPlan = plan,
- OrderID = (scheduledPlanList.Any(x => x.ExaminationPlan.ExaminationDate == examinationDate
- && x.ExaminationPlan.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent).Select(w => w.UserID)
- .Intersect(plan.ExaminationPlan.CF_Student.Select(w => (Guid?)w.UserID)).Count() > 0)
- ||
- source.Any(x => x.ExaminationPlan.ExaminationDate == examinationDate
- && x.ExaminationPlan.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent).Select(w => w.UserID)
- .Intersect(plan.ExaminationPlan.CF_Student.Select(w => (Guid?)w.UserID)).Count() > 0)
- ) ? 0 : 1,
- NeedScheduleCount = plan.MissionStudentCount - plan.StudentCount
- }).OrderBy(x => x.ExaminationPlan.ExaminationPlan.CoursematerialID).ThenBy(x => x.OrderID).ThenByDescending(x => x.NeedScheduleCount)
- .Select(x => x.ExaminationPlan).ToList();
- return q;
- }
- public void SetTime(IList<Guid?> examinationPlanIDList, DateTime? examinationDate, TimeSpan? startTime, TimeSpan? endTime)
- {
- if (!examinationDate.HasValue)
- {
- throw new Exception("必须指定考试日期。");
- }
- if (!startTime.HasValue)
- {
- throw new Exception("必须指定开始时间。");
- }
- if (!endTime.HasValue)
- {
- throw new Exception("必须指定结束时间。");
- }
- if (examinationDate.Value.Date < DateTime.Today)
- {
- throw new Exception("考试日期需在当天之后。");
- }
- if (startTime.Value >= endTime.Value)
- {
- throw new Exception("结束时间需在开始时间之后。");
- }
- var errorMessageList = new List<string>();
- var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- if (examinationDate.HasValue && startTime.HasValue && endTime.HasValue)
- {
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var examinationPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID))
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).ToList();
- var submitedPlanClassNameList = examinationPlanViewList.Where(x => x.ExaminationPlan.RecordStatus != (int)EX_ExaminationPlanStatus.NotSubmitted).ToList();
- if (submitedPlanClassNameList.Count > 0)
- {
- throw new Exception(string.Join("、", submitedPlanClassNameList.Select(x => x.ExaminationPlan.ClassName)) + "已经提交,不能设置时间。");
- }
- var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationDate
- && x.StartTime <= endTime && x.EndTime >= startTime && x.EX_ExaminationRoomLayout.Count() > 0
- && !examinationPlanIDList.Contains(x.ExaminationPlanID))
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList()
- .Select(x => new ExamiationPlanAutoScheduleView
- {
- ExaminationPlan = x,
- MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
- StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
- }).ToList();
- var timeSegment = new TimeSegmentView { ExaminationDate = examinationDate.Value, StartTime = startTime.Value, EndTime = endTime.Value };
- var classroomIDList = examinationPlanViewList.SelectMany(x => x.ExaminationPlan.EX_ExaminationRoomLayout).Select(x => x.ClassroomID).ToList();
- var classroomList = ClassroomDAL.ClassroomRepository.GetList(x => classroomIDList.Contains(x.ClassroomID)).ToList();
- //获取排课
- var scheduleDateTimeList = new List<StartEndTimeView> {
- new StartEndTimeView { StartTime = examinationDate.Value.Add(startTime.Value),
- EndTime = examinationDate.Value.Add(endTime.Value) } };
- var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
- curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- foreach (var examinationPlanView in examinationPlanViewList)
- {
- foreach (var layout in examinationPlanView.ExaminationPlan.EX_ExaminationRoomLayout)
- {
- var studentIDList = layout.EX_ExaminationRoomStudent
- .Select(x => x.UserID).ToList();
- var classroomEntity = classroomList.FirstOrDefault(x => x.ClassroomID == layout.ClassroomID);
- var staffIDList = layout.CF_Staff.Select(x => x.UserID).ToList();
- var existPlanViewList = scheduledPlanViewList
- .Concat(examinationPlanViewList
- .Where(x => x.ExaminationPlan.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID))
- .ToList();
- if (existPlanViewList.Any(x => x.ExaminationPlan.ExaminationStyleID != examinationPlanView.ExaminationPlan.ExaminationStyleID
- && x.ExaminationPlan.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == layout.ClassroomID)))
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考场" + classroomEntity.Name + "时间安排存在冲突,存在同一时间不同考试方式的排考,请重新核对后再进行设置。");
- }
- if ((classroomEntity.Examinationseating - existPlanViewList.Sum(x =>
- x.ExaminationPlan.EX_ExaminationRoomLayout.Where(w => w.ClassroomID == layout.ClassroomID).Sum(w => w.EX_ExaminationRoomStudent.Count)))
- < studentIDList.Count)
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考场" + classroomEntity.Name + "时间安排存在冲突,考场无法容纳该考试任务的学生,请重新核对后再进行设置。");
- }
- if (existPlanViewList.Any(x => x.ExaminationPlan.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent)
- .Any(w => studentIDList.Contains(w.UserID))))
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考场" + classroomEntity.Name + "时间安排存在冲突,部分考生时间安排冲突,请重新核对后再进行设置。");
- }
- var classroomScheduledTeacher = existPlanViewList.FirstOrDefault(x =>
- x.ExaminationPlan.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == layout.ClassroomID
- && w.CF_Staff.Count != w.CF_Staff.Where(y => staffIDList.Contains(y.UserID)).Count()));
- if (classroomScheduledTeacher != null)
- {
- var scheduledTeacher = string.Join("、", classroomScheduledTeacher.ExaminationPlan.EX_ExaminationRoomLayout.First().
- CF_Staff.Select(x => x.Sys_User.Name).ToList());
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考场" + classroomEntity.Name + "已由" + scheduledTeacher + "监考,请重新核对后再进行设置。");
- }
- if (existPlanViewList.Any(x => x.ExaminationPlan.EX_ExaminationRoomLayout.Where(w => w.ClassroomID != layout.ClassroomID)
- .SelectMany(w => w.CF_Staff).Any(w => staffIDList.Contains(w.UserID))))
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的监考老师时间安排冲突,请重新核对后再进行设置。");
- }
- var schedulingStudentConflictList = (from student in studentIDList
- from scheduling in schedulingList.Where(x => x.Date == examinationPlanView.ExaminationPlan.ExaminationDate
- && x.StartTime <= examinationPlanView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanView.ExaminationPlan.StartTime)
- from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
- group student by student into g
- select g.FirstOrDefault()
- ).ToList();
- if (schedulingStudentConflictList.Count > 0)
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考试时间安排冲突,部分学生由于需要上课无法安排,请重新核对后再进行设置。");
- }
- var schedulingClassroomConflictList = (from scheduling in schedulingList.Where(x => x.ClassroomID == classroomEntity.ClassroomID)
- select scheduling
- ).ToList();
- if (schedulingClassroomConflictList.Count > 0)
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考场" + classroomEntity.Name + "时间安排存在冲突,该考场被排课占用,请重新核对后再进行设置。");
- }
- var excessiveUseConflictList = (from excessiveUse in classroomExcessiveUseList.Where(x => x.ClassroomID == classroomEntity.ClassroomID)
- select excessiveUse).ToList();
- if (excessiveUseConflictList.Count > 0)
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考场" + classroomEntity.Name + "时间安排存在冲突,该考场被其他活动占用,请重新核对后再进行设置。");
- }
- var schedulingTeacherConflictList = (from teacher in staffIDList
- from scheduling in schedulingList
- from schedulingTeacher in scheduling.TeacherList.Where(x => x.UserID == teacher)
- group teacher by teacher into g
- select g.FirstOrDefault()
- ).ToList();
- if (schedulingClassroomConflictList.Count > 0)
- {
- errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
- + "的考试时间安排冲突,部分老师由于需要上课无法安排,请重新核对后再进行设置。");
- }
- }
- }
- }
- if (errorMessageList.Count > 0)
- {
- throw new Exception(string.Join(";", errorMessageList));
- }
- this.UnitOfWork.Update<EX_ExaminationPlan>((x => new EX_ExaminationPlan
- {
- ExaminationDate = examinationDate,
- StartTime = startTime,
- EndTime = endTime
- }), (x => examinationPlanIDList.Contains(x.ExaminationPlanID)));
- }
- public List<AdultExaminationPlanExportView> GetAdultExaminationPlanExportViewList(ConfiguretView examinationPlanView, IList<Guid?> examinationPlanIDList,
- Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID)
- {
- Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (examinationPlanIDList.Count > 0)
- {
- exp = exp.And(x => examinationPlanIDList.Contains(x.ExaminationPlanID));
- }
- else
- {
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if (gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
- .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (examsCategoryID.HasValue)
- {
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- }
- if (examinationModeID.HasValue)
- {
- exp = exp.And(x => x.ExaminationModeID == examinationModeID);
- }
- if (examinationStyleID.HasValue)
- {
- exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
- }
- if (starWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
- }
- if (endWeek.HasValue)
- {
- exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
- }
- if (statusID.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == statusID);
- }
- }
- var q = ExaminationPlanDAL.GetAdultExaminationPlanExportView(exp);
- if (examinationPlanIDList.Count == 0)
- {
- if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
- q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
- }
- return q.OrderByDescending(x => x.SchoolyearCode).OrderBy(x => x.MaxExaminationWeekNum).ThenBy(x => x.ClassName).ToList();
- }
- public virtual string AdultImport(string filePath, out string returnMessage)
- {
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- List<AdultExaminationPlanImportView> errList = new List<AdultExaminationPlanImportView>(); //错误数据行
- List<AdultExaminationPlanImportView> successList = new List<AdultExaminationPlanImportView>(); //导入的数据行
- DataTimeHelper dth = new DataTimeHelper();
- #region 解析文件,存放到一个List集合里
- Dictionary<string, string> cellheader = new Dictionary<string, string>
- {
- { "CoursematerialName", "考试科目" }, { "ClassName", "考试班级名称" },
- { "MissionStudentCount", "学生数" }, { "StudentCount", "排考人数" },
- { "ExamsCategoryName", "考试性质" }, { "ExaminationModeName", "考试方式" },
- { "ExaminationWeekNumString", "考试周次" }, { "ExaminationDateString", "考试日期" },
- { "StartTimeString", "考试时间起"},{ "EndTimeString", "考试时间止" },
- { "ClassroomName", "考室"},{ "TeacherNames", "监考老师" }
- };
- List<AdultExaminationPlanImportView> importRowlist =
- NpoiExcelHelper.ExcelToEntityList<AdultExaminationPlanImportView>(cellheader, filePath, out errorMsg, out errList);
- File.Delete(filePath);
- cellheader.Add("ErrorMessage", "错误信息");//还原字典项
- #endregion
- #region 清空格
- for (int i = 0; i < importRowlist.Count();i++ )
- {
- if(importRowlist[i].CoursematerialName!=null)
- importRowlist[i].CoursematerialName=importRowlist[i].CoursematerialName.Trim();
- if (importRowlist[i].ClassName != null)
- importRowlist[i].ClassName = importRowlist[i].ClassName.Trim();
- if (importRowlist[i].MissionStudentCount != null)
- importRowlist[i].MissionStudentCount = importRowlist[i].MissionStudentCount.Trim();
- if (importRowlist[i].StudentCount != null)
- importRowlist[i].StudentCount = importRowlist[i].StudentCount.Trim();
- if (importRowlist[i].ExamsCategoryName != null)
- importRowlist[i].ExamsCategoryName = importRowlist[i].ExamsCategoryName.Trim();
- if (importRowlist[i].ExaminationModeName != null)
- importRowlist[i].ExaminationModeName = importRowlist[i].ExaminationModeName.Trim();
- if (importRowlist[i].ExaminationWeekNumString != null)
- importRowlist[i].ExaminationWeekNumString = importRowlist[i].ExaminationWeekNumString.Trim();
- if (importRowlist[i].ExaminationDateString != null)
- importRowlist[i].ExaminationDateString = importRowlist[i].ExaminationDateString.Trim();
- if (importRowlist[i].StartTimeString != null)
- importRowlist[i].StartTimeString = importRowlist[i].StartTimeString.Trim();
- if (importRowlist[i].EndTimeString != null)
- importRowlist[i].EndTimeString = importRowlist[i].EndTimeString.Trim();
- if (importRowlist[i].ClassroomName != null)
- importRowlist[i].ClassroomName = importRowlist[i].ClassroomName.Trim();
- if (importRowlist[i].TeacherNames != null)
- importRowlist[i].TeacherNames = importRowlist[i].TeacherNames.Trim();
- }
-
- #endregion
- #region 检查文件中的内容
- #region 读取用于校验的数据,便于后续处理
- var coursematerialNameList = importRowlist.Select(x => x.CoursematerialName).ToList();
- var classNameList = importRowlist.Select(x => x.ClassName).ToList();
- //默认排当前学年学期的考试计划
- var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- var classroomNameList = importRowlist.Select(x => x.ClassroomName).ToList();
- var teacherNameList = importRowlist.Where(x => !string.IsNullOrEmpty(x.TeacherNames))
- .SelectMany(x => x.TeacherNames.Split('/').ToList()).Distinct().ToList();
- var coursematerialList = ExaminationPlanDAL.CoursematerialRepository.GetList(x => coursematerialNameList.Contains(x.CourseName)).ToList();
- var examinationPlanList = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => classNameList.Contains(x.ClassName) && x.SchoolyearID == curSchoolyear.SchoolYearID, (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)), (x => x.CF_Student.Select(w => w.Sys_User))).ToList();
- var examsCategoryList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExamsCategory);
- var examinationModeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExaminationMode);
- var classroomList = ExaminationRoomSettingRepository
- .GetList(x => classroomNameList.Contains(x.CF_Classroom.Name))
- .Select(x => x.CF_Classroom).ToList();
- var classroomViewList = ClassroomDAL.GetClassroomViewQueryable(x => classroomNameList.Contains(x.Name)).ToList();
- var teacherList = ExaminationPlanDAL.StaffDAL.staffRepository.GetList(x => teacherNameList.Contains(x.Sys_User.Name), (x => x.Sys_User)).ToList();
- #endregion
- foreach (var importRow in importRowlist)
- {
- string errorMessage = "";
- var errorItem = Mapper.DynamicMap<AdultExaminationPlanImportView>(importRow);
- #region 检查基本录入格式
- var curCoursematerialList = coursematerialList.Where(x => x.CourseName == (importRow.CoursematerialName ?? "").Trim()).ToList();
- var examsCategory = examsCategoryList.FirstOrDefault(x => x.Name == (importRow.ExamsCategoryName ?? "").Trim());
- var examinationMode = examinationModeList.FirstOrDefault(x => x.Name == (importRow.ExaminationModeName ?? "").Trim());
- var classroom = classroomList.FirstOrDefault(x => x.Name == (importRow.ClassroomName ?? "").Trim());
- var curTeacherNameList = (importRow.TeacherNames ?? "").Trim().Split('/').Where(x => !string.IsNullOrEmpty(x)).ToList();
- var teacher = teacherList.Where(x => curTeacherNameList.Contains(x.Sys_User.Name)).ToList();
-
- if (curCoursematerialList.Count == 0)
- {
- errorMessage += "没有对应的课程名称,请检查输入。";
- }
- if (examsCategory == null)
- {
- errorMessage += "考试性质错误,请检查输入。";
- }
- if (examinationMode == null)
- {
- errorMessage += "考试方式错误,请检查输入。";
- }
- if (importRow.StudentCount == null)
- {
- importRow.StudentCount = importRow.MissionStudentCount;
- }
- if (string.IsNullOrEmpty(importRow.ClassroomName))
- {
- errorMessage += "请填写考室。";
- }
- else if (classroom == null)
- {
- errorMessage += "考室信息错误,并未将" + importRow.ClassroomName + "安排为考室,请检查输入。";
- }
- var errorTeacherList = curTeacherNameList.Where(x => !teacher.Select(w => w.Sys_User.Name).Contains(x)).ToList();
- if (errorTeacherList.Count > 0)
- {
- errorMessage += "监考老师" + string.Join("/", errorTeacherList) + "名字输入错误,请检查输入。";
- }
- else if (teacher.Count == 0)
- {
- errorMessage += "请填写监考老师信息。";
- }
- var coursematerialIDList = curCoursematerialList.Select(x => (Guid?)x.CoursematerialID).ToList();
- var examinationPlan = examinationPlanList.FirstOrDefault(x => x.ClassName == importRow.ClassName
- && coursematerialIDList.Contains(x.CoursematerialID));
- //if (examinationPlanList.Where(x => x.ClassName == importRow.ClassName
- // && coursematerialIDList.Contains(x.CoursematerialID) && x.ExamsCategoryID == examsCategory.Value
- // && x.ExaminationModeID == examinationMode.Value ).Count() >= 2)
- //{
- // errorMessage += "存在考试科目、考试班级名称、考试性质、考试方式相同的两条或以上的数据。";
- //}
- if (examsCategory != null && examinationMode !=null)
- {
- examinationPlan = examinationPlanList.FirstOrDefault(x => x.ClassName == importRow.ClassName
- && coursematerialIDList.Contains(x.CoursematerialID) && x.ExamsCategoryID == examsCategory.Value
- && x.ExaminationModeID == examinationMode.Value);
- }
-
- if (examinationPlan == null)
- {
- examinationPlan = examinationPlanList.FirstOrDefault(x => x.ClassName == importRow.ClassName
- && coursematerialIDList.Contains(x.CoursematerialID));
- if (examinationPlan == null)
- {
- errorMessage += "当前学年学期并没有该班级名称和课程名称的考试安排,请检查输入。";
- }
- }
- else if(examinationPlan.RecordStatus == (int)CF_ApprovalStatus.Submitted)
- {
- errorMessage += "已存在相同的已提交的考试计划";
- }
- if (classroom != null && examinationPlan != null && classroom.Examinationseating < examinationPlan.CF_Student.Count)
- {
- errorMessage += "所选考室可容纳的座位数不足,无法安排学生进行考试。";
- }
- DateTime examinationDate = default(DateTime);
- if (string.IsNullOrEmpty(importRow.ExaminationDateString))
- {
- errorMessage += "请填写考试日期。";
- }
- else
- {
- try
- {
- DateTime date;
- if (DateTime.TryParse(importRow.ExaminationDateString.Trim().ToString(), out date))
- {
- examinationDate = Convert.ToDateTime(importRow.ExaminationDateString.Trim().ToString());
- }
- else
- {
- var dateTime = DateTime.FromOADate(double.Parse(importRow.ExaminationDateString.Trim().ToString()));
- examinationDate = dateTime;
- }
- }
- catch
- {
- errorMessage += "考试日期必须为年-月-日的日期格式。";
- }
- }
- TimeSpan startTime = default(TimeSpan);
- if (string.IsNullOrEmpty(importRow.StartTimeString))
- {
- errorMessage += "请填写考试时间起。";
- }
- else
- {
- try
- {
- DateTime date;
- if (DateTime.TryParse(importRow.StartTimeString.Trim().ToString(), out date))
- {
- startTime = Convert.ToDateTime(importRow.StartTimeString.Trim().ToString()).TimeOfDay;
- }
- else
- {
- var dateTime = DateTime.FromOADate(double.Parse(importRow.StartTimeString.Trim().ToString()));
- startTime = dateTime.TimeOfDay;
- }
- }
- catch
- {
- errorMessage += "考试时间起必须为时:分的时间格式。";
- }
- }
- TimeSpan endTime = default(TimeSpan);
- if (string.IsNullOrEmpty(importRow.EndTimeString))
- {
- errorMessage += "请填写考试时间止。";
- }
- else
- {
- try
- {
- DateTime date;
- if (DateTime.TryParse(importRow.EndTimeString.Trim().ToString(), out date))
- {
- endTime = Convert.ToDateTime(importRow.EndTimeString.Trim().ToString()).TimeOfDay;
- }
- else
- {
- var dateTime = DateTime.FromOADate(double.Parse(importRow.EndTimeString.Trim().ToString()));
- endTime = dateTime.TimeOfDay;
- }
- }
- catch
- {
- errorMessage += "考试时间止必须为时:分的时间格式。";
- }
- }
- if (startTime >= endTime)
- {
- errorMessage += "结束时间需大于开始时间。";
- }
- #endregion
- if (errorMessage != "")
- {
- errorItem.ErrorMessage = errorMessage;
- if(endTime!=default(TimeSpan)){
- errorItem.EndTimeString = " " + endTime;
- }
- if (startTime!=default(TimeSpan))
- {
- errorItem.StartTimeString = " " + startTime;
- }
- if(examinationDate!=default(DateTime)){
- errorItem.ExaminationDateString = " " + examinationDate;
- }
- errList.Add(errorItem);
- continue;
- }
- else
- {
- importRow.CoursematerialID = examinationPlan.CoursematerialID;
- importRow.ExaminationPlan = examinationPlan;
- importRow.ExamsCategoryID = examsCategory.Value;
- importRow.ExaminationModeID = examinationMode.Value;
- importRow.ExaminationStyleID = examinationPlan.ExaminationStyleID;
- importRow.ExaminationDate = examinationDate;
- importRow.StartTime = startTime;
- importRow.EndTime = endTime;
- importRow.ClassroomID = classroom.ClassroomID;
- importRow.Examinationseating = classroom.Examinationseating;
- importRow.TeacherList = teacher;
-
- successList.Add(importRow);
- }
- }
- #endregion
- var checkList = successList;
- #region 准备排课数据用于校验
- var scheduleDateTimeList = successList.GroupBy(x => x.ExaminationPlan.SchoolyearID)
- .Select(x => new {
- SchoolyearID = x.Key,
- DataTimeList = x.GroupBy(w => new
- {
- StartTime = w.ExaminationDate.Value.Add(w.StartTime.Value),
- EndTime = w.ExaminationDate.Value.Add(w.EndTime.Value)
- })
- .Select(w => new StartEndTimeView { StartTime = w.Key.StartTime, EndTime = w.Key.EndTime }).ToList()
- }).ToList();
- List<EducationSchedulingWeekNumView> schedulingList = new List<EducationSchedulingWeekNumView>();
- List<ClassroomExcessiveUseWeekNumView> excessiveUseList = new List<ClassroomExcessiveUseWeekNumView>();
- scheduleDateTimeList.ForEach(x =>
- {
- schedulingList.AddRange(this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewForExaminationTeacher(x.SchoolyearID.Value,
- x.DataTimeList));
- excessiveUseList.AddRange(this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
- x.SchoolyearID.Value, x.DataTimeList));
- });
- #endregion
- #region 检查导入文件内部数据的冲突
- #region 检查考室冲突
- //var classroomConflictList = (from source in successList
- // from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- // && x.ExaminationDate == source.ExaminationDate
- // && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- // && x.ClassroomID == source.ClassroomID)
- // select new { source, dest }).ToList();
- //classroomConflictList.ForEach(x =>
- //{
- // var errorItem = x.source;
- // errorItem.ErrorMessage = "考场安排和其他行存在时间冲突,请检查。";
- // errList.Add(errorItem);
- // successList.Remove(x.source);
- //});
- #endregion
- #region 检查导入文件导入同一考室,并且时间重复的,人数是否超过可排人次
- var classroomstudentCount = (from source in successList
- from studentcount in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- && x.ExaminationDate == source.ExaminationDate
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.ClassroomID == source.ClassroomID)
- group studentcount by studentcount.ExaminationPlan.ExaminationPlanID
- into gstucount
- join succ in successList
- on gstucount.Key equals succ.ExaminationPlan.ExaminationPlanID
- select new
- {
- //source,
- succ
- }).ToList();
-
- classroomstudentCount.ForEach(x =>
- {
- var count = int.Parse(x.succ.MissionStudentCount);
- var isrepeatList = checkList.Any(y => y.ExaminationPlan.ExaminationPlanID != x.succ.ExaminationPlan.ExaminationPlanID && y.ExaminationDate == x.succ.ExaminationDate
- && y.StartTime <= x.succ.EndTime && y.EndTime >= x.succ.StartTime && y.ClassroomID == x.succ.ClassroomID);
- if (isrepeatList)
- {
- var repeatList = checkList.Where(y => y.ExaminationPlan.ExaminationPlanID != x.succ.ExaminationPlan.ExaminationPlanID && y.ExaminationDate == x.succ.ExaminationDate
- && y.StartTime <= x.succ.EndTime && y.EndTime >= x.succ.StartTime && y.ClassroomID == x.succ.ClassroomID).ToList();
- foreach (var repeat in repeatList)
- {
- count = count + int.Parse(repeat.MissionStudentCount);
- }
- }
- if (count > classroomList.FirstOrDefault(w => w.ClassroomID == x.succ.ClassroomID).Examinationseating)
- {
- var errorItem = x.succ;
- errorItem.ErrorMessage = "考场座位数不足,请检查。";
- errList.Add(errorItem);
- successList.Remove(x.succ);
- }
- });
- #endregion
- #region 检查教师冲突
- var teacherConflictList = (from source in successList
- from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- && x.ExaminationDate == source.ExaminationDate
- && x.ClassroomID != source.ClassroomID
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.TeacherList.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() > 0).Take(1)
- select source).ToList();
- teacherConflictList.ForEach(x =>
- {
- var errorItem = x;
- errorItem.ErrorMessage = "监考老师和其他行存在时间冲突,请检查。";
- errList.Add(errorItem);
- successList.Remove(x);
- });
- var teacherClassroomConflictList = (from source in successList
- from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- && x.ExaminationDate == source.ExaminationDate
- && x.ClassroomID == source.ClassroomID
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.TeacherList.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() != x.TeacherList.Count).Take(1)
- select source).ToList();
- teacherClassroomConflictList.ForEach(x =>
- {
- var errorItem = x;
- errorItem.ErrorMessage = "同一考场的监考老师必须相同,请检查考室或监考老师是否存在冲突。";
- errList.Add(errorItem);
- successList.Remove(x);
- });
- #endregion
- #region 检查学生冲突
- //var studentConflictList = (from source in successList
- // from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- // && x.ExaminationDate == source.ExaminationDate
- // && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- // && x.ExaminationPlan.CF_Student.Select(w => w.UserID).Intersect(source.ExaminationPlan.CF_Student.Select(w => w.UserID)).Count() > 0)
- // select new { source, dest }).ToList();
- //studentConflictList.ForEach(x =>
- //{
- // var errorItem = x.source;
- // errorItem.ErrorMessage = "考试学生和其他行存在时间冲突,请检查。";
- // errList.Add(errorItem);
- // successList.Remove(x.source);
- //});
- #endregion
- #endregion
- #region 检查和其他考场安排之间的冲突
- var examinationDateList = successList.Select(x => x.ExaminationDate).Distinct().ToList();
- var sameDateExaminationPlanList = ExaminationPlanDAL.ExaminationRoomLayoutRepository
- .GetList(x => examinationDateList.Contains(x.EX_ExaminationPlan.ExaminationDate),
- (x => x.EX_ExaminationPlan),
- //(x => x.EX_ExaminationPlan.CF_Student),
- (x => x.CF_Staff),
- (x => x.EX_ExaminationRoomStudent)).ToList();
- #region 检查考室冲突
- //var classroomOuterConflictList = (from source in successList
- // from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- // && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
- // && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
- // && x.ClassroomID == source.ClassroomID)
- // select new { source, dest }).ToList();
- //classroomOuterConflictList.ForEach(x =>
- //{
- // var errorItem1 = x.source;
- // errorItem1.ErrorMessage = "考场安排和已有的考试安排存在时间冲突,请检查。";
- // errList.Add(errorItem1);
- // successList.Remove(x.source);
- //});
- #endregion
- #region 检查教师冲突
- var teacherOuterConflictList = (from source in successList
- from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
- && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
- && x.ClassroomID != source.ClassroomID
- && x.CF_Staff.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() > 0).Take(1)
- select new { source, dest }).ToList();
- teacherOuterConflictList.ForEach(x =>
- {
- var errorItem1 = x.source;
- errorItem1.ErrorMessage = "监考老师和已有的考试安排存在时间冲突,请检查。";
- errList.Add(errorItem1);
- successList.Remove(x.source);
- });
- var teacherOuterClassroomConflictList = (from source in successList
- from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
- && x.ClassroomID == source.ClassroomID
- && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
- && x.CF_Staff.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() != x.CF_Staff.Count).Take(1)
- select source).ToList();
- teacherOuterClassroomConflictList.ForEach(x =>
- {
- var errorItem = x;
- errorItem.ErrorMessage = "监考老师和已有的考试安排存在冲突,同一考场的监考老师必须相同,请检查。";
- errList.Add(errorItem);
- successList.Remove(x);
- });
- #endregion
- #region 检查学生冲突
- //var studentOuterConflictList = (from source in successList
- // from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
- // && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
- // && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
- // && x.EX_ExaminationPlan.CF_Student.Select(w => w.UserID).Intersect(source.ExaminationPlan.CF_Student.Select(w => w.UserID)).Count() > 0)
- // select new { source, dest }).ToList();
- //studentOuterConflictList.ForEach(x =>
- //{
- // var errorItem = x.source;
- // errorItem.ErrorMessage = "考试学生和已有的考试安排存在时间冲突,请检查。";
- // errList.Add(errorItem);
- // successList.Remove(x.source);
- //});
- #endregion
- #endregion
- #region 检查教室占用冲突
- var classroomExcessUseConflictList = (from source in successList
- from dest in excessiveUseList.Where(x =>
- x.Date == source.ExaminationDate
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.ClassroomID == source.ClassroomID).Take(1)
- select new { source, dest }).ToList();
- classroomExcessUseConflictList.ForEach(x =>
- {
- var errorItem2 = x.source;
- errorItem2.ErrorMessage = "考场已被占用,请检查。";
- errList.Add(errorItem2);
- successList.Remove(x.source);
- });
- #endregion
- #region 检查和课表的冲突
- #region 检查考室冲突
- var classroomScheduleConflictList = (from source in successList
- from dest in schedulingList.Where(x =>
- x.Date == source.ExaminationDate
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.ClassroomID == source.ClassroomID).Take(1)
- select new { source, dest }).ToList();
- classroomScheduleConflictList.ForEach(x =>
- {
- var errorItem2 = x.source;
- errorItem2.ErrorMessage = "考场安排和已有的排课存在时间冲突,请检查。";
- errList.Add(errorItem2);
- successList.Remove(x.source);
- });
- #endregion
- #region 检查教师冲突
- var teacherScheduleConflictList = (from source in successList
- from dest in schedulingList.Where(x =>
- x.Date == source.ExaminationDate
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.TeacherList.Select(w => w.UserID)
- .Intersect(source.TeacherList.Select(w => (Guid?)w.UserID)).Count() > 0).Take(1)
- select new { source, dest }).ToList();
- teacherScheduleConflictList.ForEach(x =>
- {
- var errorItem1 = x.source;
- errorItem1.ErrorMessage = "监考老师和已有的排课存在时间冲突,请检查。";
- errList.Add(errorItem1);
- successList.Remove(x.source);
- });
- #endregion
- #region 检查学生冲突
- var studentScheduleConflictList = (from source in successList
- from dest in schedulingList.Where(x =>
- x.Date == source.ExaminationDate
- && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
- && x.StudentList.Select(w => w.UserID).Intersect(source.ExaminationPlan.CF_Student.Select(w => w.UserID)).Count() > 0).Take(1)
- select new { source, dest }).ToList();
- studentScheduleConflictList.ForEach(x =>
- {
- var errorItem = x.source;
- errorItem.ErrorMessage = "考试学生和已有的排课存在时间冲突,请检查。";
- errList.Add(errorItem);
- successList.Remove(x.source);
- });
- #endregion
- #endregion
- #region 添加数据
- var scheduledStudentList = new List<StudentClassroomView>();
- var deletedExaminationPlanIDList = new List<Guid>();
- foreach (var succesResult in successList)
- {
- succesResult.ExaminationPlan.ExaminationDate = succesResult.ExaminationDate;
- succesResult.ExaminationPlan.StartTime = succesResult.StartTime;
- succesResult.ExaminationPlan.EndTime = succesResult.EndTime;
- succesResult.ExaminationStyleID = succesResult.ExaminationStyleID;
- //succesResult.ExaminationPlan.EX_ExaminationRoomLayout.ForEach(x => this.UnitOfWork.Remove(x));
- //succesResult.ExaminationPlan.EX_ExaminationRoomLayout = new HashSet<EX_ExaminationRoomLayout>();
- EX_ExaminationRoomLayout newLayout = new EX_ExaminationRoomLayout()
- {
- ExaminationRoomLayoutID = Guid.NewGuid(),
- ExaminationPlanID = succesResult.ExaminationPlan.ExaminationPlanID,
- ClassroomID = succesResult.ClassroomID,
- RowSpacing = 0,
- ColumnSpacing = 0,
- StudentOrderType = (int)CF_StudentOrderType.StudentNo,
- CF_Staff = new HashSet<CF_Staff>(succesResult.TeacherList)
- };
- this.SetNewStatus(newLayout);
- var roomRemainSeat = succesResult.Examinationseating - sameDateExaminationPlanList
- .Where(x => x.EX_ExaminationPlan != null
- && x.EX_ExaminationPlan.ExaminationPlanID != succesResult.ExaminationPlan.ExaminationPlanID
- && x.EX_ExaminationPlan.ExaminationDate == succesResult.ExaminationDate
- && x.ClassroomID == succesResult.ClassroomID
- && x.EX_ExaminationPlan.StartTime <= succesResult.EndTime
- && x.EX_ExaminationPlan.EndTime >= succesResult.StartTime).Sum(x => x.EX_ExaminationRoomStudent.Count)
- - scheduledStudentList.Where(x => x.ClassroomID == succesResult.ClassroomID
- && x.ExaminationDate == succesResult.ExaminationDate
- && x.StartTime <= succesResult.EndTime
- && x.EndTime >= succesResult.StartTime)
- .Count();
- if (roomRemainSeat <= 0)
- {
- var errorItem = succesResult;
- errorItem.ErrorMessage = "考场剩余座位不足,无法安排考试,请检查考场的使用情况。";
- errList.Add(errorItem);
- continue;
- }
- var studentList = (from s in succesResult.ExaminationPlan.CF_Student
- join ss in scheduledStudentList.Where(x => x.ExaminationDate == succesResult.ExaminationDate
- && x.StartTime <= succesResult.EndTime
- && x.EndTime >= succesResult.StartTime)
- on s.UserID equals ss.UserID into dss
- from ess in dss.DefaultIfEmpty()
- where ess == null
- select s).ToList();
- var examinationRoomStudentViewList = studentList.Take(roomRemainSeat ?? 0)
- .Select(x => new ExaminationRoomStudentView
- {
- ExaminationRoomStudentID = Guid.NewGuid(),
- ExaminationRoomLayoutID = newLayout.ExaminationRoomLayoutID,
- UserID = x.UserID,
- LoginID = x.Sys_User.LoginID,
- Remark = ""
- }).ToList();
- var classroomView = classroomViewList.FirstOrDefault(x => x.ClassroomID == succesResult.ClassroomID);
- var examinationRoomStudentList = this.SetRoomStudentSeats(examinationRoomStudentViewList, classroomView, 0, 0, CF_StudentOrderType.StudentNo);
- if (!deletedExaminationPlanIDList.Contains(succesResult.ExaminationPlan.ExaminationPlanID))
- {
- UnitOfWork.Remove<EX_ExaminationRoomStudent>(x => x.EX_ExaminationRoomLayout.ExaminationPlanID == succesResult.ExaminationPlan.ExaminationPlanID);
- UnitOfWork.Remove<EX_ExaminationRoomLayout>(x => x.ExaminationPlanID == succesResult.ExaminationPlan.ExaminationPlanID);
- deletedExaminationPlanIDList.Add(succesResult.ExaminationPlan.ExaminationPlanID);
- }
- newLayout.EX_ExaminationRoomStudent = new HashSet<EX_ExaminationRoomStudent>(examinationRoomStudentList);
- scheduledStudentList.AddRange(newLayout.EX_ExaminationRoomStudent.Select(x => new StudentClassroomView
- {
- ExaminationDate = succesResult.ExaminationDate,
- StartTime = succesResult.StartTime,
- EndTime = succesResult.EndTime,
- ClassroomID = newLayout.ClassroomID,
- UserID = x.UserID
- }));
- this.UnitOfWork.Add(newLayout);
- succesResult.ExaminationPlan.EX_ExaminationRoomLayout.Add(newLayout);
- }
- #endregion
-
- this.UnitOfWork.Commit();
- returnMessage = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。",
- (importRowlist.Count - errList.Count), errList.Count);
- if (errList.Count > 0)
- {
- return NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "导入问题列表", "");
- }
- else
- {
- return "";
- }
- }
- /// <summary>
- /// 获取期末设定学生
- /// </summary>
- /// <param name="finalExaminationID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<BaseStudentView> GetExaminationPlanStudentList(Guid examinationPlanID)
- {
- return ExaminationPlanDAL.GetExaminationPlanStudentList(examinationPlanID).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>();
- }
- /// <summary>
- /// 新增考试安排
- /// </summary>
- /// <param name="examinationPlanView"></param>
- public void AddExaminationPlan(ExaminationPlanView examinationPlanView)
- {
- try
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
- EX_ExaminationPlan examinationPlan = new EX_ExaminationPlan();
- examinationPlan.ExaminationPlanID = Guid.NewGuid();
- examinationPlan.SchoolyearID = examinationPlanView.SchoolyearID;
- examinationPlan.CollegeID = examinationPlanView.CollegeID;
- examinationPlan.CoursematerialID = examinationPlanView.CoursematerialID;
- examinationPlan.ExaminationModeID = examinationPlanView.ExaminationModeID;
- examinationPlan.ExaminationStyleID = examinationPlanView.ExaminationStyleID;
- examinationPlan.ExamsCategoryID = examinationPlanView.ExamsCategoryID;
- examinationPlan.ClassName = examinationPlanView.ClassName;
- examinationPlan.ExaminationDate = examinationPlanView.ExaminationDate;
- examinationPlan.StartTime = examinationPlanView.StartTime;
- examinationPlan.EndTime = examinationPlanView.EndTime;
- //examinationPlan.CF_Student = new HashSet<CF_Student>(graduateExamPlan.Students);
- SetNewStatus(examinationPlan);
- examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
- UnitOfWork.Add(examinationPlan);
- UnitOfWork.Commit();
- //this.UnitOfWork.BulkInsert(examinationPlan, (x => x.CF_Student));
- }
- catch (Exception)
- {
- throw;
- }
- //return null;
- }
- public ExaminationPlanView GetExaminationPlanView(Guid? examinationPlanID)
- {
- ExaminationPlanView examinationPlanView = null;
- if (examinationPlanID.HasValue)
- {
- examinationPlanView = ExaminationPlanDAL.GetExaminationPlanView(x => x.ExaminationPlanID == examinationPlanID).ToList().FirstOrDefault();
- }
- return examinationPlanView;
- }
- /// <summary>
- /// 考试安排增加学生
- /// </summary>
- /// <param name="finalExaminationID"></param>
- /// <param name="userIDs"></param>
- public void ExaminationPlanStudentAdd(Guid? examinationPlanID, List<BaseStudentView> listBaseStudentView)
- {
- try
- {
-
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 查询考试安排实体
- /// </summary>
- /// <param name="finalExaminationID"></param>
- /// <returns></returns>
- public EX_ExaminationPlan GetExaminationPlan(Guid? examinationPlanID)
- {
- return ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID, (x => x.CF_Student), (x => x.EX_ExaminationRoomLayout));
- }
- /// <summary>
- /// 重置考试安排
- /// </summary>
- /// <param name="examinationPlanIDs"></param>
- public void ResettingExaminationPlans(List<Guid> examinationPlanIDs)
- {
- try
- {
- if (examinationPlanIDs != null)
- {
- DeleteExaminationClassroomLayoutByPlanID(examinationPlanIDs);
- List<EX_ExaminationPlan> ExaminationPlans = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID)).ToList();
- foreach (EX_ExaminationPlan examinationPlan in ExaminationPlans)
- {
- if (examinationPlan.RecordStatus == (int)CF_ApprovalStatus.Submitted)
- {
- throw new Exception("选中数据包括已提交数据,不能进行重置");
- }
- examinationPlan.ExaminationDate = null;
- examinationPlan.StartTime = null;
- examinationPlan.EndTime = null;
- UnitOfWork.Update<EX_ExaminationPlan>(examinationPlan);
- }
- UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
-
- throw ex;
- }
- }
- public void DeleteExaminationClassroomLayoutByPlanID(List<Guid> examinationPlanIDs)
- {
- var examinationLayoutList = this.ExaminationPlanDAL.ExaminationRoomLayoutRepository
- .GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID.Value),
- (x => x.EX_ExaminationRoomStudent), (x => x.CF_Staff)).ToList();
- foreach (var examinationLayout in examinationLayoutList)
- {
- examinationLayout.CF_Staff = new HashSet<CF_Staff>();
- examinationLayout.EX_ExaminationRoomStudent.ToList().ForEach(x => this.UnitOfWork.Remove(x));
- this.UnitOfWork.Remove(examinationLayout);
- }
- this.UnitOfWork.Commit();
- }
- /// <summary>
- /// 撤销考试安排
- /// </summary>
- /// <param name="examinationPlanIDs"></param>
- public void CancelExaminationPlans(List<Guid> examinationPlanIDs)
- {
- try
- {
- if (examinationPlanIDs != null)
- {
- //DeleteExaminationClassroomLayout(examinationPlanIDs);
- List<EX_ExaminationPlan> ExaminationPlans = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID), (x => x.EX_ExaminationRoomLayout)).ToList();
- foreach (EX_ExaminationPlan examinationPlan in ExaminationPlans)
- {
- examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
- UnitOfWork.Update<EX_ExaminationPlan>(examinationPlan);
- }
- UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public void CheckStudentSchedule(Guid examinationPlanID, IList<Guid> studentUserIDList)
- {
- var examinationPlan = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID);
- var scheduleDateTimeList = new List<StartEndTimeView> {
- new StartEndTimeView { StartTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.StartTime.Value)
- , EndTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.EndTime.Value) }
- };
- var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(examinationPlan.SchoolyearID.Value,
- scheduleDateTimeList);
- var scheduledUserIDList = schedulingList.SelectMany(x => x.StudentList)
- .Where(x => studentUserIDList.Contains(x.UserID))
- .GroupBy(x => x.UserID)
- .Select(x => x.Key).ToList();
- if (scheduledUserIDList.Count > 0)
- {
- var userList = UserRepository.GetList(x => scheduledUserIDList.Contains(x.UserID)).ToList();
- throw new Exception(string.Format("学生{0}在该时段有课,不能参加考试,请检查考试时间设置。",
- string.Join("、", userList.Select(x => x.Name))));
- }
- }
- public void SaveGdss(ExaminationPlanGdssView examinationPlanView, IList<Guid?> staffIDList, IList<Guid?> studentIDList)
- {
- if (!examinationPlanView.ExaminationDate.HasValue)
- {
- throw new Exception("必须指定考试日期。");
- }
- if (!examinationPlanView.StartTime.HasValue)
- {
- throw new Exception("必须指定开始时间。");
- }
- if (!examinationPlanView.EndTime.HasValue)
- {
- throw new Exception("必须指定结束时间。");
- }
- if (examinationPlanView.ExaminationDate.Value.Date < DateTime.Today)
- {
- throw new Exception("考试日期需在当天之后。");
- }
- if (examinationPlanView.StartTime.Value >= examinationPlanView.EndTime.Value)
- {
- throw new Exception("结束时间需在开始时间之后。");
- }
- var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var examinationPlanEntity = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID,
- (x => x.CF_Student),
- (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
- (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student))));
- if (examinationPlanEntity == null)
- {
- throw new Exception("指定的考试计划不存在。");
- }
- else
- {
- this.SetModifyStatus(examinationPlanEntity);
- }
- examinationPlanEntity.ExaminationDate = examinationPlanView.ExaminationDate;
- examinationPlanEntity.StartTime = examinationPlanView.StartTime;
- examinationPlanEntity.EndTime = examinationPlanView.EndTime;
-
- var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationDate
- && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
- && x.ExaminationPlanID != examinationPlanView.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff.Select(e => e.Sys_User)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList();
- var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationPlanView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
- if (scheduledPlanViewList.Any(x => x.ExaminationStyleID != examinationPlanEntity.ExaminationStyleID
- && x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID)))
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,存在同一时间不同考试方式的排考,请重新核对后再进行设置。");
- }
- if ((classroomEntity.Examinationseating - scheduledPlanViewList.Sum(x =>
- x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID == examinationPlanView.ClassroomID).Sum(w => w.EX_ExaminationRoomStudent.Count)))
- < studentIDList.Count)
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,考场无法容纳该考试任务的学生,请重新核对后再进行设置。");
- }
- if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent)
- .Any(w => studentIDList.Contains(w.UserID))))
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,部分考生时间安排冲突,请重新核对后再进行设置。");
- }
- var classroomScheduledTeacher = scheduledPlanViewList.FirstOrDefault(x => x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID
- && w.CF_Staff.Count != w.CF_Staff.Where(y => staffIDList.Contains(y.UserID)).Count()));
- if (classroomScheduledTeacher != null)
- {
- var scheduledTeacher = string.Join("、", classroomScheduledTeacher.EX_ExaminationRoomLayout.First().CF_Staff.Select(x => x.Sys_User.Name).ToList());
- throw new Exception("考场" + classroomEntity.Name + "已由" + scheduledTeacher + "监考,请重新核对后再进行设置。");
- }
- if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID != examinationPlanView.ClassroomID)
- .SelectMany(w => w.CF_Staff).Any(w => staffIDList.Contains(w.UserID))))
- {
- throw new Exception("监考老师时间安排冲突,请重新核对后再进行设置。");
- }
- //获取排课
- var scheduleDateTimeList = new List<StartEndTimeView> {
- new StartEndTimeView { StartTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.StartTime.Value),
- EndTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.EndTime.Value) } };
- var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
- curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var schedulingStudentConflictList = (from student in studentIDList
- from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime)
- from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
- group student by student into g
- select g.FirstOrDefault()
- ).ToList();
- if (schedulingStudentConflictList.Count > 0)
- {
- throw new Exception("考试时间安排冲突,部分学生由于需要上课无法安排,请重新核对后再进行设置。");
- }
- var schedulingClassroomConflictList = (from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
- && x.ClassroomID == classroomEntity.ClassroomID)
- select scheduling
- ).ToList();
- if (schedulingClassroomConflictList.Count > 0)
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被排课占用,请重新核对后再进行设置。");
- }
- var excessiveUseConflictList = (from excessiveUse in classroomExcessiveUseList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
- && x.ClassroomID == classroomEntity.ClassroomID)
- select excessiveUse).ToList();
- if (excessiveUseConflictList.Count > 0)
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被其他活动占用,请重新核对后再进行设置。");
- }
- var schedulingTeacherConflictList = (from teacher in staffIDList
- from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime)
- from schedulingTeacher in scheduling.TeacherList.Where(x => x.UserID == teacher)
- group teacher by teacher into g
- select g.FirstOrDefault()
- ).ToList();
- if (schedulingClassroomConflictList.Count > 0)
- {
- throw new Exception("考试时间安排冲突,部分老师由于需要上课无法安排,请重新核对后再进行设置。");
- }
- examinationPlanEntity.EX_ExaminationRoomLayout.ForEach(x => {
- x.CF_Staff = new HashSet<CF_Staff>();
- UnitOfWork.RemoveRange(x.EX_ExaminationRoomStudent);
- });
- UnitOfWork.RemoveRange(examinationPlanEntity.EX_ExaminationRoomLayout);
- examinationPlanEntity.EX_ExaminationRoomLayout = new HashSet<EX_ExaminationRoomLayout>();
- var examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
- examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
- examinationRoomLayoutEntity.ExaminationPlanID = examinationPlanEntity.ExaminationPlanID;
- examinationRoomLayoutEntity.ClassroomID = classroomEntity.ClassroomID;
- examinationRoomLayoutEntity.RowSpacing = 0;
- examinationRoomLayoutEntity.ColumnSpacing = 0;
- examinationRoomLayoutEntity.StudentOrderType = examinationPlanView.StudentOrderType;
- var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
- examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
- this.SetNewStatus(examinationRoomLayoutEntity);
- this.UnitOfWork.Add(examinationRoomLayoutEntity);
- var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomEntity.ClassroomID).FirstOrDefault();
- var studentList = StudentsDAL.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.Sys_User)).ToList();
- var roomStudentList = this.SetRoomStudentSeats(studentList.Select(x => new ExaminationRoomStudentView
- {
- LoginID = x.Sys_User.LoginID,
- UserID = x.UserID,
- ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID
- }).ToList(), classroom, 0, 0);
- roomStudentList.ForEach(x =>
- {
- x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
- this.SetNewStatus(x);
- this.UnitOfWork.Add(x);
- });
- //考试计划对应的学生同步修改
- examinationPlanEntity.CF_Student = new HashSet<CF_Student>();
- roomStudentList.ForEach(x =>
- {
- CF_Student stu = studentList.Where(y => y.UserID == x.UserID).FirstOrDefault();
- examinationPlanEntity.CF_Student.Add(stu);
- });
- UnitOfWork.Commit();
- }
- public List<StudentAndCourseForExcelView> CheckBeforeGdssSave(ExaminationPlanGdssView examinationPlanView, IList<Guid?> staffIDList, IList<Guid?> studentIDList)
- {
- //如果是补考学生和排课存在冲突的话提醒是否强行排考
- var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- List<StudentAndCourseForExcelView> studentViewList = new List<StudentAndCourseForExcelView>();
- var examinationPlanEntity = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID,
- (x => x.CF_Student),
- (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
- (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student))));
- if (examinationPlanEntity.ExamsCategoryID == (int)CF_ExamsCategory.Resit || examinationPlanEntity.ExamsCategoryID == (int)CF_ExamsCategory.GraduationExam)
- {
- var scheduleDateTimeListforResit = new List<StartEndTimeView> {
- new StartEndTimeView { StartTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.StartTime.Value),
- EndTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.EndTime.Value) } };
- var schedulingListforResit = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeListforResit);
- var schedulingStudentConflictListforResit = (from student in studentIDList
- from scheduling in schedulingListforResit.Where(x => x.Date == examinationPlanView.ExaminationDate
- && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime)
- from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
- group student by student into g
- select g.FirstOrDefault()
- ).ToList();
- if (schedulingStudentConflictListforResit.Count > 0)
- {
- //studentViewList = StudentsDAL.GetStudentQueryable(x => schedulingStudentConflictListforResit.Contains(x.UserID)).ToList();
- var schedulingID = schedulingListforResit.Where(x => x.Date == examinationPlanView.ExaminationDate && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime).Select(x => x.EducationSchedulingID).ToList();
- var query = ExaminationPlanDAL.GetStudentAndCourseList(schedulingID, schedulingStudentConflictListforResit);
- studentViewList = query.Distinct().ToList();
- //studentViewList = schedulingStudentConflictListforResit;
- }
- }
- return studentViewList;
- }
- /// <summary>
- /// 补考排考学生和排课冲突,强行排考(不考虑学生与排课的冲突)
- /// </summary>
- /// <param name="examinationPlanView"></param>
- /// <param name="staffIDList"></param>
- /// <param name="studentIDList"></param>
- public void SaveGdssNotClashingStudent(ExaminationPlanGdssView examinationPlanView, IList<Guid?> staffIDList, IList<Guid?> studentIDList)
- {
- if (!examinationPlanView.ExaminationDate.HasValue)
- {
- throw new Exception("必须指定考试日期。");
- }
- if (!examinationPlanView.StartTime.HasValue)
- {
- throw new Exception("必须指定开始时间。");
- }
- if (!examinationPlanView.EndTime.HasValue)
- {
- throw new Exception("必须指定结束时间。");
- }
- if (examinationPlanView.ExaminationDate.Value.Date < DateTime.Today)
- {
- throw new Exception("考试日期需在当天之后。");
- }
- if (examinationPlanView.StartTime.Value >= examinationPlanView.EndTime.Value)
- {
- throw new Exception("结束时间需在开始时间之后。");
- }
- var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
- var examinationPlanEntity = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID,
- (x => x.CF_Student),
- (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
- (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student))));
- if (examinationPlanEntity == null)
- {
- throw new Exception("指定的考试计划不存在。");
- }
- else
- {
- this.SetModifyStatus(examinationPlanEntity);
- }
- examinationPlanEntity.ExaminationDate = examinationPlanView.ExaminationDate;
- examinationPlanEntity.StartTime = examinationPlanView.StartTime;
- examinationPlanEntity.EndTime = examinationPlanView.EndTime;
- var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationDate
- && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
- && x.ExaminationPlanID != examinationPlanView.ExaminationPlanID)
- .Include(x => x.CF_Student)
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff.Select(e => e.Sys_User)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
- .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
- .ToList();
- var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationPlanView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
- if (scheduledPlanViewList.Any(x => x.ExaminationStyleID != examinationPlanEntity.ExaminationStyleID
- && x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID)))
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,存在同一时间不同考试方式的排考,请重新核对后再进行设置。");
- }
- if ((classroomEntity.Examinationseating - scheduledPlanViewList.Sum(x =>
- x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID == examinationPlanView.ClassroomID).Sum(w => w.EX_ExaminationRoomStudent.Count)))
- < studentIDList.Count)
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,考场无法容纳该考试任务的学生,请重新核对后再进行设置。");
- }
- if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent)
- .Any(w => studentIDList.Contains(w.UserID))))
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,部分考生时间安排冲突,请重新核对后再进行设置。");
- }
- var classroomScheduledTeacher = scheduledPlanViewList.FirstOrDefault(x => x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID
- && w.CF_Staff.Count != w.CF_Staff.Where(y => staffIDList.Contains(y.UserID)).Count()));
- if (classroomScheduledTeacher != null)
- {
- var scheduledTeacher = string.Join("、", classroomScheduledTeacher.EX_ExaminationRoomLayout.First().CF_Staff.Select(x => x.Sys_User.Name).ToList());
- throw new Exception("考场" + classroomEntity.Name + "已由" + scheduledTeacher + "监考,请重新核对后再进行设置。");
- }
- if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID != examinationPlanView.ClassroomID)
- .SelectMany(w => w.CF_Staff).Any(w => staffIDList.Contains(w.UserID))))
- {
- throw new Exception("监考老师时间安排冲突,请重新核对后再进行设置。");
- }
- //获取排课
- var scheduleDateTimeList = new List<StartEndTimeView> {
- new StartEndTimeView { StartTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.StartTime.Value),
- EndTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.EndTime.Value) } };
- var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
- curSchoolyear.SchoolYearID.Value,
- scheduleDateTimeList);
- var schedulingClassroomConflictList = (from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
- && x.ClassroomID == classroomEntity.ClassroomID)
- select scheduling
- ).ToList();
- if (schedulingClassroomConflictList.Count > 0)
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被排课占用,请重新核对后再进行设置。");
- }
- var excessiveUseConflictList = (from excessiveUse in classroomExcessiveUseList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
- && x.ClassroomID == classroomEntity.ClassroomID)
- select excessiveUse).ToList();
- if (excessiveUseConflictList.Count > 0)
- {
- throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被其他活动占用,请重新核对后再进行设置。");
- }
- var schedulingTeacherConflictList = (from teacher in staffIDList
- from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
- && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime)
- from schedulingTeacher in scheduling.TeacherList.Where(x => x.UserID == teacher)
- group teacher by teacher into g
- select g.FirstOrDefault()
- ).ToList();
- if (schedulingClassroomConflictList.Count > 0)
- {
- throw new Exception("考试时间安排冲突,部分老师由于需要上课无法安排,请重新核对后再进行设置。");
- }
- examinationPlanEntity.EX_ExaminationRoomLayout.ForEach(x =>
- {
- x.CF_Staff = new HashSet<CF_Staff>();
- UnitOfWork.RemoveRange(x.EX_ExaminationRoomStudent);
- });
- UnitOfWork.RemoveRange(examinationPlanEntity.EX_ExaminationRoomLayout);
- examinationPlanEntity.EX_ExaminationRoomLayout = new HashSet<EX_ExaminationRoomLayout>();
- var examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
- examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
- examinationRoomLayoutEntity.ExaminationPlanID = examinationPlanEntity.ExaminationPlanID;
- examinationRoomLayoutEntity.ClassroomID = classroomEntity.ClassroomID;
- examinationRoomLayoutEntity.RowSpacing = 0;
- examinationRoomLayoutEntity.ColumnSpacing = 0;
- examinationRoomLayoutEntity.StudentOrderType = examinationPlanView.StudentOrderType;
- var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
- examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
- this.SetNewStatus(examinationRoomLayoutEntity);
- this.UnitOfWork.Add(examinationRoomLayoutEntity);
- var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomEntity.ClassroomID).FirstOrDefault();
- var studentList = StudentsDAL.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.Sys_User)).ToList();
- var roomStudentList = this.SetRoomStudentSeats(studentList.Select(x => new ExaminationRoomStudentView
- {
- LoginID = x.Sys_User.LoginID,
- UserID = x.UserID,
- ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID
- }).ToList(), classroom, 0, 0);
- roomStudentList.ForEach(x =>
- {
- x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
- this.SetNewStatus(x);
- this.UnitOfWork.Add(x);
- });
- //考试计划对应的学生同步修改
- examinationPlanEntity.CF_Student = new HashSet<CF_Student>();
- roomStudentList.ForEach(x =>
- {
- CF_Student stu = studentList.Where(y => y.UserID == x.UserID).FirstOrDefault();
- examinationPlanEntity.CF_Student.Add(stu);
- });
- UnitOfWork.Commit();
- }
- public IGridResultSet<StaffView> GetExaminationTeacherViewInfoGdss(Guid? examinationPlanID)
- {
- return ExaminationPlanDAL.GetExaminationTeacherView(x => x.ExaminationPlanID == examinationPlanID, (x => true)).ToGridResultSet();
- }
- public ExaminationPlanGdssView GetExaminationPlanGdssViewInfo(Guid? examinationPlanID)
- {
- return ExaminationPlanDAL.GetExaminationPlanGdssView(x => x.ExaminationPlanID == examinationPlanID).FirstOrDefault();
- }
- public IGridResultSet<StudentsView> GetGdssStudentListForSelect(ConfiguretView configuretView, Guid? examinationPlanID, Guid? collegeID, Guid? grademajorID, Guid? classmajorID, int pageIndex, int pageSize)
- {
- Expression<Func<CF_Student, bool>> exp = x => true;
- if(collegeID.HasValue)
- {
- exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
- }
- if(grademajorID.HasValue)
- {
- exp = exp.And(x => x.CF_Classmajor.GrademajorID == grademajorID);
- }
- if(classmajorID.HasValue)
- {
- exp = exp.And(x => x.ClassmajorID == classmajorID);
- }
- var query = ExaminationPlanDAL.GetGdssStudentListView(examinationPlanID, exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- return query.OrderByDescending(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
- //return null;
- }
- //public List<StudentsView> GetClashingStudentView(ExaminationPlanGdssView examinationPlanView, IList<Guid?> studentIDList)
- //{
- // var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- // var scheduleDateTimeList = new List<StartEndTimeView> {
- // new StartEndTimeView { StartTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.StartTime.Value),
- // EndTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.EndTime.Value) } };
- // var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
- // scheduleDateTimeList);
- // var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
- // curSchoolyear.SchoolYearID.Value,
- // scheduleDateTimeList);
- // var schedulingStudentConflictList = (from student in studentIDList
- // from scheduling in schedulingList.Where(x => x.Date == examinationPlanView.ExaminationDate
- // && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime)
- // from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
- // group student by student into g
- // select g.FirstOrDefault()
- // ).ToList();
- // var studentViewList = StudentsDAL.GetStudentQueryable(x => schedulingStudentConflictList.Contains(x.UserID)).ToList();
- // return studentViewList;
- //}
- }
-
-
- public class StudentClassroomView
- {
- public DateTime? ExaminationDate { get; set; }
- public TimeSpan? StartTime { get; set; }
- public TimeSpan? EndTime { get; set; }
- public Guid? ClassroomID { get; set; }
- public Guid ExaminationPlanID { get; set; }
- public Guid? UserID { get; set; }
- public List<Guid> TeacherIDList { get; set; }
- public int? ExaminationStyleID { get; set; }
- }
- public class AutoScheduleModifyView
- {
- public EX_ExaminationPlan ExaminationPlan { get; set; }
- public HashSet<CF_Staff> CF_Staff { get; set; }
- public DateTime? ExaminationDate { get; set; }
- public TimeSpan? StartTime { get; set; }
- public TimeSpan? EndTime { get; set; }
- public EX_ExaminationRoomSetting ExaminationRoom { get; set; }
- public List<CF_Student> ScheduleStudentList { get; set; }
- }
- }
|