| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102 |
- package com.template.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.Wrapper;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.qcloud.cos.utils.IOUtils;
- import com.seewo.open.sdk.DefaultSeewoClient;
- import com.seewo.open.sdk.SeewoClient;
- import com.seewo.open.sdk.auth.Account;
- import com.template.annotation.DESRespondSecret;
- import com.template.annotation.PassToken;
- import com.template.api.SmartUserControllerAPI;
- import com.template.common.utils.*;
- import com.template.config.ControlConfig;
- import com.template.config.SeewoConfig;
- import com.template.model.enumModel.*;
- import com.template.model.evaluate.teacher.SmartEvaluateTeacher;
- import com.template.model.pojo.*;
- import com.template.model.request.*;
- import com.template.model.result.CommonResult;
- import com.template.model.result.PageUtils;
- import com.template.model.seewo.*;
- import com.template.model.vo.*;
- import com.template.services.*;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.poi.hssf.usermodel.HSSFRow;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.DataFormatter;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFRow;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- import java.nio.charset.Charset;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.Year;
- import java.util.*;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- import java.util.zip.ZipInputStream;
- import static com.template.common.utils.AesTestOne.decrypt;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author ceshi
- * @since 2023-12-04
- */
- @RestController
- //返回参数加密注解
- @DESRespondSecret
- public class SmartUserController implements SmartUserControllerAPI {
- @Resource
- private SeewoConfig seewoConfig;
- @Resource
- private ControlConfig controlConfig;
- @Autowired
- private SmartUserService smartUserService;
- @Autowired
- private SmartGradeService smartGradeService;
- @Autowired
- private SmartClassService smartClassService;
- @Autowired
- private SmartUploadService smartUploadService;
- @Autowired
- private SmartDutiesService smartDutiesService;
- @Autowired
- private SmartDepartmentService smartDepartmentService;
- @Autowired
- private SmartIdentityService smartIdentityService;
- @Autowired
- private SmartTimeGroupService smartTimeGroupService;
- @Autowired
- private SmartAuthorityService smartAuthorityService;
- @Autowired
- private SmartFamilyIndexService smartFamilyIndexService;
- @Autowired
- private SmartTeachingService smartTeachingService;
- @Autowired
- private SmartAuthorGroupService smartAuthorGroupService;
- @Autowired
- private SmartSemesterService smartSemesterService;
- @Autowired
- private SmartSubjectService smartSubjectService;
- @Autowired
- private SmartEvaluateTeacherService smartEvaluateTeacherService;
- @Autowired
- private SmartOperationUserService smartOperationUserService;
- private static Logger logger = LoggerFactory.getLogger(SmartUserController.class);
- //region 开发自己导数据用的接口
- @Override
- public CommonResult testDeleteUserById(int userId) throws Exception {
- SmartUser user = smartUserService.getSmartById(userId);
- bsDeleteStudent(user);
- return CommonResult.ok();
- }
- @Override
- public CommonResult insertSmartUserPhoto() throws JsonProcessingException {
- Integer userType = eSeewoUserType.Student.getValue();
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- List<SmartUser> students = smartUserService.queryStudentDatas();
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- for (SmartUser student : students) {
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(student.getHeadImage());
- photo.setUserCode(student.getCardNo());
- photoList.add(photo);
- }
- int num = (int) Math.ceil((double) photoList.size() / 1000);
- for (int count = 1; count <= num; count++) {
- int startIndex = (count - 1) * 1000;
- int endIndex = count * 1000;
- if (count == num) {
- endIndex = startIndex + (photoList.size() % 1000);
- }
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, userType);
- if (!result.isSuccess()) {
- return result;
- }
- }
- return CommonResult.ok("图片上传成功");
- }
- @Override
- public CommonResult importExcelUserBsno(MultipartFile excelFile) throws IOException {
- //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
- if (excelFile.isEmpty() || excelFile.getSize() == 0) {
- return CommonResult.fail("压缩包中的excel文件不能为空");
- }
- List<SmartUser> result = new ArrayList<>();
- String ContentType = excelFile.getContentType();
- InputStream inputStream = excelFile.getInputStream();
- if (ContentType.equals(eFileType.Xlsx.getValue())) {
- CommonResult<List<SmartUser>> resultData = readBsXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- if (result == null) {
- return CommonResult.fail("文档内容为空,导入失败");
- }
- } else {
- return CommonResult.fail("用户导入只支持Xlsx");
- }
- List<String> gradeIds = result.stream().map(SmartUser::getGrade).distinct().collect(Collectors.toList());
- if (gradeIds != null && gradeIds.size() > 0) {
- List<SmartUser> users = smartUserService.queryStudentsByGrade(gradeIds);
- for (SmartUser user : users) {
- Optional<SmartUser> resultData = result.stream().filter(e -> e.getCardNo().equals(user.getCardNo()) && e.getName().equals(user.getName())).findFirst();
- if (resultData != null && resultData.isPresent()) {
- user.setBsStudentNo(resultData.get().getBsStudentNo());
- }
- }
- if (users != null && users.size() > 0) {
- boolean insertData = smartUserService.updateUserBatchById(users);
- if (!insertData) {
- return CommonResult.fail("导入失败");
- }
- }
- }
- return CommonResult.ok("导入成功");
- }
- /**
- * Xlsx文件读取方法ss
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readBsXlsx(InputStream inputStream) throws IOException {
- List<SmartUser> users = new ArrayList<>();
- List<String> idCards = new ArrayList<>();
- List<String> cardNos = new ArrayList<>();
- XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
- List<SmartGrade> grades = smartGradeService.list(null); //年级
- //读取第一张sheet
- XSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- try {
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- XSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 0) {
- String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//年级
- if (!schoolClass.equals("年级")) {
- return CommonResult.fail("导入数据第一列为年级");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第四列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第五列为姓名");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(5));//学生编码
- if (!sex.equals("学生编码")) {
- return CommonResult.fail("导入数据第六列为学生编码");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(4));
- if (ObjectUtils.isEmpty(name)) {
- return CommonResult.fail("第" + (rowNum + 1) + "条数据的姓名不能为空");
- }
- String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
- if (ObjectUtils.isEmpty(schoolGrade)) {
- return CommonResult.fail(name + "的年级不能为空");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
- if (ObjectUtils.isEmpty(cardNo)) {
- return CommonResult.fail(name + "的学号不能为空");
- }
- //学号重复判断
- if (!ObjectUtils.isEmpty(cardNo)) {
- cardNos.add(cardNo);
- }
- if (cardNos.stream().distinct().count() != cardNos.size()) {
- return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
- }
- String studentNo = dataFormatter.formatCellValue(row.getCell(5));//学生编码
- if (ObjectUtils.isEmpty(studentNo)) {
- return CommonResult.fail(name + "的学生编码不能为空");
- }
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(schoolGrade)).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- Integer gradeId = oGrade.get().getId();
- user.setGrade(String.valueOf(gradeId));
- } else {
- return CommonResult.fail(name + "的年级数据无效,导入失败");
- }
- user.setName(name);
- user.setBsStudentNo(studentNo);
- user.setCardNo(cardNo);
- users.add(user);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(users);
- }
- @Override
- public CommonResult importExcelFamilys(MultipartFile excelFile) throws Exception {
- //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
- if (excelFile.isEmpty() || excelFile.getSize() == 0) {
- return CommonResult.fail("压缩包中的excel文件不能为空");
- }
- String ContentType = excelFile.getContentType();
- InputStream inputStream = excelFile.getInputStream();
- List<SmartFamilyIndex> result = new ArrayList<>();
- CommonResult<List<SmartFamilyIndex>> resultData = readFamilyXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- boolean insertBatch = smartFamilyIndexService.saveBatch(result);
- return insertBatch ? CommonResult.ok("操作成功") : CommonResult.fail("操作失败");
- }
- /**
- * Xlsx文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartFamilyIndex>> readFamilyXlsx(InputStream inputStream) throws IOException {
- List<SmartFamilyIndex> result = new ArrayList<>();
- XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
- //读取第一张sheet
- XSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- try {
- for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- XSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum < 3) {
- //不做校验处理了
- } else {
- String cardNo = dataFormatter.formatCellValue(row.getCell(4));//学号
- if (ObjectUtils.isEmpty(cardNo)) {
- continue;
- }
- String phone1 = dataFormatter.formatCellValue(row.getCell(10));//手机号1
- if (!ObjectUtils.isEmpty(phone1)) {
- SmartFamilyIndex index = new SmartFamilyIndex();
- index.setStudentNo(cardNo);
- index.setParentPhone(phone1);
- index.setIndexData(0);
- result.add(index);
- }
- String phone2 = dataFormatter.formatCellValue(row.getCell(12));//手机号1
- if (!ObjectUtils.isEmpty(phone1)) {
- SmartFamilyIndex index = new SmartFamilyIndex();
- index.setStudentNo(cardNo);
- index.setParentPhone(phone1);
- index.setIndexData(1);
- result.add(index);
- }
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- /**
- * 批量导入压缩包用户信息
- * 以身份证号作为判断依据 如果存在重复数据就提示存在重复数据
- * 开发流程:建议先去拿到excel中的所有数据的身份证号去数据库中找一遍是否存在重复数据
- * 如果不存在重复数据就把附件文件夹中的附件文件上传到cos服务器上
- * 然后手动拼接一个人脸照片文件地址存入对应的数据中
- *
- * @param zipFile zip压缩包
- * @return
- */
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult importZipUsers(MultipartFile zipFile) throws IOException {
- List<SmartUser> result = new ArrayList<>();
- MultipartFile excelFile = null;
- List<MultipartFile> multipartFileHashMap = new ArrayList<>();
- String excelStr = null;
- if (zipFile != null) {
- //解压压缩文件并上传文件
- ByteArrayOutputStream byteOut = null;
- ZipInputStream zipIn = null;
- try {
- java.util.zip.ZipEntry zipEntry = null;
- zipIn = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK"));
- while ((zipEntry = zipIn.getNextEntry()) != null) {
- String fileName = zipEntry.getName();
- if (fileName.contains("人脸照片") && (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg"))) {
- byteOut = new ByteArrayOutputStream();
- IOUtils.copy(zipIn, byteOut);
- InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
- MultipartFile multipartFile = FileUtils.getMultipartFile(inputStream, fileName);
- multipartFileHashMap.add(multipartFile);
- } else if (fileName.contains("人员信息采集表") && (fileName.endsWith(".xlsx") || fileName.endsWith(".xls"))) {
- excelStr = fileName.endsWith(".xlsx") ? "xlsx" : "xls";
- byteOut = new ByteArrayOutputStream();
- IOUtils.copy(zipIn, byteOut);
- InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
- excelFile = FileUtils.getMultipartFile(inputStream, fileName);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (byteOut != null) {
- byteOut.close();
- }
- if (zipIn != null) {
- zipIn.close();
- }
- }
- }
- //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
- if (excelFile.isEmpty() || excelFile.getSize() == 0) {
- return CommonResult.fail("压缩包中的excel文件不能为空");
- }
- String ContentType = excelFile.getContentType();
- InputStream inputStream = excelFile.getInputStream();
- //xls格式文件
- if (excelStr.equals("xls")) {
- CommonResult<List<SmartUser>> resultData = readXls(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else if (excelStr.equals("xlsx")) {
- CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else {
- return CommonResult.fail("用户导入只支持Xls、Xlsx");
- }
- //cos上传 返回图片地址
- String uploadResult = smartUploadService.upload(multipartFileHashMap.toArray(new MultipartFile[0]));
- List<String> uploadImages = Arrays.asList(uploadResult.split(","));
- for (SmartUser user : result) {
- Optional<String> headImage = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/headImage/" + user.getHeadImage())).findFirst();
- if (headImage != null && headImage.isPresent()) {
- user.setHeadImage(headImage.get());
- }
- }
- //批量存储用户信息
- boolean resultBool = smartUserService.saveBatch(result);
- return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
- }
- //endregion
- //region 注销账号
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult logoffAccount(useridsRequest ur, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- int user = smartUserService.getSmartUserCountByIds(ur.getUserIds());
- if (user != ur.getUserIds().size()) {
- return CommonResult.fail("用户信息已失效");
- }
- return 0 > 0 ? CommonResult.ok("注销成功") : CommonResult.fail("注销失败");
- }
- //endregion
- //region 移动多个用户到其他部门
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult changeDepartment(changeDepartmentRequest cdr, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- List<SmartUser> users = smartUserService.getSmartUserByIds(cdr.getUserIds());
- if (users == null) {
- return CommonResult.fail("用户信息无效,移动失败!");
- }
- if (users.size() != cdr.getUserIds().size()) {
- return CommonResult.fail("存在无效用户数据,移动失败!");
- }
- for (SmartUser user : users) {
- user.setDepartmentId(cdr.getDepartmentId());
- }
- boolean result = smartUserService.updateUserBatchById(users);
- return result ? CommonResult.ok("移动成功") : CommonResult.fail("移动失败");
- }
- //endregion
- //region 批量新增用户
- //region 批量新增用户方法
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult importExcelUsers(MultipartFile excelFile, String headImage) throws Exception {
- List<SmartUser> result = new ArrayList<>();
- int useXw = 1;
- int useBs = 1;
- //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
- if (excelFile.isEmpty() || excelFile.getSize() == 0) {
- return CommonResult.fail("压缩包中的excel文件不能为空");
- }
- String ContentType = excelFile.getContentType();
- InputStream inputStream = excelFile.getInputStream();
- //xls格式文件
- if (ContentType.equals(eFileType.Xls.getValue())) {
- CommonResult<List<SmartUser>> resultData = readXls(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
- CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else {
- return CommonResult.fail("用户导入只支持Xls、Xlsx");
- }
- List<String> uploadImages = Arrays.asList(headImage.split(","));
- for (SmartUser user : result) {
- Optional<String> image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/" + user.getHeadImage())).findFirst();
- if (image != null && image.isPresent()) {
- user.setHeadImage(image.get());
- } else {
- if (user.getIdentityId().equals(eIdentityStatu.Student.getValue())
- || user.getIdentityId().equals(eIdentityStatu.Teacher.getValue())) {
- return CommonResult.fail(user.getName() + "头像不存在,导入失败");
- }
- }
- }
- //region 将数据加入第三方
- List<SmartUser> studentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
- if (studentDatas != null && studentDatas.size() > 0) {
- //判断是否存在重复数据
- List<String> cardNos = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
- if (cardNos == null) {
- return CommonResult.fail("文档内容为空,导入失败");
- }
- if (cardNos.size() <= 0) {
- return CommonResult.fail("文档内容为空,导入失败");
- }
- List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
- if (existUsers != null && existUsers.size() > 0) {
- String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
- return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
- }
- //获取班级Uid
- List<SmartClass> classDatas = smartClassService.getSmartClasss();
- if (classDatas == null) {
- return CommonResult.fail("班级数据无效,新增失败");
- }
- List<SmartGrade> gradeDatas = smartGradeService.getSmartGrades();
- if (gradeDatas == null) {
- return CommonResult.fail("年级数据无效,新增失败");
- }
- HashMap<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> seewoDatas = new HashMap<>();
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- for (SmartUser student : studentDatas) {
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(student.getHeadImage());
- photo.setUserCode(student.getCardNo());
- photoList.add(photo);
- //region 学生参数必填判断:年级、班级
- if (student.getGrade() == null) {
- return CommonResult.fail("学生年级不能为空");
- }
- if (student.getSchoolClass() == null) {
- return CommonResult.fail("学生班级不能为空");
- }
- //endregion
- Optional<SmartClass> oClassData = classDatas.stream().filter(e -> e.getId().equals(student.getSchoolClass())).findFirst();
- if (oClassData == null) {
- return CommonResult.fail("班级数据无效,新增失败");
- }
- Optional<SmartGrade> oGradeData = gradeDatas.stream().filter(e -> e.getId().intValue() == Integer.valueOf(student.getGrade())).findFirst();
- if (oGradeData == null) {
- return CommonResult.fail("年级数据无效,新增失败");
- }
- SmartClass classData = oClassData.get();
- SmartGrade gradeData = oGradeData.get();
- //region 凑希沃参数
- if (useXw == 1) {
- if (!seewoDatas.containsKey(classData.getClassUid())) {
- seewoDatas.put(classData.getClassUid(), new ArrayList<>());
- }
- StudentServiceBatchSaveClassStudentsParam.StudentInfo studentSeewo = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
- .studentName(student.getName())
- .studentCode(student.getCardNo())
- .gender(student.getSexId())
- .phone(student.getPhone() == null ? "" : student.getPhone())
- .build();
- seewoDatas.get(classData.getClassUid()).add(studentSeewo);
- }
- //endregion
- //region 百胜新增学生信息
- if (useBs == 1) {
- /**
- * 学生数据的有效期是到毕业年份的8月31日
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = queryGraduationYear(gradeData.getGradeNo());
- CommonResult<String> insertBsStudent = bsInsertStudent(student.getName(), student.getCardNo(), student.getSexId(), student.getHeadImage(), student.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, student.getIdCard());
- if (!insertBsStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
- }
- student.setBsStudentNo(insertBsStudent.getData());
- }
- //endregion
- }
- if (useXw == 1) {
- //初始化客户端
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultDatas = new ArrayList<>();
- for (Map.Entry<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> entry : seewoDatas.entrySet()) {
- String classUid = entry.getKey();
- CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> insertStudents = SeewoInsertBatchStudent(seewoClient, entry.getValue(), classUid);
- if (!insertStudents.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertStudents.getMessage());
- }
- seewoResultDatas.addAll(insertStudents.getData());
- }
- for (SmartUser student : studentDatas) {
- Optional<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultData = seewoResultDatas.stream().filter(e -> e.getStudentCode().equals(student.getCardNo())).findFirst();
- if (seewoResultData != null && seewoResultData.isPresent()) {
- student.setXwStudentUid(seewoResultData.get().getUserUid());
- }
- }
- }
- if (studentDatas != null && studentDatas.size() > 0) {
- //批量存储学生信息
- boolean resultBool = smartUserService.saveBatch(studentDatas);
- if (!resultBool) {
- return CommonResult.fail("导入失败");
- } else {
- // 需添加到海康平台
- ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
- for (SmartUser studentData : studentDatas) {
- Integer id = studentData.getId();
- SmartOperationUser smartOperationUser = new SmartOperationUser();
- smartOperationUser.setOperationId(id);
- smartOperationUser.setOperationMode("1");
- smartOperationUser.setStatus(1);
- smartOperationUser.setType(studentData.getIdentityId());
- operationUsers.add(smartOperationUser);
- }
- smartOperationUserService.saveBatch(operationUsers);
- }
- List<SmartFamilyIndex> familyIndexs = new ArrayList<>();
- //region 希沃新增编辑学生家长信息
- if (useXw == 1) {
- int num = (int) Math.ceil((double) studentDatas.size() / 100);
- for (int count = 1; count <= num; count++) {
- int startIndex = (count - 1) * 100;
- int endIndex = count * 100;
- if (count == num) {
- endIndex = startIndex + (studentDatas.size() % 100);
- }
- List<SmartUser> currentStudentDatas = studentDatas.subList(startIndex, endIndex);//结尾不包含下标100
- //学生与家长列表,最大100条
- List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
- for (SmartUser student : currentStudentDatas) {
- ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
- .studentCode(student.getCardNo())
- .build();
- List<SmartUser> parentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList());
- List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
- int i = 0;
- for (SmartUser parent : parentDatas) {
- SmartFamilyIndex familyIndex = new SmartFamilyIndex();
- familyIndex.setParentPhone(parent.getPhone());
- familyIndex.setStudentNo(student.getCardNo());
- familyIndex.setIndexData(i);
- familyIndexs.add(familyIndex);
- ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
- .name(parent.getName())
- .phone(parent.getPhone())
- .index(i)
- .build();
- parents.add(data);
- ++i;
- }
- if (parents != null && parents.size() > 0) {
- studentParents.add(students);
- //家长列表,最多4个
- students.setParents(parents);
- }
- }
- //初始化客户端
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
- //响应体,MimeType为 application/json
- ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //query
- ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .build();
- requestBody.setQuery(query);
- query.setStudentParents(studentParents);
- param.setRequestBody(requestBody);
- ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
- String jsonString = JSON.toJSONString(request);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request);
- logger.info("出参:" + parentResult);
- if (parentResult == null) {
- return CommonResult.fail("希沃学生家长数据添加失败!");
- }
- if (!parentResult.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + parentResult.getResponseBody().getMessage());
- }
- }
- }
- //endregion
- if (familyIndexs != null && familyIndexs.size() > 0) {
- boolean insertBatch = smartFamilyIndexService.saveBatch(familyIndexs);
- if (!insertBatch) {
- return CommonResult.fail("导入失败!");
- }
- }
- }
- //endregion
- List<SmartUser> parents = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
- //双胞胎家长
- List<SmartUser> newParents = new ArrayList<>();
- if (cardNos != null && cardNos.size() > 0) {
- List<SmartUser> students = smartUserService.querySmartUserByCardNos(cardNos);
- for (SmartUser parent : parents) {
- Optional<SmartUser> student = students.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
- if (student != null && student.isPresent()) {
- //先查找是否存在
- Optional<SmartUser> newData = newParents.stream().filter(e -> e.getName().equals(parent.getName()) && e.getPhone().equals(parent.getPhone()) && e.getShip().equals(parent.getShip())).findFirst();
- if (newData != null && newData.isPresent()) {
- String affiliate = newData.get().getAffiliate() + "," + student.get().getId();
- newData.get().setAffiliate(affiliate);
- } else {
- SmartUser newParent = new SmartUser();
- newParent.setName(parent.getName());
- newParent.setDepartmentId(parent.getDepartmentId());
- newParent.setPhone(parent.getPhone());
- newParent.setIdentityId(parent.getIdentityId());
- newParent.setSexId(parent.getSexId());
- newParent.setIsCancel(parent.getIsCancel());
- newParent.setAffiliate(String.valueOf(student.get().getId()));
- newParent.setShip(parent.getShip());
- newParents.add(newParent);
- }
- }
- }
- if (newParents != null && newParents.size() > 0) {
- //批量存储家长信息
- boolean resultBool = smartUserService.saveBatch(newParents);
- if (!resultBool) {
- return CommonResult.fail("导入失败!");
- }
- }
- //region 最后上传学生图片 这样能保证图片上传失败也不影响数据导入
- if (useXw == 1) {
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- int num = (int) Math.ceil((double) photoList.size() / 1000);
- for (int count = 1; count <= num; count++) {
- int startIndex = (count - 1) * 1000;
- int endIndex = count * 1000;
- if (count == num) {
- endIndex = startIndex + (photoList.size() % 1000);
- }
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
- CommonResult photoResult = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, eSeewoUserType.Student.getValue());
- if (!photoResult.isSuccess()) {
- return photoResult;
- }
- }
- }
- //endregion
- }
- } else {
- List<SmartUser> teacherDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()).collect(Collectors.toList());
- //判断是否存在重复数据
- List<String> cardNos = teacherDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
- if (cardNos == null) {
- return CommonResult.fail("文档内容为空,导入失败");
- }
- if (cardNos.size() <= 0) {
- return CommonResult.fail("文档内容为空,导入失败");
- }
- List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
- if (existUsers != null && existUsers.size() > 0) {
- String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
- return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
- }
- //获取班级Uid
- List<SmartClass> classDatas = smartClassService.getSmartClasss();
- List<SmartDepartment> departmentDatas = smartDepartmentService.list(null);
- //region
- //region 希沃添加教师数据
- if (useXw == 1) {
- int num = (int) Math.ceil((double) teacherDatas.size() / 100);
- for (int count = 1; count <= num; count++) {
- int startIndex = (count - 1) * 100;
- int endIndex = count * 100;
- if (count == num) {
- endIndex = startIndex + (teacherDatas.size() % 100);
- }
- List<SmartUser> currentStudentDatas = teacherDatas.subList(startIndex, endIndex);//结尾不包含下标100
- //初始化客户端
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- // 老师列表
- List<TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery> teachers = new ArrayList<>();
- for (SmartUser teacher : currentStudentDatas) {
- TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teacherData = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
- .account(teacher.getPhone())//用户账号
- .name(teacher.getName())//用户名字
- .accountType("phone")//账号类型 phone:手机号 email:邮箱
- .teacherCode(teacher.getCardNo())//教师工号
- .photoUrl(teacher.getHeadImage())//图片链接
- .build();
- teachers.add(teacherData);
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(teacher.getHeadImage());
- photo.setUserCode(teacher.getPhone());
- photoList.add(photo);
- }
- CommonResult<List<TeacherServiceBatchSaveOrUpdateTeacherResult.TeacherBaseInfoDto>> insertTeacher = SeewoInsertBatchTeacher(seewoClient, teachers);
- if (!insertTeacher.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
- }
- CommonResult insertPhotoResult = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
- if (!insertPhotoResult.isSuccess()) {
- return insertPhotoResult;
- }
- for (SmartUser teacher : teacherDatas) {
- if (teacher.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- Optional<SmartClass> oClass = classDatas.stream().filter(e -> e.getId().equals(teacher.getSchoolClass())).findFirst();
- if (oClass != null && oClass.isPresent()) {
- //获取班级Uid
- //region 将班主任推送到希沃
- if (useXw == 1) {
- CommonResult pushMaster = SeewoPushMaster(seewoClient, teacher.getPhone(), oClass.get().getClassUid());
- if (!pushMaster.isSuccess()) {
- return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
- }
- }
- //endregion
- } else {
- return CommonResult.fail(teacher.getName() + "班级数据无效,导入失败");
- }
- }
- }
- }
- }
- //endregion
- //region 百胜添加教师数据
- if (useBs == 1) {
- for (SmartUser teacher : teacherDatas) {
- Optional<SmartDepartment> oDepartment = departmentDatas.stream().filter(e -> e.getId().equals(teacher.getDepartmentId())).findFirst();
- if (!(oDepartment != null && oDepartment.isPresent())) {
- return CommonResult.fail(teacher.getName() + "的部门数据无效,导入失败");
- }
- /**
- * 教师数据的有效期是20年
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = TimeExchange.addYear(20);
- if (ObjectUtils.isEmpty(teacher.getBsStaffCode())) {
- CommonResult<String> insertBsTeacher = bsInsertTeacher(teacher, oDepartment.get().getBsDepartmentNo(), startTime, endTime);
- if (!insertBsTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
- }
- teacher.setBsStaffCode(insertBsTeacher.getData());
- } else {
- CommonResult<String> bsUpdateTeacher = updateBsTeacher(teacher, oDepartment.get().getBsDepartmentNo(), startTime, endTime);
- if (!bsUpdateTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + bsUpdateTeacher.getMessage());
- }
- teacher.setBsStaffCode(bsUpdateTeacher.getData());
- }
- }
- }
- //endregion
- if (teacherDatas != null && teacherDatas.size() > 0) {
- //批量存储老师信息
- boolean resultBool = smartUserService.saveBatch(teacherDatas);
- if (!resultBool) {
- return CommonResult.fail("导入失败");
- } else {
- // 需添加到海康平台
- ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
- for (SmartUser teacherData : teacherDatas) {
- Integer id = teacherData.getId();
- SmartOperationUser smartOperationUser = new SmartOperationUser();
- smartOperationUser.setOperationId(id);
- smartOperationUser.setOperationMode("1");
- smartOperationUser.setStatus(1);
- smartOperationUser.setType(teacherData.getIdentityId());
- operationUsers.add(smartOperationUser);
- }
- smartOperationUserService.saveBatch(operationUsers);
- }
- }
- }
- return CommonResult.ok("导入成功");
- }
- //endregion
- //region 批量新增Xlsx文件读取方法
- /**
- * Xlsx文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readXlsx(InputStream inputStream) throws IOException {
- List<String> idCards = new ArrayList<>();
- List<String> cardNos = new ArrayList<>();
- List<SmartUser> result = new ArrayList<>();
- XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- List<SmartGrade> grades = smartGradeService.list(null); //年级
- List<SmartClass> classs = smartClassService.list(null);//班级
- List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
- //读取第一张sheet
- XSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- //region 判断是老师还是学生导入
- boolean isTeacher = false;
- XSSFRow checkRow = sheetAt.getRow(0);
- if (checkRow != null) {
- String firstCow = dataFormatter.formatCellValue(checkRow.getCell(0));//第一列 学生是年级 老师是 学校名称
- if (firstCow.equals("学校名称")) {
- isTeacher = true;
- }
- }
- //endregion
- try {
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- XSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- if (!isTeacher) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 0) {
- String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
- if (!schoolGrade.equals("年级")) {
- return CommonResult.fail("导入数据第一列为年级");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
- if (!schoolClass.equals("班级")) {
- return CommonResult.fail("导入数据第一列为班级");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(2));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第二列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第三列为姓名");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
- if (!sex.equals("性别")) {
- return CommonResult.fail("导入数据第四列为性别");
- }
- String nation = dataFormatter.formatCellValue(row.getCell(5));//民族
- if (!nation.equals("民族")) {
- return CommonResult.fail("导入数据第五列为民族");
- }
- String cardId = dataFormatter.formatCellValue(row.getCell(6));//身份证
- if (!cardId.equals("身份证")) {
- return CommonResult.fail("导入数据第六列为身份证");
- }
- String headImage = dataFormatter.formatCellValue(row.getCell(7));//照片
- if (!headImage.equals("照片")) {
- return CommonResult.fail("导入数据第七列为照片");
- }
- String timeGroup = dataFormatter.formatCellValue(row.getCell(8));//常规时间组
- if (!timeGroup.equals("常规时间组")) {
- return CommonResult.fail("导入数据第八列为常规时间组");
- }
- String address = dataFormatter.formatCellValue(row.getCell(9));//住址
- if (!address.equals("住址")) {
- return CommonResult.fail("导入数据第九列为住址");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(10));//联系电话
- if (!phone.equals("联系电话")) {
- return CommonResult.fail("导入数据第十列为联系电话");
- }
- String family = dataFormatter.formatCellValue(row.getCell(11));//家属
- if (!family.equals("家属")) {
- return CommonResult.fail("导入数据第十一列为家属");
- }
- String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
- if (!familyShip.equals("家属与本人关系")) {
- return CommonResult.fail("导入数据第十二列为家属与本人关系");
- }
- String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
- if (!phoneTwo.equals("联系电话2")) {
- return CommonResult.fail("导入数据第十三列为联系电话2");
- }
- String familyTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
- if (!familyTwo.equals("家属2")) {
- return CommonResult.fail("导入数据第十四列为家属2");
- }
- String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
- if (!familyShipTwo.equals("家属与本人关系2")) {
- return CommonResult.fail("导入数据第十五列为家属与本人关系2");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(3));
- // if (ObjectUtils.isEmpty(name)) {
- // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
- // }
- if (ObjectUtils.isEmpty(name)) {
- continue;
- }
- String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
- if (ObjectUtils.isEmpty(schoolGrade)) {
- return CommonResult.fail(name + "的年级不能为空");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的班级不能为空");
- }
- //不判断重复性 因为会出现双胞胎
- String phone = dataFormatter.formatCellValue(row.getCell(10));
- // if (!ObjectUtils.isEmpty(phone)) {
- // phones.add(phone);
- // }
- // if (phones.stream().distinct().count() != phones.size()) {
- // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
- // }
- //性别是否为空判断
- String sex = dataFormatter.formatCellValue(row.getCell(4));
- if (ObjectUtils.isEmpty(sex)) {
- return CommonResult.fail(name + "的性别不能为空");
- }
- //家庭住址是否为空判断
- String address = dataFormatter.formatCellValue(row.getCell(9));
- //民族是否为空判断
- String nation = dataFormatter.formatCellValue(row.getCell(5));
- if (ObjectUtils.isEmpty(nation)) {
- return CommonResult.fail(name + "的民族不能为空");
- }
- //部门是否为空判断
- String department = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "学生";
- if (ObjectUtils.isEmpty(department)) {
- return CommonResult.fail(name + "的部门不能为空");
- }
- Integer departmentId = null;
- Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst();
- if (departModel != null && departModel.isPresent()) {
- departmentId = departModel.get().getId();
- } else {
- departmentId = 1;
- }
- //学号重复判断
- String cardNo = dataFormatter.formatCellValue(row.getCell(2));
- if (!ObjectUtils.isEmpty(cardNo)) {
- cardNos.add(cardNo);
- }
- if (cardNos.stream().distinct().count() != cardNos.size()) {
- return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
- }
- //身份证重复判断
- String idCard = dataFormatter.formatCellValue(row.getCell(6));
- if (!ObjectUtils.isEmpty(idCard)) {
- idCards.add(idCard);
- }
- if (idCards.stream().distinct().count() != idCards.size()) {
- return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
- }
- user.setCardNo(cardNo == null ? "" : cardNo);
- user.setName(name == null ? "" : name);
- user.setIdentityId(eIdentityStatu.Student.getValue());
- user.setIdCard(idCard == null ? "" : idCard);
- user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
- user.setDepartmentId(departmentId);
- String cellImage = dataFormatter.formatCellValue(row.getCell(7));
- user.setHeadImage(cellImage);
- user.setDormitoryNumber("");
- String grade = schoolGrade == null ? "" : schoolGrade;
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- Integer gradeId = oGrade.get().getId();
- user.setGrade(String.valueOf(gradeId));
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
- if (oClass != null && oClass.isPresent()) {
- user.setSchoolClass(oClass.get().getId());
- } else {
- return CommonResult.fail(name + "的班级数据无效,导入失败");
- }
- } else {
- return CommonResult.fail(name + "的年级数据无效,导入失败");
- }
- user.setCollege("");
- user.setSpeciality("");
- user.setCampus("");
- user.setPhone("");
- user.setAffiliate("");
- user.setTitle("");
- user.setAddress(address == null ? "" : address);
- user.setNation(nation == null ? "" : nation);
- user.setOfStudent("");
- user.setGraduate("");
- user.setDuties(null);
- String timeGroup = dataFormatter.formatCellValue(row.getCell(8));
- Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
- if (groupData != null && groupData.isPresent()) {
- user.setTimeGroupId(groupData.get().getId());
- } else {
- user.setTimeGroupId(0);
- }
- user.setIsCancel(eLogOff.Unlogout.getValue());
- result.add(user);
- //部门是否为空判断
- String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
- Integer familyDepartmentId = null;
- Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
- if (familyDepartModel != null && familyDepartModel.isPresent()) {
- familyDepartmentId = familyDepartModel.get().getId();
- } else {
- familyDepartmentId = 16;
- }
- //region 家属
- if (!ObjectUtils.isEmpty(phone)) {
- if (phone.length() != 11) {
- return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
- }
- SmartUser familyOne = new SmartUser();
- String family = dataFormatter.formatCellValue(row.getCell(11));//家属
- familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
- familyOne.setDepartmentId(familyDepartmentId);
- familyOne.setPhone(phone);
- familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
- familyOne.setSexId(eSexStatu.Man.getValue());
- familyOne.setIsCancel(eLogOff.Unlogout.getValue());
- familyOne.setAffiliate(user.getCardNo());
- String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
- familyOne.setShip(familyShip == null ? "其他" : familyShip);
- result.add(familyOne);
- }
- String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
- if (!ObjectUtils.isEmpty(phoneTwo)) {
- if (phoneTwo.length() != 11) {
- return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
- }
- SmartUser familyTwo = new SmartUser();
- String familyNameTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
- familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
- familyTwo.setDepartmentId(familyDepartmentId);
- familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
- familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
- familyTwo.setSexId(eSexStatu.Man.getValue());
- familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
- familyTwo.setAffiliate(user.getCardNo());
- String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
- familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
- result.add(familyTwo);
- }
- //endregion
- //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
- if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(13)))) {
- if (phone.equals(dataFormatter.formatCellValue(row.getCell(13)))) {
- return CommonResult.fail(name + "的学生家长手机号不可重复");
- }
- }
- //endregion
- }
- } else {
- //教师导入
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 0) {
- String schoolName = dataFormatter.formatCellValue(row.getCell(0));//学校名称
- if (!schoolName.equals("学校名称")) {
- return CommonResult.fail("导入数据第一列为学校名称");
- }
- String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
- if (!departmentNo.equals("部门编码")) {
- return CommonResult.fail("导入数据第二列为部门编码");
- }
- String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
- if (!departmentName.equals("部门名称")) {
- return CommonResult.fail("导入数据第三列为部门名称");
- }
- String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
- if (!teacherNo.equals("教师编码")) {
- return CommonResult.fail("导入数据第四列为教师编码");
- }
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第五列为姓名");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
- if (!sex.equals("性别")) {
- return CommonResult.fail("导入数据第六列为性别");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
- if (!phone.equals("联系电话")) {
- return CommonResult.fail("导入数据第七列为联系电话");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//管理班级
- if (!schoolClass.equals("管理班级")) {
- return CommonResult.fail("导入数据第八列为身份证");
- }
- String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
- if (!nation.equals("民族")) {
- return CommonResult.fail("导入数据第九列为民族");
- }
- String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
- if (!card.equals("身份证(允许为空)")) {
- return CommonResult.fail("导入数据第十列为身份证");
- }
- String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
- if (!photo.equals("照片")) {
- return CommonResult.fail("导入数据第十一列为照片");
- }
- String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
- if (!timeGroup.equals("常规时间组")) {
- return CommonResult.fail("导入数据第十二列为常规时间组");
- }
- String address = dataFormatter.formatCellValue(row.getCell(12));//住址
- if (!address.equals("住址")) {
- return CommonResult.fail("导入数据第十三列为住址");
- }
- } else {
- SmartUser user = new SmartUser();
- user.setIdentityId(eIdentityStatu.Teacher.getValue());
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (ObjectUtils.isEmpty(name)) {
- continue;
- }
- user.setName(name);
- String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
- user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
- String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
- if (ObjectUtils.isEmpty(departmentName)) {
- return CommonResult.fail(name + "的部门名称不能为空");
- }
- String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
- if (ObjectUtils.isEmpty(departmentNo)) {
- return CommonResult.fail(name + "的部门编码不能为空");
- }
- Optional<SmartDepartment> oDepartment = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
- if (!(oDepartment != null && oDepartment.isPresent())) {
- return CommonResult.fail(departmentName + "部门数据在系统中不存在");
- }
- user.setDepartmentId(oDepartment.get().getId());
- if (departmentName.equals("班主任")) {
- String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//班级
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的管理班级不能为空");
- }
- //班级和年级
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
- if (!(oClass != null && oClass.isPresent())) {
- return CommonResult.fail(schoolClass + "的班级数据在系统中不存在");
- }
- user.setSchoolClass(oClass.get().getId());
- user.setGrade(String.valueOf(oClass.get().getGradeId()));
- user.setDuties(eDuties.ClassTeacher.getValue());
- } else {
- user.setDuties(5);//任课老师
- }
- String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
- if (!ObjectUtils.isEmpty(teacherNo)) {
- user.setBsStaffCode(teacherNo);
- }
- String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
- if (ObjectUtils.isEmpty(phone)) {
- return CommonResult.fail(name + "的手机号不能为空");
- }
- user.setCardNo(phone);
- user.setPhone(phone);
- user.setXwTeacherCode(phone);
- String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
- if (!ObjectUtils.isEmpty(nation)) {
- user.setNation(nation);
- }
- String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
- if (!ObjectUtils.isEmpty(card)) {
- user.setIdCard(card);
- }
- String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
- if (!ObjectUtils.isEmpty(photo)) {
- user.setHeadImage(photo);
- }
- String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
- if (!ObjectUtils.isEmpty(timeGroup)) {
- Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
- if (groupData != null && groupData.isPresent()) {
- user.setTimeGroupId(groupData.get().getId());
- }
- }
- String address = dataFormatter.formatCellValue(row.getCell(12));//住址
- if (!ObjectUtils.isEmpty(address)) {
- user.setAddress(address);
- }
- user.setIsCancel(eLogOff.Unlogout.getValue());
- result.add(user);
- }
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 批量新增Xls文件读取方法
- /**
- * Xls文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readXls(InputStream inputStream) throws IOException {
- List<String> idCards = new ArrayList<>();
- List<String> cardNos = new ArrayList<>();
- List<SmartUser> result = new ArrayList<>();
- HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- List<SmartGrade> grades = smartGradeService.list(null); //年级
- List<SmartClass> classs = smartClassService.list(null);//班级
- List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
- //读取第一张sheet
- HSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- //region 判断是老师还是学生导入
- boolean isTeacher = false;
- HSSFRow checkRow = sheetAt.getRow(0);
- if (checkRow != null) {
- String firstCow = dataFormatter.formatCellValue(checkRow.getCell(0));//第一列 学生是年级 老师是 学校名称
- if (firstCow.equals("学校名称")) {
- isTeacher = true;
- }
- }
- //endregion
- try {
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- HSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- if (!isTeacher) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 0) {
- String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
- if (!schoolGrade.equals("年级")) {
- return CommonResult.fail("导入数据第一列为年级");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
- if (!schoolClass.equals("班级")) {
- return CommonResult.fail("导入数据第一列为班级");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(2));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第二列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第三列为姓名");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
- if (!sex.equals("性别")) {
- return CommonResult.fail("导入数据第四列为性别");
- }
- String nation = dataFormatter.formatCellValue(row.getCell(5));//民族
- if (!nation.equals("民族")) {
- return CommonResult.fail("导入数据第五列为民族");
- }
- String cardId = dataFormatter.formatCellValue(row.getCell(6));//身份证
- if (!cardId.equals("身份证")) {
- return CommonResult.fail("导入数据第六列为身份证");
- }
- String headImage = dataFormatter.formatCellValue(row.getCell(7));//照片
- if (!headImage.equals("照片")) {
- return CommonResult.fail("导入数据第七列为照片");
- }
- String timeGroup = dataFormatter.formatCellValue(row.getCell(8));//常规时间组
- if (!timeGroup.equals("常规时间组")) {
- return CommonResult.fail("导入数据第八列为常规时间组");
- }
- String address = dataFormatter.formatCellValue(row.getCell(9));//住址
- if (!address.equals("住址")) {
- return CommonResult.fail("导入数据第九列为住址");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(10));//联系电话
- if (!phone.equals("联系电话")) {
- return CommonResult.fail("导入数据第十列为联系电话");
- }
- String family = dataFormatter.formatCellValue(row.getCell(11));//家属
- if (!family.equals("家属")) {
- return CommonResult.fail("导入数据第十一列为家属");
- }
- String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
- if (!familyShip.equals("家属与本人关系")) {
- return CommonResult.fail("导入数据第十二列为家属与本人关系");
- }
- String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
- if (!phoneTwo.equals("联系电话2")) {
- return CommonResult.fail("导入数据第十三列为联系电话2");
- }
- String familyTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
- if (!familyTwo.equals("家属2")) {
- return CommonResult.fail("导入数据第十四列为家属2");
- }
- String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
- if (!familyShipTwo.equals("家属与本人关系2")) {
- return CommonResult.fail("导入数据第十五列为家属与本人关系2");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(3));
- // if (ObjectUtils.isEmpty(name)) {
- // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
- // }
- if (ObjectUtils.isEmpty(name)) {
- continue;
- }
- String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
- if (ObjectUtils.isEmpty(schoolGrade)) {
- return CommonResult.fail(name + "的年级不能为空");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的班级不能为空");
- }
- //不判断重复性 因为会出现双胞胎
- String phone = dataFormatter.formatCellValue(row.getCell(10));
- // if (!ObjectUtils.isEmpty(phone)) {
- // phones.add(phone);
- // }
- // if (phones.stream().distinct().count() != phones.size()) {
- // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
- // }
- //性别是否为空判断
- String sex = dataFormatter.formatCellValue(row.getCell(4));
- if (ObjectUtils.isEmpty(sex)) {
- return CommonResult.fail(name + "的性别不能为空");
- }
- //家庭住址是否为空判断
- String address = dataFormatter.formatCellValue(row.getCell(9));
- //民族是否为空判断
- String nation = dataFormatter.formatCellValue(row.getCell(5));
- if (ObjectUtils.isEmpty(nation)) {
- return CommonResult.fail(name + "的民族不能为空");
- }
- //部门是否为空判断
- String department = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "学生";
- if (ObjectUtils.isEmpty(department)) {
- return CommonResult.fail(name + "的部门不能为空");
- }
- Integer departmentId = null;
- Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst();
- if (departModel != null && departModel.isPresent()) {
- departmentId = departModel.get().getId();
- } else {
- departmentId = 1;
- }
- //学号重复判断
- String cardNo = dataFormatter.formatCellValue(row.getCell(2));
- if (!ObjectUtils.isEmpty(cardNo)) {
- cardNos.add(cardNo);
- }
- if (cardNos.stream().distinct().count() != cardNos.size()) {
- return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
- }
- //身份证重复判断
- String idCard = dataFormatter.formatCellValue(row.getCell(6));
- if (!ObjectUtils.isEmpty(idCard)) {
- idCards.add(idCard);
- }
- if (idCards.stream().distinct().count() != idCards.size()) {
- return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
- }
- user.setCardNo(cardNo == null ? "" : cardNo);
- user.setName(name == null ? "" : name);
- user.setIdentityId(eIdentityStatu.Student.getValue());
- user.setIdCard(idCard == null ? "" : idCard);
- user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
- user.setDepartmentId(departmentId);
- String cellImage = dataFormatter.formatCellValue(row.getCell(7));
- user.setHeadImage(cellImage);
- user.setDormitoryNumber("");
- String grade = schoolGrade == null ? "" : schoolGrade;
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- Integer gradeId = oGrade.get().getId();
- user.setGrade(String.valueOf(gradeId));
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
- if (oClass != null && oClass.isPresent()) {
- user.setSchoolClass(oClass.get().getId());
- } else {
- return CommonResult.fail(name + "的班级数据无效,导入失败");
- }
- } else {
- return CommonResult.fail(name + "的年级数据无效,导入失败");
- }
- user.setCollege("");
- user.setSpeciality("");
- user.setCampus("");
- user.setPhone("");
- user.setAffiliate("");
- user.setTitle("");
- user.setAddress(address == null ? "" : address);
- user.setNation(nation == null ? "" : nation);
- user.setOfStudent("");
- user.setGraduate("");
- user.setDuties(null);
- String timeGroup = dataFormatter.formatCellValue(row.getCell(8));
- Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
- if (groupData != null && groupData.isPresent()) {
- user.setTimeGroupId(groupData.get().getId());
- } else {
- user.setTimeGroupId(0);
- }
- user.setIsCancel(eLogOff.Unlogout.getValue());
- result.add(user);
- //部门是否为空判断
- String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
- Integer familyDepartmentId = null;
- Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
- if (familyDepartModel != null && familyDepartModel.isPresent()) {
- familyDepartmentId = familyDepartModel.get().getId();
- } else {
- familyDepartmentId = 16;
- }
- //region 家属
- if (!ObjectUtils.isEmpty(phone)) {
- if (phone.length() != 11) {
- return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
- }
- SmartUser familyOne = new SmartUser();
- String family = dataFormatter.formatCellValue(row.getCell(11));//家属
- familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
- familyOne.setDepartmentId(familyDepartmentId);
- familyOne.setPhone(phone);
- familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
- familyOne.setSexId(eSexStatu.Man.getValue());
- familyOne.setIsCancel(eLogOff.Unlogout.getValue());
- familyOne.setAffiliate(user.getCardNo());
- String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
- familyOne.setShip(familyShip == null ? "其他" : familyShip);
- result.add(familyOne);
- }
- String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
- if (!ObjectUtils.isEmpty(phoneTwo)) {
- if (phoneTwo.length() != 11) {
- return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
- }
- SmartUser familyTwo = new SmartUser();
- String familyNameTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
- familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
- familyTwo.setDepartmentId(familyDepartmentId);
- familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
- familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
- familyTwo.setSexId(eSexStatu.Man.getValue());
- familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
- familyTwo.setAffiliate(user.getCardNo());
- String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
- familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
- result.add(familyTwo);
- }
- //endregion
- //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
- if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(13)))) {
- if (phone.equals(dataFormatter.formatCellValue(row.getCell(13)))) {
- return CommonResult.fail(name + "的学生家长手机号不可重复");
- }
- }
- //endregion
- }
- } else {
- //教师导入
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 0) {
- String schoolName = dataFormatter.formatCellValue(row.getCell(0));//学校名称
- if (!schoolName.equals("学校名称")) {
- return CommonResult.fail("导入数据第一列为学校名称");
- }
- String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
- if (!departmentNo.equals("部门编码")) {
- return CommonResult.fail("导入数据第二列为部门编码");
- }
- String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
- if (!departmentName.equals("部门名称")) {
- return CommonResult.fail("导入数据第三列为部门名称");
- }
- String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
- if (!teacherNo.equals("教师编码")) {
- return CommonResult.fail("导入数据第四列为教师编码");
- }
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第五列为姓名");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
- if (!sex.equals("性别")) {
- return CommonResult.fail("导入数据第六列为性别");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
- if (!phone.equals("联系电话")) {
- return CommonResult.fail("导入数据第七列为联系电话");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//管理班级
- if (!schoolClass.equals("管理班级")) {
- return CommonResult.fail("导入数据第八列为身份证");
- }
- String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
- if (!nation.equals("民族")) {
- return CommonResult.fail("导入数据第九列为民族");
- }
- String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
- if (!card.equals("身份证(允许为空)")) {
- return CommonResult.fail("导入数据第十列为身份证");
- }
- String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
- if (!photo.equals("照片")) {
- return CommonResult.fail("导入数据第十一列为照片");
- }
- String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
- if (!timeGroup.equals("常规时间组")) {
- return CommonResult.fail("导入数据第十二列为常规时间组");
- }
- String address = dataFormatter.formatCellValue(row.getCell(12));//住址
- if (!address.equals("住址")) {
- return CommonResult.fail("导入数据第十三列为住址");
- }
- } else {
- SmartUser user = new SmartUser();
- user.setIdentityId(eIdentityStatu.Teacher.getValue());
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (ObjectUtils.isEmpty(name)) {
- continue;
- }
- user.setName(name);
- String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
- user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
- String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
- if (ObjectUtils.isEmpty(departmentName)) {
- return CommonResult.fail(name + "的部门名称不能为空");
- }
- String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
- if (ObjectUtils.isEmpty(departmentNo)) {
- return CommonResult.fail(name + "的部门编码不能为空");
- }
- Optional<SmartDepartment> oDepartment = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
- if (!(oDepartment != null && oDepartment.isPresent())) {
- return CommonResult.fail(departmentName + "部门数据在系统中不存在");
- }
- user.setDepartmentId(oDepartment.get().getId());
- if (departmentName.equals("班主任")) {
- String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//班级
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的管理班级不能为空");
- }
- //班级和年级
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
- if (!(oClass != null && oClass.isPresent())) {
- return CommonResult.fail(schoolClass + "的班级数据在系统中不存在");
- }
- user.setSchoolClass(oClass.get().getId());
- user.setGrade(String.valueOf(oClass.get().getGradeId()));
- user.setDuties(eDuties.ClassTeacher.getValue());
- } else {
- user.setDuties(5);//任课老师
- }
- String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
- if (!ObjectUtils.isEmpty(teacherNo)) {
- user.setBsStaffCode(teacherNo);
- }
- String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
- if (ObjectUtils.isEmpty(phone)) {
- return CommonResult.fail(name + "的手机号不能为空");
- }
- user.setCardNo(phone);
- user.setPhone(phone);
- user.setXwTeacherCode(phone);
- String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
- if (!ObjectUtils.isEmpty(nation)) {
- user.setNation(nation);
- }
- String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
- if (!ObjectUtils.isEmpty(card)) {
- user.setIdCard(card);
- }
- String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
- if (!ObjectUtils.isEmpty(photo)) {
- user.setHeadImage(photo);
- }
- String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
- if (!ObjectUtils.isEmpty(timeGroup)) {
- Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
- if (groupData != null && groupData.isPresent()) {
- user.setTimeGroupId(groupData.get().getId());
- }
- }
- String address = dataFormatter.formatCellValue(row.getCell(12));//住址
- if (!ObjectUtils.isEmpty(address)) {
- user.setAddress(address);
- }
- user.setIsCancel(eLogOff.Unlogout.getValue());
- result.add(user);
- }
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- //endregion
- //endregion
- //region 批量更新用户
- //region 批量更新用户方法
- /**
- * 只更新 姓名 班级 时间组
- *
- * @param excelFile excel文件
- * @return
- * @throws IOException
- */
- @Override
- public CommonResult importExcelUpdateUsers(MultipartFile excelFile) throws Exception {
- List<SmartUser> result = new ArrayList<>();
- int useXw = 1;
- int useBs = 1;
- //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
- if (excelFile.isEmpty() || excelFile.getSize() == 0) {
- return CommonResult.fail("excel文件不能为空");
- }
- String ContentType = excelFile.getContentType();
- InputStream inputStream = excelFile.getInputStream();
- //xls格式文件
- if (ContentType.equals(eFileType.Xls.getValue())) {
- CommonResult<List<SmartUser>> resultData = readUpdateXls(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
- CommonResult<List<SmartUser>> resultData = readUpdateXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else {
- return CommonResult.fail("用户导入只支持Xls、Xlsx");
- }
- //获取导入学生的相关数据
- List<String> cardNos = result.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
- if (cardNos == null) {
- return CommonResult.fail("文档内容为空,批量更新失败");
- }
- List<SmartGrade> grades = smartGradeService.list(null);
- List<SmartUser> studentDatas = smartUserService.querySmartUserByCardNos(cardNos);
- List<SmartClass> classes = smartClassService.list(null);
- List<SmartUser> updateStudent = new ArrayList<>();
- for (SmartUser studentData : result) {
- Optional<SmartUser> oldStudent = studentDatas.stream().filter(e -> e.getCardNo().equals(studentData.getCardNo())).findFirst();
- if (oldStudent != null && oldStudent.isPresent()) {
- oldStudent.get().setName(studentData.getName());//姓名
- oldStudent.get().setSchoolClass(studentData.getSchoolClass());//班级
- oldStudent.get().setGrade(studentData.getGrade());//可能会变年级
- oldStudent.get().setTimeGroupId(studentData.getTimeGroupId());//时间组
- updateStudent.add(oldStudent.get());
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> String.valueOf(e.getId()).equals(studentData.getGrade())).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(studentData.getSchoolClass())).findFirst();
- if (oClass != null && oClass.isPresent()) {
- if (useXw == 1) {
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- CommonResult updateSwStudent = SeewoUpdateStudent(seewoClient, oldStudent.get());
- if (!updateSwStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + updateSwStudent.getMessage());
- }
- }
- if (useBs == 1) {
- /**
- * 学生数据的有效期是到毕业年份的8月31日
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = queryGraduationYear(oGrade.get().getGradeNo());
- CommonResult<String> updateBsStudent = bsEUpdateStudent(oldStudent.get(), oClass.get().getBsClassNo(), startTime, endTime);
- if (!updateBsStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
- }
- }
- } else {
- return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的班级数据无效,无法进行更新操作");
- }
- } else {
- return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的年级数据无效,无法进行更新操作");
- }
- } else {
- return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的数据在系统中不存在,无法进行更新操作");
- }
- }
- if (updateStudent != null && updateStudent.size() > 0) {
- boolean updateBatch = smartUserService.updateUserBatchById(updateStudent);
- if (!updateBatch) {
- return CommonResult.fail("系统批量更新出错,导入失败");
- } else {
- // 修改需同步到海康平台
- for (SmartUser su : updateStudent) {
- Integer identityId = su.getIdentityId();
- if (2 == identityId || identityId == 3) {
- Integer id = su.getId();
- SmartOperationUser smartOperationUser = new SmartOperationUser();
- smartOperationUser.setOperationId(id);
- smartOperationUser.setOperationMode("2");
- smartOperationUser.setStatus(1);
- smartOperationUser.setType(identityId);
- smartOperationUserService.save(smartOperationUser);
- }
- }
- }
- }
- return CommonResult.ok("导入成功");
- }
- //endregion
- //region Xls文件读取方法
- /**
- * Xls文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readUpdateXls(InputStream inputStream) throws IOException {
- List<SmartUser> result = new ArrayList<>();
- HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
- List<SmartClass> classs = smartClassService.list(null);//班级
- List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
- //读取第一张sheet
- HSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- try {
- for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- HSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 1) {
- String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
- if (!xwNo.equals("希沃编号")) {
- return CommonResult.fail("导入数据第二列为希沃编号");
- }
- String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
- if (!bsNo.equals("百胜编号")) {
- return CommonResult.fail("导入数据第三列为百胜编号");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第四列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第五列为姓名");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
- if (!schoolClass.equals("班级")) {
- return CommonResult.fail("导入数据第六列为班级");
- }
- String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
- if (!group.equals("时间组")) {
- return CommonResult.fail("导入数据第七列为时间组");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (ObjectUtils.isEmpty(name)) {
- return CommonResult.fail("第" + (rowNum) + "条数据的名称不能为空");
- }
- String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
- if (ObjectUtils.isEmpty(xwNo)) {
- return CommonResult.fail(name + "的希沃编号不能为空");
- }
- String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
- if (ObjectUtils.isEmpty(bsNo)) {
- return CommonResult.fail(name + "的百胜编号不能为空");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
- if (ObjectUtils.isEmpty(cardNo)) {
- return CommonResult.fail(name + "的学号不能为空");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的班级不能为空");
- }
- String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
- if (ObjectUtils.isEmpty(group)) {
- return CommonResult.fail(name + "的时间组不能为空");
- }
- user.setCardNo(cardNo == null ? "" : cardNo);
- user.setName(name == null ? "" : name);
- user.setIdentityId(eIdentityStatu.Student.getValue());
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
- if (oClass != null && oClass.isPresent()) {
- user.setSchoolClass(oClass.get().getId());
- user.setGrade(String.valueOf(oClass.get().getGradeId()));
- } else {
- return CommonResult.fail(name + "的班级数据无效,导入失败");
- }
- Optional<SmartTimeGroup> oGroup = timeGroups.stream().filter(e -> e.getName().equals(group)).findFirst();
- if (oGroup != null && oGroup.isPresent()) {
- user.setTimeGroupId(oGroup.get().getId());
- }
- result.add(user);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region Xlsx文件读取方法
- /**
- * Xlsx文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readUpdateXlsx(InputStream inputStream) throws IOException {
- List<SmartUser> result = new ArrayList<>();
- XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
- List<SmartClass> classs = smartClassService.list(null);//班级
- List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
- //读取第一张sheet
- XSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- try {
- for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- XSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //标题 校验
- if (rowNum == 1) {
- String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
- if (!xwNo.equals("希沃编号")) {
- return CommonResult.fail("导入数据第二列为希沃编号");
- }
- String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
- if (!bsNo.equals("百胜编号")) {
- return CommonResult.fail("导入数据第三列为百胜编号");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第四列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第五列为姓名");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
- if (!schoolClass.equals("班级")) {
- return CommonResult.fail("导入数据第六列为班级");
- }
- String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
- if (!group.equals("时间组")) {
- return CommonResult.fail("导入数据第七列为时间组");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
- if (ObjectUtils.isEmpty(name)) {
- return CommonResult.fail("第" + (rowNum) + "条数据的名称不能为空");
- }
- String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
- if (ObjectUtils.isEmpty(xwNo)) {
- return CommonResult.fail(name + "的希沃编号不能为空");
- }
- String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
- if (ObjectUtils.isEmpty(bsNo)) {
- return CommonResult.fail(name + "的百胜编号不能为空");
- }
- String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
- if (ObjectUtils.isEmpty(cardNo)) {
- return CommonResult.fail(name + "的学号不能为空");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的班级不能为空");
- }
- String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
- if (ObjectUtils.isEmpty(group)) {
- return CommonResult.fail(name + "的时间组不能为空");
- }
- user.setCardNo(cardNo == null ? "" : cardNo);
- user.setName(name == null ? "" : name);
- user.setIdentityId(eIdentityStatu.Student.getValue());
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
- if (oClass != null && oClass.isPresent()) {
- user.setSchoolClass(oClass.get().getId());
- user.setGrade(String.valueOf(oClass.get().getGradeId()));
- } else {
- return CommonResult.fail(name + "的班级数据无效,导入失败");
- }
- Optional<SmartTimeGroup> oGroup = timeGroups.stream().filter(e -> e.getName().equals(group)).findFirst();
- if (oGroup != null && oGroup.isPresent()) {
- user.setTimeGroupId(oGroup.get().getId());
- }
- result.add(user);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- //endregion
- //endregion
- //region 时间组数据集合
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult timeGroups() throws Exception {
- List<TimeGroupVo> result = new ArrayList<>();
- //region 获取百胜的时间组
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "timegroup/searchtimegroup";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsTimeGroupVo bsDataResult = objectMapper.readValue(bsResult, BsTimeGroupVo.class);
- if (!bsResult.contains("查询成功")) {
- return CommonResult.fail(bsDataResult.getMsg());
- }
- // URL解码
- String decodedUrl = URLDecoder.decode(bsDataResult.getData(), "UTF-8");
- BsTimeGroupNoVo timeGroupNos = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsTimeGroupNoVo.class);
- //endregion
- List<SmartTimeGroup> groups = smartTimeGroupService.queryTimeGroups();
- List<SmartTimeGroup> newGroups = new ArrayList<>();
- List<SmartTimeGroup> oldGroups = new ArrayList<>();
- if (timeGroupNos.getData() != null) {
- for (BsTimeGroupNoListVo timeGroup : timeGroupNos.getData()) {
- Optional<SmartTimeGroup> oGroup = groups == null ? null : groups.stream().filter(e -> e.getBsno().equals(timeGroup.getTg_no())).findFirst();
- if (oGroup != null && oGroup.isPresent()) {
- SmartTimeGroup oldData = new SmartTimeGroup();
- oldData.setId(oGroup.get().getId());
- oldData.setBsno(timeGroup.getTg_no());
- oldData.setName(timeGroup.getTg_name());
- oldData.setRemark(timeGroup.getTg_remark());
- oldGroups.add(oldData);
- } else {
- SmartTimeGroup newData = new SmartTimeGroup();
- newData.setBsno(timeGroup.getTg_no());
- newData.setName(timeGroup.getTg_name());
- newData.setRemark(timeGroup.getTg_remark());
- newGroups.add(newData);
- }
- }
- }
- if (oldGroups != null && oldGroups.size() > 0) {
- boolean updateGroup = smartTimeGroupService.updateSmartTimeGroups(oldGroups);
- if (!updateGroup) {
- return CommonResult.fail("获取时间组失败");
- }
- }
- if (newGroups != null && newGroups.size() > 0) {
- boolean insertGroup = smartTimeGroupService.insertSmartTimeGroups(newGroups);
- if (!insertGroup) {
- return CommonResult.fail("获取时间组失败");
- }
- }
- //oldData集合不在newDatas集合中的内容
- List<Integer> newDatas = oldGroups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
- List<Integer> oldDatas = groups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
- List<Integer> deleteIds = oldDatas.stream().filter(item -> !newDatas.contains(item)).collect(Collectors.toList());//需要删除的id
- if (deleteIds.size() > 0) {
- int deleted = smartTimeGroupService.deletedTimeGroupByIds(deleteIds);
- if (deleted <= 0) {
- throw new Exception("获取时间组失败!");
- }
- }
- List<SmartTimeGroup> groupDatas = smartTimeGroupService.queryTimeGroups();
- for (SmartTimeGroup groupData : groupDatas) {
- TimeGroupVo data = new TimeGroupVo();
- data.setId(groupData.getId());
- data.setName(groupData.getName());
- data.setRemark(groupData.getRemark());
- result.add(data);
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 新增用户
- /**
- * 新增用户
- *
- * @param isur 用户数据
- * @param bindingResult
- * @return
- */
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult insertSmartUser(insertSmartUserRequest isur, BindingResult bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- int useBs = 1;
- int useXw = 1;
- SmartGrade gradeData = null;
- SmartClass classData = null;
- if (org.springframework.util.StringUtils.hasText(isur.getCardNo())) {
- //重复性判断
- int existCount = smartUserService.querySmartUserByCardNo(isur.getCardNo());
- if (existCount > 0) {
- return CommonResult.fail("当前学号已存在,请勿重复添加");
- }
- }
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- SmartUser su = new SmartUser();
- su.setTimeGroupId(isur.getTimeGroupId());
- su.setCardNo(isur.getCardNo());
- su.setName(isur.getName());
- su.setIdentityId(isur.getIdentityId());
- su.setIdCard(isur.getIdCard());
- su.setSexId(isur.getSexId());
- su.setDepartmentId(isur.getDepartmentId());
- su.setHeadImage(isur.getHeadImage());
- su.setGrade(isur.getGrade());
- su.setCollege(isur.getCollege());
- su.setSpeciality(isur.getSpeciality());
- su.setSchoolClass(isur.getSchoolClass());
- su.setCampus(isur.getCampus());
- su.setDormitoryNumber(isur.getDormitoryNumber());
- su.setPhone(isur.getPhone());
- su.setAffiliate(StringUtils.join(isur.getAffiliate(), ","));
- su.setTitle(isur.getTitle());
- su.setAddress(isur.getAddress());
- su.setNation(isur.getNation());
- su.setOfStudent(isur.getOfStudent());
- su.setGraduate(isur.getGraduate());
- su.setDuties(isur.getDuties());
- su.setIsCancel(eLogOff.Unlogout.getValue());
- //region 人员信息加入到第三方api
- //要将用户数据加入到希沃和百胜中
- //希沃和百胜的老师、学生数据添加是不一样的,所以按身份添加
- if (isur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
- //region 家长参数必填判断:手机号
- if (isur.getPhone() == null) {
- return CommonResult.fail("家长手机号不能为空");
- }
- //endregion
- //拿到被关联学生的信息去获取对应的卡号
- //有多个学生就循环学生
- if (isur.getAffiliate() == null) {
- return CommonResult.fail("被关联人不能为空");
- }
- if (isur.getAffiliate().size() <= 0) {
- return CommonResult.fail("被关联人不能为空");
- }
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(isur.getAffiliate());
- //region 希沃新增编辑学生家长信息
- if (useXw == 1) {
- CommonResult insertOrUpdateStudent = insertOrUpdateStudentParent(seewoClient, studentDatas, isur.getName(), isur.getPhone(), true);
- if (!insertOrUpdateStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertOrUpdateStudent.getMessage());
- }
- }
- //endregion
- } else if (isur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
- //region 学生参数必填判断:年级、班级
- if (isur.getGrade() == null) {
- return CommonResult.fail("学生年级不能为空");
- }
- if (isur.getSchoolClass() == null) {
- return CommonResult.fail("学生班级不能为空");
- }
- //endregion
- //获取班级Uid
- classData = smartClassService.getSmartClassById(isur.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,新增失败");
- }
- gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(isur.getGrade()));
- if (gradeData == null) {
- return CommonResult.fail("年级数据无效,新增失败");
- }
- //region 希沃新增学生信息
- if (useXw == 1) {
- CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getPhone(), classData.getClassUid());
- if (!insertStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
- }
- su.setXwStudentUid(insertStudent.getData());
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(su.getHeadImage());
- photo.setUserCode(su.getCardNo());
- photoList.add(photo);
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
- if (!result.isSuccess()) {
- return result;
- }
- }
- //endregion
- //region 百胜新增学生信息
- if (useBs == 1) {
- /**
- * 学生数据的有效期是到毕业年份的8月31日
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = queryGraduationYear(gradeData.getGradeNo());
- CommonResult<String> insertBsStudent = bsInsertStudent(isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getHeadImage(), isur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, isur.getIdCard());
- if (!insertBsStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
- }
- su.setBsStudentNo(insertBsStudent.getData());
- }
- //endregion
- } else if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//老师
- //region 老师参数必填判断:职称、手机号
- if (isur.getTitle() == null) {
- return CommonResult.fail("老师职称不能为空");
- }
- if (isur.getPhone() == null) {
- return CommonResult.fail("老师手机号不能为空");
- }
- //endregion
- //region 希沃添加教师数据
- if (useXw == 1) {
- CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, isur.getPhone(), isur.getName(), isur.getHeadImage());
- if (!insertTeacher.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
- }
- su.setXwTeacherCode(insertTeacher.getData());
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(su.getHeadImage());
- photo.setUserCode(su.getPhone());
- photoList.add(photo);
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
- if (!result.isSuccess()) {
- return result;
- }
- }
- //endregion
- if (isur.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- //获取班级Uid
- classData = smartClassService.getSmartClassById(isur.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,新增失败");
- }
- //region 将班主任推送到希沃
- if (useXw == 1) {
- CommonResult pushMaster = SeewoPushMaster(seewoClient, isur.getPhone(), classData.getClassUid());
- if (!pushMaster.isSuccess()) {
- return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
- }
- }
- //endregion
- }
- SmartDepartment departmentData = smartDepartmentService.getSmartById(isur.getDepartmentId());
- if (departmentData == null) {
- return CommonResult.fail("部门数据无效,新增教师失败");
- }
- String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
- if (departmentNo == null) {
- return CommonResult.fail("百胜部门编号为空,新增教师失败");
- }
- //region 百胜添加教师数据
- if (useBs == 1) {
- /**
- * 教师数据的有效期是20年
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = TimeExchange.addYear(20);
- CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
- if (!insertBsTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
- }
- su.setBsStaffCode(insertBsTeacher.getData());
- }
- //endregion
- }
- //endregion
- //最后都要把数据加入到数据库中
- if (org.springframework.util.StringUtils.hasText(isur.getPhone())) {
- //多身份
- List<SmartUser> users = smartUserService.getPhoneUsers(isur.getPhone());
- if (users != null && users.size() > 0) {
- Optional<SmartUser> ownerUser = users.stream().filter(e -> org.springframework.util.StringUtils.hasText(e.getXOpenId())).findFirst();
- if (ownerUser != null && ownerUser.isPresent()) {
- su.setXOpenId(ownerUser.get().getXOpenId());
- }
- }
- }
- int result = smartUserService.insertSmartUser(su);
- if (result > 0) {
- // 将添加的用户同步到海康平台
- Integer identityId = su.getIdentityId();
- if (2 == identityId || identityId == 3) {
- Integer id = su.getId();
- SmartOperationUser smartOperationUser = new SmartOperationUser();
- smartOperationUser.setOperationId(id);
- smartOperationUser.setOperationMode("1");
- smartOperationUser.setStatus(1);
- smartOperationUser.setType(identityId);
- smartOperationUserService.save(smartOperationUser);
- }
- if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue() && isur.getIsr() != null && isur.getIsr().size() > 0) {
- List<SmartTeaching> teachings = new ArrayList<>();
- for (isrRequest sv : isur.getIsr()) {
- if (sv.getIds() != null && sv.getIds().size() > 0) {
- SmartTeaching st = new SmartTeaching();
- st.setUserId(result);
- st.setSubjectId(sv.getIds().size() > 0 ? sv.getIds().get(0) : 0);
- st.setGradeId(sv.getIds().size() > 1 ? sv.getIds().get(1) : 0);
- st.setClassId(sv.getIds().size() > 2 ? sv.getIds().get(2) : 0);
- teachings.add(st);
- }
- }
- if (teachings != null && teachings.size() > 0) {
- boolean insertBatch = smartTeachingService.saveBatch(teachings);
- if (!insertBatch) {
- return CommonResult.fail("任课数据添加失败");
- }
- //region 添加教师综合素质评价
- List<Integer> ids = teachings.stream().map(SmartTeaching::getClassId).collect(Collectors.toList());
- List<SmartClass> classes = smartClassService.getSmartClasss(ids);
- List<Integer> subjectIds = teachings.stream().map(SmartTeaching::getSubjectId).collect(Collectors.toList());
- List<SmartSubject> subjects = smartSubjectService.getSmartSubjectId(subjectIds);
- List<Integer> gradeIds = teachings.stream().map(SmartTeaching::getGradeId).collect(Collectors.toList());
- List<SmartGrade> grades = smartGradeService.queryGradeByIds(gradeIds);
- List<SmartEvaluateTeacher> eTeachers = new ArrayList<>();
- LocalDateTime now = LocalDateTime.now();
- List<SmartSemester> semesters = smartSemesterService.getSemestersByTime(now);
- for (SmartSemester semester : semesters) {
- for (SmartTeaching teacher : teachings) {
- Optional<SmartClass> classTeacherData = classes != null && classes.size() > 0 ?
- classes.stream().filter(e -> e.getId().equals(teacher.getClassId())).findFirst() : null;
- Optional<SmartSubject> subjectData = subjects != null && subjects.size() > 0 ?
- subjects.stream().filter(e -> e.getId().equals(teacher.getSubjectId())).findFirst() : null;
- Optional<SmartGrade> ogradeData = grades != null && grades.size() > 0 ?
- grades.stream().filter(e -> e.getId().equals(teacher.getGradeId())).findFirst() : null;
- SmartEvaluateTeacher set = new SmartEvaluateTeacher();
- set.setCardNo(su.getCardNo());
- set.setName(su.getName());
- set.setUserId(su.getId());
- set.setGradeId(teacher.getGradeId());
- set.setGradeName(ogradeData != null && ogradeData.isPresent() ? ogradeData.get().getName() : "");
- set.setTermId(semester.getId());
- set.setTerm(semester.getName());
- set.setSubjectId(teacher.getSubjectId());
- set.setSubject(subjectData != null && subjectData.isPresent() ? subjectData.get().getName() : "");
- set.setClassId(su.getSchoolClass());
- set.setClassName(classTeacherData != null && classTeacherData.isPresent() ? classTeacherData.get().getName() : "");
- set.setTotalScore(0.0);
- set.setLowingScore(0.0);
- eTeachers.add(set);
- }
- }
- if (eTeachers != null && eTeachers.size() > 0) {
- boolean teacherBatch = smartEvaluateTeacherService.saveBatch(eTeachers);
- if (!teacherBatch) {
- throw new Exception("教师综合评价添加失败!");
- }
- }
- //endregion
- }
- }
- //新增用户得将用户信息通过接口推送到希沃、百胜
- }
- return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
- }
- //endregion
- //region 更新用户
- /**
- * 更新用户
- *
- * @param usur 更新用户数据
- * @param bindingResult
- * @return
- */
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult updateSmartUserById(updateSmartUserRequest usur, BindingResult bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- //region 参数判断
- if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
- if (usur.getTimeGroupId() == null) {
- return CommonResult.fail("学生时间组不能为空");
- }
- if (usur.getCardNo() == null) {
- return CommonResult.fail("学生编号不能为空");
- }
- if (usur.getHeadImage() == null) {
- return CommonResult.fail("学生人脸照片不能为空");
- }
- }
- //endregion
- int useXw = 1;
- int useBs = 1;
- //更新的同时将百胜用户信息同步过去或者同步过来?
- SmartUser su = smartUserService.getSmartById(usur.getId());
- if (su == null) {
- return CommonResult.fail("用户数据已失效,修改失败!");
- }
- //是否转换身份
- boolean changeIdentity = false;
- Integer oldIdentity = null;
- String oldAffiliate = su.getAffiliate();
- Integer oldSchoolClass = su.getSchoolClass();
- String oldStaffNo = su.getBsStaffCode();
- String oldCardNo = su.getCardNo();
- if (usur.getIdentityId().intValue() != su.getIdentityId().intValue()) {
- changeIdentity = true;
- oldIdentity = su.getIdentityId().intValue();
- }
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- su.setTimeGroupId(usur.getTimeGroupId());
- su.setCardNo(usur.getCardNo());
- su.setName(usur.getName());
- su.setIdentityId(usur.getIdentityId());
- su.setIdCard(usur.getIdCard());
- su.setSexId(usur.getSexId());
- su.setDepartmentId(usur.getDepartmentId());
- su.setHeadImage(usur.getHeadImage());
- su.setGrade(usur.getGrade());
- su.setCollege(usur.getCollege());
- su.setSpeciality(usur.getSpeciality());
- su.setSchoolClass(usur.getSchoolClass());
- su.setCampus(usur.getCampus());
- su.setDormitoryNumber(usur.getDormitoryNumber());
- su.setPhone(usur.getPhone());
- su.setAffiliate(StringUtils.join(usur.getAffiliate(), ","));
- su.setTitle(usur.getTitle());
- su.setAddress(usur.getAddress());
- su.setNation(usur.getNation());
- su.setOfStudent(usur.getOfStudent());
- su.setGraduate(usur.getGraduate());
- su.setDuties(usur.getDuties());
- su.setIsCancel(eLogOff.Unlogout.getValue());
- if (usur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
- //拿到被关联学生的信息去获取对应的卡号
- //有多个学生就循环学生
- if (usur.getAffiliate() == null) {
- return CommonResult.fail("被关联人不能为空");
- }
- if (usur.getAffiliate().size() <= 0) {
- return CommonResult.fail("被关联人不能为空");
- }
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(usur.getAffiliate());
- if (!changeIdentity) {
- //region 希沃新增编辑学生家长信息
- if (useXw == 1) {
- //学生与家长列表,最大100条
- CommonResult insertOrUpdateResult = insertOrUpdateStudentParent(seewoClient, studentDatas, usur.getName(), usur.getPhone(), false);
- if (!insertOrUpdateResult.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertOrUpdateResult.getMessage());
- }
- }
- //endregion
- } else {
- if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
- //region 希沃删除学生
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
- if (classData == null) {
- return CommonResult.fail("班级数据无效,更新失败");
- }
- if (useXw == 1) {
- CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
- if (!deleteStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
- }
- }
- //endregion
- //region 百胜删除学生
- if (useBs == 1) {
- CommonResult deleteBsStudent = bsDeleteStudent(su);
- if (!deleteBsStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
- }
- }
- //endregion
- } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
- if (classData == null) {
- return CommonResult.fail("班级数据无效,更新失败");
- }
- //region 希沃删除教师
- if (useXw == 1) {
- CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
- if (!deleteTeacher.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
- }
- }
- //endregion
- //region 希沃删除班主任
- if (useXw == 1) {
- CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
- if (deleteTeacherMaster.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
- }
- }
- //endregion
- //region 百胜删除教师
- if (useBs == 1) {
- CommonResult bsDeleteTeacher = bsDeleteTeacher(oldStaffNo);
- if (!bsDeleteTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + bsDeleteTeacher.getMessage());
- }
- }
- //endregion
- }
- //region 希沃新增编辑学生家长信息
- if (useXw == 1) {
- List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(su.getCardNo());
- if (indexs != null && indexs.size() >= 4) {
- return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
- }
- CommonResult insertOrUpdate = insertOrUpdateStudentParent(seewoClient, studentDatas, su.getName(), su.getPhone(), true);
- if (!insertOrUpdate.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertOrUpdate.getMessage());
- }
- }
- //endregion
- }
- } else if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
- //region 年级和班级不能为空
- if (usur.getGrade() == null) {
- return CommonResult.fail("学生年级不能为空");
- }
- if (usur.getSchoolClass() == null) {
- return CommonResult.fail("学生班级不能为空");
- }
- //endregion
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,更新失败");
- }
- //获取年级Uid
- SmartGrade gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(su.getGrade()));
- if (gradeData == null) {
- return CommonResult.fail("年级数据无效,新增失败");
- }
- if (!changeIdentity) {
- //region 更新希沃学生信息
- if (useXw == 1) {
- CommonResult updateStudent = SeewoUpdateStudent(seewoClient, su);
- if (!updateStudent.isSuccess()) {
- if (updateStudent.getMessage().equals("学生不存在")) {
- CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
- if (!insertStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
- }
- }
- }
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(su.getHeadImage());
- photo.setUserCode(su.getCardNo());
- photoList.add(photo);
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
- if (!result.isSuccess()) {
- return result;
- }
- }
- //endregion
- //region 更新百胜学生信息
- if (useBs == 1) {
- /**
- * 学生数据的有效期是到毕业年份的8月31日
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = queryGraduationYear(gradeData.getGradeNo());
- CommonResult updateBsStudent = bsUpdateStudent(su, startTime, endTime);
- if (!updateBsStudent.isSuccess()) {
- if (updateBsStudent.getMessage().equals("人员不存在或已删除")) {
- //region 百胜新增学生信息
- CommonResult<String> insertBsStudent = bsInsertStudent(usur.getName(), usur.getCardNo(), usur.getSexId(), usur.getHeadImage(), usur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, usur.getIdCard());
- if (!insertBsStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
- }
- su.setBsStudentNo(insertBsStudent.getData());
- //endregion
- } else {
- return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
- }
- }
- }
- //endregion
- } else {
- if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
- //region 希沃删除原有的家长关系
- if (useXw == 1) {
- CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
- if (!deleteResult.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteResult.getMessage());
- }
- smartFamilyIndexService.deleteSmartFamilyByPhone(su.getPhone());
- }
- //endregion
- } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
- //获取班级Uid
- SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
- if (oldClassData == null) {
- return CommonResult.fail("班级数据无效,更新失败");
- }
- //region 希沃删除教师
- if (useXw == 1) {
- CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
- if (!deleteTeacher.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
- }
- }
- //endregion
- //region 希沃删除班主任
- if (useXw == 1) {
- CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
- if (!deleteMaster.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteMaster.getMessage());
- }
- }
- //endregion
- //region 百胜删除教师
- if (useBs == 1) {
- CommonResult deleteBsTeacher = bsDeleteTeacher(oldStaffNo);
- if (!deleteBsTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + deleteBsTeacher.getMessage());
- }
- }
- //endregion
- }
- //region 希沃新增学生信息
- if (useXw == 1) {
- CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
- if (!insertStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
- } else {
- su.setXwStudentUid(insertStudent.getData());
- }
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(su.getHeadImage());
- photo.setUserCode(su.getCardNo());
- photoList.add(photo);
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
- if (!result.isSuccess()) {
- return result;
- }
- }
- //endregion
- //region 百胜新增学生信息
- if (useBs == 1) {
- /**
- * 学生数据的有效期是到毕业年份的8月31日
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = queryGraduationYear(gradeData.getGradeNo());
- CommonResult<String> insertBsStudent = bsInsertStudent(su.getName(), su.getCardNo(), su.getSexId(), su.getHeadImage(), su.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, su.getIdCard());
- if (insertBsStudent.isSuccess()) {
- su.setBsStudentNo(insertBsStudent.getData());
- } else {
- //region 希沃删除学生
- //百胜数据插入失败后需要把已插入到希沃的数据删除
- CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
- if (!deleteStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + deleteStudent.getMessage());
- }
- //endregion
- return CommonResult.fail("切换身份后," + insertBsStudent.getMessage() + ",百胜无法插入学生数据");
- }
- }
- //endregion
- }
- } else if (usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//教师
- if (!changeIdentity) {
- //region 希沃更新教师数据
- if (useXw == 1) {
- CommonResult<String> updateTeacher = SeewoUpdateTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
- if (!updateTeacher.isSuccess()) {
- return CommonResult.fail("希沃平台:" + updateTeacher.getMessage());
- }
- su.setXwTeacherCode(updateTeacher.getData());
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(su.getHeadImage());
- photo.setUserCode(su.getPhone());
- photoList.add(photo);
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
- if (!result.isSuccess()) {
- return result;
- }
- }
- if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,新增失败");
- }
- //region 将班主任推送到希沃
- if (useXw == 1) {
- CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
- if (!pushMaster.isSuccess()) {
- return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
- }
- }
- //endregion
- }
- //endregion
- SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
- if (departmentData == null) {
- return CommonResult.fail("部门数据无效,更新教师失败");
- }
- String departmentNo = departmentData.getBsDepartmentNo();
- if (departmentNo == null) {
- return CommonResult.fail("百胜部门编号为空,新增教师失败");
- }
- //region 百胜更新教师数据
- if (useBs == 1) {
- /**
- * 教师数据的有效期是20年
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = TimeExchange.addYear(20);
- CommonResult<String> bsUpdateTeacher = updateBsTeacher(su, departmentNo, startTime, endTime);
- if (!bsUpdateTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + bsUpdateTeacher.getMessage());
- }
- su.setBsStaffCode(bsUpdateTeacher.getData());
- }
- //endregion
- } else {
- if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
- //region 希沃删除原有的家长关系
- if (useXw == 1) {
- CommonResult deleteOldShip = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
- if (!deleteOldShip.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteOldShip.getMessage());
- }
- smartFamilyIndexService.deleteSmartFamilyByPhone(su.getPhone());
- }
- //endregion
- } else if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
- if (classData == null) {
- return CommonResult.fail("班级数据无效,更新失败");
- }
- //region 希沃删除学生
- if (useXw == 1) {
- CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
- if (!deleteStudent.isSuccess()) {
- return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
- }
- }
- //endregion
- //region 百胜删除学生
- if (useBs == 1) {
- CommonResult deleteBsStudent = bsDeleteStudent(su);
- if (!deleteBsStudent.isSuccess()) {
- return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
- }
- }
- //endregion
- }
- //region 希沃添加教师数据
- if (useXw == 1) {
- CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
- if (!insertTeacher.isSuccess()) {
- return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
- }
- su.setXwTeacherCode(insertTeacher.getData());
- //上传图片
- List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
- PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
- photo.setPhotoUrl(su.getHeadImage());
- photo.setUserCode(su.getPhone());
- photoList.add(photo);
- CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
- if (!result.isSuccess()) {
- return result;
- }
- }
- //endregion
- if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,新增失败");
- }
- //region 将班主任推送到希沃
- if (useXw == 1) {
- CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
- if (!pushMaster.isSuccess()) {
- return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
- }
- }
- //endregion
- }
- SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
- if (departmentData == null) {
- return CommonResult.fail("部门数据无效,新增教师失败");
- }
- String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
- if (departmentNo == null) {
- return CommonResult.fail("百胜部门编号为空,新增教师失败");
- }
- //region 百胜添加教师数据
- if (useBs == 1) {
- /**
- * 教师数据的有效期是20年
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = TimeExchange.addYear(20);
- CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
- if (!insertBsTeacher.isSuccess()) {
- return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
- }
- su.setBsStaffCode(insertBsTeacher.getData());
- }
- //endregion
- }
- }
- int result = smartUserService.updateSmartUser(su);
- // 修改需同步到海康平台
- if (result > 0) {
- Integer identityId = su.getIdentityId();
- if (2 == identityId || identityId == 3) {
- Integer id = su.getId();
- SmartOperationUser smartOperationUser = new SmartOperationUser();
- smartOperationUser.setOperationId(id);
- smartOperationUser.setOperationMode("2");
- smartOperationUser.setStatus(1);
- smartOperationUser.setType(identityId);
- smartOperationUserService.save(smartOperationUser);
- }
- }
- //region 任课数据
- if (result > 0 && usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
- //查找原有的任课数据
- List<SmartTeaching> oldTeachings = smartTeachingService.queryTeachingByUserId(su.getId());
- smartTeachingService.deleteByUserId(su.getId());//删除任课
- List<SmartTeaching> newTeachings = new ArrayList<>();
- List<SmartTeaching> newEteachings = new ArrayList<>();
- if (usur.getUsr() != null && usur.getUsr().size() > 0) {
- for (isrRequest sv : usur.getUsr()) {
- if (sv.getIds() != null && sv.getIds().size() > 0) {
- SmartTeaching st = new SmartTeaching();
- st.setUserId(su.getId());
- st.setSubjectId(sv.getIds().size() > 0 ? sv.getIds().get(0) : 0);
- st.setGradeId(sv.getIds().size() > 1 ? sv.getIds().get(1) : 0);
- st.setClassId(sv.getIds().size() > 2 ? sv.getIds().get(2) : 0);
- long existCount = oldTeachings.stream().filter(e -> e.getUserId().equals(st.getUserId()) && e.getSubjectId().equals(st.getSubjectId())
- && e.getGradeId().equals(st.getGradeId()) && e.getClassId().equals(st.getClassId())).count();
- if (existCount <= 0) {
- newEteachings.add(st);
- }
- newTeachings.add(st);
- }
- }
- if (newEteachings != null && newEteachings.size() > 0) {
- //region 添加教师综合素质评价
- List<Integer> ids = newEteachings.stream().map(SmartTeaching::getClassId).collect(Collectors.toList());
- List<SmartClass> classes = smartClassService.getSmartClasss(ids);
- List<Integer> subjectIds = newEteachings.stream().map(SmartTeaching::getSubjectId).collect(Collectors.toList());
- List<SmartSubject> subjects = smartSubjectService.getSmartSubjectId(subjectIds);
- List<Integer> gradeIds = newEteachings.stream().map(SmartTeaching::getGradeId).collect(Collectors.toList());
- List<SmartGrade> grades = smartGradeService.queryGradeByIds(gradeIds);
- List<SmartEvaluateTeacher> eTeachers = new ArrayList<>();
- LocalDateTime now = LocalDateTime.now();
- List<SmartSemester> semesters = smartSemesterService.getSemestersByTime(now);
- for (SmartSemester semester : semesters) {
- for (SmartTeaching teacher : newEteachings) {
- Optional<SmartClass> classTeacherData = classes != null && classes.size() > 0 ?
- classes.stream().filter(e -> e.getId().equals(teacher.getClassId())).findFirst() : null;
- Optional<SmartSubject> subjectData = subjects != null && subjects.size() > 0 ?
- subjects.stream().filter(e -> e.getId().equals(teacher.getSubjectId())).findFirst() : null;
- Optional<SmartGrade> gradeData = grades != null && grades.size() > 0 ?
- grades.stream().filter(e -> e.getId().equals(teacher.getGradeId())).findFirst() : null;
- SmartEvaluateTeacher set = new SmartEvaluateTeacher();
- set.setCardNo(su.getCardNo());
- set.setName(su.getName());
- set.setUserId(su.getId());
- set.setGradeId(teacher.getGradeId());
- set.setGradeName(gradeData != null && gradeData.isPresent() ? gradeData.get().getName() : "");
- set.setTermId(semester.getId());
- set.setTerm(semester.getName());
- set.setSubjectId(teacher.getSubjectId());
- set.setSubject(subjectData != null && subjectData.isPresent() ? subjectData.get().getName() : "");
- set.setClassId(teacher.getClassId());
- set.setClassName(classTeacherData != null && classTeacherData.isPresent() ? classTeacherData.get().getName() : "");
- set.setTotalScore(0.0);
- set.setLowingScore(0.0);
- eTeachers.add(set);
- }
- }
- if (eTeachers != null && eTeachers.size() > 0) {
- List<SmartEvaluateTeacher> insertEts = new ArrayList<>();
- //已存在在老师综合评价里的就不再加进去了
- List<SmartEvaluateTeacher> teachers = smartEvaluateTeacherService.queryEvaluateTeachersByUserId(su.getId());
- for (SmartEvaluateTeacher et:eTeachers) {
- long existCount = teachers.stream().filter(e -> e.getUserId().equals(et.getUserId()) && e.getTermId().equals(et.getTermId())
- && e.getGradeId().equals(et.getGradeId()) && e.getSubjectId().equals(et.getSubjectId()) && e.getClassId().equals(et.getClassId())).count();
- if(existCount <= 0){
- insertEts.add(et);
- }
- }
- if(insertEts != null && insertEts.size() > 0){
- boolean teacherBatch = smartEvaluateTeacherService.saveBatch(insertEts);
- if (!teacherBatch) {
- throw new Exception("教师综合评价添加失败!");
- }
- }
- }
- //endregion
- }
- }
- if (newTeachings != null && newTeachings.size() > 0) {
- boolean insertBatch = smartTeachingService.saveBatch(newTeachings);
- if (!insertBatch) {
- return CommonResult.fail("任课数据添加失败");
- }
- }
- }
- //endregion
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- //endregion
- //region 希沃增删改查方法
- //region 希沃批量上传头像
- /**
- * 希沃批量上传头像 如果当前用户已存在图片 会进行覆盖
- *
- * @param seewoClient 链接配置
- * @param photoList 头像集合
- * @param userType 用户类型
- * @return
- * @throws JsonProcessingException
- */
- public CommonResult SeewoInsertBatchPhoto(SeewoClient
- seewoClient, List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList, Integer userType) throws
- JsonProcessingException {
- //region 希沃上传第三方图片信息
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- PhotoServiceSavePhotosParam param = new PhotoServiceSavePhotosParam();
- //请求体,MimeType为 application/json
- PhotoServiceSavePhotosParam.JSONRequestBody requestBody = PhotoServiceSavePhotosParam.JSONRequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //
- PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery query = PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery.builder()
- .appId(seewoConfig.getAppId())
- .unitUid(seewoConfig.getSchoolId())
- .userType(userType)
- .build();
- requestBody.setQuery(query);
- // 图片保存列表
- query.setPhotoList(photoList);
- PhotoServiceSavePhotosRequest request = new PhotoServiceSavePhotosRequest(param);
- // 该接口需要数据权限,请将授权资源id替换至下方,请妥善保管好授权资源id,避免泄露
- // permissionId位置: 控制台 -> 应用详情 -> 我申请的 -> 已通过的接口 -> 调用范围 -> 审批信息 中查看授权资源的「学校id」或「区域id」
- //request.setPermissionId(seewoConfig.getSchoolId());
- logger.info("入参:" + request);
- logger.info("入参:" + JSON.toJSON(request));
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- PhotoServiceSavePhotosResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- ObjectMapper objectMapper = new ObjectMapper();
- XwBodyVo xwResult = objectMapper.readValue(result.getBody(), XwBodyVo.class);
- if (!xwResult.getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getMessage());
- }
- //endregion
- return CommonResult.ok("200", "图片添加成功");
- }
- //endregion
- //region 希沃批量新增学生信息
- public CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> SeewoInsertBatchStudent
- (SeewoClient seewoClient, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo> students, String
- classUid) {
- //region 希沃新增学生信息
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
- //请求体,MimeType为 application/json
- StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //查询条件
- StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .classUid(classUid)
- .build();
- requestBody.setQuery(query);
- // 学生列表
- query.setStudents(students);
- query.setInPlaceOld(false);// 是否删除旧学生再保存
- param.setRequestBody(requestBody);
- StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃学生数据新增失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- return CommonResult.ok("200", "添加成功", result.getResponseBody().getData());
- //endregion
- }
- //endregion
- //region 希沃新增学生信息
- public CommonResult<String> SeewoInsertStudent(SeewoClient seewoClient, String name, String cardNo, Integer
- sexId, String Phone, String classUid) {
- //region 希沃新增学生信息
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
- //请求体,MimeType为 application/json
- StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //查询条件
- StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .classUid(classUid)
- .build();
- requestBody.setQuery(query);
- // 学生列表
- StudentServiceBatchSaveClassStudentsParam.StudentInfo students = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
- .studentName(name)
- .studentCode(cardNo)
- .gender(sexId)
- .phone(Phone == null ? "" : Phone)
- .build();
- query.setStudents(java.util.Collections.singletonList(students));
- query.setInPlaceOld(false);// 是否删除旧学生再保存
- param.setRequestBody(requestBody);
- StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃学生数据新增失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- return CommonResult.ok("200", "添加成功", result.getResponseBody().getData().get(0).getUserUid());
- //endregion
- }
- //endregion
- //region 希沃更新学生信息
- public CommonResult SeewoUpdateStudent(SeewoClient seewoClient, SmartUser su) {
- //region 更新希沃学生信息
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- StudentServiceUpdateStudentInfoParam param = new StudentServiceUpdateStudentInfoParam();
- //响应体,MimeType为 application/json
- StudentServiceUpdateStudentInfoParam.RequestBody requestBody = StudentServiceUpdateStudentInfoParam.RequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //query
- StudentServiceUpdateStudentInfoParam.Query query = StudentServiceUpdateStudentInfoParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .studentUid(su.getXwStudentUid())
- .studentCode(su.getCardNo())
- .studentName(su.getName())
- .build();
- requestBody.setQuery(query);
- param.setRequestBody(requestBody);
- StudentServiceUpdateStudentInfoRequest request = new StudentServiceUpdateStudentInfoRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- StudentServiceUpdateStudentInfoResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃学生数据更新失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- return CommonResult.ok("更新成功");
- //endregion
- }
- //endregion
- //region 希沃删除学生
- public CommonResult SeewoDeleteStudent(SeewoClient seewoClient, String ClassUid, String CardNo) {
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- StudentServiceRemoveClassStudentsParam deleteParam = new StudentServiceRemoveClassStudentsParam();
- //请求体,MimeType为 application/json
- StudentServiceRemoveClassStudentsParam.JSONRequestBody deleteRequestBody = StudentServiceRemoveClassStudentsParam.JSONRequestBody.builder()
- .build();
- deleteParam.setRequestBody(deleteRequestBody);
- //查询条件
- StudentServiceRemoveClassStudentsParam.UnbindStudentQuery deleteQuery = StudentServiceRemoveClassStudentsParam.UnbindStudentQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .classUid(ClassUid)
- .studentCodes(java.util.Collections.singletonList(CardNo))
- .build();
- deleteRequestBody.setQuery(deleteQuery);
- deleteParam.setRequestBody(deleteRequestBody);
- StudentServiceRemoveClassStudentsRequest deleteRequest = new StudentServiceRemoveClassStudentsRequest(deleteParam);
- logger.info("入参:" + deleteRequest);
- //如果想要调用沙箱环境,请通过设置 deleteRequest 对象的 serverUrl 属性,如:
- //deleteRequest.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- StudentServiceRemoveClassStudentsResult deleteResult = seewoClient.invoke(deleteRequest);
- logger.info("出参:" + deleteResult);
- if (deleteResult == null) {
- return CommonResult.fail("希沃删除学生数据失败!");
- }
- if (!deleteResult.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + deleteResult.getResponseBody().getMessage());
- }
- return CommonResult.ok("删除成功");
- }
- //endregion
- //region 希沃添加老师数据
- //老师数据会根据手机号判断新增不新增
- //手机号相同的情况下更新不新增
- public CommonResult<String> SeewoInsertTeacher(SeewoClient seewoClient, String phone, String name, String
- headImage) {
- //region 希沃添加教师数据
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
- //请求体,MimeType为 application/json
- TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //老师信息
- TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .build();
- requestBody.setQuery(query);
- // 老师列表
- TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
- .account(phone)//用户账号
- .name(name)//用户名字
- .accountType("phone")//账号类型 phone:手机号 email:邮箱
- .teacherCode(phone)//教师工号
- .photoUrl(headImage)//图片链接
- .build();
- query.setTeachers(java.util.Collections.singletonList(teachers));
- param.setRequestBody(requestBody);
- TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃教师数据新增失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- String teacherCode = phone;
- if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
- teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
- }
- return CommonResult.ok("200", "操作成功", teacherCode);
- //endregion
- }
- //endregion
- //region 希沃批量添加老师数据
- //老师数据会根据手机号判断新增不新增
- //手机号相同的情况下更新不新增
- public CommonResult<List<TeacherServiceBatchSaveOrUpdateTeacherResult.TeacherBaseInfoDto>> SeewoInsertBatchTeacher
- (SeewoClient seewoClient, List<TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery> teachers) {
- //region 希沃添加教师数据
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
- //请求体,MimeType为 application/json
- TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //老师信息
- TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .build();
- requestBody.setQuery(query);
- query.setTeachers(teachers);
- param.setRequestBody(requestBody);
- TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃教师数据新增失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
- return CommonResult.ok("200", "操作成功", result.getResponseBody().getData());
- }
- return CommonResult.ok("200", "操作成功", null);
- //endregion
- }
- //endregion
- //region 希沃更新教师
- public CommonResult<String> SeewoUpdateTeacher(SeewoClient seewoClient, String phone, String name, String
- headImage) {
- //region 希沃更新教师数据
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
- //请求体,MimeType为 application/json
- TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //老师信息
- TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .build();
- requestBody.setQuery(query);
- // 老师列表
- TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
- .account(phone)//用户账号
- .name(name)//用户名字
- .accountType("phone")//账号类型 phone:手机号 email:邮箱
- .teacherCode(phone)//教师工号
- .photoUrl(headImage)//图片链接
- .build();
- query.setTeachers(java.util.Collections.singletonList(teachers));
- param.setRequestBody(requestBody);
- TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃教师数据更新失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- String teacherCode = phone;
- if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
- teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
- }
- return CommonResult.ok("200", "操作成功", teacherCode);
- //endregion
- }
- //endregion
- //region 希沃删除教师
- public CommonResult SeewoDeleteTeacher(SeewoClient seewoClient, String phone) {
- //region 希沃删除教师
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- TeacherServiceBatchRemoveTeachersParam param = new TeacherServiceBatchRemoveTeachersParam();
- //响应体,MimeType为 application/json
- TeacherServiceBatchRemoveTeachersParam.RequestBody requestBody = TeacherServiceBatchRemoveTeachersParam.RequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //query
- TeacherServiceBatchRemoveTeachersParam.Query query = TeacherServiceBatchRemoveTeachersParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .phones(java.util.Collections.singletonList(phone))
- .build();
- requestBody.setQuery(query);
- param.setRequestBody(requestBody);
- TeacherServiceBatchRemoveTeachersRequest request = new TeacherServiceBatchRemoveTeachersRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- TeacherServiceBatchRemoveTeachersResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃教师数据删除失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- return CommonResult.ok("删除成功");
- //endregion
- }
- //endregion
- //region 希沃删除班主任
- public CommonResult SeewoDeleteTeacherMaster(SeewoClient seewoClient, String classUid, String phone) {
- //region 希沃删除班主任
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- TeacherServiceBatchRemoveClassMastersParam mastersParam = new TeacherServiceBatchRemoveClassMastersParam();
- //响应体,MimeType为 application/json
- TeacherServiceBatchRemoveClassMastersParam.RequestBody mastersRequestBody = TeacherServiceBatchRemoveClassMastersParam.RequestBody.builder()
- .build();
- mastersParam.setRequestBody(mastersRequestBody);
- //query
- TeacherServiceBatchRemoveClassMastersParam.Query mastersQuery = TeacherServiceBatchRemoveClassMastersParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .classUid(classUid)
- .userPhones(java.util.Collections.singletonList(phone))
- .build();
- mastersRequestBody.setQuery(mastersQuery);
- mastersParam.setRequestBody(mastersRequestBody);
- TeacherServiceBatchRemoveClassMastersRequest mastersRequest = new TeacherServiceBatchRemoveClassMastersRequest(mastersParam);
- logger.info("入参:" + mastersRequest);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- TeacherServiceBatchRemoveClassMastersResult masterResult = seewoClient.invoke(mastersRequest);
- logger.info("出参:" + masterResult);
- if (masterResult == null) {
- return CommonResult.fail("希沃教师数据删除失败!");
- }
- if (!masterResult.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + masterResult.getResponseBody().getMessage());
- }
- return CommonResult.ok("删除成功");
- //endregion
- }
- //endregion
- //region 希沃推送班主任
- public CommonResult SeewoPushMaster(SeewoClient seewoClient, String phone, String classUid) {
- //region 将班主任推送到希沃
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- TeacherServiceBatchSetClassMastersParam teacherClassParam = new TeacherServiceBatchSetClassMastersParam();
- //响应体,MimeType为 application/json
- TeacherServiceBatchSetClassMastersParam.RequestBody teacherClassRequestBody = TeacherServiceBatchSetClassMastersParam.RequestBody.builder()
- .build();
- teacherClassParam.setRequestBody(teacherClassRequestBody);
- //query
- List<String> teacherPhones = new ArrayList<>();
- teacherPhones.add(phone);
- TeacherServiceBatchSetClassMastersParam.Query teacherClassQuery = TeacherServiceBatchSetClassMastersParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .classUid(classUid)
- .userPhones(teacherPhones)
- .build();
- teacherClassRequestBody.setQuery(teacherClassQuery);
- teacherClassParam.setRequestBody(teacherClassRequestBody);
- TeacherServiceBatchSetClassMastersRequest teacherClassRequest = new TeacherServiceBatchSetClassMastersRequest(teacherClassParam);
- logger.info("入参:" + teacherClassRequest);
- //如果想要调用沙箱环境,请通过设置 teacherClassRequest 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- TeacherServiceBatchSetClassMastersResult teacherClassResult = seewoClient.invoke(teacherClassRequest);
- logger.info("出参:" + teacherClassResult);
- if (teacherClassResult == null) {
- return CommonResult.fail("希沃教师数据新增失败!");
- }
- if (!teacherClassResult.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + teacherClassResult.getResponseBody().getMessage());
- }
- return CommonResult.ok("添加成功");
- //endregion
- }
- //endregion
- //region 希沃新增编辑学生家长信息
- public CommonResult insertOrUpdateStudentParent(SeewoClient
- seewoClient, List<SmartUser> studentDatas, String name, String phone, boolean isInsert) {
- //region 希沃新增编辑学生家长信息
- //学生与家长列表,最大100条
- List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
- List<SmartFamilyIndex> insertIndexs = new ArrayList<>();
- for (SmartUser student : studentDatas) {
- int index = 0;
- if (isInsert) {
- List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(student.getCardNo());
- if (indexs != null && indexs.size() >= 4) {
- return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
- }
- if (indexs != null) {
- for (SmartFamilyIndex data : indexs) {
- if (data.getIndexData().intValue() == index && index < 3) {
- index++;
- continue;
- } else {
- break;
- }
- }
- }
- SmartFamilyIndex insertFamily = new SmartFamilyIndex();
- insertFamily.setParentPhone(phone);
- insertFamily.setStudentNo(student.getCardNo());
- insertFamily.setIndexData(index);
- insertIndexs.add(insertFamily);
- } else {
- SmartFamilyIndex familyIndex = smartFamilyIndexService.queryFamilyByPhoneCardNo(phone, student.getCardNo());
- if (familyIndex == null) {
- List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(student.getCardNo());
- if (indexs != null && indexs.size() >= 4) {
- return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
- }
- if (indexs != null) {
- for (SmartFamilyIndex data : indexs) {
- if (data.getIndexData().intValue() == index && index < 3) {
- index++;
- continue;
- } else {
- break;
- }
- }
- }
- SmartFamilyIndex insertFamily = new SmartFamilyIndex();
- insertFamily.setParentPhone(phone);
- insertFamily.setStudentNo(student.getCardNo());
- insertFamily.setIndexData(index);
- insertIndexs.add(insertFamily);
- } else {
- familyIndex.setStudentNo(student.getCardNo());
- familyIndex.setParentPhone(phone);
- index = familyIndex.getIndexData();
- int updateFamily = smartFamilyIndexService.updateSmartFamily(familyIndex);
- if (updateFamily <= 0) {
- return CommonResult.fail("绑定失败");
- }
- }
- }
- ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
- .studentCode(student.getCardNo())
- .build();
- studentParents.add(students);
- //家长列表,最多4个
- ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
- .name(name)
- .phone(phone)
- .index(index)
- .build();
- students.setParents(java.util.Collections.singletonList(parents));
- }
- if (insertIndexs != null && insertIndexs.size() > 0) {
- smartFamilyIndexService.saveBatch(insertIndexs);
- }
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
- //响应体,MimeType为 application/json
- ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //query
- ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .build();
- requestBody.setQuery(query);
- query.setStudentParents(studentParents);
- param.setRequestBody(requestBody);
- ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃学生家长数据更新失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
- }
- return CommonResult.ok("新增成功");
- //endregion
- }
- //endregion
- //region 希沃删除学生原有的家长关系
- public CommonResult deleteOldStudentParentShip(SeewoClient seewoClient, String cardNo, List<String> phones) throws
- JsonProcessingException {
- //region 删除原有的家长关系
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
- //请求体,MimeType为 application/json
- ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
- .build();
- deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
- //
- ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- //.studentCodes(java.util.Collections.singletonList(cardNo))//传卡号会把该学生的家长都删掉
- .parentPhones(phones)
- .build();
- deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
- deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
- ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
- logger.info("入参:" + deleteOldFamilyRequest);
- //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
- //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
- logger.info("出参:" + deleteOldFamilyResult);
- if (deleteOldFamilyResult == null) {
- return CommonResult.fail("希沃家长数据删除失败!");
- }
- if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
- ObjectMapper objectMapper = new ObjectMapper();
- XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
- if (!result.getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getMessage());
- }
- } else {
- if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + deleteOldFamilyResult.getResponseBody().getResult().getMessage());
- }
- }
- return CommonResult.ok("删除成功");
- //endregion
- }
- //endregion
- //region 希沃删除原有的家长关系
- public CommonResult deleteOldParentShip(SeewoClient seewoClient, List<SmartUser> studentDatas, String phone) throws
- JsonProcessingException {
- //region 删除原有的家长关系
- //初始化客户端
- //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
- //请求体,MimeType为 application/json
- ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
- .build();
- deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
- //
- ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- //.studentCodes(studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList()))//不能传卡号 传了卡号会把该学生的家长都删掉
- .parentPhones(java.util.Collections.singletonList(phone))
- .build();
- deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
- deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
- ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
- logger.info("入参:" + deleteOldFamilyRequest);
- logger.info("入参:" + JSON.toJSON(deleteOldFamilyRequest));
- //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
- //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
- logger.info("出参:" + deleteOldFamilyResult);
- if (deleteOldFamilyResult == null) {
- return CommonResult.fail("希沃家长数据删除失败!");
- }
- if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
- ObjectMapper objectMapper = new ObjectMapper();
- XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
- if (!result.getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + result.getMessage());
- }
- } else {
- if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
- return CommonResult.fail("希沃平台:" + deleteOldFamilyResult.getResponseBody().getResult().getMessage());
- }
- }
- return CommonResult.ok("删除成功");
- //endregion
- }
- //endregion
- //endregion
- //region 百胜增删改查方法
- //region 百胜更新学生信息 给批量导入用的
- public CommonResult bsEUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws
- Exception {
- //region 更新百胜学生信息
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "student/update";
- String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
- String bsGroupNo = eGroupTime(su.getTimeGroupId());
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\",\"student_name\":\"" + su.getName() + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + su.getCardNo() + "\",\"student_sex\":\"" + su.getSexId() + idCardStr + "\",\"student_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\",\"student_name\":\"" + su.getName() + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + su.getCardNo() + "\",\"student_sex\":\"" + su.getSexId() + idCardStr + "\",\"student_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPosts(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
- if (!bsResult.contains("更新成功")) {
- return CommonResult.fail("百胜平台:" + result.getMsg());
- }
- return CommonResult.ok("更新成功");
- //endregion
- }
- //endregion
- //region 百胜更新学生信息 给设置时间组接口用的
- public CommonResult bsTUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws
- Exception {
- //region 更新百胜学生信息
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "student/update";
- String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
- String bsGroupNo = eGroupTime(su.getTimeGroupId());
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\",\"student_name\":\"" + su.getName() + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + su.getCardNo() + "\",\"student_sex\":\"" + su.getSexId() + idCardStr + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\",\"student_name\":\"" + su.getName() + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + su.getCardNo() + "\",\"student_sex\":\"" + su.getSexId() + idCardStr + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPosts(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
- if (!bsResult.contains("更新成功")) {
- return CommonResult.fail("百胜平台:" + result.getMsg());
- }
- return CommonResult.ok("更新成功");
- //endregion
- }
- //endregion
- //region 百胜更新学生信息
- public CommonResult bsUpdateStudent(SmartUser su, String startDate, String endDate) throws Exception {
- //region 更新百胜学生信息
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "student/update";
- String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
- String bsGroupNo = eGroupTime(su.getTimeGroupId());
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\",\"student_name\":\"" + su.getName() + "\",\"student_number\":\"" + su.getCardNo() + "\",\"student_sex\":\"" + su.getSexId() + idCardStr + "\",\"student_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\",\"student_name\":\"" + su.getName() + "\",\"student_number\":\"" + su.getCardNo() + "\",\"student_sex\":\"" + su.getSexId() + idCardStr + "\",\"student_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
- if (!bsResult.contains("更新成功")) {
- return CommonResult.fail("百胜平台:" + result.getMsg());
- }
- return CommonResult.ok("更新成功");
- //endregion
- }
- //endregion
- //region 百胜新增学生
- public CommonResult<String> bsInsertStudent(String name, String cardNo, Integer sexId, String
- headImage, Integer timeGroupId, String bsClassNo, String startDate, String endDate, String idCard) throws
- Exception {
- //region 百胜新增学生信息
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "student/create";
- String idCardStr = org.springframework.util.StringUtils.hasText(idCard) ? "\",\"student_idcard\":\"" + idCard : "\",\"student_idcard\":\"" + "";
- String bsGroupNo = eGroupTime(timeGroupId);
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_name\":\"" + name + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + cardNo + "\",\"student_sex\":\"" + sexId + idCardStr + "\",\"student_photo\":\"" + imageUtils.getBase64Url(headImage) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_name\":\"" + name + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + cardNo + "\",\"student_sex\":\"" + sexId + idCardStr + "\",\"student_photo\":\"" + imageUtils.getBase64Url(headImage) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"student_tgno\":\"" + bsGroupNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsStudentVo grade = objectMapper.readValue(bsResult, BsStudentVo.class);
- if (!bsResult.contains("添加成功")) {
- return CommonResult.fail("百胜平台:" + grade.getMsg());
- }
- // URL解码
- String decodedUrl = URLDecoder.decode(grade.getData(), "UTF-8");
- BsStudentNoVo studentNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStudentNoVo.class);
- return CommonResult.ok("200", "新增成功", studentNo.getStudent_no());
- //endregion
- }
- //endregion
- //region 百胜删除学生
- public CommonResult bsDeleteStudent(SmartUser su) throws Exception {
- //region 百胜删除学生
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "student/delete";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
- if (!bsResult.contains("删除学生成功")) {
- return CommonResult.fail("百胜平台:" + result.getMsg());
- }
- return CommonResult.ok("操作成功");
- //endregion
- }
- //endregion
- //region 百胜添加教师
- public CommonResult<String> bsInsertTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
- Exception {
- //region 百胜添加教师数据
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "staff/create";
- String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"staff_idcard\":\"" + su.getIdCard() : "\",\"staff_idcard\":\"" + "";
- String bsGroupNo = eGroupTime(su.getTimeGroupId());
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"staff_name\":\"" + su.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"staff_number\":\"" + su.getCardNo() + "\",\"staff_phone\":\"" + su.getPhone() + "\",\"staff_sex\":\"" + su.getSexId() + idCardStr + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"staff_tgno\":\"" + bsGroupNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"staff_name\":\"" + su.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"staff_number\":\"" + su.getCardNo() + "\",\"staff_phone\":\"" + su.getPhone() + "\",\"staff_sex\":\"" + su.getSexId() + idCardStr + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"staff_tgno\":\"" + bsGroupNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
- if (!bsResult.contains("添加成功")) {
- return CommonResult.fail("百胜平台:" + staff.getMsg());
- }
- // URL解码
- String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
- BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
- su.setBsStaffCode(staffNo.getStaff_no());
- return CommonResult.ok("200", "新增成功", staffNo.getStaff_no());
- //endregion
- }
- //endregion
- //region 百胜更新教师
- public CommonResult<String> updateBsTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
- Exception {
- //region 百胜更新教师数据
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "staff/update";
- String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"staff_idcard\":\"" + su.getIdCard() : "\",\"staff_idcard\":\"" + "";
- String bsGroupNo = eGroupTime(su.getTimeGroupId());
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"staff_no\":\"" + su.getBsStaffCode() + "\",\"staff_name\":\"" + su.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"staff_number\":\"" + su.getCardNo() + "\",\"staff_phone\":\"" + su.getPhone() + "\",\"staff_sex\":\"" + su.getSexId() + idCardStr + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"staff_tgno\":\"" + bsGroupNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"staff_no\":\"" + su.getBsStaffCode() + "\",\"staff_name\":\"" + su.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"staff_number\":\"" + su.getCardNo() + "\",\"staff_phone\":\"" + su.getPhone() + "\",\"staff_sex\":\"" + su.getSexId() + idCardStr + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\",\"student_startdate\":\"" + startDate + "\",\"student_effdate\":\"" + endDate + "\",\"staff_tgno\":\"" + bsGroupNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
- if (!bsResult.contains("更新成功")) {
- return CommonResult.fail("百胜平台:" + staff.getMsg());
- }
- // URL解码
- String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
- BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
- return CommonResult.ok("200", "操作成功", staffNo.getStaff_no());
- //endregion
- }
- //endregion
- //region百胜删除教师
- public CommonResult bsDeleteTeacher(String staffNo) throws Exception {
- //region 百胜删除教师
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = controlConfig.getUrl() + "staff/delete";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"staff_no\":\"" + staffNo + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"staff_no\":\"" + staffNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret;
- String sign = CommonUtil.MD5(md5Str);
- //sign签名
- jsonobject.put("sign", sign);
- //返回的结果中 code为1表示成功
- String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
- ObjectMapper objectMapper = new ObjectMapper();
- BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
- if (!bsResult.contains("删除员工成功")) {
- return CommonResult.fail("百胜平台:" + result.getMsg());
- }
- return CommonResult.ok("删除成功");
- //endregion
- }
- //endregion
- //endregion
- //region 用户分页数据
- /**
- * 用户分页数据查询
- *
- * @param currentPage 当前页数
- * @param pageCount 一页数据条数
- * @param departmentId 部门ID
- * @return
- */
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult queryPageSmartUser(int currentPage, int pageCount, Integer departmentId, String
- name, String userhead) {
- //region 角色判断
- String userID = AesUtils.decrypt(userhead);
- SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
- if (operateData == null) {
- return CommonResult.fail("用户信息不合法,无法查看");
- }
- QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("user_id", operateData.getId());
- List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
- if (authorities == null) {
- return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
- }
- if (authorities.size() <= 0) {
- return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
- }
- List<String> viewAuthors = new ArrayList<>();//部门查看权限
- List<String> manageAuthors = new ArrayList<>();//部门管理权限
- for (SmartAuthority author : authorities) {
- List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
- if (views != null && views.size() > 0) {
- viewAuthors.addAll(views);
- }
- List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
- if (manages != null && manages.size() > 0) {
- manageAuthors.addAll(manages);
- }
- }
- List<String> AllAuths = new ArrayList<>();
- AllAuths.addAll(viewAuthors);
- AllAuths.addAll(manageAuthors);
- AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
- //endregion
- //获取该部门下的所有子级部门ID
- List<Integer> childDepartmentIds = new ArrayList<>();
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- childDepartmentIds.add(departmentId);
- QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
- if (departmentId == null) {
- childDepartmentIds = null;
- }
- List<Integer> authDepartments = new ArrayList<>();
- for (Integer child : childDepartmentIds) {
- if (AllAuths.contains(String.valueOf(child))) {
- authDepartments.add(child);
- }
- }
- PageUtils<UserVo> result = null;
- if (authDepartments != null && authDepartments.size() > 0) {
- result = smartUserService.querySmartUserPages(currentPage, pageCount, authDepartments, name);
- } else {
- IPage<UserVo> userData = new Page<>();
- result = new PageUtils<UserVo>(userData);
- }
- if (result != null && result.getList() != null) {
- List<Integer> studentIds = new ArrayList<>();
- List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
- for (String studentStr : studentStrs) {
- if (!ObjectUtils.isEmpty(studentStr)) {
- studentIds.add(Integer.valueOf(studentStr));
- }
- }
- List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
- List<SmartClass> classs = smartClassService.list(null);
- List<SmartIdentity> idnetitys = smartIdentityService.list(null);
- List<SmartTimeGroup> timeGroups = smartTimeGroupService.list(null);
- List<Integer> userIds = result.getList().stream().map(UserVo::getId).collect(Collectors.toList());
- List<UserSubjectVo> teachings = smartTeachingService.querySmartTeachings(userIds);
- for (UserVo data : result.getList()) {
- //region 任课数据
- List<UserSubjectVo> ownerTeachings = teachings.stream().filter(e -> e.getUserId().equals(data.getId())).collect(Collectors.toList());
- if (ownerTeachings != null && ownerTeachings.size() > 0) {
- List<isrRequest> subjectVos = new ArrayList<>();
- for (UserSubjectVo ownerTeaching : ownerTeachings) {
- isrRequest ir = new isrRequest();
- Integer[] ids = new Integer[3];
- //用这种方式能避免重复引用
- //简单说,重复引用就是一个集合/对象中的多个元素/属性同时引用同一对象,循环引用就是集合/对象中的多个元素/属性存在相互引用导致循环。
- Integer subjectId = new Integer(ownerTeaching.getSubjectId());
- ids[0] = subjectId;
- Integer gradeId = new Integer(ownerTeaching.getGradeId());
- ids[1] = gradeId;
- Integer classId = new Integer(ownerTeaching.getClassId());
- ids[2] = classId;
- ir.setIds(Arrays.asList(ids));
- subjectVos.add(ir);
- }
- data.setSubjectVos(subjectVos);
- }
- //endregion
- //时间组
- Optional<SmartTimeGroup> oTimeGroup = timeGroups.stream().filter(e -> e.getId().equals(data.getTimeGroupId())).findFirst();
- if (oTimeGroup != null && oTimeGroup.isPresent()) {
- data.setTimeGroupName(oTimeGroup.get().getName());
- }
- Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
- if (identityData != null && identityData.isPresent()) {
- data.setIdentity(identityData.get().getName());
- }
- data.setSex(eSexStatu.stringOf(data.getSexId()));
- Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
- if (departmentData != null && departmentData.isPresent()) {
- data.setDepartment(departmentData.get().getName());
- }
- Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
- if (nowClass != null && nowClass.isPresent()) {
- data.setClassStr(nowClass.get().getName());
- }
- List<AffiliateUserVo> datas = new ArrayList<>();
- if (data.getAffiliate() != null) {
- List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
- for (String a : affiliates) {
- if (!ObjectUtils.isEmpty(a)) {
- Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
- if (student != null && student.isPresent()) {
- AffiliateUserVo affiliate = new AffiliateUserVo();
- affiliate.setId(student.get().getId());
- affiliate.setName(student.get().getName());
- affiliate.setCardNo(student.get().getCardNo());
- affiliate.setDepartmentId(student.get().getDepartmentId());
- datas.add(affiliate);
- }
- }
- }
- }
- data.setAffiliates(datas);
- }
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 用户分页数据
- /**
- * 用户分页数据查询
- *
- * @param currentPage 当前页数
- * @param pageCount 一页数据条数
- * @param departmentId 部门ID
- * @return
- */
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult queryPageSmartUserNoAuth(int currentPage, int pageCount, Integer departmentId, String
- name, String userhead) {
- //region 角色判断
- String userID = AesUtils.decrypt(userhead);
- SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
- if (operateData == null) {
- return CommonResult.fail("用户信息不合法,无法查看");
- }
- //endregion
- //获取该部门下的所有子级部门ID
- List<Integer> childDepartmentIds = new ArrayList<>();
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- childDepartmentIds.add(departmentId);
- QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
- if (departmentId == null) {
- childDepartmentIds = null;
- }
- PageUtils<UserVo> result = null;
- if (childDepartmentIds != null && childDepartmentIds.size() > 0) {
- result = smartUserService.querySmartUserPages(currentPage, pageCount, childDepartmentIds, name);
- } else {
- IPage<UserVo> userData = new Page<>();
- result = new PageUtils<UserVo>(userData);
- }
- if (result != null && result.getList() != null) {
- List<Integer> studentIds = new ArrayList<>();
- List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
- for (String studentStr : studentStrs) {
- if (!ObjectUtils.isEmpty(studentStr)) {
- studentIds.add(Integer.valueOf(studentStr));
- }
- }
- List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
- List<SmartClass> classs = smartClassService.list(null);
- List<SmartIdentity> idnetitys = smartIdentityService.list(null);
- for (UserVo data : result.getList()) {
- data.setTimeGroupName(eGroupTime(data.getTimeGroupId()));
- Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
- if (identityData != null && identityData.isPresent()) {
- data.setIdentity(identityData.get().getName());
- }
- data.setSex(eSexStatu.stringOf(data.getSexId()));
- Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
- if (departmentData != null && departmentData.isPresent()) {
- data.setDepartment(departmentData.get().getName());
- }
- Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
- if (nowClass != null && nowClass.isPresent()) {
- data.setClassStr(nowClass.get().getName());
- }
- List<AffiliateUserVo> datas = new ArrayList<>();
- if (data.getAffiliate() != null) {
- List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
- for (String a : affiliates) {
- if (!ObjectUtils.isEmpty(a)) {
- Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
- if (student != null && student.isPresent()) {
- AffiliateUserVo affiliate = new AffiliateUserVo();
- affiliate.setId(student.get().getId());
- affiliate.setName(student.get().getName());
- affiliate.setCardNo(student.get().getCardNo());
- affiliate.setDepartmentId(student.get().getDepartmentId());
- datas.add(affiliate);
- }
- }
- }
- }
- data.setAffiliates(datas);
- }
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 导出表头列表集合
- @Override
- @DESRespondSecret(validated = false)
- public CommonResult gauageOutfit() {
- int i = 1;
- List<gauageOutfitVo> govs = new ArrayList<>();
- //region 学号
- gauageOutfitVo cardNo = new gauageOutfitVo();
- cardNo.setId(i);
- cardNo.setName("学号");
- govs.add(cardNo);
- i++;
- //endregion
- //region 姓名
- gauageOutfitVo name = new gauageOutfitVo();
- name.setId(i);
- name.setName("姓名");
- govs.add(name);
- i++;
- //endregion
- //region 身份
- gauageOutfitVo identity = new gauageOutfitVo();
- identity.setId(i);
- identity.setName("身份");
- govs.add(identity);
- i++;
- //endregion
- //region 职务
- gauageOutfitVo duties = new gauageOutfitVo();
- duties.setId(i);
- duties.setName("职务");
- govs.add(duties);
- i++;
- //endregion
- //region 身份证号
- gauageOutfitVo idcard = new gauageOutfitVo();
- idcard.setId(i);
- idcard.setName("身份证号");
- govs.add(idcard);
- i++;
- //endregion
- //region 性别
- gauageOutfitVo sex = new gauageOutfitVo();
- sex.setId(i);
- sex.setName("性别");
- govs.add(sex);
- i++;
- //endregion
- //region 部门
- gauageOutfitVo department = new gauageOutfitVo();
- department.setId(i);
- department.setName("部门");
- govs.add(department);
- i++;
- //endregion
- //region 人脸照片
- gauageOutfitVo iamge = new gauageOutfitVo();
- iamge.setId(i);
- iamge.setName("人脸照片");
- govs.add(iamge);
- i++;
- //endregion
- //region 年级
- gauageOutfitVo grade = new gauageOutfitVo();
- grade.setId(i);
- grade.setName("年级");
- govs.add(grade);
- i++;
- //endregion
- //region 班级
- gauageOutfitVo classes = new gauageOutfitVo();
- classes.setId(i);
- classes.setName("班级");
- govs.add(classes);
- i++;
- //endregion
- //region 时间组
- gauageOutfitVo timeGroup = new gauageOutfitVo();
- timeGroup.setId(i);
- timeGroup.setName("时间组");
- govs.add(timeGroup);
- i++;
- //endregion
- //region 学院
- gauageOutfitVo college = new gauageOutfitVo();
- college.setId(i);
- college.setName("学院");
- govs.add(college);
- i++;
- //endregion
- //region 专业
- gauageOutfitVo speciality = new gauageOutfitVo();
- speciality.setId(i);
- speciality.setName("专业");
- govs.add(speciality);
- i++;
- //endregion
- //region 校区
- gauageOutfitVo campus = new gauageOutfitVo();
- campus.setId(i);
- campus.setName("校区");
- govs.add(campus);
- i++;
- //endregion
- //region 宿舍号
- gauageOutfitVo dormitory = new gauageOutfitVo();
- dormitory.setId(i);
- dormitory.setName("宿舍号");
- govs.add(dormitory);
- i++;
- //endregion
- //region 手机号
- gauageOutfitVo phone = new gauageOutfitVo();
- phone.setId(i);
- phone.setName("手机号");
- govs.add(phone);
- i++;
- //endregion
- //region 关联人
- gauageOutfitVo affiliate = new gauageOutfitVo();
- affiliate.setId(i);
- affiliate.setName("关联人");
- govs.add(affiliate);
- i++;
- //endregion
- //region 职称
- gauageOutfitVo title = new gauageOutfitVo();
- title.setId(i);
- title.setName("职称");
- govs.add(title);
- i++;
- //endregion
- //region 家庭地址
- gauageOutfitVo address = new gauageOutfitVo();
- address.setId(i);
- address.setName("家庭地址");
- govs.add(address);
- i++;
- //endregion
- //region 民族
- gauageOutfitVo nation = new gauageOutfitVo();
- nation.setId(i);
- nation.setName("民族");
- govs.add(nation);
- i++;
- //endregion
- //region 生源地
- gauageOutfitVo student = new gauageOutfitVo();
- student.setId(i);
- student.setName("生源地");
- govs.add(student);
- i++;
- //endregion
- //region 毕业学院
- gauageOutfitVo graduate = new gauageOutfitVo();
- graduate.setId(i);
- graduate.setName("毕业学院");
- govs.add(graduate);
- //endregion
- return CommonResult.ok(govs);
- }
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult getPage(int currentPage, int pageCount, String keyWord) {
- LambdaQueryWrapper<SmartUser> wrapper = new LambdaQueryWrapper<>();
- wrapper.like(ObjectUtils.isNotEmpty(keyWord), SmartUser::getName, keyWord);
- IPage<SmartUser> page = smartUserService.page(new Page<>(currentPage, pageCount), wrapper);
- return CommonResult.ok(page);
- }
- @Override
- @DESRespondSecret(validated = true)
- @PassToken
- public CommonResult studentSelect(String keyWord) {
- if (ObjectUtils.isEmpty(keyWord)) {
- return CommonResult.fail();
- }
- List<StudentSelectVo> list = smartUserService.studentSelect(keyWord);
- return CommonResult.ok(list);
- }
- //endregion
- //region 用户导出
- /**
- * @param response 响应头
- * @param userhead 请求头
- * @param sure 请求参数
- */
- @Override
- @DESRespondSecret(validated = false)
- public CommonResult smartUserExport(HttpServletResponse response, String userhead, smartUserExportRequest sure) {
- if (sure.getGauageOutfitVos() == null) {
- return CommonResult.fail("表头数据为空");
- }
- if (sure.getGauageOutfitVos().size() <= 0) {
- return CommonResult.fail("表头数据为空");
- }
- //region 角色判断
- String userID = AesUtils.decrypt(userhead);
- SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
- if (operateData != null && sure != null && sure.getGauageOutfitVos() != null && sure.getGauageOutfitVos().size() > 0) {
- QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("user_id", operateData.getId());
- List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
- if (authorities != null && authorities.size() > 0) {
- List<String> viewAuthors = new ArrayList<>();//部门查看权限
- List<String> manageAuthors = new ArrayList<>();//部门管理权限
- for (SmartAuthority author : authorities) {
- List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
- if (views != null && views.size() > 0) {
- viewAuthors.addAll(views);
- }
- List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
- if (manages != null && manages.size() > 0) {
- manageAuthors.addAll(manages);
- }
- }
- List<String> AllAuths = new ArrayList<>();
- AllAuths.addAll(viewAuthors);
- AllAuths.addAll(manageAuthors);
- AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
- //endregion
- //获取该部门下的所有子级部门ID
- List<Integer> childDepartmentIds = new ArrayList<>();
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- Integer departmentId = sure != null ? sure.getDepartmentId() : null;
- childDepartmentIds.add(departmentId);
- QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
- if (departmentId == null) {
- childDepartmentIds = null;
- }
- List<Integer> authDepartments = new ArrayList<>();
- for (Integer child : childDepartmentIds) {
- if (AllAuths.contains(String.valueOf(child))) {
- authDepartments.add(child);
- }
- }
- String name = sure != null ? sure.getName() : null;
- List<SmartUser> users = smartUserService.querySmartUsers(authDepartments, name);
- List<String> affiliates = new ArrayList<>();
- List<String> affiliateStr = users.stream().map(SmartUser::getAffiliate).distinct().collect(Collectors.toList());
- for (String datas : affiliateStr) {
- if (!ObjectUtils.isEmpty(datas)) {
- String[] dataArray = datas.split(",");
- for (int i = 0; i < dataArray.length; i++) {
- affiliates.add(dataArray[i]);
- }
- }
- }
- List<SmartUser> affiliateDatas = affiliates != null && affiliates.size() > 0 ? smartUserService.getSmartUserIds(affiliates) : null;
- List<Integer> dutieIds = users != null && users.size() > 0 ? users.stream().map(SmartUser::getDuties).collect(Collectors.toList()) : null;
- //职务数据
- List<SmartDuties> duties = dutieIds != null && dutieIds.size() > 0 ? smartDutiesService.queryDutiesByIds(dutieIds) : null;
- //年级
- List<SmartGrade> grades = smartGradeService.list(null);
- //班级
- List<SmartClass> classes = smartClassService.list(null);
- //导出
- Workbook workbook = new XSSFWorkbook();
- Sheet sheet = workbook.createSheet("用户信息管理");
- Row headerRow = sheet.createRow(0);
- int exportIndex = 1;
- List<String> gauageStrs = sure.getGauageOutfitVos().stream().map(gauageOutfitVo::getName).collect(Collectors.toList());
- headerRow.createCell(0).setCellValue("序号");
- if (gauageStrs.contains("学号")) {
- headerRow.createCell(exportIndex).setCellValue("学号");
- exportIndex++;
- }
- if (gauageStrs.contains("姓名")) {
- headerRow.createCell(exportIndex).setCellValue("姓名");
- exportIndex++;
- }
- if (gauageStrs.contains("身份")) {
- headerRow.createCell(exportIndex).setCellValue("身份");
- exportIndex++;
- }
- if (gauageStrs.contains("职务")) {
- headerRow.createCell(exportIndex).setCellValue("职务");
- exportIndex++;
- }
- if (gauageStrs.contains("身份证号")) {
- headerRow.createCell(exportIndex).setCellValue("身份证号");
- exportIndex++;
- }
- if (gauageStrs.contains("性别")) {
- headerRow.createCell(exportIndex).setCellValue("性别");
- exportIndex++;
- }
- if (gauageStrs.contains("部门")) {
- headerRow.createCell(exportIndex).setCellValue("部门");
- exportIndex++;
- }
- if (gauageStrs.contains("人脸照片")) {
- headerRow.createCell(exportIndex).setCellValue("人脸照片");
- exportIndex++;
- }
- if (gauageStrs.contains("年级")) {
- headerRow.createCell(exportIndex).setCellValue("年级");
- exportIndex++;
- }
- if (gauageStrs.contains("班级")) {
- headerRow.createCell(exportIndex).setCellValue("班级");
- exportIndex++;
- }
- if (gauageStrs.contains("时间组")) {
- headerRow.createCell(exportIndex).setCellValue("时间组");
- exportIndex++;
- }
- if (gauageStrs.contains("学院")) {
- headerRow.createCell(exportIndex).setCellValue("学院");
- exportIndex++;
- }
- if (gauageStrs.contains("专业")) {
- headerRow.createCell(exportIndex).setCellValue("专业");
- exportIndex++;
- }
- if (gauageStrs.contains("校区")) {
- headerRow.createCell(exportIndex).setCellValue("校区");
- exportIndex++;
- }
- if (gauageStrs.contains("宿舍号")) {
- headerRow.createCell(exportIndex).setCellValue("宿舍号");
- exportIndex++;
- }
- if (gauageStrs.contains("手机号")) {
- headerRow.createCell(exportIndex).setCellValue("手机号");
- exportIndex++;
- }
- if (gauageStrs.contains("关联人")) {
- headerRow.createCell(exportIndex).setCellValue("关联人");
- exportIndex++;
- }
- if (gauageStrs.contains("职称")) {
- headerRow.createCell(exportIndex).setCellValue("职称");
- exportIndex++;
- }
- if (gauageStrs.contains("家庭住址")) {
- headerRow.createCell(exportIndex).setCellValue("家庭住址");
- exportIndex++;
- }
- if (gauageStrs.contains("民族")) {
- headerRow.createCell(exportIndex).setCellValue("民族");
- exportIndex++;
- }
- if (gauageStrs.contains("生源地")) {
- headerRow.createCell(exportIndex).setCellValue("生源地");
- exportIndex++;
- }
- if (gauageStrs.contains("毕业学院")) {
- headerRow.createCell(exportIndex).setCellValue("毕业学院");
- exportIndex++;
- }
- List<SmartTimeGroup> timeGroups = new ArrayList<>();
- if (gauageStrs.contains("时间组")) {
- timeGroups = smartTimeGroupService.list(null);
- }
- for (int i = 0; i < users.size(); i++) {
- int valueIndex = 1;
- SmartUser user = users.get(i);
- Row dataRow = sheet.createRow(i + 1);
- dataRow.createCell(0).setCellValue(i + 1);//序号
- if (gauageStrs.contains("学号")) {
- dataRow.createCell(valueIndex).setCellValue(user.getCardNo());//学号
- valueIndex++;
- }
- if (gauageStrs.contains("姓名")) {
- dataRow.createCell(valueIndex).setCellValue(user.getName());//姓名
- valueIndex++;
- }
- if (gauageStrs.contains("身份")) {
- dataRow.createCell(valueIndex).setCellValue(eIdentityStatu.stringOf(user.getIdentityId()));//身份
- valueIndex++;
- }
- if (gauageStrs.contains("职务")) {
- String dutieStr = "";
- if (duties != null && duties.size() > 0 && user.getDuties() != null) {
- Optional<SmartDuties> oduty = duties.stream().filter(e -> e.getId().equals(user.getDuties())).findFirst();
- if (oduty != null && oduty.isPresent()) {
- dutieStr = oduty.get().getName();
- }
- }
- dataRow.createCell(valueIndex).setCellValue(dutieStr);//职务
- valueIndex++;
- }
- if (gauageStrs.contains("身份证号")) {
- dataRow.createCell(valueIndex).setCellValue(user.getIdCard());//身份证号
- valueIndex++;
- }
- if (gauageStrs.contains("性别")) {
- dataRow.createCell(valueIndex).setCellValue(eSexStatu.stringOf(user.getSexId()));//性别
- valueIndex++;
- }
- if (gauageStrs.contains("部门")) {
- //获取父级部门ID
- Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(user.getDepartmentId())).findFirst();
- if (department != null && department.isPresent()) {
- dataRow.createCell(valueIndex).setCellValue(QueryParentDepartments(department.get().getParentId(), departments, null));//部门
- }
- valueIndex++;
- }
- if (gauageStrs.contains("人脸照片")) {
- dataRow.createCell(valueIndex).setCellValue(user.getHeadImage() == null ? "" : user.getHeadImage());//人脸
- valueIndex++;
- }
- if (gauageStrs.contains("年级")) {
- String grade = "";
- Optional<SmartGrade> gradeData = grades == null ? null : grades.stream().filter(e -> e.getId().toString().equals(user.getGrade())).findFirst();
- if (gradeData != null && gradeData.isPresent()) {
- grade = gradeData.get().getName();
- }
- dataRow.createCell(valueIndex).setCellValue(grade);//年级
- valueIndex++;
- }
- if (gauageStrs.contains("班级")) {
- String classStr = "";
- Optional<SmartClass> classData = classes == null ? null : classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
- if (classData != null && classData.isPresent()) {
- classStr = classData.get().getName();
- }
- dataRow.createCell(valueIndex).setCellValue(classStr);//班级
- valueIndex++;
- }
- if (gauageStrs.contains("时间组")) {
- Optional<SmartTimeGroup> oTime = timeGroups != null && timeGroups.size() > 0 && user.getTimeGroupId() != null ? timeGroups.stream().filter(e -> e.getId().equals(user.getTimeGroupId())).findFirst() : null;
- String timeStr = "";
- if (oTime != null && oTime.isPresent()) {
- timeStr = oTime.get().getName();
- }
- dataRow.createCell(valueIndex).setCellValue(timeStr);//时间组
- valueIndex++;
- }
- if (gauageStrs.contains("学院")) {
- dataRow.createCell(valueIndex).setCellValue(user.getCollege() == null ? "" : user.getCollege());//学院
- valueIndex++;
- }
- if (gauageStrs.contains("专业")) {
- dataRow.createCell(valueIndex).setCellValue(user.getSpeciality() == null ? "" : user.getSpeciality());//专业
- valueIndex++;
- }
- if (gauageStrs.contains("校区")) {
- dataRow.createCell(valueIndex).setCellValue(user.getCampus() == null ? "" : user.getCampus());//校区
- valueIndex++;
- }
- if (gauageStrs.contains("宿舍号")) {
- dataRow.createCell(valueIndex).setCellValue(user.getDormitoryNumber() == null ? "" : user.getDormitoryNumber());//宿舍号
- valueIndex++;
- }
- if (gauageStrs.contains("手机号")) {
- dataRow.createCell(valueIndex).setCellValue(user.getPhone() == null ? "" : user.getPhone());//手机号
- valueIndex++;
- }
- if (gauageStrs.contains("关联人")) {
- List<String> affiliateCellStrs = new ArrayList<>();
- if (user.getAffiliate() != null && affiliateDatas != null) {
- String[] affArrayStr = user.getAffiliate().split(",");
- for (int j = 0; j < affArrayStr.length; j++) {
- String affArrayIndex = affArrayStr[j];
- Optional<SmartUser> affUser = affiliateDatas.stream().filter(e -> e.getId().toString().equals(affArrayIndex)).findFirst();
- if (affUser != null && affUser.isPresent()) {
- affiliateCellStrs.add(affUser.get().getName());
- }
- }
- }
- dataRow.createCell(valueIndex).setCellValue(StringUtils.join(affiliateCellStrs, ","));//关联人
- valueIndex++;
- }
- if (gauageStrs.contains("职称")) {
- dataRow.createCell(valueIndex).setCellValue(user.getTitle() == null ? "" : user.getTitle());//职称
- valueIndex++;
- }
- if (gauageStrs.contains("家庭住址")) {
- dataRow.createCell(valueIndex).setCellValue(user.getAddress() == null ? "" : user.getAddress());//家庭住址
- valueIndex++;
- }
- if (gauageStrs.contains("民族")) {
- dataRow.createCell(valueIndex).setCellValue(user.getNation() == null ? "" : user.getNation());//民族
- valueIndex++;
- }
- if (gauageStrs.contains("生源地")) {
- dataRow.createCell(valueIndex).setCellValue(user.getOfStudent() == null ? "" : user.getOfStudent());//生源地
- valueIndex++;
- }
- if (gauageStrs.contains("毕业学院")) {
- dataRow.createCell(valueIndex).setCellValue(user.getGraduate() == null ? "" : user.getGraduate());//毕业学校
- valueIndex++;
- }
- }
- // 将工作簿写入文件
- ExcelUtils.excelDownload(workbook, "用户信息.xlsx", response);
- }
- }
- return CommonResult.ok("导出成功");
- }
- //endregion
- //region 根据父级ID获取树形数据
- /**
- * 根据父级ID获取树形数据
- *
- * @param parentID 父级ID
- * @param lists 数据集合
- * @return
- */
- private List<DepartmentTreeVo> QueryDepartmentTreeRecords
- (Integer
- parentID, List<SmartDepartment> lists, List<Integer> departmentIds) {
- List<DepartmentTreeVo> newTrees = new ArrayList<>();
- List<SmartDepartment> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
- for (SmartDepartment data : datas) {
- departmentIds.add(data.getId());
- QueryDepartmentTreeRecords(data.getId(), lists, departmentIds);
- }
- return newTrees;
- }
- //endregion
- //region 根据父级ID往上查找父级数据
- /**
- * 根据父级ID获取父级数据
- *
- * @param parentID 子级ID
- * @param lists 数据集合
- * @return
- */
- private String QueryParentDepartments
- (Integer
- parentID, List<SmartDepartment> lists, String
- departmentStr) {
- Optional<SmartDepartment> data = lists.stream().filter(e -> e.getId().equals(parentID)).findFirst();
- if (data != null && data.isPresent()) {
- departmentStr = departmentStr == null ? data.get().getName() : data.get().getName() + "/" + departmentStr;
- departmentStr = QueryParentDepartments(data.get().getParentId(), lists, departmentStr);
- }
- return departmentStr;
- }
- //endregion
- //region 根据数据ID删除用户数据(旧的)
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult deleteSmartUserByIdOld
- (useridsRequest ur, BindingResult
- bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
- if (users.size() != ur.getUserIds().size()) {
- return CommonResult.fail("存在无效用户数据,删除失败!");
- }
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- for (SmartUser user : users) {
- if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
- List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
- //region 删除原有的家长关系
- CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
- if (!deleteResult.isSuccess()) {
- return CommonResult.fail(deleteResult.getMessage());
- }
- //endregion
- } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
- //查找家长
- List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,更新失败");
- }
- //region 百胜删除学生
- CommonResult deleteBsStudent = bsDeleteStudent(user);
- if (!deleteBsStudent.isSuccess()) {
- return CommonResult.fail(deleteBsStudent.getMessage());
- }
- //endregion
- //region 希沃删除学生
- CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
- if (!deleteStudent.isSuccess()) {
- return CommonResult.fail(deleteStudent.getMessage());
- }
- //endregion
- if (parents != null) {
- //region 删除原有的家长关系
- CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
- if (!deleteResult.isSuccess()) {
- return CommonResult.fail(deleteResult.getMessage());
- }
- //endregion
- }
- } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
- //region 希沃删除教师
- CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
- if (!deleteTeacher.isSuccess()) {
- return CommonResult.fail(deleteTeacher.getMessage());
- }
- //endregion
- if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- if (user.getSchoolClass() == null) {
- return CommonResult.fail("班级数据无效,删除失败");
- }
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据无效,删除失败");
- }
- //region 希沃删除班主任
- if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
- if (deleteTeacherMaster.isSuccess()) {
- return CommonResult.fail(deleteTeacherMaster.getMessage());
- }
- }
- //endregion
- }
- //region 百胜删除教师
- CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
- if (!bsDeleteTeacher.isSuccess()) {
- return CommonResult.fail(bsDeleteTeacher.getMessage());
- }
- //endregion
- }
- }
- int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
- if (result > 0) {
- smartTeachingService.deleteByUserIds(ur.getUserIds());
- }
- return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
- }
- //endregion
- //region 根据数据ID删除用户数据
- @Override
- public CommonResult deleteSmartUserById
- (useridsRequest ur, BindingResult
- bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
- if (users.size() != ur.getUserIds().size()) {
- return CommonResult.fail("存在无效用户数据,删除失败!");
- }
- //先删除咱自己数据库里的用户数据
- int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
- if (result <= 0) {
- return CommonResult.fail("删除失败");
- } else {
- // 删除同步到海康平台
- for (SmartUser user : users) {
- Integer identityId = user.getIdentityId();
- if (2 == identityId || identityId == 3) {
- Integer id = user.getId();
- SmartOperationUser smartOperationUser = new SmartOperationUser();
- smartOperationUser.setOperationId(id);
- smartOperationUser.setOperationMode("3");
- smartOperationUser.setStatus(1);
- smartOperationUser.setType(identityId);
- smartOperationUserService.save(smartOperationUser);
- }
- }
- }
- List<deleteUserVo> deleteUsers = new ArrayList<>();
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- for (SmartUser user : users) {
- deleteUserVo deleteUser = new deleteUserVo();
- deleteUser.setId(user.getId());
- if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
- List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
- //region 删除原有的家长关系
- CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
- if (!deleteResult.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败:" + deleteResult.getMessage() + ";";
- deleteUser.setReason(reason);
- //return CommonResult.fail(deleteResult.getMessage());
- }
- //endregion
- //删除家长 根据家长手机号删除下标数据
- smartFamilyIndexService.deleteSmartFamilyByPhone(user.getPhone());
- } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
- //查找家长
- List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
- if (classData == null) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;";
- deleteUser.setReason(reason);
- //return CommonResult.fail("班级数据无效,更新失败");
- }
- //region 百胜删除学生
- CommonResult deleteBsStudent = bsDeleteStudent(user);
- if (!deleteBsStudent.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除学生失败;" + deleteBsStudent.getMessage() + ";";
- deleteUser.setReason(reason);
- //return CommonResult.fail(deleteBsStudent.getMessage());
- }
- //endregion
- //region 希沃删除学生
- CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
- if (!deleteStudent.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除学生失败;" + deleteStudent.getMessage() + ";";
- ;
- deleteUser.setReason(reason);
- //return CommonResult.fail(deleteStudent.getMessage());
- }
- //endregion
- if (parents != null) {
- //region 删除原有的家长关系
- CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
- if (!deleteResult.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败;" + deleteResult.getMessage() + ";";
- ;
- deleteUser.setReason(reason);
- //return CommonResult.fail(deleteResult.getMessage());
- }
- //endregion
- //删除学生 根据学生学号删除下标数据
- smartFamilyIndexService.deleteSmartFamilyByCardNo(user.getCardNo());
- }
- } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
- if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
- if (user.getSchoolClass() == null) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,希沃删除班主任失败;";
- deleteUser.setReason(reason);
- } else {
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
- if (classData == null) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,希沃删除教师失败;";
- deleteUser.setReason(reason);
- //return CommonResult.fail("班级数据无效,更新失败");
- }
- //region 希沃删除班主任
- CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
- if (!deleteTeacherMaster.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除班主任失败;" + deleteTeacherMaster.getMessage() + ";";
- deleteUser.setReason(reason);
- //return CommonResult.fail(deleteTeacherMaster.getMessage());
- }
- //endregion
- }
- }
- //region 希沃删除教师
- CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
- if (!deleteTeacher.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + deleteTeacher.getMessage() + ";";
- deleteUser.setReason(reason);
- //return CommonResult.fail(deleteTeacher.getMessage());
- }
- //endregion
- //region 百胜删除教师
- CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
- if (!bsDeleteTeacher.isSuccess()) {
- String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + bsDeleteTeacher.getMessage() + ";";
- deleteUser.setReason(reason);
- //return CommonResult.fail(bsDeleteTeacher.getMessage());
- }
- //endregion
- }
- if (deleteUser.getReason() != null) {
- deleteUsers.add(deleteUser);
- }
- }
- if (deleteUsers != null && deleteUsers.size() > 0) {
- int deleteUser = smartUserService.deleteUserBatch(deleteUsers);
- if (deleteUser > 0) {
- List<SmartAuthorGroup> allDatas = new ArrayList<>();//要被更新的权限组数据
- List<Integer> deleteGroupId = new ArrayList<>();//要被删除的权限组
- List<Integer> deleteUserId = new ArrayList<>();//要被删除的管理组权限
- for (deleteUserVo dUser : deleteUsers) {
- deleteUserId.add(dUser.getId());
- List<SmartAuthorGroup> authGroups = smartAuthorGroupService.smartAuthorGroup(dUser.getId());
- for (SmartAuthorGroup authGroup : authGroups) {
- List<String> newUserId = new ArrayList<>();
- List<String> userIds = Arrays.asList(authGroup.getUserId().split(","));
- for (String userId : userIds) {
- if (!userId.equals(String.valueOf(dUser.getId()))) {
- newUserId.add(userId);
- }
- }
- if (newUserId != null && newUserId.size() > 0) {
- authGroup.setUserId(StringUtils.join(newUserId, ","));
- allDatas.add(authGroup);
- } else {
- deleteGroupId.add(authGroup.getId());
- }
- }
- }
- if (allDatas != null && allDatas.size() > 0) {//更新权限组
- smartAuthorGroupService.saveBatch(allDatas);
- }
- if (deleteGroupId != null && deleteGroupId.size() > 0) {//删除权限组
- smartAuthorGroupService.deleteSmartAuthorGroupByIds(deleteGroupId);
- }
- if (deleteUserId != null && deleteUserId.size() > 0) {//删除管理组权限
- smartAuthorityService.deleteAuthorityByUserIds(deleteUserId);
- }
- } else {
- return CommonResult.fail("删除失败");
- }
- }
- return CommonResult.ok("删除成功");
- }
- //endregion
- //region 根据当前用户ID获取受访学生数据
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult queryAffiliateUserById
- (int id) {
- List<AffiliateUserVo> result = smartUserService.queryAffiliateUserById(id);
- if (result != null && result.size() > 0) {
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- for (AffiliateUserVo data : result) {
- //获取父级部门ID
- Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
- if (department != null && department.isPresent()) {
- String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
- data.setDepartmentName(departmentName);
- }
- }
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 导出人员Excel模板
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult downloadUserExcel
- () {
- return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/人员信息表.xlsx");
- }
- //endregion
- //region 导出教师模板
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult downloadTeacherExcel
- () {
- return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/教师信息表.xlsx");
- }
- //endregion
- //region 导出更新人员Excel模板
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult downloadUpdateUserExcel
- () {
- return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/更新信息表.xlsx");
- }
- //endregion
- //region 根据用户ID查询学生
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult queryStudents(
- int userId) {
- List<SmartUser> students = new ArrayList<>();
- SmartUser user = smartUserService.getSmartById(userId);
- if (user == null) {
- return CommonResult.fail("用户信息为空,获取学生列表数据失败");
- }
- if (user.getAffiliate() == null) {
- return CommonResult.ok(students);
- }
- List<Integer> affiliateIds = new ArrayList<>();
- List<String> affiliates = Arrays.asList(user.getAffiliate().split(","));
- for (String affiliate : affiliates) {
- affiliateIds.add(Integer.valueOf(affiliate));
- }
- students = smartUserService.getSmartUserByIds(affiliateIds);
- List<ParentOfStudentsVo> result = new ArrayList<>();
- for (SmartUser student : students) {
- ParentOfStudentsVo data = new ParentOfStudentsVo();
- data.setId(student.getId());
- data.setName(student.getName());
- data.setCardNo(student.getCardNo());
- data.setDepartmentId(student.getDepartmentId());
- result.add(data);
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 根据数据ID获取用户信息
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult queryInfoData(
- int id) {
- SmartUser su = smartUserService.getSmartById(id);
- if (su == null) {
- return CommonResult.fail("用户信息失效,获取用户信息失败");
- }
- //部门数据集合
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- //年级数据
- List<SmartGrade> grades = smartGradeService.list(null);
- WechatUserVo userData = new WechatUserVo();
- userData.setId(su.getId());
- userData.setCardNo(su.getCardNo());
- userData.setTimeGroupId(su.getTimeGroupId());
- userData.setName(su.getName());
- userData.setIdentityId(su.getIdentityId());
- userData.setIdCard(su.getIdCard());
- userData.setSexId(su.getSexId());
- userData.setDepartmentId(su.getDepartmentId());
- Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(su.getDepartmentId())).findFirst();
- if (department != null && department.isPresent()) {
- String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
- userData.setDepartmentName(departmentName == null ? "" : departmentName + "/" + department.get().getName());
- }
- userData.setHeadImage(su.getHeadImage());
- if (org.springframework.util.StringUtils.hasText(su.getGrade())) {
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> String.valueOf(e.getId()).equals(su.getGrade())).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- userData.setGrade(oGrade.get().getName());
- }
- }
- userData.setCollege(su.getCollege());
- userData.setSpeciality(su.getSpeciality());
- userData.setSchoolClass(su.getSchoolClass());
- userData.setCampus(su.getCampus());
- userData.setDormitoryNumber(su.getDormitoryNumber());
- userData.setPhone(su.getPhone());
- userData.setAffiliate(su.getAffiliate());
- //查找关联人
- if (su.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
- List<AffiliateParentVo> parents = smartUserService.queryAffiliateParents(su.getId());
- if (parents != null && parents.size() > 0) {
- String affiliateStr = StringUtils.join(parents.stream().map(AffiliateParentVo::getName).collect(Collectors.toList()), ",");
- userData.setAffiliateName(affiliateStr);
- }
- } else if (su.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
- if (su.getAffiliate() != null) {
- List<String> affiliates = Arrays.asList(su.getAffiliate().split(","));
- List<SmartUser> childs = smartUserService.getSmartUserIds(affiliates);
- String affiliateStr = StringUtils.join(childs.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
- userData.setAffiliateName(affiliateStr);
- }
- }
- //关联人名称用逗号隔开
- userData.setTitle(su.getTitle());
- userData.setAddress(su.getAddress());
- userData.setNation(su.getNation());
- userData.setOfStudent(su.getOfStudent());
- userData.setGraduate(su.getGraduate());
- userData.setDuties(su.getDuties());
- userData.setIsPush(su.getIsPush());
- userData.setIsCancel(su.getIsCancel());
- userData.setOpenId(su.getOpenId());
- userData.setXOpenId(su.getXOpenId());
- userData.setGzhOpenId(su.getGzhOpenId());
- userData.setXwStudentUid(su.getXwStudentUid());
- userData.setBsStudentNo(su.getBsStudentNo());
- userData.setXwTeacherCode(su.getXwTeacherCode());
- userData.setBsStaffCode(su.getBsStaffCode());
- return CommonResult.ok(userData);
- }
- //endregion
- //region 绑定学生
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult bindStudent
- (bindStudentRequest
- bsr, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- SmartUser parentUser = smartUserService.getSmartById(bsr.getUserId());
- if (parentUser == null) {
- return CommonResult.fail("当前用户信息无效,绑定失败!");
- }
- if (parentUser.getIdentityId().intValue() != eIdentityStatu.Parent.getValue()) {
- return CommonResult.fail("当前用户身份无法进行绑定操作");
- }
- //查找是否存在学生数据
- SmartUser studentUser = smartUserService.queryUserInfo(bsr.getName(), bsr.getCardNo(), bsr.getIdCard());
- if (studentUser == null) {
- return CommonResult.fail("当前学生不存在,绑定失败!");
- }
- //判断是否已绑定过
- if (parentUser.getAffiliate() == null) {
- parentUser.setAffiliate(String.valueOf(studentUser.getId()));
- } else {
- List<String> newAffiliates = new ArrayList<>();
- List<String> affiliates = Arrays.asList(parentUser.getAffiliate().split(","));
- long existCount = affiliates.stream().filter(e -> e.equals(String.valueOf(studentUser.getId()))).count();
- if (existCount > 0) {
- return CommonResult.fail("当前学生信息已绑定过,请勿重复操作!");
- }
- parentUser.setAffiliate(parentUser.getAffiliate() + "," + studentUser.getId());
- }
- List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(studentUser.getCardNo());
- if (indexs != null && indexs.size() >= 4) {
- return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
- }
- int index = 0;
- if (indexs != null) {
- for (SmartFamilyIndex data : indexs) {
- if (data.getIndexData().intValue() == index && index < 3) {
- index++;
- continue;
- } else {
- break;
- }
- }
- }
- //region 新增希沃学生家长信息
- //初始化客户端
- SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
- ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
- //响应体,MimeType为 application/json
- ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
- .build();
- param.setRequestBody(requestBody);
- //query
- ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
- .appId(seewoConfig.getAppId())
- .schoolUid(seewoConfig.getSchoolId())
- .build();
- requestBody.setQuery(query);
- //学生与家长列表,最大100条
- ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem studentParents = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
- .studentCode(studentUser.getCardNo())
- .build();
- query.setStudentParents(java.util.Collections.singletonList(studentParents));
- //家长列表,最多4个
- ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
- .name(parentUser.getName())
- .phone(parentUser.getPhone())
- .index(index)
- .build();
- studentParents.setParents(java.util.Collections.singletonList(parents));
- param.setRequestBody(requestBody);
- ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
- logger.info("入参:" + request);
- //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
- //request.setServerUrl("https://openapi.test.seewo.com")
- //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
- ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
- logger.info("出参:" + result);
- if (result == null) {
- return CommonResult.fail("希沃学生家长数据添加失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail(result.getResponseBody().getMessage());
- }
- //endregion
- int updateResult = smartUserService.updateSmartUser(parentUser);
- return updateResult > 0 ? CommonResult.ok("绑定成功") : CommonResult.fail("绑定失败");
- }
- //endregion
- //region 根据数据ID获取用户信息
- @Override
- public CommonResult queryUserData(
- int id) {
- SmartUserVo user = smartUserService.querySmartUserById(id);
- return CommonResult.ok(user);
- }
- //endregion
- //region 删除记录的分页数据
- @Override
- public CommonResult queryUserDeletePage
- (int currentPage, int pageCount) {
- PageUtils<UserDeleteVo> result = smartUserService.queryUserDeletePage(currentPage, pageCount);
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- for (UserDeleteVo data : result.getList()) {
- data.setIdentityStr(eIdentityStatu.stringOf(data.getIdentityId()));//身份
- //获取父级部门ID
- Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
- if (department != null && department.isPresent()) {
- String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
- data.setDepartmentStr(departmentName);
- }
- }
- return CommonResult.ok(result);
- }
- //endregion
- //region 获取班级下的学生
- @Override
- public CommonResult queryClassUser(
- int userId, String keyWord) {
- SmartUser userData = smartUserService.getSmartById(userId);
- if (userData == null) {
- return CommonResult.fail("未查到用户信息,获取失败");
- }
- if (userData.getSchoolClass() == null) {
- return CommonResult.fail("当前用户所在班级为空,获取失败");
- }
- SmartClass classData = smartClassService.getSmartClassById(userData.getSchoolClass());
- if (classData == null) {
- return CommonResult.fail("班级数据为空,获取失败");
- }
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- if (departments == null) {
- return CommonResult.fail("部门数据为空,获取失败");
- }
- //查找部门名称
- String departmentName = classData.getName().replace("年级", "") + "学生";
- Optional<SmartDepartment> department = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
- if (!(department != null && department.isPresent())) {
- return CommonResult.fail("部门数据为空,获取失败");
- }
- String departmentStr = QueryParentDepartments(department.get().getParentId(), departments, null);
- ClassUserVo result = new ClassUserVo();
- result.setClassId(userData.getSchoolClass());
- result.setName(departmentStr);
- List<ClassUserDetailVo> userDetails = new ArrayList<>();
- //region 用户明细集合数据
- List<SmartUser> users = smartUserService.queryUsersByClass(userData.getSchoolClass());
- if (users != null && users.size() > 0) {
- List<SmartTimeGroup> timeGroups = smartTimeGroupService.list(null);
- for (SmartUser user : users) {
- ClassUserDetailVo userDetail = new ClassUserDetailVo();
- userDetail.setId(user.getId());
- userDetail.setName(user.getName());
- userDetail.setCardNo(user.getCardNo());
- Optional<SmartTimeGroup> timeGroup = timeGroups.stream().filter(e -> e.getId().equals(user.getTimeGroupId())).findFirst();
- if (timeGroup != null && timeGroup.isPresent()) {
- userDetail.setTimeGroup(timeGroup.get().getName());
- }
- userDetails.add(userDetail);
- }
- if (!ObjectUtils.isEmpty(keyWord)) {
- userDetails = userDetails.stream().filter(e -> (e.getName() != null && e.getName().contains(keyWord)) || (e.getTimeGroup() != null && e.getTimeGroup().contains(keyWord))).collect(Collectors.toList());
- }
- }
- //endregion
- result.setUserDetails(userDetails);
- return CommonResult.ok(result);
- }
- //endregion
- //region 批量设置学生时间组
- @Override
- public CommonResult setUserTimeGroup
- (setUserTimeGroupRequest
- isur, BindingResult bindingResult) throws
- Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- logger.info("批量设置时间组1" + TimeExchange.getDateMillS());
- SmartTimeGroup timeGroup = smartTimeGroupService.queryTimeGroupById(isur.getTimeGroupId());
- if (timeGroup == null) {
- return CommonResult.fail("时间组数据无效,批量同步时间组失败!");
- }
- logger.info("批量设置时间组2" + TimeExchange.getDateMillS());
- //region 批量更新百胜学生的时间组
- List<SmartUser> users = smartUserService.getSmartUserByIds(isur.getIds());
- if (users == null) {
- return CommonResult.fail("用户数据无效,批量同步时间组失败!");
- }
- logger.info("批量设置时间组3" + TimeExchange.getDateMillS());
- List<SmartGrade> grades = smartGradeService.list(null);
- List<SmartClass> classes = smartClassService.list(null);
- logger.info("批量设置时间组4" + TimeExchange.getDateMillS());
- for (SmartUser user : users) {
- user.setTimeGroupId(isur.getTimeGroupId());
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getId().equals(Integer.valueOf(user.getGrade()))).findFirst();
- if (!(oGrade != null && oGrade.isPresent())) {
- return CommonResult.fail("年级数据无效,批量同步时间组失败!");
- }
- Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
- if (!(oClass != null && oClass.isPresent())) {
- return CommonResult.fail("班级数据无效,批量同步时间组失败!");
- }
- // 开始时间
- long stime = System.currentTimeMillis();
- logger.info("开始循环调用百胜一次:" + TimeExchange.getDateMillS());
- /**
- * 学生数据的有效期是到毕业年份的8月31日
- */
- String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
- String endTime = queryGraduationYear(oGrade.get().getGradeNo());
- CommonResult<String> updateBsStudent = bsTUpdateStudent(user, oClass.get().getBsClassNo(), startTime, endTime);
- if (!updateBsStudent.isSuccess()) {
- return CommonResult.fail(updateBsStudent.getMessage());
- }
- // 结束时间
- long etime = System.currentTimeMillis();
- // 计算执行时间
- logger.info("结束循环调用百胜一次,执行时长:%d 毫秒.", (etime - stime));
- //endregion
- }
- logger.info("循环结束:" + TimeExchange.getDateMillS());
- //region 批量更新学生数据
- boolean updateBatch = smartUserService.updateUserBatchById(users);
- logger.info("存储结束:" + TimeExchange.getDateMillS());
- return updateBatch ? CommonResult.ok("批量同步成功") : CommonResult.fail("批量同步失败");
- }
- @Override
- @DESRespondSecret(validated = true)
- @PassToken
- public CommonResult getPhoneUser
- (String phone) {
- if (ObjectUtils.isEmpty(phone)) {
- return CommonResult.fail("参数异常");
- }
- // 通过手机号找到对应用户
- SmartUser smartUser = smartUserService.getPhoneUser(phone);
- return CommonResult.ok(smartUser);
- }
- @Override
- @DESRespondSecret(validated = true)
- @PassToken
- public CommonResult getPhoneAffiliate(String phone) {
- if (ObjectUtils.isEmpty(phone)) {
- return CommonResult.fail("参数异常");
- }
- SmartUser smartUser = smartUserService.getPhoneUser(phone);
- // 用户id,多个就用逗号隔开
- String affiliate = smartUser.getAffiliate();
- if (ObjectUtils.isEmpty(affiliate)) {
- return CommonResult.fail("未关联学生");
- }
- // 通过关联人找到对应用户
- List<SmartUserAffiliateVo> smartUsers = smartUserService.getAffiliateUser(affiliate);
- return CommonResult.ok(smartUsers);
- }
- //endregion
- //region 查询时间组编号
- public String eGroupTime(Integer id) {
- SmartTimeGroup result = smartTimeGroupService.queryTimeGroupById(id);
- return result == null ? "" : result.getBsno();
- }
- //endregion
- //region 查询时间组ID
- public Integer eGroupTime(String name) {
- SmartTimeGroup result = smartTimeGroupService.queryTimeGroupByName(name);
- return result == null ? 0 : result.getId();
- }
- //endregion
- //region 根据年级查询毕业年份
- /**
- * 根据年级查询毕业年份
- *
- * @return
- */
- public String queryGraduationYear(
- int grade) {
- String endTime = "";
- int endYear = Year.now().getValue();
- // 获取当前年份
- LocalDate currentDate = LocalDate.now();
- switch (grade) {
- case 7:
- if (currentDate.getMonthValue() < 9) {
- endYear = endYear + 2;
- } else {
- endYear = endYear + 3;
- }
- break;
- case 8:
- if (currentDate.getMonthValue() < 9) {
- endYear = endYear + 1;
- } else {
- endYear = endYear + 2;
- }
- break;
- case 9:
- break;
- default:
- break;
- }
- endTime = endYear + "-08-31 23:59:59";
- return endTime;
- }
- //endregion
- }
|