SmartUserController.java 307 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.Wrapper;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.fasterxml.jackson.core.JsonProcessingException;
  11. import com.fasterxml.jackson.databind.ObjectMapper;
  12. import com.qcloud.cos.utils.IOUtils;
  13. import com.seewo.open.sdk.DefaultSeewoClient;
  14. import com.seewo.open.sdk.SeewoClient;
  15. import com.seewo.open.sdk.auth.Account;
  16. import com.template.annotation.DESRespondSecret;
  17. import com.template.annotation.PassToken;
  18. import com.template.api.SmartUserControllerAPI;
  19. import com.template.common.utils.*;
  20. import com.template.config.ControlConfig;
  21. import com.template.config.SeewoConfig;
  22. import com.template.model.enumModel.*;
  23. import com.template.model.evaluate.teacher.SmartEvaluateTeacher;
  24. import com.template.model.pojo.*;
  25. import com.template.model.request.*;
  26. import com.template.model.result.CommonResult;
  27. import com.template.model.result.PageUtils;
  28. import com.template.model.seewo.*;
  29. import com.template.model.vo.*;
  30. import com.template.services.*;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.apache.poi.hssf.usermodel.HSSFRow;
  33. import org.apache.poi.hssf.usermodel.HSSFSheet;
  34. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  35. import org.apache.poi.ss.usermodel.DataFormatter;
  36. import org.apache.poi.ss.usermodel.Row;
  37. import org.apache.poi.ss.usermodel.Sheet;
  38. import org.apache.poi.ss.usermodel.Workbook;
  39. import org.apache.poi.xssf.usermodel.XSSFRow;
  40. import org.apache.poi.xssf.usermodel.XSSFSheet;
  41. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  42. import org.slf4j.Logger;
  43. import org.slf4j.LoggerFactory;
  44. import org.springframework.beans.factory.annotation.Autowired;
  45. import org.springframework.validation.BindingResult;
  46. import org.springframework.web.bind.annotation.RequestParam;
  47. import org.springframework.web.bind.annotation.RestController;
  48. import org.springframework.web.multipart.MultipartFile;
  49. import javax.annotation.Resource;
  50. import javax.servlet.http.HttpServletResponse;
  51. import java.io.*;
  52. import java.net.URLDecoder;
  53. import java.net.URLEncoder;
  54. import java.nio.charset.Charset;
  55. import java.time.LocalDate;
  56. import java.time.LocalDateTime;
  57. import java.time.Year;
  58. import java.util.*;
  59. import java.util.stream.Collectors;
  60. import java.util.stream.Stream;
  61. import java.util.zip.ZipInputStream;
  62. import static com.template.common.utils.AesTestOne.decrypt;
  63. /**
  64. * <p>
  65. * 前端控制器
  66. * </p>
  67. *
  68. * @author ceshi
  69. * @since 2023-12-04
  70. */
  71. @RestController
  72. //返回参数加密注解
  73. @DESRespondSecret
  74. public class SmartUserController implements SmartUserControllerAPI {
  75. @Resource
  76. private SeewoConfig seewoConfig;
  77. @Resource
  78. private ControlConfig controlConfig;
  79. @Autowired
  80. private SmartUserService smartUserService;
  81. @Autowired
  82. private SmartGradeService smartGradeService;
  83. @Autowired
  84. private SmartClassService smartClassService;
  85. @Autowired
  86. private SmartUploadService smartUploadService;
  87. @Autowired
  88. private SmartDutiesService smartDutiesService;
  89. @Autowired
  90. private SmartDepartmentService smartDepartmentService;
  91. @Autowired
  92. private SmartIdentityService smartIdentityService;
  93. @Autowired
  94. private SmartTimeGroupService smartTimeGroupService;
  95. @Autowired
  96. private SmartAuthorityService smartAuthorityService;
  97. @Autowired
  98. private SmartFamilyIndexService smartFamilyIndexService;
  99. @Autowired
  100. private SmartTeachingService smartTeachingService;
  101. @Autowired
  102. private SmartAuthorGroupService smartAuthorGroupService;
  103. @Autowired
  104. private SmartSemesterService smartSemesterService;
  105. @Autowired
  106. private SmartSubjectService smartSubjectService;
  107. @Autowired
  108. private SmartEvaluateTeacherService smartEvaluateTeacherService;
  109. @Autowired
  110. private SmartOperationUserService smartOperationUserService;
  111. private static Logger logger = LoggerFactory.getLogger(SmartUserController.class);
  112. //region 开发自己导数据用的接口
  113. @Override
  114. public CommonResult testDeleteUserById(int userId) throws Exception {
  115. SmartUser user = smartUserService.getSmartById(userId);
  116. bsDeleteStudent(user);
  117. return CommonResult.ok();
  118. }
  119. @Override
  120. public CommonResult insertSmartUserPhoto() throws JsonProcessingException {
  121. Integer userType = eSeewoUserType.Student.getValue();
  122. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  123. List<SmartUser> students = smartUserService.queryStudentDatas();
  124. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  125. for (SmartUser student : students) {
  126. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  127. photo.setPhotoUrl(student.getHeadImage());
  128. photo.setUserCode(student.getCardNo());
  129. photoList.add(photo);
  130. }
  131. int num = (int) Math.ceil((double) photoList.size() / 1000);
  132. for (int count = 1; count <= num; count++) {
  133. int startIndex = (count - 1) * 1000;
  134. int endIndex = count * 1000;
  135. if (count == num) {
  136. endIndex = startIndex + (photoList.size() % 1000);
  137. }
  138. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  139. CommonResult result = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, userType);
  140. if (!result.isSuccess()) {
  141. return result;
  142. }
  143. }
  144. return CommonResult.ok("图片上传成功");
  145. }
  146. @Override
  147. public CommonResult importExcelUserBsno(MultipartFile excelFile) throws IOException {
  148. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  149. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  150. return CommonResult.fail("压缩包中的excel文件不能为空");
  151. }
  152. List<SmartUser> result = new ArrayList<>();
  153. String ContentType = excelFile.getContentType();
  154. InputStream inputStream = excelFile.getInputStream();
  155. if (ContentType.equals(eFileType.Xlsx.getValue())) {
  156. CommonResult<List<SmartUser>> resultData = readBsXlsx(inputStream);
  157. if (!resultData.isSuccess()) {
  158. return resultData;
  159. }
  160. result = resultData.getData();
  161. if (result == null) {
  162. return CommonResult.fail("文档内容为空,导入失败");
  163. }
  164. } else {
  165. return CommonResult.fail("用户导入只支持Xlsx");
  166. }
  167. List<String> gradeIds = result.stream().map(SmartUser::getGrade).distinct().collect(Collectors.toList());
  168. if (gradeIds != null && gradeIds.size() > 0) {
  169. List<SmartUser> users = smartUserService.queryStudentsByGrade(gradeIds);
  170. for (SmartUser user : users) {
  171. Optional<SmartUser> resultData = result.stream().filter(e -> e.getCardNo().equals(user.getCardNo()) && e.getName().equals(user.getName())).findFirst();
  172. if (resultData != null && resultData.isPresent()) {
  173. user.setBsStudentNo(resultData.get().getBsStudentNo());
  174. }
  175. }
  176. if (users != null && users.size() > 0) {
  177. boolean insertData = smartUserService.updateUserBatchById(users);
  178. if (!insertData) {
  179. return CommonResult.fail("导入失败");
  180. }
  181. }
  182. }
  183. return CommonResult.ok("导入成功");
  184. }
  185. /**
  186. * Xlsx文件读取方法ss
  187. *
  188. * @param inputStream 文件流
  189. * @return
  190. * @throws IOException
  191. */
  192. private CommonResult<List<SmartUser>> readBsXlsx(InputStream inputStream) throws IOException {
  193. List<SmartUser> users = new ArrayList<>();
  194. List<String> idCards = new ArrayList<>();
  195. List<String> cardNos = new ArrayList<>();
  196. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  197. List<SmartGrade> grades = smartGradeService.list(null); //年级
  198. //读取第一张sheet
  199. XSSFSheet sheetAt = sheets.getSheetAt(0);
  200. DataFormatter dataFormatter = new DataFormatter();
  201. try {
  202. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  203. XSSFRow row = sheetAt.getRow(rowNum);
  204. if (row != null) {
  205. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  206. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  207. //然后poi会根据字符串读取它
  208. //标题 校验
  209. if (rowNum == 0) {
  210. String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//年级
  211. if (!schoolClass.equals("年级")) {
  212. return CommonResult.fail("导入数据第一列为年级");
  213. }
  214. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  215. if (!cardNo.equals("学号")) {
  216. return CommonResult.fail("导入数据第四列为学号");
  217. }
  218. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  219. if (!name.equals("姓名")) {
  220. return CommonResult.fail("导入数据第五列为姓名");
  221. }
  222. String sex = dataFormatter.formatCellValue(row.getCell(5));//学生编码
  223. if (!sex.equals("学生编码")) {
  224. return CommonResult.fail("导入数据第六列为学生编码");
  225. }
  226. } else {
  227. SmartUser user = new SmartUser();
  228. String name = dataFormatter.formatCellValue(row.getCell(4));
  229. if (ObjectUtils.isEmpty(name)) {
  230. return CommonResult.fail("第" + (rowNum + 1) + "条数据的姓名不能为空");
  231. }
  232. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  233. if (ObjectUtils.isEmpty(schoolGrade)) {
  234. return CommonResult.fail(name + "的年级不能为空");
  235. }
  236. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  237. if (ObjectUtils.isEmpty(cardNo)) {
  238. return CommonResult.fail(name + "的学号不能为空");
  239. }
  240. //学号重复判断
  241. if (!ObjectUtils.isEmpty(cardNo)) {
  242. cardNos.add(cardNo);
  243. }
  244. if (cardNos.stream().distinct().count() != cardNos.size()) {
  245. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  246. }
  247. String studentNo = dataFormatter.formatCellValue(row.getCell(5));//学生编码
  248. if (ObjectUtils.isEmpty(studentNo)) {
  249. return CommonResult.fail(name + "的学生编码不能为空");
  250. }
  251. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(schoolGrade)).findFirst();
  252. if (oGrade != null && oGrade.isPresent()) {
  253. Integer gradeId = oGrade.get().getId();
  254. user.setGrade(String.valueOf(gradeId));
  255. } else {
  256. return CommonResult.fail(name + "的年级数据无效,导入失败");
  257. }
  258. user.setName(name);
  259. user.setBsStudentNo(studentNo);
  260. user.setCardNo(cardNo);
  261. users.add(user);
  262. }
  263. }
  264. }
  265. } catch (Exception e) {
  266. return CommonResult.fail("请按模板格式导入数据");
  267. }
  268. return CommonResult.ok(users);
  269. }
  270. @Override
  271. public CommonResult importExcelFamilys(MultipartFile excelFile) throws Exception {
  272. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  273. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  274. return CommonResult.fail("压缩包中的excel文件不能为空");
  275. }
  276. String ContentType = excelFile.getContentType();
  277. InputStream inputStream = excelFile.getInputStream();
  278. List<SmartFamilyIndex> result = new ArrayList<>();
  279. CommonResult<List<SmartFamilyIndex>> resultData = readFamilyXlsx(inputStream);
  280. if (!resultData.isSuccess()) {
  281. return resultData;
  282. }
  283. result = resultData.getData();
  284. boolean insertBatch = smartFamilyIndexService.saveBatch(result);
  285. return insertBatch ? CommonResult.ok("操作成功") : CommonResult.fail("操作失败");
  286. }
  287. /**
  288. * Xlsx文件读取方法
  289. *
  290. * @param inputStream 文件流
  291. * @return
  292. * @throws IOException
  293. */
  294. private CommonResult<List<SmartFamilyIndex>> readFamilyXlsx(InputStream inputStream) throws IOException {
  295. List<SmartFamilyIndex> result = new ArrayList<>();
  296. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  297. //读取第一张sheet
  298. XSSFSheet sheetAt = sheets.getSheetAt(0);
  299. DataFormatter dataFormatter = new DataFormatter();
  300. try {
  301. for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  302. XSSFRow row = sheetAt.getRow(rowNum);
  303. if (row != null) {
  304. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  305. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  306. //然后poi会根据字符串读取它
  307. //标题 校验
  308. if (rowNum < 3) {
  309. //不做校验处理了
  310. } else {
  311. String cardNo = dataFormatter.formatCellValue(row.getCell(4));//学号
  312. if (ObjectUtils.isEmpty(cardNo)) {
  313. continue;
  314. }
  315. String phone1 = dataFormatter.formatCellValue(row.getCell(10));//手机号1
  316. if (!ObjectUtils.isEmpty(phone1)) {
  317. SmartFamilyIndex index = new SmartFamilyIndex();
  318. index.setStudentNo(cardNo);
  319. index.setParentPhone(phone1);
  320. index.setIndexData(0);
  321. result.add(index);
  322. }
  323. String phone2 = dataFormatter.formatCellValue(row.getCell(12));//手机号1
  324. if (!ObjectUtils.isEmpty(phone1)) {
  325. SmartFamilyIndex index = new SmartFamilyIndex();
  326. index.setStudentNo(cardNo);
  327. index.setParentPhone(phone1);
  328. index.setIndexData(1);
  329. result.add(index);
  330. }
  331. }
  332. }
  333. }
  334. } catch (Exception e) {
  335. return CommonResult.fail("请按模板格式导入数据");
  336. }
  337. return CommonResult.ok(result);
  338. }
  339. /**
  340. * 批量导入压缩包用户信息
  341. * 以身份证号作为判断依据 如果存在重复数据就提示存在重复数据
  342. * 开发流程:建议先去拿到excel中的所有数据的身份证号去数据库中找一遍是否存在重复数据
  343. * 如果不存在重复数据就把附件文件夹中的附件文件上传到cos服务器上
  344. * 然后手动拼接一个人脸照片文件地址存入对应的数据中
  345. *
  346. * @param zipFile zip压缩包
  347. * @return
  348. */
  349. @Override
  350. @DESRespondSecret(validated = true)
  351. public CommonResult importZipUsers(MultipartFile zipFile) throws IOException {
  352. List<SmartUser> result = new ArrayList<>();
  353. MultipartFile excelFile = null;
  354. List<MultipartFile> multipartFileHashMap = new ArrayList<>();
  355. String excelStr = null;
  356. if (zipFile != null) {
  357. //解压压缩文件并上传文件
  358. ByteArrayOutputStream byteOut = null;
  359. ZipInputStream zipIn = null;
  360. try {
  361. java.util.zip.ZipEntry zipEntry = null;
  362. zipIn = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK"));
  363. while ((zipEntry = zipIn.getNextEntry()) != null) {
  364. String fileName = zipEntry.getName();
  365. if (fileName.contains("人脸照片") && (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg"))) {
  366. byteOut = new ByteArrayOutputStream();
  367. IOUtils.copy(zipIn, byteOut);
  368. InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
  369. MultipartFile multipartFile = FileUtils.getMultipartFile(inputStream, fileName);
  370. multipartFileHashMap.add(multipartFile);
  371. } else if (fileName.contains("人员信息采集表") && (fileName.endsWith(".xlsx") || fileName.endsWith(".xls"))) {
  372. excelStr = fileName.endsWith(".xlsx") ? "xlsx" : "xls";
  373. byteOut = new ByteArrayOutputStream();
  374. IOUtils.copy(zipIn, byteOut);
  375. InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
  376. excelFile = FileUtils.getMultipartFile(inputStream, fileName);
  377. }
  378. }
  379. } catch (Exception e) {
  380. e.printStackTrace();
  381. } finally {
  382. if (byteOut != null) {
  383. byteOut.close();
  384. }
  385. if (zipIn != null) {
  386. zipIn.close();
  387. }
  388. }
  389. }
  390. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  391. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  392. return CommonResult.fail("压缩包中的excel文件不能为空");
  393. }
  394. String ContentType = excelFile.getContentType();
  395. InputStream inputStream = excelFile.getInputStream();
  396. //xls格式文件
  397. if (excelStr.equals("xls")) {
  398. CommonResult<List<SmartUser>> resultData = readXls(inputStream);
  399. if (!resultData.isSuccess()) {
  400. return resultData;
  401. }
  402. result = resultData.getData();
  403. } else if (excelStr.equals("xlsx")) {
  404. CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
  405. if (!resultData.isSuccess()) {
  406. return resultData;
  407. }
  408. result = resultData.getData();
  409. } else {
  410. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  411. }
  412. //cos上传 返回图片地址
  413. String uploadResult = smartUploadService.upload(multipartFileHashMap.toArray(new MultipartFile[0]));
  414. List<String> uploadImages = Arrays.asList(uploadResult.split(","));
  415. for (SmartUser user : result) {
  416. Optional<String> headImage = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/headImage/" + user.getHeadImage())).findFirst();
  417. if (headImage != null && headImage.isPresent()) {
  418. user.setHeadImage(headImage.get());
  419. }
  420. }
  421. //批量存储用户信息
  422. boolean resultBool = smartUserService.saveBatch(result);
  423. return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
  424. }
  425. //endregion
  426. //region 注销账号
  427. @Override
  428. @DESRespondSecret(validated = true)
  429. public CommonResult logoffAccount(useridsRequest ur, BindingResult bindingResult) {
  430. if (bindingResult.hasErrors()) {
  431. String st = paramUtils.getParamError(bindingResult);
  432. return CommonResult.fail(st);
  433. }
  434. int user = smartUserService.getSmartUserCountByIds(ur.getUserIds());
  435. if (user != ur.getUserIds().size()) {
  436. return CommonResult.fail("用户信息已失效");
  437. }
  438. return 0 > 0 ? CommonResult.ok("注销成功") : CommonResult.fail("注销失败");
  439. }
  440. //endregion
  441. //region 移动多个用户到其他部门
  442. @Override
  443. @DESRespondSecret(validated = true)
  444. public CommonResult changeDepartment(changeDepartmentRequest cdr, BindingResult bindingResult) {
  445. if (bindingResult.hasErrors()) {
  446. String st = paramUtils.getParamError(bindingResult);
  447. return CommonResult.fail(st);
  448. }
  449. List<SmartUser> users = smartUserService.getSmartUserByIds(cdr.getUserIds());
  450. if (users == null) {
  451. return CommonResult.fail("用户信息无效,移动失败!");
  452. }
  453. if (users.size() != cdr.getUserIds().size()) {
  454. return CommonResult.fail("存在无效用户数据,移动失败!");
  455. }
  456. for (SmartUser user : users) {
  457. user.setDepartmentId(cdr.getDepartmentId());
  458. }
  459. boolean result = smartUserService.updateUserBatchById(users);
  460. return result ? CommonResult.ok("移动成功") : CommonResult.fail("移动失败");
  461. }
  462. //endregion
  463. //region 批量新增用户
  464. //region 批量新增用户方法
  465. @Override
  466. @DESRespondSecret(validated = true)
  467. public CommonResult importExcelUsers(MultipartFile excelFile, String headImage) throws Exception {
  468. List<SmartUser> result = new ArrayList<>();
  469. int useXw = 1;
  470. int useBs = 1;
  471. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  472. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  473. return CommonResult.fail("压缩包中的excel文件不能为空");
  474. }
  475. String ContentType = excelFile.getContentType();
  476. InputStream inputStream = excelFile.getInputStream();
  477. //xls格式文件
  478. if (ContentType.equals(eFileType.Xls.getValue())) {
  479. CommonResult<List<SmartUser>> resultData = readXls(inputStream);
  480. if (!resultData.isSuccess()) {
  481. return resultData;
  482. }
  483. result = resultData.getData();
  484. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  485. CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
  486. if (!resultData.isSuccess()) {
  487. return resultData;
  488. }
  489. result = resultData.getData();
  490. } else {
  491. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  492. }
  493. List<String> uploadImages = Arrays.asList(headImage.split(","));
  494. for (SmartUser user : result) {
  495. Optional<String> image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/" + user.getHeadImage())).findFirst();
  496. if (image != null && image.isPresent()) {
  497. user.setHeadImage(image.get());
  498. } else {
  499. if (user.getIdentityId().equals(eIdentityStatu.Student.getValue())
  500. || user.getIdentityId().equals(eIdentityStatu.Teacher.getValue())) {
  501. return CommonResult.fail(user.getName() + "头像不存在,导入失败");
  502. }
  503. }
  504. }
  505. //region 将数据加入第三方
  506. List<SmartUser> studentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
  507. if (studentDatas != null && studentDatas.size() > 0) {
  508. //判断是否存在重复数据
  509. List<String> cardNos = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  510. if (cardNos == null) {
  511. return CommonResult.fail("文档内容为空,导入失败");
  512. }
  513. if (cardNos.size() <= 0) {
  514. return CommonResult.fail("文档内容为空,导入失败");
  515. }
  516. List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
  517. if (existUsers != null && existUsers.size() > 0) {
  518. String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  519. return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
  520. }
  521. //获取班级Uid
  522. List<SmartClass> classDatas = smartClassService.getSmartClasss();
  523. if (classDatas == null) {
  524. return CommonResult.fail("班级数据无效,新增失败");
  525. }
  526. List<SmartGrade> gradeDatas = smartGradeService.getSmartGrades();
  527. if (gradeDatas == null) {
  528. return CommonResult.fail("年级数据无效,新增失败");
  529. }
  530. HashMap<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> seewoDatas = new HashMap<>();
  531. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  532. for (SmartUser student : studentDatas) {
  533. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  534. photo.setPhotoUrl(student.getHeadImage());
  535. photo.setUserCode(student.getCardNo());
  536. photoList.add(photo);
  537. //region 学生参数必填判断:年级、班级
  538. if (student.getGrade() == null) {
  539. return CommonResult.fail("学生年级不能为空");
  540. }
  541. if (student.getSchoolClass() == null) {
  542. return CommonResult.fail("学生班级不能为空");
  543. }
  544. //endregion
  545. Optional<SmartClass> oClassData = classDatas.stream().filter(e -> e.getId().equals(student.getSchoolClass())).findFirst();
  546. if (oClassData == null) {
  547. return CommonResult.fail("班级数据无效,新增失败");
  548. }
  549. Optional<SmartGrade> oGradeData = gradeDatas.stream().filter(e -> e.getId().intValue() == Integer.valueOf(student.getGrade())).findFirst();
  550. if (oGradeData == null) {
  551. return CommonResult.fail("年级数据无效,新增失败");
  552. }
  553. SmartClass classData = oClassData.get();
  554. SmartGrade gradeData = oGradeData.get();
  555. //region 凑希沃参数
  556. if (useXw == 1) {
  557. if (!seewoDatas.containsKey(classData.getClassUid())) {
  558. seewoDatas.put(classData.getClassUid(), new ArrayList<>());
  559. }
  560. StudentServiceBatchSaveClassStudentsParam.StudentInfo studentSeewo = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  561. .studentName(student.getName())
  562. .studentCode(student.getCardNo())
  563. .gender(student.getSexId())
  564. .phone(student.getPhone() == null ? "" : student.getPhone())
  565. .build();
  566. seewoDatas.get(classData.getClassUid()).add(studentSeewo);
  567. }
  568. //endregion
  569. //region 百胜新增学生信息
  570. if (useBs == 1) {
  571. /**
  572. * 学生数据的有效期是到毕业年份的8月31日
  573. */
  574. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  575. String endTime = queryGraduationYear(gradeData.getGradeNo());
  576. CommonResult<String> insertBsStudent = bsInsertStudent(student.getName(), student.getCardNo(), student.getSexId(), student.getHeadImage(), student.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, student.getIdCard());
  577. if (!insertBsStudent.isSuccess()) {
  578. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  579. }
  580. student.setBsStudentNo(insertBsStudent.getData());
  581. }
  582. //endregion
  583. }
  584. if (useXw == 1) {
  585. //初始化客户端
  586. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  587. List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultDatas = new ArrayList<>();
  588. for (Map.Entry<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> entry : seewoDatas.entrySet()) {
  589. String classUid = entry.getKey();
  590. CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> insertStudents = SeewoInsertBatchStudent(seewoClient, entry.getValue(), classUid);
  591. if (!insertStudents.isSuccess()) {
  592. return CommonResult.fail("希沃平台:" + insertStudents.getMessage());
  593. }
  594. seewoResultDatas.addAll(insertStudents.getData());
  595. }
  596. for (SmartUser student : studentDatas) {
  597. Optional<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultData = seewoResultDatas.stream().filter(e -> e.getStudentCode().equals(student.getCardNo())).findFirst();
  598. if (seewoResultData != null && seewoResultData.isPresent()) {
  599. student.setXwStudentUid(seewoResultData.get().getUserUid());
  600. }
  601. }
  602. }
  603. if (studentDatas != null && studentDatas.size() > 0) {
  604. //批量存储学生信息
  605. boolean resultBool = smartUserService.saveBatch(studentDatas);
  606. if (!resultBool) {
  607. return CommonResult.fail("导入失败");
  608. } else {
  609. // 需添加到海康平台
  610. ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
  611. for (SmartUser studentData : studentDatas) {
  612. Integer id = studentData.getId();
  613. SmartOperationUser smartOperationUser = new SmartOperationUser();
  614. smartOperationUser.setOperationId(id);
  615. smartOperationUser.setOperationMode("1");
  616. smartOperationUser.setStatus(1);
  617. smartOperationUser.setType(studentData.getIdentityId());
  618. operationUsers.add(smartOperationUser);
  619. }
  620. smartOperationUserService.saveBatch(operationUsers);
  621. }
  622. List<SmartFamilyIndex> familyIndexs = new ArrayList<>();
  623. //region 希沃新增编辑学生家长信息
  624. if (useXw == 1) {
  625. int num = (int) Math.ceil((double) studentDatas.size() / 100);
  626. for (int count = 1; count <= num; count++) {
  627. int startIndex = (count - 1) * 100;
  628. int endIndex = count * 100;
  629. if (count == num) {
  630. endIndex = startIndex + (studentDatas.size() % 100);
  631. }
  632. List<SmartUser> currentStudentDatas = studentDatas.subList(startIndex, endIndex);//结尾不包含下标100
  633. //学生与家长列表,最大100条
  634. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  635. for (SmartUser student : currentStudentDatas) {
  636. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  637. .studentCode(student.getCardNo())
  638. .build();
  639. List<SmartUser> parentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList());
  640. List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
  641. int i = 0;
  642. for (SmartUser parent : parentDatas) {
  643. SmartFamilyIndex familyIndex = new SmartFamilyIndex();
  644. familyIndex.setParentPhone(parent.getPhone());
  645. familyIndex.setStudentNo(student.getCardNo());
  646. familyIndex.setIndexData(i);
  647. familyIndexs.add(familyIndex);
  648. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  649. .name(parent.getName())
  650. .phone(parent.getPhone())
  651. .index(i)
  652. .build();
  653. parents.add(data);
  654. ++i;
  655. }
  656. if (parents != null && parents.size() > 0) {
  657. studentParents.add(students);
  658. //家长列表,最多4个
  659. students.setParents(parents);
  660. }
  661. }
  662. //初始化客户端
  663. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  664. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  665. //响应体,MimeType为 application/json
  666. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  667. .build();
  668. param.setRequestBody(requestBody);
  669. //query
  670. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  671. .appId(seewoConfig.getAppId())
  672. .schoolUid(seewoConfig.getSchoolId())
  673. .build();
  674. requestBody.setQuery(query);
  675. query.setStudentParents(studentParents);
  676. param.setRequestBody(requestBody);
  677. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  678. String jsonString = JSON.toJSONString(request);
  679. logger.info("入参:" + request);
  680. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  681. //request.setServerUrl("https://openapi.test.seewo.com")
  682. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  683. ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request);
  684. logger.info("出参:" + parentResult);
  685. if (parentResult == null) {
  686. return CommonResult.fail("希沃学生家长数据添加失败!");
  687. }
  688. if (!parentResult.getResponseBody().getCode().equals("000000")) {
  689. return CommonResult.fail("希沃平台:" + parentResult.getResponseBody().getMessage());
  690. }
  691. }
  692. }
  693. //endregion
  694. if (familyIndexs != null && familyIndexs.size() > 0) {
  695. boolean insertBatch = smartFamilyIndexService.saveBatch(familyIndexs);
  696. if (!insertBatch) {
  697. return CommonResult.fail("导入失败!");
  698. }
  699. }
  700. }
  701. //endregion
  702. List<SmartUser> parents = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
  703. //双胞胎家长
  704. List<SmartUser> newParents = new ArrayList<>();
  705. if (cardNos != null && cardNos.size() > 0) {
  706. List<SmartUser> students = smartUserService.querySmartUserByCardNos(cardNos);
  707. for (SmartUser parent : parents) {
  708. Optional<SmartUser> student = students.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
  709. if (student != null && student.isPresent()) {
  710. //先查找是否存在
  711. Optional<SmartUser> newData = newParents.stream().filter(e -> e.getName().equals(parent.getName()) && e.getPhone().equals(parent.getPhone()) && e.getShip().equals(parent.getShip())).findFirst();
  712. if (newData != null && newData.isPresent()) {
  713. String affiliate = newData.get().getAffiliate() + "," + student.get().getId();
  714. newData.get().setAffiliate(affiliate);
  715. } else {
  716. SmartUser newParent = new SmartUser();
  717. newParent.setName(parent.getName());
  718. newParent.setDepartmentId(parent.getDepartmentId());
  719. newParent.setPhone(parent.getPhone());
  720. newParent.setIdentityId(parent.getIdentityId());
  721. newParent.setSexId(parent.getSexId());
  722. newParent.setIsCancel(parent.getIsCancel());
  723. newParent.setAffiliate(String.valueOf(student.get().getId()));
  724. newParent.setShip(parent.getShip());
  725. newParents.add(newParent);
  726. }
  727. }
  728. }
  729. if (newParents != null && newParents.size() > 0) {
  730. //批量存储家长信息
  731. boolean resultBool = smartUserService.saveBatch(newParents);
  732. if (!resultBool) {
  733. return CommonResult.fail("导入失败!");
  734. }
  735. }
  736. //region 最后上传学生图片 这样能保证图片上传失败也不影响数据导入
  737. if (useXw == 1) {
  738. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  739. int num = (int) Math.ceil((double) photoList.size() / 1000);
  740. for (int count = 1; count <= num; count++) {
  741. int startIndex = (count - 1) * 1000;
  742. int endIndex = count * 1000;
  743. if (count == num) {
  744. endIndex = startIndex + (photoList.size() % 1000);
  745. }
  746. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  747. CommonResult photoResult = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, eSeewoUserType.Student.getValue());
  748. if (!photoResult.isSuccess()) {
  749. return photoResult;
  750. }
  751. }
  752. }
  753. //endregion
  754. }
  755. } else {
  756. List<SmartUser> teacherDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()).collect(Collectors.toList());
  757. //判断是否存在重复数据
  758. List<String> cardNos = teacherDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  759. if (cardNos == null) {
  760. return CommonResult.fail("文档内容为空,导入失败");
  761. }
  762. if (cardNos.size() <= 0) {
  763. return CommonResult.fail("文档内容为空,导入失败");
  764. }
  765. List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
  766. if (existUsers != null && existUsers.size() > 0) {
  767. String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  768. return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
  769. }
  770. //获取班级Uid
  771. List<SmartClass> classDatas = smartClassService.getSmartClasss();
  772. List<SmartDepartment> departmentDatas = smartDepartmentService.list(null);
  773. //region
  774. //region 希沃添加教师数据
  775. if (useXw == 1) {
  776. int num = (int) Math.ceil((double) teacherDatas.size() / 100);
  777. for (int count = 1; count <= num; count++) {
  778. int startIndex = (count - 1) * 100;
  779. int endIndex = count * 100;
  780. if (count == num) {
  781. endIndex = startIndex + (teacherDatas.size() % 100);
  782. }
  783. List<SmartUser> currentStudentDatas = teacherDatas.subList(startIndex, endIndex);//结尾不包含下标100
  784. //初始化客户端
  785. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  786. //上传图片
  787. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  788. // 老师列表
  789. List<TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery> teachers = new ArrayList<>();
  790. for (SmartUser teacher : currentStudentDatas) {
  791. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teacherData = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  792. .account(teacher.getPhone())//用户账号
  793. .name(teacher.getName())//用户名字
  794. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  795. .teacherCode(teacher.getCardNo())//教师工号
  796. .photoUrl(teacher.getHeadImage())//图片链接
  797. .build();
  798. teachers.add(teacherData);
  799. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  800. photo.setPhotoUrl(teacher.getHeadImage());
  801. photo.setUserCode(teacher.getPhone());
  802. photoList.add(photo);
  803. }
  804. CommonResult<List<TeacherServiceBatchSaveOrUpdateTeacherResult.TeacherBaseInfoDto>> insertTeacher = SeewoInsertBatchTeacher(seewoClient, teachers);
  805. if (!insertTeacher.isSuccess()) {
  806. return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
  807. }
  808. CommonResult insertPhotoResult = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  809. if (!insertPhotoResult.isSuccess()) {
  810. return insertPhotoResult;
  811. }
  812. for (SmartUser teacher : teacherDatas) {
  813. if (teacher.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  814. Optional<SmartClass> oClass = classDatas.stream().filter(e -> e.getId().equals(teacher.getSchoolClass())).findFirst();
  815. if (oClass != null && oClass.isPresent()) {
  816. //获取班级Uid
  817. //region 将班主任推送到希沃
  818. if (useXw == 1) {
  819. CommonResult pushMaster = SeewoPushMaster(seewoClient, teacher.getPhone(), oClass.get().getClassUid());
  820. if (!pushMaster.isSuccess()) {
  821. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  822. }
  823. }
  824. //endregion
  825. } else {
  826. return CommonResult.fail(teacher.getName() + "班级数据无效,导入失败");
  827. }
  828. }
  829. }
  830. }
  831. }
  832. //endregion
  833. //region 百胜添加教师数据
  834. if (useBs == 1) {
  835. for (SmartUser teacher : teacherDatas) {
  836. Optional<SmartDepartment> oDepartment = departmentDatas.stream().filter(e -> e.getId().equals(teacher.getDepartmentId())).findFirst();
  837. if (!(oDepartment != null && oDepartment.isPresent())) {
  838. return CommonResult.fail(teacher.getName() + "的部门数据无效,导入失败");
  839. }
  840. /**
  841. * 教师数据的有效期是20年
  842. */
  843. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  844. String endTime = TimeExchange.addYear(20);
  845. if (ObjectUtils.isEmpty(teacher.getBsStaffCode())) {
  846. CommonResult<String> insertBsTeacher = bsInsertTeacher(teacher, oDepartment.get().getBsDepartmentNo(), startTime, endTime);
  847. if (!insertBsTeacher.isSuccess()) {
  848. return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
  849. }
  850. teacher.setBsStaffCode(insertBsTeacher.getData());
  851. } else {
  852. CommonResult<String> bsUpdateTeacher = updateBsTeacher(teacher, oDepartment.get().getBsDepartmentNo(), startTime, endTime);
  853. if (!bsUpdateTeacher.isSuccess()) {
  854. return CommonResult.fail("百胜平台:" + bsUpdateTeacher.getMessage());
  855. }
  856. teacher.setBsStaffCode(bsUpdateTeacher.getData());
  857. }
  858. }
  859. }
  860. //endregion
  861. if (teacherDatas != null && teacherDatas.size() > 0) {
  862. //批量存储老师信息
  863. boolean resultBool = smartUserService.saveBatch(teacherDatas);
  864. if (!resultBool) {
  865. return CommonResult.fail("导入失败");
  866. } else {
  867. // 需添加到海康平台
  868. ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
  869. for (SmartUser teacherData : teacherDatas) {
  870. Integer id = teacherData.getId();
  871. SmartOperationUser smartOperationUser = new SmartOperationUser();
  872. smartOperationUser.setOperationId(id);
  873. smartOperationUser.setOperationMode("1");
  874. smartOperationUser.setStatus(1);
  875. smartOperationUser.setType(teacherData.getIdentityId());
  876. operationUsers.add(smartOperationUser);
  877. }
  878. smartOperationUserService.saveBatch(operationUsers);
  879. }
  880. }
  881. }
  882. return CommonResult.ok("导入成功");
  883. }
  884. //endregion
  885. //region 批量新增Xlsx文件读取方法
  886. /**
  887. * Xlsx文件读取方法
  888. *
  889. * @param inputStream 文件流
  890. * @return
  891. * @throws IOException
  892. */
  893. private CommonResult<List<SmartUser>> readXlsx(InputStream inputStream) throws IOException {
  894. List<String> idCards = new ArrayList<>();
  895. List<String> cardNos = new ArrayList<>();
  896. List<SmartUser> result = new ArrayList<>();
  897. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  898. List<SmartDepartment> departments = smartDepartmentService.list(null);
  899. List<SmartGrade> grades = smartGradeService.list(null); //年级
  900. List<SmartClass> classs = smartClassService.list(null);//班级
  901. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  902. //读取第一张sheet
  903. XSSFSheet sheetAt = sheets.getSheetAt(0);
  904. DataFormatter dataFormatter = new DataFormatter();
  905. //region 判断是老师还是学生导入
  906. boolean isTeacher = false;
  907. XSSFRow checkRow = sheetAt.getRow(0);
  908. if (checkRow != null) {
  909. String firstCow = dataFormatter.formatCellValue(checkRow.getCell(0));//第一列 学生是年级 老师是 学校名称
  910. if (firstCow.equals("学校名称")) {
  911. isTeacher = true;
  912. }
  913. }
  914. //endregion
  915. try {
  916. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  917. XSSFRow row = sheetAt.getRow(rowNum);
  918. if (row != null) {
  919. if (!isTeacher) {
  920. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  921. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  922. //然后poi会根据字符串读取它
  923. //标题 校验
  924. if (rowNum == 0) {
  925. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  926. if (!schoolGrade.equals("年级")) {
  927. return CommonResult.fail("导入数据第一列为年级");
  928. }
  929. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  930. if (!schoolClass.equals("班级")) {
  931. return CommonResult.fail("导入数据第一列为班级");
  932. }
  933. String cardNo = dataFormatter.formatCellValue(row.getCell(2));//学号
  934. if (!cardNo.equals("学号")) {
  935. return CommonResult.fail("导入数据第二列为学号");
  936. }
  937. String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
  938. if (!name.equals("姓名")) {
  939. return CommonResult.fail("导入数据第三列为姓名");
  940. }
  941. String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
  942. if (!sex.equals("性别")) {
  943. return CommonResult.fail("导入数据第四列为性别");
  944. }
  945. String nation = dataFormatter.formatCellValue(row.getCell(5));//民族
  946. if (!nation.equals("民族")) {
  947. return CommonResult.fail("导入数据第五列为民族");
  948. }
  949. String cardId = dataFormatter.formatCellValue(row.getCell(6));//身份证
  950. if (!cardId.equals("身份证")) {
  951. return CommonResult.fail("导入数据第六列为身份证");
  952. }
  953. String headImage = dataFormatter.formatCellValue(row.getCell(7));//照片
  954. if (!headImage.equals("照片")) {
  955. return CommonResult.fail("导入数据第七列为照片");
  956. }
  957. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));//常规时间组
  958. if (!timeGroup.equals("常规时间组")) {
  959. return CommonResult.fail("导入数据第八列为常规时间组");
  960. }
  961. String address = dataFormatter.formatCellValue(row.getCell(9));//住址
  962. if (!address.equals("住址")) {
  963. return CommonResult.fail("导入数据第九列为住址");
  964. }
  965. String phone = dataFormatter.formatCellValue(row.getCell(10));//联系电话
  966. if (!phone.equals("联系电话")) {
  967. return CommonResult.fail("导入数据第十列为联系电话");
  968. }
  969. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  970. if (!family.equals("家属")) {
  971. return CommonResult.fail("导入数据第十一列为家属");
  972. }
  973. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  974. if (!familyShip.equals("家属与本人关系")) {
  975. return CommonResult.fail("导入数据第十二列为家属与本人关系");
  976. }
  977. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  978. if (!phoneTwo.equals("联系电话2")) {
  979. return CommonResult.fail("导入数据第十三列为联系电话2");
  980. }
  981. String familyTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  982. if (!familyTwo.equals("家属2")) {
  983. return CommonResult.fail("导入数据第十四列为家属2");
  984. }
  985. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  986. if (!familyShipTwo.equals("家属与本人关系2")) {
  987. return CommonResult.fail("导入数据第十五列为家属与本人关系2");
  988. }
  989. } else {
  990. SmartUser user = new SmartUser();
  991. String name = dataFormatter.formatCellValue(row.getCell(3));
  992. // if (ObjectUtils.isEmpty(name)) {
  993. // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
  994. // }
  995. if (ObjectUtils.isEmpty(name)) {
  996. continue;
  997. }
  998. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  999. if (ObjectUtils.isEmpty(schoolGrade)) {
  1000. return CommonResult.fail(name + "的年级不能为空");
  1001. }
  1002. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1003. if (ObjectUtils.isEmpty(schoolClass)) {
  1004. return CommonResult.fail(name + "的班级不能为空");
  1005. }
  1006. //不判断重复性 因为会出现双胞胎
  1007. String phone = dataFormatter.formatCellValue(row.getCell(10));
  1008. // if (!ObjectUtils.isEmpty(phone)) {
  1009. // phones.add(phone);
  1010. // }
  1011. // if (phones.stream().distinct().count() != phones.size()) {
  1012. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  1013. // }
  1014. //性别是否为空判断
  1015. String sex = dataFormatter.formatCellValue(row.getCell(4));
  1016. if (ObjectUtils.isEmpty(sex)) {
  1017. return CommonResult.fail(name + "的性别不能为空");
  1018. }
  1019. //家庭住址是否为空判断
  1020. String address = dataFormatter.formatCellValue(row.getCell(9));
  1021. //民族是否为空判断
  1022. String nation = dataFormatter.formatCellValue(row.getCell(5));
  1023. if (ObjectUtils.isEmpty(nation)) {
  1024. return CommonResult.fail(name + "的民族不能为空");
  1025. }
  1026. //部门是否为空判断
  1027. String department = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "学生";
  1028. if (ObjectUtils.isEmpty(department)) {
  1029. return CommonResult.fail(name + "的部门不能为空");
  1030. }
  1031. Integer departmentId = null;
  1032. Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst();
  1033. if (departModel != null && departModel.isPresent()) {
  1034. departmentId = departModel.get().getId();
  1035. } else {
  1036. departmentId = 1;
  1037. }
  1038. //学号重复判断
  1039. String cardNo = dataFormatter.formatCellValue(row.getCell(2));
  1040. if (!ObjectUtils.isEmpty(cardNo)) {
  1041. cardNos.add(cardNo);
  1042. }
  1043. if (cardNos.stream().distinct().count() != cardNos.size()) {
  1044. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  1045. }
  1046. //身份证重复判断
  1047. String idCard = dataFormatter.formatCellValue(row.getCell(6));
  1048. if (!ObjectUtils.isEmpty(idCard)) {
  1049. idCards.add(idCard);
  1050. }
  1051. if (idCards.stream().distinct().count() != idCards.size()) {
  1052. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  1053. }
  1054. user.setCardNo(cardNo == null ? "" : cardNo);
  1055. user.setName(name == null ? "" : name);
  1056. user.setIdentityId(eIdentityStatu.Student.getValue());
  1057. user.setIdCard(idCard == null ? "" : idCard);
  1058. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1059. user.setDepartmentId(departmentId);
  1060. String cellImage = dataFormatter.formatCellValue(row.getCell(7));
  1061. user.setHeadImage(cellImage);
  1062. user.setDormitoryNumber("");
  1063. String grade = schoolGrade == null ? "" : schoolGrade;
  1064. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  1065. if (oGrade != null && oGrade.isPresent()) {
  1066. Integer gradeId = oGrade.get().getId();
  1067. user.setGrade(String.valueOf(gradeId));
  1068. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  1069. if (oClass != null && oClass.isPresent()) {
  1070. user.setSchoolClass(oClass.get().getId());
  1071. } else {
  1072. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1073. }
  1074. } else {
  1075. return CommonResult.fail(name + "的年级数据无效,导入失败");
  1076. }
  1077. user.setCollege("");
  1078. user.setSpeciality("");
  1079. user.setCampus("");
  1080. user.setPhone("");
  1081. user.setAffiliate("");
  1082. user.setTitle("");
  1083. user.setAddress(address == null ? "" : address);
  1084. user.setNation(nation == null ? "" : nation);
  1085. user.setOfStudent("");
  1086. user.setGraduate("");
  1087. user.setDuties(null);
  1088. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));
  1089. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1090. if (groupData != null && groupData.isPresent()) {
  1091. user.setTimeGroupId(groupData.get().getId());
  1092. } else {
  1093. user.setTimeGroupId(0);
  1094. }
  1095. user.setIsCancel(eLogOff.Unlogout.getValue());
  1096. result.add(user);
  1097. //部门是否为空判断
  1098. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  1099. Integer familyDepartmentId = null;
  1100. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  1101. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  1102. familyDepartmentId = familyDepartModel.get().getId();
  1103. } else {
  1104. familyDepartmentId = 16;
  1105. }
  1106. //region 家属
  1107. if (!ObjectUtils.isEmpty(phone)) {
  1108. if (phone.length() != 11) {
  1109. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1110. }
  1111. SmartUser familyOne = new SmartUser();
  1112. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  1113. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  1114. familyOne.setDepartmentId(familyDepartmentId);
  1115. familyOne.setPhone(phone);
  1116. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  1117. familyOne.setSexId(eSexStatu.Man.getValue());
  1118. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  1119. familyOne.setAffiliate(user.getCardNo());
  1120. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  1121. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  1122. result.add(familyOne);
  1123. }
  1124. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  1125. if (!ObjectUtils.isEmpty(phoneTwo)) {
  1126. if (phoneTwo.length() != 11) {
  1127. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1128. }
  1129. SmartUser familyTwo = new SmartUser();
  1130. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  1131. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  1132. familyTwo.setDepartmentId(familyDepartmentId);
  1133. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  1134. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  1135. familyTwo.setSexId(eSexStatu.Man.getValue());
  1136. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  1137. familyTwo.setAffiliate(user.getCardNo());
  1138. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  1139. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  1140. result.add(familyTwo);
  1141. }
  1142. //endregion
  1143. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  1144. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(13)))) {
  1145. if (phone.equals(dataFormatter.formatCellValue(row.getCell(13)))) {
  1146. return CommonResult.fail(name + "的学生家长手机号不可重复");
  1147. }
  1148. }
  1149. //endregion
  1150. }
  1151. } else {
  1152. //教师导入
  1153. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1154. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1155. //然后poi会根据字符串读取它
  1156. //标题 校验
  1157. if (rowNum == 0) {
  1158. String schoolName = dataFormatter.formatCellValue(row.getCell(0));//学校名称
  1159. if (!schoolName.equals("学校名称")) {
  1160. return CommonResult.fail("导入数据第一列为学校名称");
  1161. }
  1162. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1163. if (!departmentNo.equals("部门编码")) {
  1164. return CommonResult.fail("导入数据第二列为部门编码");
  1165. }
  1166. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1167. if (!departmentName.equals("部门名称")) {
  1168. return CommonResult.fail("导入数据第三列为部门名称");
  1169. }
  1170. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1171. if (!teacherNo.equals("教师编码")) {
  1172. return CommonResult.fail("导入数据第四列为教师编码");
  1173. }
  1174. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1175. if (!name.equals("姓名")) {
  1176. return CommonResult.fail("导入数据第五列为姓名");
  1177. }
  1178. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1179. if (!sex.equals("性别")) {
  1180. return CommonResult.fail("导入数据第六列为性别");
  1181. }
  1182. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1183. if (!phone.equals("联系电话")) {
  1184. return CommonResult.fail("导入数据第七列为联系电话");
  1185. }
  1186. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//管理班级
  1187. if (!schoolClass.equals("管理班级")) {
  1188. return CommonResult.fail("导入数据第八列为身份证");
  1189. }
  1190. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1191. if (!nation.equals("民族")) {
  1192. return CommonResult.fail("导入数据第九列为民族");
  1193. }
  1194. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1195. if (!card.equals("身份证(允许为空)")) {
  1196. return CommonResult.fail("导入数据第十列为身份证");
  1197. }
  1198. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1199. if (!photo.equals("照片")) {
  1200. return CommonResult.fail("导入数据第十一列为照片");
  1201. }
  1202. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1203. if (!timeGroup.equals("常规时间组")) {
  1204. return CommonResult.fail("导入数据第十二列为常规时间组");
  1205. }
  1206. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1207. if (!address.equals("住址")) {
  1208. return CommonResult.fail("导入数据第十三列为住址");
  1209. }
  1210. } else {
  1211. SmartUser user = new SmartUser();
  1212. user.setIdentityId(eIdentityStatu.Teacher.getValue());
  1213. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1214. if (ObjectUtils.isEmpty(name)) {
  1215. continue;
  1216. }
  1217. user.setName(name);
  1218. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1219. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1220. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1221. if (ObjectUtils.isEmpty(departmentName)) {
  1222. return CommonResult.fail(name + "的部门名称不能为空");
  1223. }
  1224. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1225. if (ObjectUtils.isEmpty(departmentNo)) {
  1226. return CommonResult.fail(name + "的部门编码不能为空");
  1227. }
  1228. Optional<SmartDepartment> oDepartment = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  1229. if (!(oDepartment != null && oDepartment.isPresent())) {
  1230. return CommonResult.fail(departmentName + "部门数据在系统中不存在");
  1231. }
  1232. user.setDepartmentId(oDepartment.get().getId());
  1233. if (departmentName.equals("班主任")) {
  1234. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//班级
  1235. if (ObjectUtils.isEmpty(schoolClass)) {
  1236. return CommonResult.fail(name + "的管理班级不能为空");
  1237. }
  1238. //班级和年级
  1239. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  1240. if (!(oClass != null && oClass.isPresent())) {
  1241. return CommonResult.fail(schoolClass + "的班级数据在系统中不存在");
  1242. }
  1243. user.setSchoolClass(oClass.get().getId());
  1244. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  1245. user.setDuties(eDuties.ClassTeacher.getValue());
  1246. } else {
  1247. user.setDuties(5);//任课老师
  1248. }
  1249. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1250. if (!ObjectUtils.isEmpty(teacherNo)) {
  1251. user.setBsStaffCode(teacherNo);
  1252. }
  1253. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1254. if (ObjectUtils.isEmpty(phone)) {
  1255. return CommonResult.fail(name + "的手机号不能为空");
  1256. }
  1257. user.setCardNo(phone);
  1258. user.setPhone(phone);
  1259. user.setXwTeacherCode(phone);
  1260. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1261. if (!ObjectUtils.isEmpty(nation)) {
  1262. user.setNation(nation);
  1263. }
  1264. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1265. if (!ObjectUtils.isEmpty(card)) {
  1266. user.setIdCard(card);
  1267. }
  1268. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1269. if (!ObjectUtils.isEmpty(photo)) {
  1270. user.setHeadImage(photo);
  1271. }
  1272. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1273. if (!ObjectUtils.isEmpty(timeGroup)) {
  1274. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1275. if (groupData != null && groupData.isPresent()) {
  1276. user.setTimeGroupId(groupData.get().getId());
  1277. }
  1278. }
  1279. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1280. if (!ObjectUtils.isEmpty(address)) {
  1281. user.setAddress(address);
  1282. }
  1283. user.setIsCancel(eLogOff.Unlogout.getValue());
  1284. result.add(user);
  1285. }
  1286. }
  1287. }
  1288. }
  1289. } catch (Exception e) {
  1290. return CommonResult.fail("请按模板格式导入数据");
  1291. }
  1292. return CommonResult.ok(result);
  1293. }
  1294. //endregion
  1295. //region 批量新增Xls文件读取方法
  1296. /**
  1297. * Xls文件读取方法
  1298. *
  1299. * @param inputStream 文件流
  1300. * @return
  1301. * @throws IOException
  1302. */
  1303. private CommonResult<List<SmartUser>> readXls(InputStream inputStream) throws IOException {
  1304. List<String> idCards = new ArrayList<>();
  1305. List<String> cardNos = new ArrayList<>();
  1306. List<SmartUser> result = new ArrayList<>();
  1307. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  1308. List<SmartDepartment> departments = smartDepartmentService.list(null);
  1309. List<SmartGrade> grades = smartGradeService.list(null); //年级
  1310. List<SmartClass> classs = smartClassService.list(null);//班级
  1311. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  1312. //读取第一张sheet
  1313. HSSFSheet sheetAt = sheets.getSheetAt(0);
  1314. DataFormatter dataFormatter = new DataFormatter();
  1315. //region 判断是老师还是学生导入
  1316. boolean isTeacher = false;
  1317. HSSFRow checkRow = sheetAt.getRow(0);
  1318. if (checkRow != null) {
  1319. String firstCow = dataFormatter.formatCellValue(checkRow.getCell(0));//第一列 学生是年级 老师是 学校名称
  1320. if (firstCow.equals("学校名称")) {
  1321. isTeacher = true;
  1322. }
  1323. }
  1324. //endregion
  1325. try {
  1326. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  1327. HSSFRow row = sheetAt.getRow(rowNum);
  1328. if (row != null) {
  1329. if (!isTeacher) {
  1330. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1331. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1332. //然后poi会根据字符串读取它
  1333. //标题 校验
  1334. if (rowNum == 0) {
  1335. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  1336. if (!schoolGrade.equals("年级")) {
  1337. return CommonResult.fail("导入数据第一列为年级");
  1338. }
  1339. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1340. if (!schoolClass.equals("班级")) {
  1341. return CommonResult.fail("导入数据第一列为班级");
  1342. }
  1343. String cardNo = dataFormatter.formatCellValue(row.getCell(2));//学号
  1344. if (!cardNo.equals("学号")) {
  1345. return CommonResult.fail("导入数据第二列为学号");
  1346. }
  1347. String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
  1348. if (!name.equals("姓名")) {
  1349. return CommonResult.fail("导入数据第三列为姓名");
  1350. }
  1351. String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
  1352. if (!sex.equals("性别")) {
  1353. return CommonResult.fail("导入数据第四列为性别");
  1354. }
  1355. String nation = dataFormatter.formatCellValue(row.getCell(5));//民族
  1356. if (!nation.equals("民族")) {
  1357. return CommonResult.fail("导入数据第五列为民族");
  1358. }
  1359. String cardId = dataFormatter.formatCellValue(row.getCell(6));//身份证
  1360. if (!cardId.equals("身份证")) {
  1361. return CommonResult.fail("导入数据第六列为身份证");
  1362. }
  1363. String headImage = dataFormatter.formatCellValue(row.getCell(7));//照片
  1364. if (!headImage.equals("照片")) {
  1365. return CommonResult.fail("导入数据第七列为照片");
  1366. }
  1367. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));//常规时间组
  1368. if (!timeGroup.equals("常规时间组")) {
  1369. return CommonResult.fail("导入数据第八列为常规时间组");
  1370. }
  1371. String address = dataFormatter.formatCellValue(row.getCell(9));//住址
  1372. if (!address.equals("住址")) {
  1373. return CommonResult.fail("导入数据第九列为住址");
  1374. }
  1375. String phone = dataFormatter.formatCellValue(row.getCell(10));//联系电话
  1376. if (!phone.equals("联系电话")) {
  1377. return CommonResult.fail("导入数据第十列为联系电话");
  1378. }
  1379. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  1380. if (!family.equals("家属")) {
  1381. return CommonResult.fail("导入数据第十一列为家属");
  1382. }
  1383. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  1384. if (!familyShip.equals("家属与本人关系")) {
  1385. return CommonResult.fail("导入数据第十二列为家属与本人关系");
  1386. }
  1387. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  1388. if (!phoneTwo.equals("联系电话2")) {
  1389. return CommonResult.fail("导入数据第十三列为联系电话2");
  1390. }
  1391. String familyTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  1392. if (!familyTwo.equals("家属2")) {
  1393. return CommonResult.fail("导入数据第十四列为家属2");
  1394. }
  1395. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  1396. if (!familyShipTwo.equals("家属与本人关系2")) {
  1397. return CommonResult.fail("导入数据第十五列为家属与本人关系2");
  1398. }
  1399. } else {
  1400. SmartUser user = new SmartUser();
  1401. String name = dataFormatter.formatCellValue(row.getCell(3));
  1402. // if (ObjectUtils.isEmpty(name)) {
  1403. // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
  1404. // }
  1405. if (ObjectUtils.isEmpty(name)) {
  1406. continue;
  1407. }
  1408. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  1409. if (ObjectUtils.isEmpty(schoolGrade)) {
  1410. return CommonResult.fail(name + "的年级不能为空");
  1411. }
  1412. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1413. if (ObjectUtils.isEmpty(schoolClass)) {
  1414. return CommonResult.fail(name + "的班级不能为空");
  1415. }
  1416. //不判断重复性 因为会出现双胞胎
  1417. String phone = dataFormatter.formatCellValue(row.getCell(10));
  1418. // if (!ObjectUtils.isEmpty(phone)) {
  1419. // phones.add(phone);
  1420. // }
  1421. // if (phones.stream().distinct().count() != phones.size()) {
  1422. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  1423. // }
  1424. //性别是否为空判断
  1425. String sex = dataFormatter.formatCellValue(row.getCell(4));
  1426. if (ObjectUtils.isEmpty(sex)) {
  1427. return CommonResult.fail(name + "的性别不能为空");
  1428. }
  1429. //家庭住址是否为空判断
  1430. String address = dataFormatter.formatCellValue(row.getCell(9));
  1431. //民族是否为空判断
  1432. String nation = dataFormatter.formatCellValue(row.getCell(5));
  1433. if (ObjectUtils.isEmpty(nation)) {
  1434. return CommonResult.fail(name + "的民族不能为空");
  1435. }
  1436. //部门是否为空判断
  1437. String department = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "学生";
  1438. if (ObjectUtils.isEmpty(department)) {
  1439. return CommonResult.fail(name + "的部门不能为空");
  1440. }
  1441. Integer departmentId = null;
  1442. Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst();
  1443. if (departModel != null && departModel.isPresent()) {
  1444. departmentId = departModel.get().getId();
  1445. } else {
  1446. departmentId = 1;
  1447. }
  1448. //学号重复判断
  1449. String cardNo = dataFormatter.formatCellValue(row.getCell(2));
  1450. if (!ObjectUtils.isEmpty(cardNo)) {
  1451. cardNos.add(cardNo);
  1452. }
  1453. if (cardNos.stream().distinct().count() != cardNos.size()) {
  1454. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  1455. }
  1456. //身份证重复判断
  1457. String idCard = dataFormatter.formatCellValue(row.getCell(6));
  1458. if (!ObjectUtils.isEmpty(idCard)) {
  1459. idCards.add(idCard);
  1460. }
  1461. if (idCards.stream().distinct().count() != idCards.size()) {
  1462. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  1463. }
  1464. user.setCardNo(cardNo == null ? "" : cardNo);
  1465. user.setName(name == null ? "" : name);
  1466. user.setIdentityId(eIdentityStatu.Student.getValue());
  1467. user.setIdCard(idCard == null ? "" : idCard);
  1468. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1469. user.setDepartmentId(departmentId);
  1470. String cellImage = dataFormatter.formatCellValue(row.getCell(7));
  1471. user.setHeadImage(cellImage);
  1472. user.setDormitoryNumber("");
  1473. String grade = schoolGrade == null ? "" : schoolGrade;
  1474. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  1475. if (oGrade != null && oGrade.isPresent()) {
  1476. Integer gradeId = oGrade.get().getId();
  1477. user.setGrade(String.valueOf(gradeId));
  1478. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  1479. if (oClass != null && oClass.isPresent()) {
  1480. user.setSchoolClass(oClass.get().getId());
  1481. } else {
  1482. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1483. }
  1484. } else {
  1485. return CommonResult.fail(name + "的年级数据无效,导入失败");
  1486. }
  1487. user.setCollege("");
  1488. user.setSpeciality("");
  1489. user.setCampus("");
  1490. user.setPhone("");
  1491. user.setAffiliate("");
  1492. user.setTitle("");
  1493. user.setAddress(address == null ? "" : address);
  1494. user.setNation(nation == null ? "" : nation);
  1495. user.setOfStudent("");
  1496. user.setGraduate("");
  1497. user.setDuties(null);
  1498. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));
  1499. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1500. if (groupData != null && groupData.isPresent()) {
  1501. user.setTimeGroupId(groupData.get().getId());
  1502. } else {
  1503. user.setTimeGroupId(0);
  1504. }
  1505. user.setIsCancel(eLogOff.Unlogout.getValue());
  1506. result.add(user);
  1507. //部门是否为空判断
  1508. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  1509. Integer familyDepartmentId = null;
  1510. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  1511. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  1512. familyDepartmentId = familyDepartModel.get().getId();
  1513. } else {
  1514. familyDepartmentId = 16;
  1515. }
  1516. //region 家属
  1517. if (!ObjectUtils.isEmpty(phone)) {
  1518. if (phone.length() != 11) {
  1519. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1520. }
  1521. SmartUser familyOne = new SmartUser();
  1522. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  1523. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  1524. familyOne.setDepartmentId(familyDepartmentId);
  1525. familyOne.setPhone(phone);
  1526. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  1527. familyOne.setSexId(eSexStatu.Man.getValue());
  1528. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  1529. familyOne.setAffiliate(user.getCardNo());
  1530. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  1531. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  1532. result.add(familyOne);
  1533. }
  1534. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  1535. if (!ObjectUtils.isEmpty(phoneTwo)) {
  1536. if (phoneTwo.length() != 11) {
  1537. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1538. }
  1539. SmartUser familyTwo = new SmartUser();
  1540. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  1541. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  1542. familyTwo.setDepartmentId(familyDepartmentId);
  1543. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  1544. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  1545. familyTwo.setSexId(eSexStatu.Man.getValue());
  1546. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  1547. familyTwo.setAffiliate(user.getCardNo());
  1548. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  1549. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  1550. result.add(familyTwo);
  1551. }
  1552. //endregion
  1553. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  1554. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(13)))) {
  1555. if (phone.equals(dataFormatter.formatCellValue(row.getCell(13)))) {
  1556. return CommonResult.fail(name + "的学生家长手机号不可重复");
  1557. }
  1558. }
  1559. //endregion
  1560. }
  1561. } else {
  1562. //教师导入
  1563. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1564. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1565. //然后poi会根据字符串读取它
  1566. //标题 校验
  1567. if (rowNum == 0) {
  1568. String schoolName = dataFormatter.formatCellValue(row.getCell(0));//学校名称
  1569. if (!schoolName.equals("学校名称")) {
  1570. return CommonResult.fail("导入数据第一列为学校名称");
  1571. }
  1572. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1573. if (!departmentNo.equals("部门编码")) {
  1574. return CommonResult.fail("导入数据第二列为部门编码");
  1575. }
  1576. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1577. if (!departmentName.equals("部门名称")) {
  1578. return CommonResult.fail("导入数据第三列为部门名称");
  1579. }
  1580. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1581. if (!teacherNo.equals("教师编码")) {
  1582. return CommonResult.fail("导入数据第四列为教师编码");
  1583. }
  1584. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1585. if (!name.equals("姓名")) {
  1586. return CommonResult.fail("导入数据第五列为姓名");
  1587. }
  1588. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1589. if (!sex.equals("性别")) {
  1590. return CommonResult.fail("导入数据第六列为性别");
  1591. }
  1592. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1593. if (!phone.equals("联系电话")) {
  1594. return CommonResult.fail("导入数据第七列为联系电话");
  1595. }
  1596. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//管理班级
  1597. if (!schoolClass.equals("管理班级")) {
  1598. return CommonResult.fail("导入数据第八列为身份证");
  1599. }
  1600. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1601. if (!nation.equals("民族")) {
  1602. return CommonResult.fail("导入数据第九列为民族");
  1603. }
  1604. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1605. if (!card.equals("身份证(允许为空)")) {
  1606. return CommonResult.fail("导入数据第十列为身份证");
  1607. }
  1608. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1609. if (!photo.equals("照片")) {
  1610. return CommonResult.fail("导入数据第十一列为照片");
  1611. }
  1612. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1613. if (!timeGroup.equals("常规时间组")) {
  1614. return CommonResult.fail("导入数据第十二列为常规时间组");
  1615. }
  1616. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1617. if (!address.equals("住址")) {
  1618. return CommonResult.fail("导入数据第十三列为住址");
  1619. }
  1620. } else {
  1621. SmartUser user = new SmartUser();
  1622. user.setIdentityId(eIdentityStatu.Teacher.getValue());
  1623. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1624. if (ObjectUtils.isEmpty(name)) {
  1625. continue;
  1626. }
  1627. user.setName(name);
  1628. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1629. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1630. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1631. if (ObjectUtils.isEmpty(departmentName)) {
  1632. return CommonResult.fail(name + "的部门名称不能为空");
  1633. }
  1634. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1635. if (ObjectUtils.isEmpty(departmentNo)) {
  1636. return CommonResult.fail(name + "的部门编码不能为空");
  1637. }
  1638. Optional<SmartDepartment> oDepartment = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  1639. if (!(oDepartment != null && oDepartment.isPresent())) {
  1640. return CommonResult.fail(departmentName + "部门数据在系统中不存在");
  1641. }
  1642. user.setDepartmentId(oDepartment.get().getId());
  1643. if (departmentName.equals("班主任")) {
  1644. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//班级
  1645. if (ObjectUtils.isEmpty(schoolClass)) {
  1646. return CommonResult.fail(name + "的管理班级不能为空");
  1647. }
  1648. //班级和年级
  1649. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  1650. if (!(oClass != null && oClass.isPresent())) {
  1651. return CommonResult.fail(schoolClass + "的班级数据在系统中不存在");
  1652. }
  1653. user.setSchoolClass(oClass.get().getId());
  1654. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  1655. user.setDuties(eDuties.ClassTeacher.getValue());
  1656. } else {
  1657. user.setDuties(5);//任课老师
  1658. }
  1659. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1660. if (!ObjectUtils.isEmpty(teacherNo)) {
  1661. user.setBsStaffCode(teacherNo);
  1662. }
  1663. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1664. if (ObjectUtils.isEmpty(phone)) {
  1665. return CommonResult.fail(name + "的手机号不能为空");
  1666. }
  1667. user.setCardNo(phone);
  1668. user.setPhone(phone);
  1669. user.setXwTeacherCode(phone);
  1670. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1671. if (!ObjectUtils.isEmpty(nation)) {
  1672. user.setNation(nation);
  1673. }
  1674. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1675. if (!ObjectUtils.isEmpty(card)) {
  1676. user.setIdCard(card);
  1677. }
  1678. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1679. if (!ObjectUtils.isEmpty(photo)) {
  1680. user.setHeadImage(photo);
  1681. }
  1682. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1683. if (!ObjectUtils.isEmpty(timeGroup)) {
  1684. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1685. if (groupData != null && groupData.isPresent()) {
  1686. user.setTimeGroupId(groupData.get().getId());
  1687. }
  1688. }
  1689. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1690. if (!ObjectUtils.isEmpty(address)) {
  1691. user.setAddress(address);
  1692. }
  1693. user.setIsCancel(eLogOff.Unlogout.getValue());
  1694. result.add(user);
  1695. }
  1696. }
  1697. }
  1698. }
  1699. } catch (Exception e) {
  1700. return CommonResult.fail("请按模板格式导入数据");
  1701. }
  1702. return CommonResult.ok(result);
  1703. }
  1704. //endregion
  1705. //endregion
  1706. //region 批量更新用户
  1707. //region 批量更新用户方法
  1708. /**
  1709. * 只更新 姓名 班级 时间组
  1710. *
  1711. * @param excelFile excel文件
  1712. * @return
  1713. * @throws IOException
  1714. */
  1715. @Override
  1716. public CommonResult importExcelUpdateUsers(MultipartFile excelFile) throws Exception {
  1717. List<SmartUser> result = new ArrayList<>();
  1718. int useXw = 1;
  1719. int useBs = 1;
  1720. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  1721. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  1722. return CommonResult.fail("excel文件不能为空");
  1723. }
  1724. String ContentType = excelFile.getContentType();
  1725. InputStream inputStream = excelFile.getInputStream();
  1726. //xls格式文件
  1727. if (ContentType.equals(eFileType.Xls.getValue())) {
  1728. CommonResult<List<SmartUser>> resultData = readUpdateXls(inputStream);
  1729. if (!resultData.isSuccess()) {
  1730. return resultData;
  1731. }
  1732. result = resultData.getData();
  1733. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  1734. CommonResult<List<SmartUser>> resultData = readUpdateXlsx(inputStream);
  1735. if (!resultData.isSuccess()) {
  1736. return resultData;
  1737. }
  1738. result = resultData.getData();
  1739. } else {
  1740. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  1741. }
  1742. //获取导入学生的相关数据
  1743. List<String> cardNos = result.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  1744. if (cardNos == null) {
  1745. return CommonResult.fail("文档内容为空,批量更新失败");
  1746. }
  1747. List<SmartGrade> grades = smartGradeService.list(null);
  1748. List<SmartUser> studentDatas = smartUserService.querySmartUserByCardNos(cardNos);
  1749. List<SmartClass> classes = smartClassService.list(null);
  1750. List<SmartUser> updateStudent = new ArrayList<>();
  1751. for (SmartUser studentData : result) {
  1752. Optional<SmartUser> oldStudent = studentDatas.stream().filter(e -> e.getCardNo().equals(studentData.getCardNo())).findFirst();
  1753. if (oldStudent != null && oldStudent.isPresent()) {
  1754. oldStudent.get().setName(studentData.getName());//姓名
  1755. oldStudent.get().setSchoolClass(studentData.getSchoolClass());//班级
  1756. oldStudent.get().setGrade(studentData.getGrade());//可能会变年级
  1757. oldStudent.get().setTimeGroupId(studentData.getTimeGroupId());//时间组
  1758. updateStudent.add(oldStudent.get());
  1759. Optional<SmartGrade> oGrade = grades.stream().filter(e -> String.valueOf(e.getId()).equals(studentData.getGrade())).findFirst();
  1760. if (oGrade != null && oGrade.isPresent()) {
  1761. Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(studentData.getSchoolClass())).findFirst();
  1762. if (oClass != null && oClass.isPresent()) {
  1763. if (useXw == 1) {
  1764. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1765. CommonResult updateSwStudent = SeewoUpdateStudent(seewoClient, oldStudent.get());
  1766. if (!updateSwStudent.isSuccess()) {
  1767. return CommonResult.fail("希沃平台:" + updateSwStudent.getMessage());
  1768. }
  1769. }
  1770. if (useBs == 1) {
  1771. /**
  1772. * 学生数据的有效期是到毕业年份的8月31日
  1773. */
  1774. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1775. String endTime = queryGraduationYear(oGrade.get().getGradeNo());
  1776. CommonResult<String> updateBsStudent = bsEUpdateStudent(oldStudent.get(), oClass.get().getBsClassNo(), startTime, endTime);
  1777. if (!updateBsStudent.isSuccess()) {
  1778. return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
  1779. }
  1780. }
  1781. } else {
  1782. return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的班级数据无效,无法进行更新操作");
  1783. }
  1784. } else {
  1785. return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的年级数据无效,无法进行更新操作");
  1786. }
  1787. } else {
  1788. return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的数据在系统中不存在,无法进行更新操作");
  1789. }
  1790. }
  1791. if (updateStudent != null && updateStudent.size() > 0) {
  1792. boolean updateBatch = smartUserService.updateUserBatchById(updateStudent);
  1793. if (!updateBatch) {
  1794. return CommonResult.fail("系统批量更新出错,导入失败");
  1795. } else {
  1796. // 修改需同步到海康平台
  1797. for (SmartUser su : updateStudent) {
  1798. Integer identityId = su.getIdentityId();
  1799. if (2 == identityId || identityId == 3) {
  1800. Integer id = su.getId();
  1801. SmartOperationUser smartOperationUser = new SmartOperationUser();
  1802. smartOperationUser.setOperationId(id);
  1803. smartOperationUser.setOperationMode("2");
  1804. smartOperationUser.setStatus(1);
  1805. smartOperationUser.setType(identityId);
  1806. smartOperationUserService.save(smartOperationUser);
  1807. }
  1808. }
  1809. }
  1810. }
  1811. return CommonResult.ok("导入成功");
  1812. }
  1813. //endregion
  1814. //region Xls文件读取方法
  1815. /**
  1816. * Xls文件读取方法
  1817. *
  1818. * @param inputStream 文件流
  1819. * @return
  1820. * @throws IOException
  1821. */
  1822. private CommonResult<List<SmartUser>> readUpdateXls(InputStream inputStream) throws IOException {
  1823. List<SmartUser> result = new ArrayList<>();
  1824. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  1825. List<SmartClass> classs = smartClassService.list(null);//班级
  1826. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  1827. //读取第一张sheet
  1828. HSSFSheet sheetAt = sheets.getSheetAt(0);
  1829. DataFormatter dataFormatter = new DataFormatter();
  1830. try {
  1831. for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  1832. HSSFRow row = sheetAt.getRow(rowNum);
  1833. if (row != null) {
  1834. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1835. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1836. //然后poi会根据字符串读取它
  1837. //标题 校验
  1838. if (rowNum == 1) {
  1839. String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
  1840. if (!xwNo.equals("希沃编号")) {
  1841. return CommonResult.fail("导入数据第二列为希沃编号");
  1842. }
  1843. String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
  1844. if (!bsNo.equals("百胜编号")) {
  1845. return CommonResult.fail("导入数据第三列为百胜编号");
  1846. }
  1847. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  1848. if (!cardNo.equals("学号")) {
  1849. return CommonResult.fail("导入数据第四列为学号");
  1850. }
  1851. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1852. if (!name.equals("姓名")) {
  1853. return CommonResult.fail("导入数据第五列为姓名");
  1854. }
  1855. String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
  1856. if (!schoolClass.equals("班级")) {
  1857. return CommonResult.fail("导入数据第六列为班级");
  1858. }
  1859. String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
  1860. if (!group.equals("时间组")) {
  1861. return CommonResult.fail("导入数据第七列为时间组");
  1862. }
  1863. } else {
  1864. SmartUser user = new SmartUser();
  1865. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1866. if (ObjectUtils.isEmpty(name)) {
  1867. return CommonResult.fail("第" + (rowNum) + "条数据的名称不能为空");
  1868. }
  1869. String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
  1870. if (ObjectUtils.isEmpty(xwNo)) {
  1871. return CommonResult.fail(name + "的希沃编号不能为空");
  1872. }
  1873. String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
  1874. if (ObjectUtils.isEmpty(bsNo)) {
  1875. return CommonResult.fail(name + "的百胜编号不能为空");
  1876. }
  1877. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  1878. if (ObjectUtils.isEmpty(cardNo)) {
  1879. return CommonResult.fail(name + "的学号不能为空");
  1880. }
  1881. String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
  1882. if (ObjectUtils.isEmpty(schoolClass)) {
  1883. return CommonResult.fail(name + "的班级不能为空");
  1884. }
  1885. String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
  1886. if (ObjectUtils.isEmpty(group)) {
  1887. return CommonResult.fail(name + "的时间组不能为空");
  1888. }
  1889. user.setCardNo(cardNo == null ? "" : cardNo);
  1890. user.setName(name == null ? "" : name);
  1891. user.setIdentityId(eIdentityStatu.Student.getValue());
  1892. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  1893. if (oClass != null && oClass.isPresent()) {
  1894. user.setSchoolClass(oClass.get().getId());
  1895. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  1896. } else {
  1897. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1898. }
  1899. Optional<SmartTimeGroup> oGroup = timeGroups.stream().filter(e -> e.getName().equals(group)).findFirst();
  1900. if (oGroup != null && oGroup.isPresent()) {
  1901. user.setTimeGroupId(oGroup.get().getId());
  1902. }
  1903. result.add(user);
  1904. }
  1905. }
  1906. }
  1907. } catch (Exception e) {
  1908. return CommonResult.fail("请按模板格式导入数据");
  1909. }
  1910. return CommonResult.ok(result);
  1911. }
  1912. //endregion
  1913. //region Xlsx文件读取方法
  1914. /**
  1915. * Xlsx文件读取方法
  1916. *
  1917. * @param inputStream 文件流
  1918. * @return
  1919. * @throws IOException
  1920. */
  1921. private CommonResult<List<SmartUser>> readUpdateXlsx(InputStream inputStream) throws IOException {
  1922. List<SmartUser> result = new ArrayList<>();
  1923. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  1924. List<SmartClass> classs = smartClassService.list(null);//班级
  1925. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  1926. //读取第一张sheet
  1927. XSSFSheet sheetAt = sheets.getSheetAt(0);
  1928. DataFormatter dataFormatter = new DataFormatter();
  1929. try {
  1930. for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  1931. XSSFRow row = sheetAt.getRow(rowNum);
  1932. if (row != null) {
  1933. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1934. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1935. //然后poi会根据字符串读取它
  1936. //标题 校验
  1937. if (rowNum == 1) {
  1938. String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
  1939. if (!xwNo.equals("希沃编号")) {
  1940. return CommonResult.fail("导入数据第二列为希沃编号");
  1941. }
  1942. String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
  1943. if (!bsNo.equals("百胜编号")) {
  1944. return CommonResult.fail("导入数据第三列为百胜编号");
  1945. }
  1946. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  1947. if (!cardNo.equals("学号")) {
  1948. return CommonResult.fail("导入数据第四列为学号");
  1949. }
  1950. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1951. if (!name.equals("姓名")) {
  1952. return CommonResult.fail("导入数据第五列为姓名");
  1953. }
  1954. String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
  1955. if (!schoolClass.equals("班级")) {
  1956. return CommonResult.fail("导入数据第六列为班级");
  1957. }
  1958. String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
  1959. if (!group.equals("时间组")) {
  1960. return CommonResult.fail("导入数据第七列为时间组");
  1961. }
  1962. } else {
  1963. SmartUser user = new SmartUser();
  1964. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1965. if (ObjectUtils.isEmpty(name)) {
  1966. return CommonResult.fail("第" + (rowNum) + "条数据的名称不能为空");
  1967. }
  1968. String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
  1969. if (ObjectUtils.isEmpty(xwNo)) {
  1970. return CommonResult.fail(name + "的希沃编号不能为空");
  1971. }
  1972. String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
  1973. if (ObjectUtils.isEmpty(bsNo)) {
  1974. return CommonResult.fail(name + "的百胜编号不能为空");
  1975. }
  1976. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  1977. if (ObjectUtils.isEmpty(cardNo)) {
  1978. return CommonResult.fail(name + "的学号不能为空");
  1979. }
  1980. String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
  1981. if (ObjectUtils.isEmpty(schoolClass)) {
  1982. return CommonResult.fail(name + "的班级不能为空");
  1983. }
  1984. String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
  1985. if (ObjectUtils.isEmpty(group)) {
  1986. return CommonResult.fail(name + "的时间组不能为空");
  1987. }
  1988. user.setCardNo(cardNo == null ? "" : cardNo);
  1989. user.setName(name == null ? "" : name);
  1990. user.setIdentityId(eIdentityStatu.Student.getValue());
  1991. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  1992. if (oClass != null && oClass.isPresent()) {
  1993. user.setSchoolClass(oClass.get().getId());
  1994. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  1995. } else {
  1996. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1997. }
  1998. Optional<SmartTimeGroup> oGroup = timeGroups.stream().filter(e -> e.getName().equals(group)).findFirst();
  1999. if (oGroup != null && oGroup.isPresent()) {
  2000. user.setTimeGroupId(oGroup.get().getId());
  2001. }
  2002. result.add(user);
  2003. }
  2004. }
  2005. }
  2006. } catch (Exception e) {
  2007. return CommonResult.fail("请按模板格式导入数据");
  2008. }
  2009. return CommonResult.ok(result);
  2010. }
  2011. //endregion
  2012. //endregion
  2013. //region 时间组数据集合
  2014. @Override
  2015. @DESRespondSecret(validated = true)
  2016. public CommonResult timeGroups() throws Exception {
  2017. List<TimeGroupVo> result = new ArrayList<>();
  2018. //region 获取百胜的时间组
  2019. String appId = controlConfig.getAppId();
  2020. String schoolno = controlConfig.getSchoolCode();
  2021. String timestamp = TimeExchange.DateNowTimeStamo();
  2022. String appSecret = controlConfig.getAppSecret();
  2023. String url = controlConfig.getUrl() + "timegroup/searchtimegroup";
  2024. JSONObject jsonobject = new JSONObject();
  2025. jsonobject.put("appid", appId);
  2026. String str = "{\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}";
  2027. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2028. jsonobject.put("data", aesStr);
  2029. jsonobject.put("schoolno", schoolno);
  2030. jsonobject.put("timestamp", timestamp);
  2031. String md5Str = "appid=" + appId + "&data={\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  2032. String sign = CommonUtil.MD5(md5Str);
  2033. //sign签名
  2034. jsonobject.put("sign", sign);
  2035. //返回的结果中 code为1表示成功
  2036. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2037. ObjectMapper objectMapper = new ObjectMapper();
  2038. BsTimeGroupVo bsDataResult = objectMapper.readValue(bsResult, BsTimeGroupVo.class);
  2039. if (!bsResult.contains("查询成功")) {
  2040. return CommonResult.fail(bsDataResult.getMsg());
  2041. }
  2042. // URL解码
  2043. String decodedUrl = URLDecoder.decode(bsDataResult.getData(), "UTF-8");
  2044. BsTimeGroupNoVo timeGroupNos = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsTimeGroupNoVo.class);
  2045. //endregion
  2046. List<SmartTimeGroup> groups = smartTimeGroupService.queryTimeGroups();
  2047. List<SmartTimeGroup> newGroups = new ArrayList<>();
  2048. List<SmartTimeGroup> oldGroups = new ArrayList<>();
  2049. if (timeGroupNos.getData() != null) {
  2050. for (BsTimeGroupNoListVo timeGroup : timeGroupNos.getData()) {
  2051. Optional<SmartTimeGroup> oGroup = groups == null ? null : groups.stream().filter(e -> e.getBsno().equals(timeGroup.getTg_no())).findFirst();
  2052. if (oGroup != null && oGroup.isPresent()) {
  2053. SmartTimeGroup oldData = new SmartTimeGroup();
  2054. oldData.setId(oGroup.get().getId());
  2055. oldData.setBsno(timeGroup.getTg_no());
  2056. oldData.setName(timeGroup.getTg_name());
  2057. oldData.setRemark(timeGroup.getTg_remark());
  2058. oldGroups.add(oldData);
  2059. } else {
  2060. SmartTimeGroup newData = new SmartTimeGroup();
  2061. newData.setBsno(timeGroup.getTg_no());
  2062. newData.setName(timeGroup.getTg_name());
  2063. newData.setRemark(timeGroup.getTg_remark());
  2064. newGroups.add(newData);
  2065. }
  2066. }
  2067. }
  2068. if (oldGroups != null && oldGroups.size() > 0) {
  2069. boolean updateGroup = smartTimeGroupService.updateSmartTimeGroups(oldGroups);
  2070. if (!updateGroup) {
  2071. return CommonResult.fail("获取时间组失败");
  2072. }
  2073. }
  2074. if (newGroups != null && newGroups.size() > 0) {
  2075. boolean insertGroup = smartTimeGroupService.insertSmartTimeGroups(newGroups);
  2076. if (!insertGroup) {
  2077. return CommonResult.fail("获取时间组失败");
  2078. }
  2079. }
  2080. //oldData集合不在newDatas集合中的内容
  2081. List<Integer> newDatas = oldGroups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
  2082. List<Integer> oldDatas = groups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
  2083. List<Integer> deleteIds = oldDatas.stream().filter(item -> !newDatas.contains(item)).collect(Collectors.toList());//需要删除的id
  2084. if (deleteIds.size() > 0) {
  2085. int deleted = smartTimeGroupService.deletedTimeGroupByIds(deleteIds);
  2086. if (deleted <= 0) {
  2087. throw new Exception("获取时间组失败!");
  2088. }
  2089. }
  2090. List<SmartTimeGroup> groupDatas = smartTimeGroupService.queryTimeGroups();
  2091. for (SmartTimeGroup groupData : groupDatas) {
  2092. TimeGroupVo data = new TimeGroupVo();
  2093. data.setId(groupData.getId());
  2094. data.setName(groupData.getName());
  2095. data.setRemark(groupData.getRemark());
  2096. result.add(data);
  2097. }
  2098. return CommonResult.ok(result);
  2099. }
  2100. //endregion
  2101. //region 新增用户
  2102. /**
  2103. * 新增用户
  2104. *
  2105. * @param isur 用户数据
  2106. * @param bindingResult
  2107. * @return
  2108. */
  2109. @Override
  2110. @DESRespondSecret(validated = true)
  2111. public CommonResult insertSmartUser(insertSmartUserRequest isur, BindingResult bindingResult) throws Exception {
  2112. if (bindingResult.hasErrors()) {
  2113. String st = paramUtils.getParamError(bindingResult);
  2114. return CommonResult.fail(st);
  2115. }
  2116. int useBs = 1;
  2117. int useXw = 1;
  2118. SmartGrade gradeData = null;
  2119. SmartClass classData = null;
  2120. if (org.springframework.util.StringUtils.hasText(isur.getCardNo())) {
  2121. //重复性判断
  2122. int existCount = smartUserService.querySmartUserByCardNo(isur.getCardNo());
  2123. if (existCount > 0) {
  2124. return CommonResult.fail("当前学号已存在,请勿重复添加");
  2125. }
  2126. }
  2127. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2128. SmartUser su = new SmartUser();
  2129. su.setTimeGroupId(isur.getTimeGroupId());
  2130. su.setCardNo(isur.getCardNo());
  2131. su.setName(isur.getName());
  2132. su.setIdentityId(isur.getIdentityId());
  2133. su.setIdCard(isur.getIdCard());
  2134. su.setSexId(isur.getSexId());
  2135. su.setDepartmentId(isur.getDepartmentId());
  2136. su.setHeadImage(isur.getHeadImage());
  2137. su.setGrade(isur.getGrade());
  2138. su.setCollege(isur.getCollege());
  2139. su.setSpeciality(isur.getSpeciality());
  2140. su.setSchoolClass(isur.getSchoolClass());
  2141. su.setCampus(isur.getCampus());
  2142. su.setDormitoryNumber(isur.getDormitoryNumber());
  2143. su.setPhone(isur.getPhone());
  2144. su.setAffiliate(StringUtils.join(isur.getAffiliate(), ","));
  2145. su.setTitle(isur.getTitle());
  2146. su.setAddress(isur.getAddress());
  2147. su.setNation(isur.getNation());
  2148. su.setOfStudent(isur.getOfStudent());
  2149. su.setGraduate(isur.getGraduate());
  2150. su.setDuties(isur.getDuties());
  2151. su.setIsCancel(eLogOff.Unlogout.getValue());
  2152. //region 人员信息加入到第三方api
  2153. //要将用户数据加入到希沃和百胜中
  2154. //希沃和百胜的老师、学生数据添加是不一样的,所以按身份添加
  2155. if (isur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  2156. //region 家长参数必填判断:手机号
  2157. if (isur.getPhone() == null) {
  2158. return CommonResult.fail("家长手机号不能为空");
  2159. }
  2160. //endregion
  2161. //拿到被关联学生的信息去获取对应的卡号
  2162. //有多个学生就循环学生
  2163. if (isur.getAffiliate() == null) {
  2164. return CommonResult.fail("被关联人不能为空");
  2165. }
  2166. if (isur.getAffiliate().size() <= 0) {
  2167. return CommonResult.fail("被关联人不能为空");
  2168. }
  2169. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(isur.getAffiliate());
  2170. //region 希沃新增编辑学生家长信息
  2171. if (useXw == 1) {
  2172. CommonResult insertOrUpdateStudent = insertOrUpdateStudentParent(seewoClient, studentDatas, isur.getName(), isur.getPhone(), true);
  2173. if (!insertOrUpdateStudent.isSuccess()) {
  2174. return CommonResult.fail("希沃平台:" + insertOrUpdateStudent.getMessage());
  2175. }
  2176. }
  2177. //endregion
  2178. } else if (isur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  2179. //region 学生参数必填判断:年级、班级
  2180. if (isur.getGrade() == null) {
  2181. return CommonResult.fail("学生年级不能为空");
  2182. }
  2183. if (isur.getSchoolClass() == null) {
  2184. return CommonResult.fail("学生班级不能为空");
  2185. }
  2186. //endregion
  2187. //获取班级Uid
  2188. classData = smartClassService.getSmartClassById(isur.getSchoolClass());
  2189. if (classData == null) {
  2190. return CommonResult.fail("班级数据无效,新增失败");
  2191. }
  2192. gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(isur.getGrade()));
  2193. if (gradeData == null) {
  2194. return CommonResult.fail("年级数据无效,新增失败");
  2195. }
  2196. //region 希沃新增学生信息
  2197. if (useXw == 1) {
  2198. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getPhone(), classData.getClassUid());
  2199. if (!insertStudent.isSuccess()) {
  2200. return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
  2201. }
  2202. su.setXwStudentUid(insertStudent.getData());
  2203. //上传图片
  2204. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2205. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2206. photo.setPhotoUrl(su.getHeadImage());
  2207. photo.setUserCode(su.getCardNo());
  2208. photoList.add(photo);
  2209. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  2210. if (!result.isSuccess()) {
  2211. return result;
  2212. }
  2213. }
  2214. //endregion
  2215. //region 百胜新增学生信息
  2216. if (useBs == 1) {
  2217. /**
  2218. * 学生数据的有效期是到毕业年份的8月31日
  2219. */
  2220. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2221. String endTime = queryGraduationYear(gradeData.getGradeNo());
  2222. CommonResult<String> insertBsStudent = bsInsertStudent(isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getHeadImage(), isur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, isur.getIdCard());
  2223. if (!insertBsStudent.isSuccess()) {
  2224. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  2225. }
  2226. su.setBsStudentNo(insertBsStudent.getData());
  2227. }
  2228. //endregion
  2229. } else if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//老师
  2230. //region 老师参数必填判断:职称、手机号
  2231. if (isur.getTitle() == null) {
  2232. return CommonResult.fail("老师职称不能为空");
  2233. }
  2234. if (isur.getPhone() == null) {
  2235. return CommonResult.fail("老师手机号不能为空");
  2236. }
  2237. //endregion
  2238. //region 希沃添加教师数据
  2239. if (useXw == 1) {
  2240. CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, isur.getPhone(), isur.getName(), isur.getHeadImage());
  2241. if (!insertTeacher.isSuccess()) {
  2242. return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
  2243. }
  2244. su.setXwTeacherCode(insertTeacher.getData());
  2245. //上传图片
  2246. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2247. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2248. photo.setPhotoUrl(su.getHeadImage());
  2249. photo.setUserCode(su.getPhone());
  2250. photoList.add(photo);
  2251. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  2252. if (!result.isSuccess()) {
  2253. return result;
  2254. }
  2255. }
  2256. //endregion
  2257. if (isur.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  2258. //获取班级Uid
  2259. classData = smartClassService.getSmartClassById(isur.getSchoolClass());
  2260. if (classData == null) {
  2261. return CommonResult.fail("班级数据无效,新增失败");
  2262. }
  2263. //region 将班主任推送到希沃
  2264. if (useXw == 1) {
  2265. CommonResult pushMaster = SeewoPushMaster(seewoClient, isur.getPhone(), classData.getClassUid());
  2266. if (!pushMaster.isSuccess()) {
  2267. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  2268. }
  2269. }
  2270. //endregion
  2271. }
  2272. SmartDepartment departmentData = smartDepartmentService.getSmartById(isur.getDepartmentId());
  2273. if (departmentData == null) {
  2274. return CommonResult.fail("部门数据无效,新增教师失败");
  2275. }
  2276. String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
  2277. if (departmentNo == null) {
  2278. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  2279. }
  2280. //region 百胜添加教师数据
  2281. if (useBs == 1) {
  2282. /**
  2283. * 教师数据的有效期是20年
  2284. */
  2285. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2286. String endTime = TimeExchange.addYear(20);
  2287. CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
  2288. if (!insertBsTeacher.isSuccess()) {
  2289. return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
  2290. }
  2291. su.setBsStaffCode(insertBsTeacher.getData());
  2292. }
  2293. //endregion
  2294. }
  2295. //endregion
  2296. //最后都要把数据加入到数据库中
  2297. if (org.springframework.util.StringUtils.hasText(isur.getPhone())) {
  2298. //多身份
  2299. List<SmartUser> users = smartUserService.getPhoneUsers(isur.getPhone());
  2300. if (users != null && users.size() > 0) {
  2301. Optional<SmartUser> ownerUser = users.stream().filter(e -> org.springframework.util.StringUtils.hasText(e.getXOpenId())).findFirst();
  2302. if (ownerUser != null && ownerUser.isPresent()) {
  2303. su.setXOpenId(ownerUser.get().getXOpenId());
  2304. }
  2305. }
  2306. }
  2307. int result = smartUserService.insertSmartUser(su);
  2308. if (result > 0) {
  2309. // 将添加的用户同步到海康平台
  2310. Integer identityId = su.getIdentityId();
  2311. if (2 == identityId || identityId == 3) {
  2312. Integer id = su.getId();
  2313. SmartOperationUser smartOperationUser = new SmartOperationUser();
  2314. smartOperationUser.setOperationId(id);
  2315. smartOperationUser.setOperationMode("1");
  2316. smartOperationUser.setStatus(1);
  2317. smartOperationUser.setType(identityId);
  2318. smartOperationUserService.save(smartOperationUser);
  2319. }
  2320. if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue() && isur.getIsr() != null && isur.getIsr().size() > 0) {
  2321. List<SmartTeaching> teachings = new ArrayList<>();
  2322. for (isrRequest sv : isur.getIsr()) {
  2323. if (sv.getIds() != null && sv.getIds().size() > 0) {
  2324. SmartTeaching st = new SmartTeaching();
  2325. st.setUserId(result);
  2326. st.setSubjectId(sv.getIds().size() > 0 ? sv.getIds().get(0) : 0);
  2327. st.setGradeId(sv.getIds().size() > 1 ? sv.getIds().get(1) : 0);
  2328. st.setClassId(sv.getIds().size() > 2 ? sv.getIds().get(2) : 0);
  2329. teachings.add(st);
  2330. }
  2331. }
  2332. if (teachings != null && teachings.size() > 0) {
  2333. boolean insertBatch = smartTeachingService.saveBatch(teachings);
  2334. if (!insertBatch) {
  2335. return CommonResult.fail("任课数据添加失败");
  2336. }
  2337. //region 添加教师综合素质评价
  2338. List<Integer> ids = teachings.stream().map(SmartTeaching::getClassId).collect(Collectors.toList());
  2339. List<SmartClass> classes = smartClassService.getSmartClasss(ids);
  2340. List<Integer> subjectIds = teachings.stream().map(SmartTeaching::getSubjectId).collect(Collectors.toList());
  2341. List<SmartSubject> subjects = smartSubjectService.getSmartSubjectId(subjectIds);
  2342. List<Integer> gradeIds = teachings.stream().map(SmartTeaching::getGradeId).collect(Collectors.toList());
  2343. List<SmartGrade> grades = smartGradeService.queryGradeByIds(gradeIds);
  2344. List<SmartEvaluateTeacher> eTeachers = new ArrayList<>();
  2345. LocalDateTime now = LocalDateTime.now();
  2346. List<SmartSemester> semesters = smartSemesterService.getSemestersByTime(now);
  2347. for (SmartSemester semester : semesters) {
  2348. for (SmartTeaching teacher : teachings) {
  2349. Optional<SmartClass> classTeacherData = classes != null && classes.size() > 0 ?
  2350. classes.stream().filter(e -> e.getId().equals(teacher.getClassId())).findFirst() : null;
  2351. Optional<SmartSubject> subjectData = subjects != null && subjects.size() > 0 ?
  2352. subjects.stream().filter(e -> e.getId().equals(teacher.getSubjectId())).findFirst() : null;
  2353. Optional<SmartGrade> ogradeData = grades != null && grades.size() > 0 ?
  2354. grades.stream().filter(e -> e.getId().equals(teacher.getGradeId())).findFirst() : null;
  2355. SmartEvaluateTeacher set = new SmartEvaluateTeacher();
  2356. set.setCardNo(su.getCardNo());
  2357. set.setName(su.getName());
  2358. set.setUserId(su.getId());
  2359. set.setGradeId(teacher.getGradeId());
  2360. set.setGradeName(ogradeData != null && ogradeData.isPresent() ? ogradeData.get().getName() : "");
  2361. set.setTermId(semester.getId());
  2362. set.setTerm(semester.getName());
  2363. set.setSubjectId(teacher.getSubjectId());
  2364. set.setSubject(subjectData != null && subjectData.isPresent() ? subjectData.get().getName() : "");
  2365. set.setClassId(su.getSchoolClass());
  2366. set.setClassName(classTeacherData != null && classTeacherData.isPresent() ? classTeacherData.get().getName() : "");
  2367. set.setTotalScore(0.0);
  2368. set.setLowingScore(0.0);
  2369. eTeachers.add(set);
  2370. }
  2371. }
  2372. if (eTeachers != null && eTeachers.size() > 0) {
  2373. boolean teacherBatch = smartEvaluateTeacherService.saveBatch(eTeachers);
  2374. if (!teacherBatch) {
  2375. throw new Exception("教师综合评价添加失败!");
  2376. }
  2377. }
  2378. //endregion
  2379. }
  2380. }
  2381. //新增用户得将用户信息通过接口推送到希沃、百胜
  2382. }
  2383. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  2384. }
  2385. //endregion
  2386. //region 更新用户
  2387. /**
  2388. * 更新用户
  2389. *
  2390. * @param usur 更新用户数据
  2391. * @param bindingResult
  2392. * @return
  2393. */
  2394. @Override
  2395. @DESRespondSecret(validated = true)
  2396. public CommonResult updateSmartUserById(updateSmartUserRequest usur, BindingResult bindingResult) throws Exception {
  2397. if (bindingResult.hasErrors()) {
  2398. String st = paramUtils.getParamError(bindingResult);
  2399. return CommonResult.fail(st);
  2400. }
  2401. //region 参数判断
  2402. if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  2403. if (usur.getTimeGroupId() == null) {
  2404. return CommonResult.fail("学生时间组不能为空");
  2405. }
  2406. if (usur.getCardNo() == null) {
  2407. return CommonResult.fail("学生编号不能为空");
  2408. }
  2409. if (usur.getHeadImage() == null) {
  2410. return CommonResult.fail("学生人脸照片不能为空");
  2411. }
  2412. }
  2413. //endregion
  2414. int useXw = 1;
  2415. int useBs = 1;
  2416. //更新的同时将百胜用户信息同步过去或者同步过来?
  2417. SmartUser su = smartUserService.getSmartById(usur.getId());
  2418. if (su == null) {
  2419. return CommonResult.fail("用户数据已失效,修改失败!");
  2420. }
  2421. //是否转换身份
  2422. boolean changeIdentity = false;
  2423. Integer oldIdentity = null;
  2424. String oldAffiliate = su.getAffiliate();
  2425. Integer oldSchoolClass = su.getSchoolClass();
  2426. String oldStaffNo = su.getBsStaffCode();
  2427. String oldCardNo = su.getCardNo();
  2428. if (usur.getIdentityId().intValue() != su.getIdentityId().intValue()) {
  2429. changeIdentity = true;
  2430. oldIdentity = su.getIdentityId().intValue();
  2431. }
  2432. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2433. su.setTimeGroupId(usur.getTimeGroupId());
  2434. su.setCardNo(usur.getCardNo());
  2435. su.setName(usur.getName());
  2436. su.setIdentityId(usur.getIdentityId());
  2437. su.setIdCard(usur.getIdCard());
  2438. su.setSexId(usur.getSexId());
  2439. su.setDepartmentId(usur.getDepartmentId());
  2440. su.setHeadImage(usur.getHeadImage());
  2441. su.setGrade(usur.getGrade());
  2442. su.setCollege(usur.getCollege());
  2443. su.setSpeciality(usur.getSpeciality());
  2444. su.setSchoolClass(usur.getSchoolClass());
  2445. su.setCampus(usur.getCampus());
  2446. su.setDormitoryNumber(usur.getDormitoryNumber());
  2447. su.setPhone(usur.getPhone());
  2448. su.setAffiliate(StringUtils.join(usur.getAffiliate(), ","));
  2449. su.setTitle(usur.getTitle());
  2450. su.setAddress(usur.getAddress());
  2451. su.setNation(usur.getNation());
  2452. su.setOfStudent(usur.getOfStudent());
  2453. su.setGraduate(usur.getGraduate());
  2454. su.setDuties(usur.getDuties());
  2455. su.setIsCancel(eLogOff.Unlogout.getValue());
  2456. if (usur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  2457. //拿到被关联学生的信息去获取对应的卡号
  2458. //有多个学生就循环学生
  2459. if (usur.getAffiliate() == null) {
  2460. return CommonResult.fail("被关联人不能为空");
  2461. }
  2462. if (usur.getAffiliate().size() <= 0) {
  2463. return CommonResult.fail("被关联人不能为空");
  2464. }
  2465. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(usur.getAffiliate());
  2466. if (!changeIdentity) {
  2467. //region 希沃新增编辑学生家长信息
  2468. if (useXw == 1) {
  2469. //学生与家长列表,最大100条
  2470. CommonResult insertOrUpdateResult = insertOrUpdateStudentParent(seewoClient, studentDatas, usur.getName(), usur.getPhone(), false);
  2471. if (!insertOrUpdateResult.isSuccess()) {
  2472. return CommonResult.fail("希沃平台:" + insertOrUpdateResult.getMessage());
  2473. }
  2474. }
  2475. //endregion
  2476. } else {
  2477. if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  2478. //region 希沃删除学生
  2479. //获取班级Uid
  2480. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  2481. if (classData == null) {
  2482. return CommonResult.fail("班级数据无效,更新失败");
  2483. }
  2484. if (useXw == 1) {
  2485. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  2486. if (!deleteStudent.isSuccess()) {
  2487. return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
  2488. }
  2489. }
  2490. //endregion
  2491. //region 百胜删除学生
  2492. if (useBs == 1) {
  2493. CommonResult deleteBsStudent = bsDeleteStudent(su);
  2494. if (!deleteBsStudent.isSuccess()) {
  2495. return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
  2496. }
  2497. }
  2498. //endregion
  2499. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  2500. //获取班级Uid
  2501. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  2502. if (classData == null) {
  2503. return CommonResult.fail("班级数据无效,更新失败");
  2504. }
  2505. //region 希沃删除教师
  2506. if (useXw == 1) {
  2507. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  2508. if (!deleteTeacher.isSuccess()) {
  2509. return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
  2510. }
  2511. }
  2512. //endregion
  2513. //region 希沃删除班主任
  2514. if (useXw == 1) {
  2515. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
  2516. if (deleteTeacherMaster.isSuccess()) {
  2517. return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
  2518. }
  2519. }
  2520. //endregion
  2521. //region 百胜删除教师
  2522. if (useBs == 1) {
  2523. CommonResult bsDeleteTeacher = bsDeleteTeacher(oldStaffNo);
  2524. if (!bsDeleteTeacher.isSuccess()) {
  2525. return CommonResult.fail("百胜平台:" + bsDeleteTeacher.getMessage());
  2526. }
  2527. }
  2528. //endregion
  2529. }
  2530. //region 希沃新增编辑学生家长信息
  2531. if (useXw == 1) {
  2532. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(su.getCardNo());
  2533. if (indexs != null && indexs.size() >= 4) {
  2534. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  2535. }
  2536. CommonResult insertOrUpdate = insertOrUpdateStudentParent(seewoClient, studentDatas, su.getName(), su.getPhone(), true);
  2537. if (!insertOrUpdate.isSuccess()) {
  2538. return CommonResult.fail("希沃平台:" + insertOrUpdate.getMessage());
  2539. }
  2540. }
  2541. //endregion
  2542. }
  2543. } else if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  2544. //region 年级和班级不能为空
  2545. if (usur.getGrade() == null) {
  2546. return CommonResult.fail("学生年级不能为空");
  2547. }
  2548. if (usur.getSchoolClass() == null) {
  2549. return CommonResult.fail("学生班级不能为空");
  2550. }
  2551. //endregion
  2552. //获取班级Uid
  2553. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  2554. if (classData == null) {
  2555. return CommonResult.fail("班级数据无效,更新失败");
  2556. }
  2557. //获取年级Uid
  2558. SmartGrade gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(su.getGrade()));
  2559. if (gradeData == null) {
  2560. return CommonResult.fail("年级数据无效,新增失败");
  2561. }
  2562. if (!changeIdentity) {
  2563. //region 更新希沃学生信息
  2564. if (useXw == 1) {
  2565. CommonResult updateStudent = SeewoUpdateStudent(seewoClient, su);
  2566. if (!updateStudent.isSuccess()) {
  2567. if (updateStudent.getMessage().equals("学生不存在")) {
  2568. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
  2569. if (!insertStudent.isSuccess()) {
  2570. return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
  2571. }
  2572. }
  2573. }
  2574. //上传图片
  2575. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2576. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2577. photo.setPhotoUrl(su.getHeadImage());
  2578. photo.setUserCode(su.getCardNo());
  2579. photoList.add(photo);
  2580. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  2581. if (!result.isSuccess()) {
  2582. return result;
  2583. }
  2584. }
  2585. //endregion
  2586. //region 更新百胜学生信息
  2587. if (useBs == 1) {
  2588. /**
  2589. * 学生数据的有效期是到毕业年份的8月31日
  2590. */
  2591. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2592. String endTime = queryGraduationYear(gradeData.getGradeNo());
  2593. CommonResult updateBsStudent = bsUpdateStudent(su, startTime, endTime);
  2594. if (!updateBsStudent.isSuccess()) {
  2595. if (updateBsStudent.getMessage().equals("人员不存在或已删除")) {
  2596. //region 百胜新增学生信息
  2597. CommonResult<String> insertBsStudent = bsInsertStudent(usur.getName(), usur.getCardNo(), usur.getSexId(), usur.getHeadImage(), usur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, usur.getIdCard());
  2598. if (!insertBsStudent.isSuccess()) {
  2599. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  2600. }
  2601. su.setBsStudentNo(insertBsStudent.getData());
  2602. //endregion
  2603. } else {
  2604. return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
  2605. }
  2606. }
  2607. }
  2608. //endregion
  2609. } else {
  2610. if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
  2611. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
  2612. //region 希沃删除原有的家长关系
  2613. if (useXw == 1) {
  2614. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
  2615. if (!deleteResult.isSuccess()) {
  2616. return CommonResult.fail("希沃平台:" + deleteResult.getMessage());
  2617. }
  2618. smartFamilyIndexService.deleteSmartFamilyByPhone(su.getPhone());
  2619. }
  2620. //endregion
  2621. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  2622. //获取班级Uid
  2623. SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
  2624. if (oldClassData == null) {
  2625. return CommonResult.fail("班级数据无效,更新失败");
  2626. }
  2627. //region 希沃删除教师
  2628. if (useXw == 1) {
  2629. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  2630. if (!deleteTeacher.isSuccess()) {
  2631. return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
  2632. }
  2633. }
  2634. //endregion
  2635. //region 希沃删除班主任
  2636. if (useXw == 1) {
  2637. CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
  2638. if (!deleteMaster.isSuccess()) {
  2639. return CommonResult.fail("希沃平台:" + deleteMaster.getMessage());
  2640. }
  2641. }
  2642. //endregion
  2643. //region 百胜删除教师
  2644. if (useBs == 1) {
  2645. CommonResult deleteBsTeacher = bsDeleteTeacher(oldStaffNo);
  2646. if (!deleteBsTeacher.isSuccess()) {
  2647. return CommonResult.fail("百胜平台:" + deleteBsTeacher.getMessage());
  2648. }
  2649. }
  2650. //endregion
  2651. }
  2652. //region 希沃新增学生信息
  2653. if (useXw == 1) {
  2654. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
  2655. if (!insertStudent.isSuccess()) {
  2656. return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
  2657. } else {
  2658. su.setXwStudentUid(insertStudent.getData());
  2659. }
  2660. //上传图片
  2661. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2662. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2663. photo.setPhotoUrl(su.getHeadImage());
  2664. photo.setUserCode(su.getCardNo());
  2665. photoList.add(photo);
  2666. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  2667. if (!result.isSuccess()) {
  2668. return result;
  2669. }
  2670. }
  2671. //endregion
  2672. //region 百胜新增学生信息
  2673. if (useBs == 1) {
  2674. /**
  2675. * 学生数据的有效期是到毕业年份的8月31日
  2676. */
  2677. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2678. String endTime = queryGraduationYear(gradeData.getGradeNo());
  2679. CommonResult<String> insertBsStudent = bsInsertStudent(su.getName(), su.getCardNo(), su.getSexId(), su.getHeadImage(), su.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, su.getIdCard());
  2680. if (insertBsStudent.isSuccess()) {
  2681. su.setBsStudentNo(insertBsStudent.getData());
  2682. } else {
  2683. //region 希沃删除学生
  2684. //百胜数据插入失败后需要把已插入到希沃的数据删除
  2685. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  2686. if (!deleteStudent.isSuccess()) {
  2687. return CommonResult.fail("百胜平台:" + deleteStudent.getMessage());
  2688. }
  2689. //endregion
  2690. return CommonResult.fail("切换身份后," + insertBsStudent.getMessage() + ",百胜无法插入学生数据");
  2691. }
  2692. }
  2693. //endregion
  2694. }
  2695. } else if (usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//教师
  2696. if (!changeIdentity) {
  2697. //region 希沃更新教师数据
  2698. if (useXw == 1) {
  2699. CommonResult<String> updateTeacher = SeewoUpdateTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
  2700. if (!updateTeacher.isSuccess()) {
  2701. return CommonResult.fail("希沃平台:" + updateTeacher.getMessage());
  2702. }
  2703. su.setXwTeacherCode(updateTeacher.getData());
  2704. //上传图片
  2705. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2706. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2707. photo.setPhotoUrl(su.getHeadImage());
  2708. photo.setUserCode(su.getPhone());
  2709. photoList.add(photo);
  2710. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  2711. if (!result.isSuccess()) {
  2712. return result;
  2713. }
  2714. }
  2715. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  2716. //获取班级Uid
  2717. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  2718. if (classData == null) {
  2719. return CommonResult.fail("班级数据无效,新增失败");
  2720. }
  2721. //region 将班主任推送到希沃
  2722. if (useXw == 1) {
  2723. CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
  2724. if (!pushMaster.isSuccess()) {
  2725. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  2726. }
  2727. }
  2728. //endregion
  2729. }
  2730. //endregion
  2731. SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
  2732. if (departmentData == null) {
  2733. return CommonResult.fail("部门数据无效,更新教师失败");
  2734. }
  2735. String departmentNo = departmentData.getBsDepartmentNo();
  2736. if (departmentNo == null) {
  2737. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  2738. }
  2739. //region 百胜更新教师数据
  2740. if (useBs == 1) {
  2741. /**
  2742. * 教师数据的有效期是20年
  2743. */
  2744. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2745. String endTime = TimeExchange.addYear(20);
  2746. CommonResult<String> bsUpdateTeacher = updateBsTeacher(su, departmentNo, startTime, endTime);
  2747. if (!bsUpdateTeacher.isSuccess()) {
  2748. return CommonResult.fail("百胜平台:" + bsUpdateTeacher.getMessage());
  2749. }
  2750. su.setBsStaffCode(bsUpdateTeacher.getData());
  2751. }
  2752. //endregion
  2753. } else {
  2754. if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
  2755. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
  2756. //region 希沃删除原有的家长关系
  2757. if (useXw == 1) {
  2758. CommonResult deleteOldShip = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
  2759. if (!deleteOldShip.isSuccess()) {
  2760. return CommonResult.fail("希沃平台:" + deleteOldShip.getMessage());
  2761. }
  2762. smartFamilyIndexService.deleteSmartFamilyByPhone(su.getPhone());
  2763. }
  2764. //endregion
  2765. } else if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  2766. //获取班级Uid
  2767. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  2768. if (classData == null) {
  2769. return CommonResult.fail("班级数据无效,更新失败");
  2770. }
  2771. //region 希沃删除学生
  2772. if (useXw == 1) {
  2773. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  2774. if (!deleteStudent.isSuccess()) {
  2775. return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
  2776. }
  2777. }
  2778. //endregion
  2779. //region 百胜删除学生
  2780. if (useBs == 1) {
  2781. CommonResult deleteBsStudent = bsDeleteStudent(su);
  2782. if (!deleteBsStudent.isSuccess()) {
  2783. return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
  2784. }
  2785. }
  2786. //endregion
  2787. }
  2788. //region 希沃添加教师数据
  2789. if (useXw == 1) {
  2790. CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
  2791. if (!insertTeacher.isSuccess()) {
  2792. return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
  2793. }
  2794. su.setXwTeacherCode(insertTeacher.getData());
  2795. //上传图片
  2796. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2797. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2798. photo.setPhotoUrl(su.getHeadImage());
  2799. photo.setUserCode(su.getPhone());
  2800. photoList.add(photo);
  2801. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  2802. if (!result.isSuccess()) {
  2803. return result;
  2804. }
  2805. }
  2806. //endregion
  2807. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  2808. //获取班级Uid
  2809. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  2810. if (classData == null) {
  2811. return CommonResult.fail("班级数据无效,新增失败");
  2812. }
  2813. //region 将班主任推送到希沃
  2814. if (useXw == 1) {
  2815. CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
  2816. if (!pushMaster.isSuccess()) {
  2817. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  2818. }
  2819. }
  2820. //endregion
  2821. }
  2822. SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
  2823. if (departmentData == null) {
  2824. return CommonResult.fail("部门数据无效,新增教师失败");
  2825. }
  2826. String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
  2827. if (departmentNo == null) {
  2828. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  2829. }
  2830. //region 百胜添加教师数据
  2831. if (useBs == 1) {
  2832. /**
  2833. * 教师数据的有效期是20年
  2834. */
  2835. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2836. String endTime = TimeExchange.addYear(20);
  2837. CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
  2838. if (!insertBsTeacher.isSuccess()) {
  2839. return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
  2840. }
  2841. su.setBsStaffCode(insertBsTeacher.getData());
  2842. }
  2843. //endregion
  2844. }
  2845. }
  2846. int result = smartUserService.updateSmartUser(su);
  2847. // 修改需同步到海康平台
  2848. if (result > 0) {
  2849. Integer identityId = su.getIdentityId();
  2850. if (2 == identityId || identityId == 3) {
  2851. Integer id = su.getId();
  2852. SmartOperationUser smartOperationUser = new SmartOperationUser();
  2853. smartOperationUser.setOperationId(id);
  2854. smartOperationUser.setOperationMode("2");
  2855. smartOperationUser.setStatus(1);
  2856. smartOperationUser.setType(identityId);
  2857. smartOperationUserService.save(smartOperationUser);
  2858. }
  2859. }
  2860. //region 任课数据
  2861. if (result > 0 && usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  2862. //查找原有的任课数据
  2863. List<SmartTeaching> oldTeachings = smartTeachingService.queryTeachingByUserId(su.getId());
  2864. smartTeachingService.deleteByUserId(su.getId());//删除任课
  2865. List<SmartTeaching> newTeachings = new ArrayList<>();
  2866. List<SmartTeaching> newEteachings = new ArrayList<>();
  2867. if (usur.getUsr() != null && usur.getUsr().size() > 0) {
  2868. for (isrRequest sv : usur.getUsr()) {
  2869. if (sv.getIds() != null && sv.getIds().size() > 0) {
  2870. SmartTeaching st = new SmartTeaching();
  2871. st.setUserId(su.getId());
  2872. st.setSubjectId(sv.getIds().size() > 0 ? sv.getIds().get(0) : 0);
  2873. st.setGradeId(sv.getIds().size() > 1 ? sv.getIds().get(1) : 0);
  2874. st.setClassId(sv.getIds().size() > 2 ? sv.getIds().get(2) : 0);
  2875. long existCount = oldTeachings.stream().filter(e -> e.getUserId().equals(st.getUserId()) && e.getSubjectId().equals(st.getSubjectId())
  2876. && e.getGradeId().equals(st.getGradeId()) && e.getClassId().equals(st.getClassId())).count();
  2877. if (existCount <= 0) {
  2878. newEteachings.add(st);
  2879. }
  2880. newTeachings.add(st);
  2881. }
  2882. }
  2883. if (newEteachings != null && newEteachings.size() > 0) {
  2884. //region 添加教师综合素质评价
  2885. List<Integer> ids = newEteachings.stream().map(SmartTeaching::getClassId).collect(Collectors.toList());
  2886. List<SmartClass> classes = smartClassService.getSmartClasss(ids);
  2887. List<Integer> subjectIds = newEteachings.stream().map(SmartTeaching::getSubjectId).collect(Collectors.toList());
  2888. List<SmartSubject> subjects = smartSubjectService.getSmartSubjectId(subjectIds);
  2889. List<Integer> gradeIds = newEteachings.stream().map(SmartTeaching::getGradeId).collect(Collectors.toList());
  2890. List<SmartGrade> grades = smartGradeService.queryGradeByIds(gradeIds);
  2891. List<SmartEvaluateTeacher> eTeachers = new ArrayList<>();
  2892. LocalDateTime now = LocalDateTime.now();
  2893. List<SmartSemester> semesters = smartSemesterService.getSemestersByTime(now);
  2894. for (SmartSemester semester : semesters) {
  2895. for (SmartTeaching teacher : newEteachings) {
  2896. Optional<SmartClass> classTeacherData = classes != null && classes.size() > 0 ?
  2897. classes.stream().filter(e -> e.getId().equals(teacher.getClassId())).findFirst() : null;
  2898. Optional<SmartSubject> subjectData = subjects != null && subjects.size() > 0 ?
  2899. subjects.stream().filter(e -> e.getId().equals(teacher.getSubjectId())).findFirst() : null;
  2900. Optional<SmartGrade> gradeData = grades != null && grades.size() > 0 ?
  2901. grades.stream().filter(e -> e.getId().equals(teacher.getGradeId())).findFirst() : null;
  2902. SmartEvaluateTeacher set = new SmartEvaluateTeacher();
  2903. set.setCardNo(su.getCardNo());
  2904. set.setName(su.getName());
  2905. set.setUserId(su.getId());
  2906. set.setGradeId(teacher.getGradeId());
  2907. set.setGradeName(gradeData != null && gradeData.isPresent() ? gradeData.get().getName() : "");
  2908. set.setTermId(semester.getId());
  2909. set.setTerm(semester.getName());
  2910. set.setSubjectId(teacher.getSubjectId());
  2911. set.setSubject(subjectData != null && subjectData.isPresent() ? subjectData.get().getName() : "");
  2912. set.setClassId(teacher.getClassId());
  2913. set.setClassName(classTeacherData != null && classTeacherData.isPresent() ? classTeacherData.get().getName() : "");
  2914. set.setTotalScore(0.0);
  2915. set.setLowingScore(0.0);
  2916. eTeachers.add(set);
  2917. }
  2918. }
  2919. if (eTeachers != null && eTeachers.size() > 0) {
  2920. List<SmartEvaluateTeacher> insertEts = new ArrayList<>();
  2921. //已存在在老师综合评价里的就不再加进去了
  2922. List<SmartEvaluateTeacher> teachers = smartEvaluateTeacherService.queryEvaluateTeachersByUserId(su.getId());
  2923. for (SmartEvaluateTeacher et:eTeachers) {
  2924. long existCount = teachers.stream().filter(e -> e.getUserId().equals(et.getUserId()) && e.getTermId().equals(et.getTermId())
  2925. && e.getGradeId().equals(et.getGradeId()) && e.getSubjectId().equals(et.getSubjectId()) && e.getClassId().equals(et.getClassId())).count();
  2926. if(existCount <= 0){
  2927. insertEts.add(et);
  2928. }
  2929. }
  2930. if(insertEts != null && insertEts.size() > 0){
  2931. boolean teacherBatch = smartEvaluateTeacherService.saveBatch(insertEts);
  2932. if (!teacherBatch) {
  2933. throw new Exception("教师综合评价添加失败!");
  2934. }
  2935. }
  2936. }
  2937. //endregion
  2938. }
  2939. }
  2940. if (newTeachings != null && newTeachings.size() > 0) {
  2941. boolean insertBatch = smartTeachingService.saveBatch(newTeachings);
  2942. if (!insertBatch) {
  2943. return CommonResult.fail("任课数据添加失败");
  2944. }
  2945. }
  2946. }
  2947. //endregion
  2948. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  2949. }
  2950. //endregion
  2951. //region 希沃增删改查方法
  2952. //region 希沃批量上传头像
  2953. /**
  2954. * 希沃批量上传头像 如果当前用户已存在图片 会进行覆盖
  2955. *
  2956. * @param seewoClient 链接配置
  2957. * @param photoList 头像集合
  2958. * @param userType 用户类型
  2959. * @return
  2960. * @throws JsonProcessingException
  2961. */
  2962. public CommonResult SeewoInsertBatchPhoto(SeewoClient
  2963. seewoClient, List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList, Integer userType) throws
  2964. JsonProcessingException {
  2965. //region 希沃上传第三方图片信息
  2966. //初始化客户端
  2967. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2968. PhotoServiceSavePhotosParam param = new PhotoServiceSavePhotosParam();
  2969. //请求体,MimeType为 application/json
  2970. PhotoServiceSavePhotosParam.JSONRequestBody requestBody = PhotoServiceSavePhotosParam.JSONRequestBody.builder()
  2971. .build();
  2972. param.setRequestBody(requestBody);
  2973. //
  2974. PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery query = PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery.builder()
  2975. .appId(seewoConfig.getAppId())
  2976. .unitUid(seewoConfig.getSchoolId())
  2977. .userType(userType)
  2978. .build();
  2979. requestBody.setQuery(query);
  2980. // 图片保存列表
  2981. query.setPhotoList(photoList);
  2982. PhotoServiceSavePhotosRequest request = new PhotoServiceSavePhotosRequest(param);
  2983. // 该接口需要数据权限,请将授权资源id替换至下方,请妥善保管好授权资源id,避免泄露
  2984. // permissionId位置: 控制台 -> 应用详情 -> 我申请的 -> 已通过的接口 -> 调用范围 -> 审批信息 中查看授权资源的「学校id」或「区域id」
  2985. //request.setPermissionId(seewoConfig.getSchoolId());
  2986. logger.info("入参:" + request);
  2987. logger.info("入参:" + JSON.toJSON(request));
  2988. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2989. PhotoServiceSavePhotosResult result = seewoClient.invoke(request);
  2990. logger.info("出参:" + result);
  2991. ObjectMapper objectMapper = new ObjectMapper();
  2992. XwBodyVo xwResult = objectMapper.readValue(result.getBody(), XwBodyVo.class);
  2993. if (!xwResult.getCode().equals("000000")) {
  2994. return CommonResult.fail("希沃平台:" + result.getMessage());
  2995. }
  2996. //endregion
  2997. return CommonResult.ok("200", "图片添加成功");
  2998. }
  2999. //endregion
  3000. //region 希沃批量新增学生信息
  3001. public CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> SeewoInsertBatchStudent
  3002. (SeewoClient seewoClient, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo> students, String
  3003. classUid) {
  3004. //region 希沃新增学生信息
  3005. //初始化客户端
  3006. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3007. StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
  3008. //请求体,MimeType为 application/json
  3009. StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
  3010. .build();
  3011. param.setRequestBody(requestBody);
  3012. //查询条件
  3013. StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
  3014. .appId(seewoConfig.getAppId())
  3015. .schoolUid(seewoConfig.getSchoolId())
  3016. .classUid(classUid)
  3017. .build();
  3018. requestBody.setQuery(query);
  3019. // 学生列表
  3020. query.setStudents(students);
  3021. query.setInPlaceOld(false);// 是否删除旧学生再保存
  3022. param.setRequestBody(requestBody);
  3023. StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
  3024. logger.info("入参:" + request);
  3025. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3026. //request.setServerUrl("https://openapi.test.seewo.com")
  3027. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3028. StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
  3029. logger.info("出参:" + result);
  3030. if (result == null) {
  3031. return CommonResult.fail("希沃学生数据新增失败!");
  3032. }
  3033. if (!result.getResponseBody().getCode().equals("000000")) {
  3034. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3035. }
  3036. return CommonResult.ok("200", "添加成功", result.getResponseBody().getData());
  3037. //endregion
  3038. }
  3039. //endregion
  3040. //region 希沃新增学生信息
  3041. public CommonResult<String> SeewoInsertStudent(SeewoClient seewoClient, String name, String cardNo, Integer
  3042. sexId, String Phone, String classUid) {
  3043. //region 希沃新增学生信息
  3044. //初始化客户端
  3045. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3046. StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
  3047. //请求体,MimeType为 application/json
  3048. StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
  3049. .build();
  3050. param.setRequestBody(requestBody);
  3051. //查询条件
  3052. StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
  3053. .appId(seewoConfig.getAppId())
  3054. .schoolUid(seewoConfig.getSchoolId())
  3055. .classUid(classUid)
  3056. .build();
  3057. requestBody.setQuery(query);
  3058. // 学生列表
  3059. StudentServiceBatchSaveClassStudentsParam.StudentInfo students = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  3060. .studentName(name)
  3061. .studentCode(cardNo)
  3062. .gender(sexId)
  3063. .phone(Phone == null ? "" : Phone)
  3064. .build();
  3065. query.setStudents(java.util.Collections.singletonList(students));
  3066. query.setInPlaceOld(false);// 是否删除旧学生再保存
  3067. param.setRequestBody(requestBody);
  3068. StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
  3069. logger.info("入参:" + request);
  3070. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3071. //request.setServerUrl("https://openapi.test.seewo.com")
  3072. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3073. StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
  3074. logger.info("出参:" + result);
  3075. if (result == null) {
  3076. return CommonResult.fail("希沃学生数据新增失败!");
  3077. }
  3078. if (!result.getResponseBody().getCode().equals("000000")) {
  3079. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3080. }
  3081. return CommonResult.ok("200", "添加成功", result.getResponseBody().getData().get(0).getUserUid());
  3082. //endregion
  3083. }
  3084. //endregion
  3085. //region 希沃更新学生信息
  3086. public CommonResult SeewoUpdateStudent(SeewoClient seewoClient, SmartUser su) {
  3087. //region 更新希沃学生信息
  3088. //初始化客户端
  3089. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3090. StudentServiceUpdateStudentInfoParam param = new StudentServiceUpdateStudentInfoParam();
  3091. //响应体,MimeType为 application/json
  3092. StudentServiceUpdateStudentInfoParam.RequestBody requestBody = StudentServiceUpdateStudentInfoParam.RequestBody.builder()
  3093. .build();
  3094. param.setRequestBody(requestBody);
  3095. //query
  3096. StudentServiceUpdateStudentInfoParam.Query query = StudentServiceUpdateStudentInfoParam.Query.builder()
  3097. .appId(seewoConfig.getAppId())
  3098. .schoolUid(seewoConfig.getSchoolId())
  3099. .studentUid(su.getXwStudentUid())
  3100. .studentCode(su.getCardNo())
  3101. .studentName(su.getName())
  3102. .build();
  3103. requestBody.setQuery(query);
  3104. param.setRequestBody(requestBody);
  3105. StudentServiceUpdateStudentInfoRequest request = new StudentServiceUpdateStudentInfoRequest(param);
  3106. logger.info("入参:" + request);
  3107. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3108. //request.setServerUrl("https://openapi.test.seewo.com")
  3109. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3110. StudentServiceUpdateStudentInfoResult result = seewoClient.invoke(request);
  3111. logger.info("出参:" + result);
  3112. if (result == null) {
  3113. return CommonResult.fail("希沃学生数据更新失败!");
  3114. }
  3115. if (!result.getResponseBody().getCode().equals("000000")) {
  3116. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3117. }
  3118. return CommonResult.ok("更新成功");
  3119. //endregion
  3120. }
  3121. //endregion
  3122. //region 希沃删除学生
  3123. public CommonResult SeewoDeleteStudent(SeewoClient seewoClient, String ClassUid, String CardNo) {
  3124. //初始化客户端
  3125. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3126. StudentServiceRemoveClassStudentsParam deleteParam = new StudentServiceRemoveClassStudentsParam();
  3127. //请求体,MimeType为 application/json
  3128. StudentServiceRemoveClassStudentsParam.JSONRequestBody deleteRequestBody = StudentServiceRemoveClassStudentsParam.JSONRequestBody.builder()
  3129. .build();
  3130. deleteParam.setRequestBody(deleteRequestBody);
  3131. //查询条件
  3132. StudentServiceRemoveClassStudentsParam.UnbindStudentQuery deleteQuery = StudentServiceRemoveClassStudentsParam.UnbindStudentQuery.builder()
  3133. .appId(seewoConfig.getAppId())
  3134. .schoolUid(seewoConfig.getSchoolId())
  3135. .classUid(ClassUid)
  3136. .studentCodes(java.util.Collections.singletonList(CardNo))
  3137. .build();
  3138. deleteRequestBody.setQuery(deleteQuery);
  3139. deleteParam.setRequestBody(deleteRequestBody);
  3140. StudentServiceRemoveClassStudentsRequest deleteRequest = new StudentServiceRemoveClassStudentsRequest(deleteParam);
  3141. logger.info("入参:" + deleteRequest);
  3142. //如果想要调用沙箱环境,请通过设置 deleteRequest 对象的 serverUrl 属性,如:
  3143. //deleteRequest.setServerUrl("https://openapi.test.seewo.com")
  3144. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3145. StudentServiceRemoveClassStudentsResult deleteResult = seewoClient.invoke(deleteRequest);
  3146. logger.info("出参:" + deleteResult);
  3147. if (deleteResult == null) {
  3148. return CommonResult.fail("希沃删除学生数据失败!");
  3149. }
  3150. if (!deleteResult.getResponseBody().getCode().equals("000000")) {
  3151. return CommonResult.fail("希沃平台:" + deleteResult.getResponseBody().getMessage());
  3152. }
  3153. return CommonResult.ok("删除成功");
  3154. }
  3155. //endregion
  3156. //region 希沃添加老师数据
  3157. //老师数据会根据手机号判断新增不新增
  3158. //手机号相同的情况下更新不新增
  3159. public CommonResult<String> SeewoInsertTeacher(SeewoClient seewoClient, String phone, String name, String
  3160. headImage) {
  3161. //region 希沃添加教师数据
  3162. //初始化客户端
  3163. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3164. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  3165. //请求体,MimeType为 application/json
  3166. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  3167. .build();
  3168. param.setRequestBody(requestBody);
  3169. //老师信息
  3170. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  3171. .appId(seewoConfig.getAppId())
  3172. .schoolUid(seewoConfig.getSchoolId())
  3173. .build();
  3174. requestBody.setQuery(query);
  3175. // 老师列表
  3176. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  3177. .account(phone)//用户账号
  3178. .name(name)//用户名字
  3179. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  3180. .teacherCode(phone)//教师工号
  3181. .photoUrl(headImage)//图片链接
  3182. .build();
  3183. query.setTeachers(java.util.Collections.singletonList(teachers));
  3184. param.setRequestBody(requestBody);
  3185. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  3186. logger.info("入参:" + request);
  3187. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3188. //request.setServerUrl("https://openapi.test.seewo.com")
  3189. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3190. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  3191. logger.info("出参:" + result);
  3192. if (result == null) {
  3193. return CommonResult.fail("希沃教师数据新增失败!");
  3194. }
  3195. if (!result.getResponseBody().getCode().equals("000000")) {
  3196. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3197. }
  3198. String teacherCode = phone;
  3199. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  3200. teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
  3201. }
  3202. return CommonResult.ok("200", "操作成功", teacherCode);
  3203. //endregion
  3204. }
  3205. //endregion
  3206. //region 希沃批量添加老师数据
  3207. //老师数据会根据手机号判断新增不新增
  3208. //手机号相同的情况下更新不新增
  3209. public CommonResult<List<TeacherServiceBatchSaveOrUpdateTeacherResult.TeacherBaseInfoDto>> SeewoInsertBatchTeacher
  3210. (SeewoClient seewoClient, List<TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery> teachers) {
  3211. //region 希沃添加教师数据
  3212. //初始化客户端
  3213. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3214. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  3215. //请求体,MimeType为 application/json
  3216. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  3217. .build();
  3218. param.setRequestBody(requestBody);
  3219. //老师信息
  3220. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  3221. .appId(seewoConfig.getAppId())
  3222. .schoolUid(seewoConfig.getSchoolId())
  3223. .build();
  3224. requestBody.setQuery(query);
  3225. query.setTeachers(teachers);
  3226. param.setRequestBody(requestBody);
  3227. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  3228. logger.info("入参:" + request);
  3229. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3230. //request.setServerUrl("https://openapi.test.seewo.com")
  3231. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3232. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  3233. logger.info("出参:" + result);
  3234. if (result == null) {
  3235. return CommonResult.fail("希沃教师数据新增失败!");
  3236. }
  3237. if (!result.getResponseBody().getCode().equals("000000")) {
  3238. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3239. }
  3240. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  3241. return CommonResult.ok("200", "操作成功", result.getResponseBody().getData());
  3242. }
  3243. return CommonResult.ok("200", "操作成功", null);
  3244. //endregion
  3245. }
  3246. //endregion
  3247. //region 希沃更新教师
  3248. public CommonResult<String> SeewoUpdateTeacher(SeewoClient seewoClient, String phone, String name, String
  3249. headImage) {
  3250. //region 希沃更新教师数据
  3251. //初始化客户端
  3252. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3253. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  3254. //请求体,MimeType为 application/json
  3255. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  3256. .build();
  3257. param.setRequestBody(requestBody);
  3258. //老师信息
  3259. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  3260. .appId(seewoConfig.getAppId())
  3261. .schoolUid(seewoConfig.getSchoolId())
  3262. .build();
  3263. requestBody.setQuery(query);
  3264. // 老师列表
  3265. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  3266. .account(phone)//用户账号
  3267. .name(name)//用户名字
  3268. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  3269. .teacherCode(phone)//教师工号
  3270. .photoUrl(headImage)//图片链接
  3271. .build();
  3272. query.setTeachers(java.util.Collections.singletonList(teachers));
  3273. param.setRequestBody(requestBody);
  3274. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  3275. logger.info("入参:" + request);
  3276. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3277. //request.setServerUrl("https://openapi.test.seewo.com")
  3278. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3279. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  3280. logger.info("出参:" + result);
  3281. if (result == null) {
  3282. return CommonResult.fail("希沃教师数据更新失败!");
  3283. }
  3284. if (!result.getResponseBody().getCode().equals("000000")) {
  3285. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3286. }
  3287. String teacherCode = phone;
  3288. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  3289. teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
  3290. }
  3291. return CommonResult.ok("200", "操作成功", teacherCode);
  3292. //endregion
  3293. }
  3294. //endregion
  3295. //region 希沃删除教师
  3296. public CommonResult SeewoDeleteTeacher(SeewoClient seewoClient, String phone) {
  3297. //region 希沃删除教师
  3298. //初始化客户端
  3299. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3300. TeacherServiceBatchRemoveTeachersParam param = new TeacherServiceBatchRemoveTeachersParam();
  3301. //响应体,MimeType为 application/json
  3302. TeacherServiceBatchRemoveTeachersParam.RequestBody requestBody = TeacherServiceBatchRemoveTeachersParam.RequestBody.builder()
  3303. .build();
  3304. param.setRequestBody(requestBody);
  3305. //query
  3306. TeacherServiceBatchRemoveTeachersParam.Query query = TeacherServiceBatchRemoveTeachersParam.Query.builder()
  3307. .appId(seewoConfig.getAppId())
  3308. .schoolUid(seewoConfig.getSchoolId())
  3309. .phones(java.util.Collections.singletonList(phone))
  3310. .build();
  3311. requestBody.setQuery(query);
  3312. param.setRequestBody(requestBody);
  3313. TeacherServiceBatchRemoveTeachersRequest request = new TeacherServiceBatchRemoveTeachersRequest(param);
  3314. logger.info("入参:" + request);
  3315. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3316. //request.setServerUrl("https://openapi.test.seewo.com")
  3317. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3318. TeacherServiceBatchRemoveTeachersResult result = seewoClient.invoke(request);
  3319. logger.info("出参:" + result);
  3320. if (result == null) {
  3321. return CommonResult.fail("希沃教师数据删除失败!");
  3322. }
  3323. if (!result.getResponseBody().getCode().equals("000000")) {
  3324. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3325. }
  3326. return CommonResult.ok("删除成功");
  3327. //endregion
  3328. }
  3329. //endregion
  3330. //region 希沃删除班主任
  3331. public CommonResult SeewoDeleteTeacherMaster(SeewoClient seewoClient, String classUid, String phone) {
  3332. //region 希沃删除班主任
  3333. //初始化客户端
  3334. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3335. TeacherServiceBatchRemoveClassMastersParam mastersParam = new TeacherServiceBatchRemoveClassMastersParam();
  3336. //响应体,MimeType为 application/json
  3337. TeacherServiceBatchRemoveClassMastersParam.RequestBody mastersRequestBody = TeacherServiceBatchRemoveClassMastersParam.RequestBody.builder()
  3338. .build();
  3339. mastersParam.setRequestBody(mastersRequestBody);
  3340. //query
  3341. TeacherServiceBatchRemoveClassMastersParam.Query mastersQuery = TeacherServiceBatchRemoveClassMastersParam.Query.builder()
  3342. .appId(seewoConfig.getAppId())
  3343. .schoolUid(seewoConfig.getSchoolId())
  3344. .classUid(classUid)
  3345. .userPhones(java.util.Collections.singletonList(phone))
  3346. .build();
  3347. mastersRequestBody.setQuery(mastersQuery);
  3348. mastersParam.setRequestBody(mastersRequestBody);
  3349. TeacherServiceBatchRemoveClassMastersRequest mastersRequest = new TeacherServiceBatchRemoveClassMastersRequest(mastersParam);
  3350. logger.info("入参:" + mastersRequest);
  3351. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3352. //request.setServerUrl("https://openapi.test.seewo.com")
  3353. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3354. TeacherServiceBatchRemoveClassMastersResult masterResult = seewoClient.invoke(mastersRequest);
  3355. logger.info("出参:" + masterResult);
  3356. if (masterResult == null) {
  3357. return CommonResult.fail("希沃教师数据删除失败!");
  3358. }
  3359. if (!masterResult.getResponseBody().getCode().equals("000000")) {
  3360. return CommonResult.fail("希沃平台:" + masterResult.getResponseBody().getMessage());
  3361. }
  3362. return CommonResult.ok("删除成功");
  3363. //endregion
  3364. }
  3365. //endregion
  3366. //region 希沃推送班主任
  3367. public CommonResult SeewoPushMaster(SeewoClient seewoClient, String phone, String classUid) {
  3368. //region 将班主任推送到希沃
  3369. //初始化客户端
  3370. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3371. TeacherServiceBatchSetClassMastersParam teacherClassParam = new TeacherServiceBatchSetClassMastersParam();
  3372. //响应体,MimeType为 application/json
  3373. TeacherServiceBatchSetClassMastersParam.RequestBody teacherClassRequestBody = TeacherServiceBatchSetClassMastersParam.RequestBody.builder()
  3374. .build();
  3375. teacherClassParam.setRequestBody(teacherClassRequestBody);
  3376. //query
  3377. List<String> teacherPhones = new ArrayList<>();
  3378. teacherPhones.add(phone);
  3379. TeacherServiceBatchSetClassMastersParam.Query teacherClassQuery = TeacherServiceBatchSetClassMastersParam.Query.builder()
  3380. .appId(seewoConfig.getAppId())
  3381. .schoolUid(seewoConfig.getSchoolId())
  3382. .classUid(classUid)
  3383. .userPhones(teacherPhones)
  3384. .build();
  3385. teacherClassRequestBody.setQuery(teacherClassQuery);
  3386. teacherClassParam.setRequestBody(teacherClassRequestBody);
  3387. TeacherServiceBatchSetClassMastersRequest teacherClassRequest = new TeacherServiceBatchSetClassMastersRequest(teacherClassParam);
  3388. logger.info("入参:" + teacherClassRequest);
  3389. //如果想要调用沙箱环境,请通过设置 teacherClassRequest 对象的 serverUrl 属性,如:
  3390. //request.setServerUrl("https://openapi.test.seewo.com")
  3391. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3392. TeacherServiceBatchSetClassMastersResult teacherClassResult = seewoClient.invoke(teacherClassRequest);
  3393. logger.info("出参:" + teacherClassResult);
  3394. if (teacherClassResult == null) {
  3395. return CommonResult.fail("希沃教师数据新增失败!");
  3396. }
  3397. if (!teacherClassResult.getResponseBody().getCode().equals("000000")) {
  3398. return CommonResult.fail("希沃平台:" + teacherClassResult.getResponseBody().getMessage());
  3399. }
  3400. return CommonResult.ok("添加成功");
  3401. //endregion
  3402. }
  3403. //endregion
  3404. //region 希沃新增编辑学生家长信息
  3405. public CommonResult insertOrUpdateStudentParent(SeewoClient
  3406. seewoClient, List<SmartUser> studentDatas, String name, String phone, boolean isInsert) {
  3407. //region 希沃新增编辑学生家长信息
  3408. //学生与家长列表,最大100条
  3409. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  3410. List<SmartFamilyIndex> insertIndexs = new ArrayList<>();
  3411. for (SmartUser student : studentDatas) {
  3412. int index = 0;
  3413. if (isInsert) {
  3414. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(student.getCardNo());
  3415. if (indexs != null && indexs.size() >= 4) {
  3416. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  3417. }
  3418. if (indexs != null) {
  3419. for (SmartFamilyIndex data : indexs) {
  3420. if (data.getIndexData().intValue() == index && index < 3) {
  3421. index++;
  3422. continue;
  3423. } else {
  3424. break;
  3425. }
  3426. }
  3427. }
  3428. SmartFamilyIndex insertFamily = new SmartFamilyIndex();
  3429. insertFamily.setParentPhone(phone);
  3430. insertFamily.setStudentNo(student.getCardNo());
  3431. insertFamily.setIndexData(index);
  3432. insertIndexs.add(insertFamily);
  3433. } else {
  3434. SmartFamilyIndex familyIndex = smartFamilyIndexService.queryFamilyByPhoneCardNo(phone, student.getCardNo());
  3435. if (familyIndex == null) {
  3436. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(student.getCardNo());
  3437. if (indexs != null && indexs.size() >= 4) {
  3438. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  3439. }
  3440. if (indexs != null) {
  3441. for (SmartFamilyIndex data : indexs) {
  3442. if (data.getIndexData().intValue() == index && index < 3) {
  3443. index++;
  3444. continue;
  3445. } else {
  3446. break;
  3447. }
  3448. }
  3449. }
  3450. SmartFamilyIndex insertFamily = new SmartFamilyIndex();
  3451. insertFamily.setParentPhone(phone);
  3452. insertFamily.setStudentNo(student.getCardNo());
  3453. insertFamily.setIndexData(index);
  3454. insertIndexs.add(insertFamily);
  3455. } else {
  3456. familyIndex.setStudentNo(student.getCardNo());
  3457. familyIndex.setParentPhone(phone);
  3458. index = familyIndex.getIndexData();
  3459. int updateFamily = smartFamilyIndexService.updateSmartFamily(familyIndex);
  3460. if (updateFamily <= 0) {
  3461. return CommonResult.fail("绑定失败");
  3462. }
  3463. }
  3464. }
  3465. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  3466. .studentCode(student.getCardNo())
  3467. .build();
  3468. studentParents.add(students);
  3469. //家长列表,最多4个
  3470. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  3471. .name(name)
  3472. .phone(phone)
  3473. .index(index)
  3474. .build();
  3475. students.setParents(java.util.Collections.singletonList(parents));
  3476. }
  3477. if (insertIndexs != null && insertIndexs.size() > 0) {
  3478. smartFamilyIndexService.saveBatch(insertIndexs);
  3479. }
  3480. //初始化客户端
  3481. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3482. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  3483. //响应体,MimeType为 application/json
  3484. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  3485. .build();
  3486. param.setRequestBody(requestBody);
  3487. //query
  3488. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  3489. .appId(seewoConfig.getAppId())
  3490. .schoolUid(seewoConfig.getSchoolId())
  3491. .build();
  3492. requestBody.setQuery(query);
  3493. query.setStudentParents(studentParents);
  3494. param.setRequestBody(requestBody);
  3495. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  3496. logger.info("入参:" + request);
  3497. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3498. //request.setServerUrl("https://openapi.test.seewo.com")
  3499. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3500. ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
  3501. logger.info("出参:" + result);
  3502. if (result == null) {
  3503. return CommonResult.fail("希沃学生家长数据更新失败!");
  3504. }
  3505. if (!result.getResponseBody().getCode().equals("000000")) {
  3506. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  3507. }
  3508. return CommonResult.ok("新增成功");
  3509. //endregion
  3510. }
  3511. //endregion
  3512. //region 希沃删除学生原有的家长关系
  3513. public CommonResult deleteOldStudentParentShip(SeewoClient seewoClient, String cardNo, List<String> phones) throws
  3514. JsonProcessingException {
  3515. //region 删除原有的家长关系
  3516. //初始化客户端
  3517. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3518. ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
  3519. //请求体,MimeType为 application/json
  3520. ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
  3521. .build();
  3522. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  3523. //
  3524. ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
  3525. .appId(seewoConfig.getAppId())
  3526. .schoolUid(seewoConfig.getSchoolId())
  3527. //.studentCodes(java.util.Collections.singletonList(cardNo))//传卡号会把该学生的家长都删掉
  3528. .parentPhones(phones)
  3529. .build();
  3530. deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
  3531. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  3532. ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
  3533. logger.info("入参:" + deleteOldFamilyRequest);
  3534. //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
  3535. //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
  3536. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3537. ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
  3538. logger.info("出参:" + deleteOldFamilyResult);
  3539. if (deleteOldFamilyResult == null) {
  3540. return CommonResult.fail("希沃家长数据删除失败!");
  3541. }
  3542. if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
  3543. ObjectMapper objectMapper = new ObjectMapper();
  3544. XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
  3545. if (!result.getCode().equals("000000")) {
  3546. return CommonResult.fail("希沃平台:" + result.getMessage());
  3547. }
  3548. } else {
  3549. if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
  3550. return CommonResult.fail("希沃平台:" + deleteOldFamilyResult.getResponseBody().getResult().getMessage());
  3551. }
  3552. }
  3553. return CommonResult.ok("删除成功");
  3554. //endregion
  3555. }
  3556. //endregion
  3557. //region 希沃删除原有的家长关系
  3558. public CommonResult deleteOldParentShip(SeewoClient seewoClient, List<SmartUser> studentDatas, String phone) throws
  3559. JsonProcessingException {
  3560. //region 删除原有的家长关系
  3561. //初始化客户端
  3562. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3563. ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
  3564. //请求体,MimeType为 application/json
  3565. ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
  3566. .build();
  3567. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  3568. //
  3569. ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
  3570. .appId(seewoConfig.getAppId())
  3571. .schoolUid(seewoConfig.getSchoolId())
  3572. //.studentCodes(studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList()))//不能传卡号 传了卡号会把该学生的家长都删掉
  3573. .parentPhones(java.util.Collections.singletonList(phone))
  3574. .build();
  3575. deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
  3576. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  3577. ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
  3578. logger.info("入参:" + deleteOldFamilyRequest);
  3579. logger.info("入参:" + JSON.toJSON(deleteOldFamilyRequest));
  3580. //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
  3581. //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
  3582. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3583. ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
  3584. logger.info("出参:" + deleteOldFamilyResult);
  3585. if (deleteOldFamilyResult == null) {
  3586. return CommonResult.fail("希沃家长数据删除失败!");
  3587. }
  3588. if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
  3589. ObjectMapper objectMapper = new ObjectMapper();
  3590. XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
  3591. if (!result.getCode().equals("000000")) {
  3592. return CommonResult.fail("希沃平台:" + result.getMessage());
  3593. }
  3594. } else {
  3595. if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
  3596. return CommonResult.fail("希沃平台:" + deleteOldFamilyResult.getResponseBody().getResult().getMessage());
  3597. }
  3598. }
  3599. return CommonResult.ok("删除成功");
  3600. //endregion
  3601. }
  3602. //endregion
  3603. //endregion
  3604. //region 百胜增删改查方法
  3605. //region 百胜更新学生信息 给批量导入用的
  3606. public CommonResult bsEUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws
  3607. Exception {
  3608. //region 更新百胜学生信息
  3609. String appId = controlConfig.getAppId();
  3610. String schoolno = controlConfig.getSchoolCode();
  3611. String timestamp = TimeExchange.DateNowTimeStamo();
  3612. String appSecret = controlConfig.getAppSecret();
  3613. String url = controlConfig.getUrl() + "student/update";
  3614. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
  3615. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  3616. JSONObject jsonobject = new JSONObject();
  3617. jsonobject.put("appid", appId);
  3618. 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 + "\"}";
  3619. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3620. jsonobject.put("data", aesStr);
  3621. jsonobject.put("schoolno", schoolno);
  3622. jsonobject.put("timestamp", timestamp);
  3623. 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 + "&timestamp=" + timestamp + "&key=" + appSecret;
  3624. String sign = CommonUtil.MD5(md5Str);
  3625. //sign签名
  3626. jsonobject.put("sign", sign);
  3627. //返回的结果中 code为1表示成功
  3628. String bsResult = RequestUtils.httpPosts(url, jsonobject.toJSONString());
  3629. ObjectMapper objectMapper = new ObjectMapper();
  3630. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  3631. if (!bsResult.contains("更新成功")) {
  3632. return CommonResult.fail("百胜平台:" + result.getMsg());
  3633. }
  3634. return CommonResult.ok("更新成功");
  3635. //endregion
  3636. }
  3637. //endregion
  3638. //region 百胜更新学生信息 给设置时间组接口用的
  3639. public CommonResult bsTUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws
  3640. Exception {
  3641. //region 更新百胜学生信息
  3642. String appId = controlConfig.getAppId();
  3643. String schoolno = controlConfig.getSchoolCode();
  3644. String timestamp = TimeExchange.DateNowTimeStamo();
  3645. String appSecret = controlConfig.getAppSecret();
  3646. String url = controlConfig.getUrl() + "student/update";
  3647. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
  3648. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  3649. JSONObject jsonobject = new JSONObject();
  3650. jsonobject.put("appid", appId);
  3651. 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 + "\"}";
  3652. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3653. jsonobject.put("data", aesStr);
  3654. jsonobject.put("schoolno", schoolno);
  3655. jsonobject.put("timestamp", timestamp);
  3656. 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 + "&timestamp=" + timestamp + "&key=" + appSecret;
  3657. String sign = CommonUtil.MD5(md5Str);
  3658. //sign签名
  3659. jsonobject.put("sign", sign);
  3660. //返回的结果中 code为1表示成功
  3661. String bsResult = RequestUtils.httpPosts(url, jsonobject.toJSONString());
  3662. ObjectMapper objectMapper = new ObjectMapper();
  3663. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  3664. if (!bsResult.contains("更新成功")) {
  3665. return CommonResult.fail("百胜平台:" + result.getMsg());
  3666. }
  3667. return CommonResult.ok("更新成功");
  3668. //endregion
  3669. }
  3670. //endregion
  3671. //region 百胜更新学生信息
  3672. public CommonResult bsUpdateStudent(SmartUser su, String startDate, String endDate) throws Exception {
  3673. //region 更新百胜学生信息
  3674. String appId = controlConfig.getAppId();
  3675. String schoolno = controlConfig.getSchoolCode();
  3676. String timestamp = TimeExchange.DateNowTimeStamo();
  3677. String appSecret = controlConfig.getAppSecret();
  3678. String url = controlConfig.getUrl() + "student/update";
  3679. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
  3680. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  3681. JSONObject jsonobject = new JSONObject();
  3682. jsonobject.put("appid", appId);
  3683. 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 + "\"}";
  3684. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3685. jsonobject.put("data", aesStr);
  3686. jsonobject.put("schoolno", schoolno);
  3687. jsonobject.put("timestamp", timestamp);
  3688. 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 + "&timestamp=" + timestamp + "&key=" + appSecret;
  3689. String sign = CommonUtil.MD5(md5Str);
  3690. //sign签名
  3691. jsonobject.put("sign", sign);
  3692. //返回的结果中 code为1表示成功
  3693. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3694. ObjectMapper objectMapper = new ObjectMapper();
  3695. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  3696. if (!bsResult.contains("更新成功")) {
  3697. return CommonResult.fail("百胜平台:" + result.getMsg());
  3698. }
  3699. return CommonResult.ok("更新成功");
  3700. //endregion
  3701. }
  3702. //endregion
  3703. //region 百胜新增学生
  3704. public CommonResult<String> bsInsertStudent(String name, String cardNo, Integer sexId, String
  3705. headImage, Integer timeGroupId, String bsClassNo, String startDate, String endDate, String idCard) throws
  3706. Exception {
  3707. //region 百胜新增学生信息
  3708. String appId = controlConfig.getAppId();
  3709. String schoolno = controlConfig.getSchoolCode();
  3710. String timestamp = TimeExchange.DateNowTimeStamo();
  3711. String appSecret = controlConfig.getAppSecret();
  3712. String url = controlConfig.getUrl() + "student/create";
  3713. String idCardStr = org.springframework.util.StringUtils.hasText(idCard) ? "\",\"student_idcard\":\"" + idCard : "\",\"student_idcard\":\"" + "";
  3714. String bsGroupNo = eGroupTime(timeGroupId);
  3715. JSONObject jsonobject = new JSONObject();
  3716. jsonobject.put("appid", appId);
  3717. 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 + "\"}";
  3718. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3719. jsonobject.put("data", aesStr);
  3720. jsonobject.put("schoolno", schoolno);
  3721. jsonobject.put("timestamp", timestamp);
  3722. 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 + "&timestamp=" + timestamp + "&key=" + appSecret;
  3723. String sign = CommonUtil.MD5(md5Str);
  3724. //sign签名
  3725. jsonobject.put("sign", sign);
  3726. //返回的结果中 code为1表示成功
  3727. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3728. ObjectMapper objectMapper = new ObjectMapper();
  3729. BsStudentVo grade = objectMapper.readValue(bsResult, BsStudentVo.class);
  3730. if (!bsResult.contains("添加成功")) {
  3731. return CommonResult.fail("百胜平台:" + grade.getMsg());
  3732. }
  3733. // URL解码
  3734. String decodedUrl = URLDecoder.decode(grade.getData(), "UTF-8");
  3735. BsStudentNoVo studentNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStudentNoVo.class);
  3736. return CommonResult.ok("200", "新增成功", studentNo.getStudent_no());
  3737. //endregion
  3738. }
  3739. //endregion
  3740. //region 百胜删除学生
  3741. public CommonResult bsDeleteStudent(SmartUser su) throws Exception {
  3742. //region 百胜删除学生
  3743. String appId = controlConfig.getAppId();
  3744. String schoolno = controlConfig.getSchoolCode();
  3745. String timestamp = TimeExchange.DateNowTimeStamo();
  3746. String appSecret = controlConfig.getAppSecret();
  3747. String url = controlConfig.getUrl() + "student/delete";
  3748. JSONObject jsonobject = new JSONObject();
  3749. jsonobject.put("appid", appId);
  3750. String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\"}";
  3751. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3752. jsonobject.put("data", aesStr);
  3753. jsonobject.put("schoolno", schoolno);
  3754. jsonobject.put("timestamp", timestamp);
  3755. String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  3756. String sign = CommonUtil.MD5(md5Str);
  3757. //sign签名
  3758. jsonobject.put("sign", sign);
  3759. //返回的结果中 code为1表示成功
  3760. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3761. ObjectMapper objectMapper = new ObjectMapper();
  3762. BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
  3763. if (!bsResult.contains("删除学生成功")) {
  3764. return CommonResult.fail("百胜平台:" + result.getMsg());
  3765. }
  3766. return CommonResult.ok("操作成功");
  3767. //endregion
  3768. }
  3769. //endregion
  3770. //region 百胜添加教师
  3771. public CommonResult<String> bsInsertTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
  3772. Exception {
  3773. //region 百胜添加教师数据
  3774. String appId = controlConfig.getAppId();
  3775. String schoolno = controlConfig.getSchoolCode();
  3776. String timestamp = TimeExchange.DateNowTimeStamo();
  3777. String appSecret = controlConfig.getAppSecret();
  3778. String url = controlConfig.getUrl() + "staff/create";
  3779. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"staff_idcard\":\"" + su.getIdCard() : "\",\"staff_idcard\":\"" + "";
  3780. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  3781. JSONObject jsonobject = new JSONObject();
  3782. jsonobject.put("appid", appId);
  3783. 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 + "\"}";
  3784. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3785. jsonobject.put("data", aesStr);
  3786. jsonobject.put("schoolno", schoolno);
  3787. jsonobject.put("timestamp", timestamp);
  3788. 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 + "&timestamp=" + timestamp + "&key=" + appSecret;
  3789. String sign = CommonUtil.MD5(md5Str);
  3790. //sign签名
  3791. jsonobject.put("sign", sign);
  3792. //返回的结果中 code为1表示成功
  3793. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3794. ObjectMapper objectMapper = new ObjectMapper();
  3795. BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
  3796. if (!bsResult.contains("添加成功")) {
  3797. return CommonResult.fail("百胜平台:" + staff.getMsg());
  3798. }
  3799. // URL解码
  3800. String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
  3801. BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
  3802. su.setBsStaffCode(staffNo.getStaff_no());
  3803. return CommonResult.ok("200", "新增成功", staffNo.getStaff_no());
  3804. //endregion
  3805. }
  3806. //endregion
  3807. //region 百胜更新教师
  3808. public CommonResult<String> updateBsTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
  3809. Exception {
  3810. //region 百胜更新教师数据
  3811. String appId = controlConfig.getAppId();
  3812. String schoolno = controlConfig.getSchoolCode();
  3813. String timestamp = TimeExchange.DateNowTimeStamo();
  3814. String appSecret = controlConfig.getAppSecret();
  3815. String url = controlConfig.getUrl() + "staff/update";
  3816. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"staff_idcard\":\"" + su.getIdCard() : "\",\"staff_idcard\":\"" + "";
  3817. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  3818. JSONObject jsonobject = new JSONObject();
  3819. jsonobject.put("appid", appId);
  3820. 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 + "\"}";
  3821. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3822. jsonobject.put("data", aesStr);
  3823. jsonobject.put("schoolno", schoolno);
  3824. jsonobject.put("timestamp", timestamp);
  3825. 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 + "&timestamp=" + timestamp + "&key=" + appSecret;
  3826. String sign = CommonUtil.MD5(md5Str);
  3827. //sign签名
  3828. jsonobject.put("sign", sign);
  3829. //返回的结果中 code为1表示成功
  3830. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3831. ObjectMapper objectMapper = new ObjectMapper();
  3832. BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
  3833. if (!bsResult.contains("更新成功")) {
  3834. return CommonResult.fail("百胜平台:" + staff.getMsg());
  3835. }
  3836. // URL解码
  3837. String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
  3838. BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
  3839. return CommonResult.ok("200", "操作成功", staffNo.getStaff_no());
  3840. //endregion
  3841. }
  3842. //endregion
  3843. //region百胜删除教师
  3844. public CommonResult bsDeleteTeacher(String staffNo) throws Exception {
  3845. //region 百胜删除教师
  3846. String appId = controlConfig.getAppId();
  3847. String schoolno = controlConfig.getSchoolCode();
  3848. String timestamp = TimeExchange.DateNowTimeStamo();
  3849. String appSecret = controlConfig.getAppSecret();
  3850. String url = controlConfig.getUrl() + "staff/delete";
  3851. JSONObject jsonobject = new JSONObject();
  3852. jsonobject.put("appid", appId);
  3853. String str = "{\"staff_no\":\"" + staffNo + "\"}";
  3854. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3855. jsonobject.put("data", aesStr);
  3856. jsonobject.put("schoolno", schoolno);
  3857. jsonobject.put("timestamp", timestamp);
  3858. String md5Str = "appid=" + appId + "&data={\"staff_no\":\"" + staffNo + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  3859. String sign = CommonUtil.MD5(md5Str);
  3860. //sign签名
  3861. jsonobject.put("sign", sign);
  3862. //返回的结果中 code为1表示成功
  3863. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3864. ObjectMapper objectMapper = new ObjectMapper();
  3865. BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
  3866. if (!bsResult.contains("删除员工成功")) {
  3867. return CommonResult.fail("百胜平台:" + result.getMsg());
  3868. }
  3869. return CommonResult.ok("删除成功");
  3870. //endregion
  3871. }
  3872. //endregion
  3873. //endregion
  3874. //region 用户分页数据
  3875. /**
  3876. * 用户分页数据查询
  3877. *
  3878. * @param currentPage 当前页数
  3879. * @param pageCount 一页数据条数
  3880. * @param departmentId 部门ID
  3881. * @return
  3882. */
  3883. @Override
  3884. @DESRespondSecret(validated = true)
  3885. public CommonResult queryPageSmartUser(int currentPage, int pageCount, Integer departmentId, String
  3886. name, String userhead) {
  3887. //region 角色判断
  3888. String userID = AesUtils.decrypt(userhead);
  3889. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  3890. if (operateData == null) {
  3891. return CommonResult.fail("用户信息不合法,无法查看");
  3892. }
  3893. QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
  3894. queryWrapper.eq("user_id", operateData.getId());
  3895. List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
  3896. if (authorities == null) {
  3897. return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
  3898. }
  3899. if (authorities.size() <= 0) {
  3900. return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
  3901. }
  3902. List<String> viewAuthors = new ArrayList<>();//部门查看权限
  3903. List<String> manageAuthors = new ArrayList<>();//部门管理权限
  3904. for (SmartAuthority author : authorities) {
  3905. List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
  3906. if (views != null && views.size() > 0) {
  3907. viewAuthors.addAll(views);
  3908. }
  3909. List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
  3910. if (manages != null && manages.size() > 0) {
  3911. manageAuthors.addAll(manages);
  3912. }
  3913. }
  3914. List<String> AllAuths = new ArrayList<>();
  3915. AllAuths.addAll(viewAuthors);
  3916. AllAuths.addAll(manageAuthors);
  3917. AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
  3918. //endregion
  3919. //获取该部门下的所有子级部门ID
  3920. List<Integer> childDepartmentIds = new ArrayList<>();
  3921. List<SmartDepartment> departments = smartDepartmentService.list(null);
  3922. childDepartmentIds.add(departmentId);
  3923. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  3924. if (departmentId == null) {
  3925. childDepartmentIds = null;
  3926. }
  3927. List<Integer> authDepartments = new ArrayList<>();
  3928. for (Integer child : childDepartmentIds) {
  3929. if (AllAuths.contains(String.valueOf(child))) {
  3930. authDepartments.add(child);
  3931. }
  3932. }
  3933. PageUtils<UserVo> result = null;
  3934. if (authDepartments != null && authDepartments.size() > 0) {
  3935. result = smartUserService.querySmartUserPages(currentPage, pageCount, authDepartments, name);
  3936. } else {
  3937. IPage<UserVo> userData = new Page<>();
  3938. result = new PageUtils<UserVo>(userData);
  3939. }
  3940. if (result != null && result.getList() != null) {
  3941. List<Integer> studentIds = new ArrayList<>();
  3942. List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
  3943. for (String studentStr : studentStrs) {
  3944. if (!ObjectUtils.isEmpty(studentStr)) {
  3945. studentIds.add(Integer.valueOf(studentStr));
  3946. }
  3947. }
  3948. List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
  3949. List<SmartClass> classs = smartClassService.list(null);
  3950. List<SmartIdentity> idnetitys = smartIdentityService.list(null);
  3951. List<SmartTimeGroup> timeGroups = smartTimeGroupService.list(null);
  3952. List<Integer> userIds = result.getList().stream().map(UserVo::getId).collect(Collectors.toList());
  3953. List<UserSubjectVo> teachings = smartTeachingService.querySmartTeachings(userIds);
  3954. for (UserVo data : result.getList()) {
  3955. //region 任课数据
  3956. List<UserSubjectVo> ownerTeachings = teachings.stream().filter(e -> e.getUserId().equals(data.getId())).collect(Collectors.toList());
  3957. if (ownerTeachings != null && ownerTeachings.size() > 0) {
  3958. List<isrRequest> subjectVos = new ArrayList<>();
  3959. for (UserSubjectVo ownerTeaching : ownerTeachings) {
  3960. isrRequest ir = new isrRequest();
  3961. Integer[] ids = new Integer[3];
  3962. //用这种方式能避免重复引用
  3963. //简单说,重复引用就是一个集合/对象中的多个元素/属性同时引用同一对象,循环引用就是集合/对象中的多个元素/属性存在相互引用导致循环。
  3964. Integer subjectId = new Integer(ownerTeaching.getSubjectId());
  3965. ids[0] = subjectId;
  3966. Integer gradeId = new Integer(ownerTeaching.getGradeId());
  3967. ids[1] = gradeId;
  3968. Integer classId = new Integer(ownerTeaching.getClassId());
  3969. ids[2] = classId;
  3970. ir.setIds(Arrays.asList(ids));
  3971. subjectVos.add(ir);
  3972. }
  3973. data.setSubjectVos(subjectVos);
  3974. }
  3975. //endregion
  3976. //时间组
  3977. Optional<SmartTimeGroup> oTimeGroup = timeGroups.stream().filter(e -> e.getId().equals(data.getTimeGroupId())).findFirst();
  3978. if (oTimeGroup != null && oTimeGroup.isPresent()) {
  3979. data.setTimeGroupName(oTimeGroup.get().getName());
  3980. }
  3981. Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
  3982. if (identityData != null && identityData.isPresent()) {
  3983. data.setIdentity(identityData.get().getName());
  3984. }
  3985. data.setSex(eSexStatu.stringOf(data.getSexId()));
  3986. Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  3987. if (departmentData != null && departmentData.isPresent()) {
  3988. data.setDepartment(departmentData.get().getName());
  3989. }
  3990. Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
  3991. if (nowClass != null && nowClass.isPresent()) {
  3992. data.setClassStr(nowClass.get().getName());
  3993. }
  3994. List<AffiliateUserVo> datas = new ArrayList<>();
  3995. if (data.getAffiliate() != null) {
  3996. List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
  3997. for (String a : affiliates) {
  3998. if (!ObjectUtils.isEmpty(a)) {
  3999. Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
  4000. if (student != null && student.isPresent()) {
  4001. AffiliateUserVo affiliate = new AffiliateUserVo();
  4002. affiliate.setId(student.get().getId());
  4003. affiliate.setName(student.get().getName());
  4004. affiliate.setCardNo(student.get().getCardNo());
  4005. affiliate.setDepartmentId(student.get().getDepartmentId());
  4006. datas.add(affiliate);
  4007. }
  4008. }
  4009. }
  4010. }
  4011. data.setAffiliates(datas);
  4012. }
  4013. }
  4014. return CommonResult.ok(result);
  4015. }
  4016. //endregion
  4017. //region 用户分页数据
  4018. /**
  4019. * 用户分页数据查询
  4020. *
  4021. * @param currentPage 当前页数
  4022. * @param pageCount 一页数据条数
  4023. * @param departmentId 部门ID
  4024. * @return
  4025. */
  4026. @Override
  4027. @DESRespondSecret(validated = true)
  4028. public CommonResult queryPageSmartUserNoAuth(int currentPage, int pageCount, Integer departmentId, String
  4029. name, String userhead) {
  4030. //region 角色判断
  4031. String userID = AesUtils.decrypt(userhead);
  4032. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  4033. if (operateData == null) {
  4034. return CommonResult.fail("用户信息不合法,无法查看");
  4035. }
  4036. //endregion
  4037. //获取该部门下的所有子级部门ID
  4038. List<Integer> childDepartmentIds = new ArrayList<>();
  4039. List<SmartDepartment> departments = smartDepartmentService.list(null);
  4040. childDepartmentIds.add(departmentId);
  4041. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  4042. if (departmentId == null) {
  4043. childDepartmentIds = null;
  4044. }
  4045. PageUtils<UserVo> result = null;
  4046. if (childDepartmentIds != null && childDepartmentIds.size() > 0) {
  4047. result = smartUserService.querySmartUserPages(currentPage, pageCount, childDepartmentIds, name);
  4048. } else {
  4049. IPage<UserVo> userData = new Page<>();
  4050. result = new PageUtils<UserVo>(userData);
  4051. }
  4052. if (result != null && result.getList() != null) {
  4053. List<Integer> studentIds = new ArrayList<>();
  4054. List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
  4055. for (String studentStr : studentStrs) {
  4056. if (!ObjectUtils.isEmpty(studentStr)) {
  4057. studentIds.add(Integer.valueOf(studentStr));
  4058. }
  4059. }
  4060. List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
  4061. List<SmartClass> classs = smartClassService.list(null);
  4062. List<SmartIdentity> idnetitys = smartIdentityService.list(null);
  4063. for (UserVo data : result.getList()) {
  4064. data.setTimeGroupName(eGroupTime(data.getTimeGroupId()));
  4065. Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
  4066. if (identityData != null && identityData.isPresent()) {
  4067. data.setIdentity(identityData.get().getName());
  4068. }
  4069. data.setSex(eSexStatu.stringOf(data.getSexId()));
  4070. Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  4071. if (departmentData != null && departmentData.isPresent()) {
  4072. data.setDepartment(departmentData.get().getName());
  4073. }
  4074. Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
  4075. if (nowClass != null && nowClass.isPresent()) {
  4076. data.setClassStr(nowClass.get().getName());
  4077. }
  4078. List<AffiliateUserVo> datas = new ArrayList<>();
  4079. if (data.getAffiliate() != null) {
  4080. List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
  4081. for (String a : affiliates) {
  4082. if (!ObjectUtils.isEmpty(a)) {
  4083. Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
  4084. if (student != null && student.isPresent()) {
  4085. AffiliateUserVo affiliate = new AffiliateUserVo();
  4086. affiliate.setId(student.get().getId());
  4087. affiliate.setName(student.get().getName());
  4088. affiliate.setCardNo(student.get().getCardNo());
  4089. affiliate.setDepartmentId(student.get().getDepartmentId());
  4090. datas.add(affiliate);
  4091. }
  4092. }
  4093. }
  4094. }
  4095. data.setAffiliates(datas);
  4096. }
  4097. }
  4098. return CommonResult.ok(result);
  4099. }
  4100. //endregion
  4101. //region 导出表头列表集合
  4102. @Override
  4103. @DESRespondSecret(validated = false)
  4104. public CommonResult gauageOutfit() {
  4105. int i = 1;
  4106. List<gauageOutfitVo> govs = new ArrayList<>();
  4107. //region 学号
  4108. gauageOutfitVo cardNo = new gauageOutfitVo();
  4109. cardNo.setId(i);
  4110. cardNo.setName("学号");
  4111. govs.add(cardNo);
  4112. i++;
  4113. //endregion
  4114. //region 姓名
  4115. gauageOutfitVo name = new gauageOutfitVo();
  4116. name.setId(i);
  4117. name.setName("姓名");
  4118. govs.add(name);
  4119. i++;
  4120. //endregion
  4121. //region 身份
  4122. gauageOutfitVo identity = new gauageOutfitVo();
  4123. identity.setId(i);
  4124. identity.setName("身份");
  4125. govs.add(identity);
  4126. i++;
  4127. //endregion
  4128. //region 职务
  4129. gauageOutfitVo duties = new gauageOutfitVo();
  4130. duties.setId(i);
  4131. duties.setName("职务");
  4132. govs.add(duties);
  4133. i++;
  4134. //endregion
  4135. //region 身份证号
  4136. gauageOutfitVo idcard = new gauageOutfitVo();
  4137. idcard.setId(i);
  4138. idcard.setName("身份证号");
  4139. govs.add(idcard);
  4140. i++;
  4141. //endregion
  4142. //region 性别
  4143. gauageOutfitVo sex = new gauageOutfitVo();
  4144. sex.setId(i);
  4145. sex.setName("性别");
  4146. govs.add(sex);
  4147. i++;
  4148. //endregion
  4149. //region 部门
  4150. gauageOutfitVo department = new gauageOutfitVo();
  4151. department.setId(i);
  4152. department.setName("部门");
  4153. govs.add(department);
  4154. i++;
  4155. //endregion
  4156. //region 人脸照片
  4157. gauageOutfitVo iamge = new gauageOutfitVo();
  4158. iamge.setId(i);
  4159. iamge.setName("人脸照片");
  4160. govs.add(iamge);
  4161. i++;
  4162. //endregion
  4163. //region 年级
  4164. gauageOutfitVo grade = new gauageOutfitVo();
  4165. grade.setId(i);
  4166. grade.setName("年级");
  4167. govs.add(grade);
  4168. i++;
  4169. //endregion
  4170. //region 班级
  4171. gauageOutfitVo classes = new gauageOutfitVo();
  4172. classes.setId(i);
  4173. classes.setName("班级");
  4174. govs.add(classes);
  4175. i++;
  4176. //endregion
  4177. //region 时间组
  4178. gauageOutfitVo timeGroup = new gauageOutfitVo();
  4179. timeGroup.setId(i);
  4180. timeGroup.setName("时间组");
  4181. govs.add(timeGroup);
  4182. i++;
  4183. //endregion
  4184. //region 学院
  4185. gauageOutfitVo college = new gauageOutfitVo();
  4186. college.setId(i);
  4187. college.setName("学院");
  4188. govs.add(college);
  4189. i++;
  4190. //endregion
  4191. //region 专业
  4192. gauageOutfitVo speciality = new gauageOutfitVo();
  4193. speciality.setId(i);
  4194. speciality.setName("专业");
  4195. govs.add(speciality);
  4196. i++;
  4197. //endregion
  4198. //region 校区
  4199. gauageOutfitVo campus = new gauageOutfitVo();
  4200. campus.setId(i);
  4201. campus.setName("校区");
  4202. govs.add(campus);
  4203. i++;
  4204. //endregion
  4205. //region 宿舍号
  4206. gauageOutfitVo dormitory = new gauageOutfitVo();
  4207. dormitory.setId(i);
  4208. dormitory.setName("宿舍号");
  4209. govs.add(dormitory);
  4210. i++;
  4211. //endregion
  4212. //region 手机号
  4213. gauageOutfitVo phone = new gauageOutfitVo();
  4214. phone.setId(i);
  4215. phone.setName("手机号");
  4216. govs.add(phone);
  4217. i++;
  4218. //endregion
  4219. //region 关联人
  4220. gauageOutfitVo affiliate = new gauageOutfitVo();
  4221. affiliate.setId(i);
  4222. affiliate.setName("关联人");
  4223. govs.add(affiliate);
  4224. i++;
  4225. //endregion
  4226. //region 职称
  4227. gauageOutfitVo title = new gauageOutfitVo();
  4228. title.setId(i);
  4229. title.setName("职称");
  4230. govs.add(title);
  4231. i++;
  4232. //endregion
  4233. //region 家庭地址
  4234. gauageOutfitVo address = new gauageOutfitVo();
  4235. address.setId(i);
  4236. address.setName("家庭地址");
  4237. govs.add(address);
  4238. i++;
  4239. //endregion
  4240. //region 民族
  4241. gauageOutfitVo nation = new gauageOutfitVo();
  4242. nation.setId(i);
  4243. nation.setName("民族");
  4244. govs.add(nation);
  4245. i++;
  4246. //endregion
  4247. //region 生源地
  4248. gauageOutfitVo student = new gauageOutfitVo();
  4249. student.setId(i);
  4250. student.setName("生源地");
  4251. govs.add(student);
  4252. i++;
  4253. //endregion
  4254. //region 毕业学院
  4255. gauageOutfitVo graduate = new gauageOutfitVo();
  4256. graduate.setId(i);
  4257. graduate.setName("毕业学院");
  4258. govs.add(graduate);
  4259. //endregion
  4260. return CommonResult.ok(govs);
  4261. }
  4262. @Override
  4263. @DESRespondSecret(validated = true)
  4264. public CommonResult getPage(int currentPage, int pageCount, String keyWord) {
  4265. LambdaQueryWrapper<SmartUser> wrapper = new LambdaQueryWrapper<>();
  4266. wrapper.like(ObjectUtils.isNotEmpty(keyWord), SmartUser::getName, keyWord);
  4267. IPage<SmartUser> page = smartUserService.page(new Page<>(currentPage, pageCount), wrapper);
  4268. return CommonResult.ok(page);
  4269. }
  4270. @Override
  4271. @DESRespondSecret(validated = true)
  4272. @PassToken
  4273. public CommonResult studentSelect(String keyWord) {
  4274. if (ObjectUtils.isEmpty(keyWord)) {
  4275. return CommonResult.fail();
  4276. }
  4277. List<StudentSelectVo> list = smartUserService.studentSelect(keyWord);
  4278. return CommonResult.ok(list);
  4279. }
  4280. //endregion
  4281. //region 用户导出
  4282. /**
  4283. * @param response 响应头
  4284. * @param userhead 请求头
  4285. * @param sure 请求参数
  4286. */
  4287. @Override
  4288. @DESRespondSecret(validated = false)
  4289. public CommonResult smartUserExport(HttpServletResponse response, String userhead, smartUserExportRequest sure) {
  4290. if (sure.getGauageOutfitVos() == null) {
  4291. return CommonResult.fail("表头数据为空");
  4292. }
  4293. if (sure.getGauageOutfitVos().size() <= 0) {
  4294. return CommonResult.fail("表头数据为空");
  4295. }
  4296. //region 角色判断
  4297. String userID = AesUtils.decrypt(userhead);
  4298. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  4299. if (operateData != null && sure != null && sure.getGauageOutfitVos() != null && sure.getGauageOutfitVos().size() > 0) {
  4300. QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
  4301. queryWrapper.eq("user_id", operateData.getId());
  4302. List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
  4303. if (authorities != null && authorities.size() > 0) {
  4304. List<String> viewAuthors = new ArrayList<>();//部门查看权限
  4305. List<String> manageAuthors = new ArrayList<>();//部门管理权限
  4306. for (SmartAuthority author : authorities) {
  4307. List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
  4308. if (views != null && views.size() > 0) {
  4309. viewAuthors.addAll(views);
  4310. }
  4311. List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
  4312. if (manages != null && manages.size() > 0) {
  4313. manageAuthors.addAll(manages);
  4314. }
  4315. }
  4316. List<String> AllAuths = new ArrayList<>();
  4317. AllAuths.addAll(viewAuthors);
  4318. AllAuths.addAll(manageAuthors);
  4319. AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
  4320. //endregion
  4321. //获取该部门下的所有子级部门ID
  4322. List<Integer> childDepartmentIds = new ArrayList<>();
  4323. List<SmartDepartment> departments = smartDepartmentService.list(null);
  4324. Integer departmentId = sure != null ? sure.getDepartmentId() : null;
  4325. childDepartmentIds.add(departmentId);
  4326. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  4327. if (departmentId == null) {
  4328. childDepartmentIds = null;
  4329. }
  4330. List<Integer> authDepartments = new ArrayList<>();
  4331. for (Integer child : childDepartmentIds) {
  4332. if (AllAuths.contains(String.valueOf(child))) {
  4333. authDepartments.add(child);
  4334. }
  4335. }
  4336. String name = sure != null ? sure.getName() : null;
  4337. List<SmartUser> users = smartUserService.querySmartUsers(authDepartments, name);
  4338. List<String> affiliates = new ArrayList<>();
  4339. List<String> affiliateStr = users.stream().map(SmartUser::getAffiliate).distinct().collect(Collectors.toList());
  4340. for (String datas : affiliateStr) {
  4341. if (!ObjectUtils.isEmpty(datas)) {
  4342. String[] dataArray = datas.split(",");
  4343. for (int i = 0; i < dataArray.length; i++) {
  4344. affiliates.add(dataArray[i]);
  4345. }
  4346. }
  4347. }
  4348. List<SmartUser> affiliateDatas = affiliates != null && affiliates.size() > 0 ? smartUserService.getSmartUserIds(affiliates) : null;
  4349. List<Integer> dutieIds = users != null && users.size() > 0 ? users.stream().map(SmartUser::getDuties).collect(Collectors.toList()) : null;
  4350. //职务数据
  4351. List<SmartDuties> duties = dutieIds != null && dutieIds.size() > 0 ? smartDutiesService.queryDutiesByIds(dutieIds) : null;
  4352. //年级
  4353. List<SmartGrade> grades = smartGradeService.list(null);
  4354. //班级
  4355. List<SmartClass> classes = smartClassService.list(null);
  4356. //导出
  4357. Workbook workbook = new XSSFWorkbook();
  4358. Sheet sheet = workbook.createSheet("用户信息管理");
  4359. Row headerRow = sheet.createRow(0);
  4360. int exportIndex = 1;
  4361. List<String> gauageStrs = sure.getGauageOutfitVos().stream().map(gauageOutfitVo::getName).collect(Collectors.toList());
  4362. headerRow.createCell(0).setCellValue("序号");
  4363. if (gauageStrs.contains("学号")) {
  4364. headerRow.createCell(exportIndex).setCellValue("学号");
  4365. exportIndex++;
  4366. }
  4367. if (gauageStrs.contains("姓名")) {
  4368. headerRow.createCell(exportIndex).setCellValue("姓名");
  4369. exportIndex++;
  4370. }
  4371. if (gauageStrs.contains("身份")) {
  4372. headerRow.createCell(exportIndex).setCellValue("身份");
  4373. exportIndex++;
  4374. }
  4375. if (gauageStrs.contains("职务")) {
  4376. headerRow.createCell(exportIndex).setCellValue("职务");
  4377. exportIndex++;
  4378. }
  4379. if (gauageStrs.contains("身份证号")) {
  4380. headerRow.createCell(exportIndex).setCellValue("身份证号");
  4381. exportIndex++;
  4382. }
  4383. if (gauageStrs.contains("性别")) {
  4384. headerRow.createCell(exportIndex).setCellValue("性别");
  4385. exportIndex++;
  4386. }
  4387. if (gauageStrs.contains("部门")) {
  4388. headerRow.createCell(exportIndex).setCellValue("部门");
  4389. exportIndex++;
  4390. }
  4391. if (gauageStrs.contains("人脸照片")) {
  4392. headerRow.createCell(exportIndex).setCellValue("人脸照片");
  4393. exportIndex++;
  4394. }
  4395. if (gauageStrs.contains("年级")) {
  4396. headerRow.createCell(exportIndex).setCellValue("年级");
  4397. exportIndex++;
  4398. }
  4399. if (gauageStrs.contains("班级")) {
  4400. headerRow.createCell(exportIndex).setCellValue("班级");
  4401. exportIndex++;
  4402. }
  4403. if (gauageStrs.contains("时间组")) {
  4404. headerRow.createCell(exportIndex).setCellValue("时间组");
  4405. exportIndex++;
  4406. }
  4407. if (gauageStrs.contains("学院")) {
  4408. headerRow.createCell(exportIndex).setCellValue("学院");
  4409. exportIndex++;
  4410. }
  4411. if (gauageStrs.contains("专业")) {
  4412. headerRow.createCell(exportIndex).setCellValue("专业");
  4413. exportIndex++;
  4414. }
  4415. if (gauageStrs.contains("校区")) {
  4416. headerRow.createCell(exportIndex).setCellValue("校区");
  4417. exportIndex++;
  4418. }
  4419. if (gauageStrs.contains("宿舍号")) {
  4420. headerRow.createCell(exportIndex).setCellValue("宿舍号");
  4421. exportIndex++;
  4422. }
  4423. if (gauageStrs.contains("手机号")) {
  4424. headerRow.createCell(exportIndex).setCellValue("手机号");
  4425. exportIndex++;
  4426. }
  4427. if (gauageStrs.contains("关联人")) {
  4428. headerRow.createCell(exportIndex).setCellValue("关联人");
  4429. exportIndex++;
  4430. }
  4431. if (gauageStrs.contains("职称")) {
  4432. headerRow.createCell(exportIndex).setCellValue("职称");
  4433. exportIndex++;
  4434. }
  4435. if (gauageStrs.contains("家庭住址")) {
  4436. headerRow.createCell(exportIndex).setCellValue("家庭住址");
  4437. exportIndex++;
  4438. }
  4439. if (gauageStrs.contains("民族")) {
  4440. headerRow.createCell(exportIndex).setCellValue("民族");
  4441. exportIndex++;
  4442. }
  4443. if (gauageStrs.contains("生源地")) {
  4444. headerRow.createCell(exportIndex).setCellValue("生源地");
  4445. exportIndex++;
  4446. }
  4447. if (gauageStrs.contains("毕业学院")) {
  4448. headerRow.createCell(exportIndex).setCellValue("毕业学院");
  4449. exportIndex++;
  4450. }
  4451. List<SmartTimeGroup> timeGroups = new ArrayList<>();
  4452. if (gauageStrs.contains("时间组")) {
  4453. timeGroups = smartTimeGroupService.list(null);
  4454. }
  4455. for (int i = 0; i < users.size(); i++) {
  4456. int valueIndex = 1;
  4457. SmartUser user = users.get(i);
  4458. Row dataRow = sheet.createRow(i + 1);
  4459. dataRow.createCell(0).setCellValue(i + 1);//序号
  4460. if (gauageStrs.contains("学号")) {
  4461. dataRow.createCell(valueIndex).setCellValue(user.getCardNo());//学号
  4462. valueIndex++;
  4463. }
  4464. if (gauageStrs.contains("姓名")) {
  4465. dataRow.createCell(valueIndex).setCellValue(user.getName());//姓名
  4466. valueIndex++;
  4467. }
  4468. if (gauageStrs.contains("身份")) {
  4469. dataRow.createCell(valueIndex).setCellValue(eIdentityStatu.stringOf(user.getIdentityId()));//身份
  4470. valueIndex++;
  4471. }
  4472. if (gauageStrs.contains("职务")) {
  4473. String dutieStr = "";
  4474. if (duties != null && duties.size() > 0 && user.getDuties() != null) {
  4475. Optional<SmartDuties> oduty = duties.stream().filter(e -> e.getId().equals(user.getDuties())).findFirst();
  4476. if (oduty != null && oduty.isPresent()) {
  4477. dutieStr = oduty.get().getName();
  4478. }
  4479. }
  4480. dataRow.createCell(valueIndex).setCellValue(dutieStr);//职务
  4481. valueIndex++;
  4482. }
  4483. if (gauageStrs.contains("身份证号")) {
  4484. dataRow.createCell(valueIndex).setCellValue(user.getIdCard());//身份证号
  4485. valueIndex++;
  4486. }
  4487. if (gauageStrs.contains("性别")) {
  4488. dataRow.createCell(valueIndex).setCellValue(eSexStatu.stringOf(user.getSexId()));//性别
  4489. valueIndex++;
  4490. }
  4491. if (gauageStrs.contains("部门")) {
  4492. //获取父级部门ID
  4493. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(user.getDepartmentId())).findFirst();
  4494. if (department != null && department.isPresent()) {
  4495. dataRow.createCell(valueIndex).setCellValue(QueryParentDepartments(department.get().getParentId(), departments, null));//部门
  4496. }
  4497. valueIndex++;
  4498. }
  4499. if (gauageStrs.contains("人脸照片")) {
  4500. dataRow.createCell(valueIndex).setCellValue(user.getHeadImage() == null ? "" : user.getHeadImage());//人脸
  4501. valueIndex++;
  4502. }
  4503. if (gauageStrs.contains("年级")) {
  4504. String grade = "";
  4505. Optional<SmartGrade> gradeData = grades == null ? null : grades.stream().filter(e -> e.getId().toString().equals(user.getGrade())).findFirst();
  4506. if (gradeData != null && gradeData.isPresent()) {
  4507. grade = gradeData.get().getName();
  4508. }
  4509. dataRow.createCell(valueIndex).setCellValue(grade);//年级
  4510. valueIndex++;
  4511. }
  4512. if (gauageStrs.contains("班级")) {
  4513. String classStr = "";
  4514. Optional<SmartClass> classData = classes == null ? null : classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
  4515. if (classData != null && classData.isPresent()) {
  4516. classStr = classData.get().getName();
  4517. }
  4518. dataRow.createCell(valueIndex).setCellValue(classStr);//班级
  4519. valueIndex++;
  4520. }
  4521. if (gauageStrs.contains("时间组")) {
  4522. Optional<SmartTimeGroup> oTime = timeGroups != null && timeGroups.size() > 0 && user.getTimeGroupId() != null ? timeGroups.stream().filter(e -> e.getId().equals(user.getTimeGroupId())).findFirst() : null;
  4523. String timeStr = "";
  4524. if (oTime != null && oTime.isPresent()) {
  4525. timeStr = oTime.get().getName();
  4526. }
  4527. dataRow.createCell(valueIndex).setCellValue(timeStr);//时间组
  4528. valueIndex++;
  4529. }
  4530. if (gauageStrs.contains("学院")) {
  4531. dataRow.createCell(valueIndex).setCellValue(user.getCollege() == null ? "" : user.getCollege());//学院
  4532. valueIndex++;
  4533. }
  4534. if (gauageStrs.contains("专业")) {
  4535. dataRow.createCell(valueIndex).setCellValue(user.getSpeciality() == null ? "" : user.getSpeciality());//专业
  4536. valueIndex++;
  4537. }
  4538. if (gauageStrs.contains("校区")) {
  4539. dataRow.createCell(valueIndex).setCellValue(user.getCampus() == null ? "" : user.getCampus());//校区
  4540. valueIndex++;
  4541. }
  4542. if (gauageStrs.contains("宿舍号")) {
  4543. dataRow.createCell(valueIndex).setCellValue(user.getDormitoryNumber() == null ? "" : user.getDormitoryNumber());//宿舍号
  4544. valueIndex++;
  4545. }
  4546. if (gauageStrs.contains("手机号")) {
  4547. dataRow.createCell(valueIndex).setCellValue(user.getPhone() == null ? "" : user.getPhone());//手机号
  4548. valueIndex++;
  4549. }
  4550. if (gauageStrs.contains("关联人")) {
  4551. List<String> affiliateCellStrs = new ArrayList<>();
  4552. if (user.getAffiliate() != null && affiliateDatas != null) {
  4553. String[] affArrayStr = user.getAffiliate().split(",");
  4554. for (int j = 0; j < affArrayStr.length; j++) {
  4555. String affArrayIndex = affArrayStr[j];
  4556. Optional<SmartUser> affUser = affiliateDatas.stream().filter(e -> e.getId().toString().equals(affArrayIndex)).findFirst();
  4557. if (affUser != null && affUser.isPresent()) {
  4558. affiliateCellStrs.add(affUser.get().getName());
  4559. }
  4560. }
  4561. }
  4562. dataRow.createCell(valueIndex).setCellValue(StringUtils.join(affiliateCellStrs, ","));//关联人
  4563. valueIndex++;
  4564. }
  4565. if (gauageStrs.contains("职称")) {
  4566. dataRow.createCell(valueIndex).setCellValue(user.getTitle() == null ? "" : user.getTitle());//职称
  4567. valueIndex++;
  4568. }
  4569. if (gauageStrs.contains("家庭住址")) {
  4570. dataRow.createCell(valueIndex).setCellValue(user.getAddress() == null ? "" : user.getAddress());//家庭住址
  4571. valueIndex++;
  4572. }
  4573. if (gauageStrs.contains("民族")) {
  4574. dataRow.createCell(valueIndex).setCellValue(user.getNation() == null ? "" : user.getNation());//民族
  4575. valueIndex++;
  4576. }
  4577. if (gauageStrs.contains("生源地")) {
  4578. dataRow.createCell(valueIndex).setCellValue(user.getOfStudent() == null ? "" : user.getOfStudent());//生源地
  4579. valueIndex++;
  4580. }
  4581. if (gauageStrs.contains("毕业学院")) {
  4582. dataRow.createCell(valueIndex).setCellValue(user.getGraduate() == null ? "" : user.getGraduate());//毕业学校
  4583. valueIndex++;
  4584. }
  4585. }
  4586. // 将工作簿写入文件
  4587. ExcelUtils.excelDownload(workbook, "用户信息.xlsx", response);
  4588. }
  4589. }
  4590. return CommonResult.ok("导出成功");
  4591. }
  4592. //endregion
  4593. //region 根据父级ID获取树形数据
  4594. /**
  4595. * 根据父级ID获取树形数据
  4596. *
  4597. * @param parentID 父级ID
  4598. * @param lists 数据集合
  4599. * @return
  4600. */
  4601. private List<DepartmentTreeVo> QueryDepartmentTreeRecords
  4602. (Integer
  4603. parentID, List<SmartDepartment> lists, List<Integer> departmentIds) {
  4604. List<DepartmentTreeVo> newTrees = new ArrayList<>();
  4605. List<SmartDepartment> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
  4606. for (SmartDepartment data : datas) {
  4607. departmentIds.add(data.getId());
  4608. QueryDepartmentTreeRecords(data.getId(), lists, departmentIds);
  4609. }
  4610. return newTrees;
  4611. }
  4612. //endregion
  4613. //region 根据父级ID往上查找父级数据
  4614. /**
  4615. * 根据父级ID获取父级数据
  4616. *
  4617. * @param parentID 子级ID
  4618. * @param lists 数据集合
  4619. * @return
  4620. */
  4621. private String QueryParentDepartments
  4622. (Integer
  4623. parentID, List<SmartDepartment> lists, String
  4624. departmentStr) {
  4625. Optional<SmartDepartment> data = lists.stream().filter(e -> e.getId().equals(parentID)).findFirst();
  4626. if (data != null && data.isPresent()) {
  4627. departmentStr = departmentStr == null ? data.get().getName() : data.get().getName() + "/" + departmentStr;
  4628. departmentStr = QueryParentDepartments(data.get().getParentId(), lists, departmentStr);
  4629. }
  4630. return departmentStr;
  4631. }
  4632. //endregion
  4633. //region 根据数据ID删除用户数据(旧的)
  4634. @Override
  4635. @DESRespondSecret(validated = true)
  4636. public CommonResult deleteSmartUserByIdOld
  4637. (useridsRequest ur, BindingResult
  4638. bindingResult) throws Exception {
  4639. if (bindingResult.hasErrors()) {
  4640. String st = paramUtils.getParamError(bindingResult);
  4641. return CommonResult.fail(st);
  4642. }
  4643. List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
  4644. if (users.size() != ur.getUserIds().size()) {
  4645. return CommonResult.fail("存在无效用户数据,删除失败!");
  4646. }
  4647. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4648. for (SmartUser user : users) {
  4649. if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
  4650. List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
  4651. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
  4652. //region 删除原有的家长关系
  4653. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
  4654. if (!deleteResult.isSuccess()) {
  4655. return CommonResult.fail(deleteResult.getMessage());
  4656. }
  4657. //endregion
  4658. } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  4659. //查找家长
  4660. List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
  4661. //获取班级Uid
  4662. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  4663. if (classData == null) {
  4664. return CommonResult.fail("班级数据无效,更新失败");
  4665. }
  4666. //region 百胜删除学生
  4667. CommonResult deleteBsStudent = bsDeleteStudent(user);
  4668. if (!deleteBsStudent.isSuccess()) {
  4669. return CommonResult.fail(deleteBsStudent.getMessage());
  4670. }
  4671. //endregion
  4672. //region 希沃删除学生
  4673. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
  4674. if (!deleteStudent.isSuccess()) {
  4675. return CommonResult.fail(deleteStudent.getMessage());
  4676. }
  4677. //endregion
  4678. if (parents != null) {
  4679. //region 删除原有的家长关系
  4680. CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
  4681. if (!deleteResult.isSuccess()) {
  4682. return CommonResult.fail(deleteResult.getMessage());
  4683. }
  4684. //endregion
  4685. }
  4686. } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  4687. //region 希沃删除教师
  4688. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
  4689. if (!deleteTeacher.isSuccess()) {
  4690. return CommonResult.fail(deleteTeacher.getMessage());
  4691. }
  4692. //endregion
  4693. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4694. if (user.getSchoolClass() == null) {
  4695. return CommonResult.fail("班级数据无效,删除失败");
  4696. }
  4697. //获取班级Uid
  4698. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  4699. if (classData == null) {
  4700. return CommonResult.fail("班级数据无效,删除失败");
  4701. }
  4702. //region 希沃删除班主任
  4703. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4704. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
  4705. if (deleteTeacherMaster.isSuccess()) {
  4706. return CommonResult.fail(deleteTeacherMaster.getMessage());
  4707. }
  4708. }
  4709. //endregion
  4710. }
  4711. //region 百胜删除教师
  4712. CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
  4713. if (!bsDeleteTeacher.isSuccess()) {
  4714. return CommonResult.fail(bsDeleteTeacher.getMessage());
  4715. }
  4716. //endregion
  4717. }
  4718. }
  4719. int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
  4720. if (result > 0) {
  4721. smartTeachingService.deleteByUserIds(ur.getUserIds());
  4722. }
  4723. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  4724. }
  4725. //endregion
  4726. //region 根据数据ID删除用户数据
  4727. @Override
  4728. public CommonResult deleteSmartUserById
  4729. (useridsRequest ur, BindingResult
  4730. bindingResult) throws Exception {
  4731. if (bindingResult.hasErrors()) {
  4732. String st = paramUtils.getParamError(bindingResult);
  4733. return CommonResult.fail(st);
  4734. }
  4735. List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
  4736. if (users.size() != ur.getUserIds().size()) {
  4737. return CommonResult.fail("存在无效用户数据,删除失败!");
  4738. }
  4739. //先删除咱自己数据库里的用户数据
  4740. int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
  4741. if (result <= 0) {
  4742. return CommonResult.fail("删除失败");
  4743. } else {
  4744. // 删除同步到海康平台
  4745. for (SmartUser user : users) {
  4746. Integer identityId = user.getIdentityId();
  4747. if (2 == identityId || identityId == 3) {
  4748. Integer id = user.getId();
  4749. SmartOperationUser smartOperationUser = new SmartOperationUser();
  4750. smartOperationUser.setOperationId(id);
  4751. smartOperationUser.setOperationMode("3");
  4752. smartOperationUser.setStatus(1);
  4753. smartOperationUser.setType(identityId);
  4754. smartOperationUserService.save(smartOperationUser);
  4755. }
  4756. }
  4757. }
  4758. List<deleteUserVo> deleteUsers = new ArrayList<>();
  4759. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4760. for (SmartUser user : users) {
  4761. deleteUserVo deleteUser = new deleteUserVo();
  4762. deleteUser.setId(user.getId());
  4763. if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
  4764. List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
  4765. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
  4766. //region 删除原有的家长关系
  4767. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
  4768. if (!deleteResult.isSuccess()) {
  4769. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败:" + deleteResult.getMessage() + ";";
  4770. deleteUser.setReason(reason);
  4771. //return CommonResult.fail(deleteResult.getMessage());
  4772. }
  4773. //endregion
  4774. //删除家长 根据家长手机号删除下标数据
  4775. smartFamilyIndexService.deleteSmartFamilyByPhone(user.getPhone());
  4776. } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  4777. //查找家长
  4778. List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
  4779. //获取班级Uid
  4780. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  4781. if (classData == null) {
  4782. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;";
  4783. deleteUser.setReason(reason);
  4784. //return CommonResult.fail("班级数据无效,更新失败");
  4785. }
  4786. //region 百胜删除学生
  4787. CommonResult deleteBsStudent = bsDeleteStudent(user);
  4788. if (!deleteBsStudent.isSuccess()) {
  4789. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除学生失败;" + deleteBsStudent.getMessage() + ";";
  4790. deleteUser.setReason(reason);
  4791. //return CommonResult.fail(deleteBsStudent.getMessage());
  4792. }
  4793. //endregion
  4794. //region 希沃删除学生
  4795. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
  4796. if (!deleteStudent.isSuccess()) {
  4797. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除学生失败;" + deleteStudent.getMessage() + ";";
  4798. ;
  4799. deleteUser.setReason(reason);
  4800. //return CommonResult.fail(deleteStudent.getMessage());
  4801. }
  4802. //endregion
  4803. if (parents != null) {
  4804. //region 删除原有的家长关系
  4805. CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
  4806. if (!deleteResult.isSuccess()) {
  4807. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败;" + deleteResult.getMessage() + ";";
  4808. ;
  4809. deleteUser.setReason(reason);
  4810. //return CommonResult.fail(deleteResult.getMessage());
  4811. }
  4812. //endregion
  4813. //删除学生 根据学生学号删除下标数据
  4814. smartFamilyIndexService.deleteSmartFamilyByCardNo(user.getCardNo());
  4815. }
  4816. } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  4817. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4818. if (user.getSchoolClass() == null) {
  4819. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,希沃删除班主任失败;";
  4820. deleteUser.setReason(reason);
  4821. } else {
  4822. //获取班级Uid
  4823. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  4824. if (classData == null) {
  4825. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,希沃删除教师失败;";
  4826. deleteUser.setReason(reason);
  4827. //return CommonResult.fail("班级数据无效,更新失败");
  4828. }
  4829. //region 希沃删除班主任
  4830. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
  4831. if (!deleteTeacherMaster.isSuccess()) {
  4832. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除班主任失败;" + deleteTeacherMaster.getMessage() + ";";
  4833. deleteUser.setReason(reason);
  4834. //return CommonResult.fail(deleteTeacherMaster.getMessage());
  4835. }
  4836. //endregion
  4837. }
  4838. }
  4839. //region 希沃删除教师
  4840. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
  4841. if (!deleteTeacher.isSuccess()) {
  4842. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + deleteTeacher.getMessage() + ";";
  4843. deleteUser.setReason(reason);
  4844. //return CommonResult.fail(deleteTeacher.getMessage());
  4845. }
  4846. //endregion
  4847. //region 百胜删除教师
  4848. CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
  4849. if (!bsDeleteTeacher.isSuccess()) {
  4850. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + bsDeleteTeacher.getMessage() + ";";
  4851. deleteUser.setReason(reason);
  4852. //return CommonResult.fail(bsDeleteTeacher.getMessage());
  4853. }
  4854. //endregion
  4855. }
  4856. if (deleteUser.getReason() != null) {
  4857. deleteUsers.add(deleteUser);
  4858. }
  4859. }
  4860. if (deleteUsers != null && deleteUsers.size() > 0) {
  4861. int deleteUser = smartUserService.deleteUserBatch(deleteUsers);
  4862. if (deleteUser > 0) {
  4863. List<SmartAuthorGroup> allDatas = new ArrayList<>();//要被更新的权限组数据
  4864. List<Integer> deleteGroupId = new ArrayList<>();//要被删除的权限组
  4865. List<Integer> deleteUserId = new ArrayList<>();//要被删除的管理组权限
  4866. for (deleteUserVo dUser : deleteUsers) {
  4867. deleteUserId.add(dUser.getId());
  4868. List<SmartAuthorGroup> authGroups = smartAuthorGroupService.smartAuthorGroup(dUser.getId());
  4869. for (SmartAuthorGroup authGroup : authGroups) {
  4870. List<String> newUserId = new ArrayList<>();
  4871. List<String> userIds = Arrays.asList(authGroup.getUserId().split(","));
  4872. for (String userId : userIds) {
  4873. if (!userId.equals(String.valueOf(dUser.getId()))) {
  4874. newUserId.add(userId);
  4875. }
  4876. }
  4877. if (newUserId != null && newUserId.size() > 0) {
  4878. authGroup.setUserId(StringUtils.join(newUserId, ","));
  4879. allDatas.add(authGroup);
  4880. } else {
  4881. deleteGroupId.add(authGroup.getId());
  4882. }
  4883. }
  4884. }
  4885. if (allDatas != null && allDatas.size() > 0) {//更新权限组
  4886. smartAuthorGroupService.saveBatch(allDatas);
  4887. }
  4888. if (deleteGroupId != null && deleteGroupId.size() > 0) {//删除权限组
  4889. smartAuthorGroupService.deleteSmartAuthorGroupByIds(deleteGroupId);
  4890. }
  4891. if (deleteUserId != null && deleteUserId.size() > 0) {//删除管理组权限
  4892. smartAuthorityService.deleteAuthorityByUserIds(deleteUserId);
  4893. }
  4894. } else {
  4895. return CommonResult.fail("删除失败");
  4896. }
  4897. }
  4898. return CommonResult.ok("删除成功");
  4899. }
  4900. //endregion
  4901. //region 根据当前用户ID获取受访学生数据
  4902. @Override
  4903. @DESRespondSecret(validated = true)
  4904. public CommonResult queryAffiliateUserById
  4905. (int id) {
  4906. List<AffiliateUserVo> result = smartUserService.queryAffiliateUserById(id);
  4907. if (result != null && result.size() > 0) {
  4908. List<SmartDepartment> departments = smartDepartmentService.list(null);
  4909. for (AffiliateUserVo data : result) {
  4910. //获取父级部门ID
  4911. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  4912. if (department != null && department.isPresent()) {
  4913. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  4914. data.setDepartmentName(departmentName);
  4915. }
  4916. }
  4917. }
  4918. return CommonResult.ok(result);
  4919. }
  4920. //endregion
  4921. //region 导出人员Excel模板
  4922. @Override
  4923. @DESRespondSecret(validated = true)
  4924. public CommonResult downloadUserExcel
  4925. () {
  4926. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/人员信息表.xlsx");
  4927. }
  4928. //endregion
  4929. //region 导出教师模板
  4930. @Override
  4931. @DESRespondSecret(validated = true)
  4932. public CommonResult downloadTeacherExcel
  4933. () {
  4934. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/教师信息表.xlsx");
  4935. }
  4936. //endregion
  4937. //region 导出更新人员Excel模板
  4938. @Override
  4939. @DESRespondSecret(validated = true)
  4940. public CommonResult downloadUpdateUserExcel
  4941. () {
  4942. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/更新信息表.xlsx");
  4943. }
  4944. //endregion
  4945. //region 根据用户ID查询学生
  4946. @Override
  4947. @DESRespondSecret(validated = true)
  4948. public CommonResult queryStudents(
  4949. int userId) {
  4950. List<SmartUser> students = new ArrayList<>();
  4951. SmartUser user = smartUserService.getSmartById(userId);
  4952. if (user == null) {
  4953. return CommonResult.fail("用户信息为空,获取学生列表数据失败");
  4954. }
  4955. if (user.getAffiliate() == null) {
  4956. return CommonResult.ok(students);
  4957. }
  4958. List<Integer> affiliateIds = new ArrayList<>();
  4959. List<String> affiliates = Arrays.asList(user.getAffiliate().split(","));
  4960. for (String affiliate : affiliates) {
  4961. affiliateIds.add(Integer.valueOf(affiliate));
  4962. }
  4963. students = smartUserService.getSmartUserByIds(affiliateIds);
  4964. List<ParentOfStudentsVo> result = new ArrayList<>();
  4965. for (SmartUser student : students) {
  4966. ParentOfStudentsVo data = new ParentOfStudentsVo();
  4967. data.setId(student.getId());
  4968. data.setName(student.getName());
  4969. data.setCardNo(student.getCardNo());
  4970. data.setDepartmentId(student.getDepartmentId());
  4971. result.add(data);
  4972. }
  4973. return CommonResult.ok(result);
  4974. }
  4975. //endregion
  4976. //region 根据数据ID获取用户信息
  4977. @Override
  4978. @DESRespondSecret(validated = true)
  4979. public CommonResult queryInfoData(
  4980. int id) {
  4981. SmartUser su = smartUserService.getSmartById(id);
  4982. if (su == null) {
  4983. return CommonResult.fail("用户信息失效,获取用户信息失败");
  4984. }
  4985. //部门数据集合
  4986. List<SmartDepartment> departments = smartDepartmentService.list(null);
  4987. //年级数据
  4988. List<SmartGrade> grades = smartGradeService.list(null);
  4989. WechatUserVo userData = new WechatUserVo();
  4990. userData.setId(su.getId());
  4991. userData.setCardNo(su.getCardNo());
  4992. userData.setTimeGroupId(su.getTimeGroupId());
  4993. userData.setName(su.getName());
  4994. userData.setIdentityId(su.getIdentityId());
  4995. userData.setIdCard(su.getIdCard());
  4996. userData.setSexId(su.getSexId());
  4997. userData.setDepartmentId(su.getDepartmentId());
  4998. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(su.getDepartmentId())).findFirst();
  4999. if (department != null && department.isPresent()) {
  5000. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  5001. userData.setDepartmentName(departmentName == null ? "" : departmentName + "/" + department.get().getName());
  5002. }
  5003. userData.setHeadImage(su.getHeadImage());
  5004. if (org.springframework.util.StringUtils.hasText(su.getGrade())) {
  5005. Optional<SmartGrade> oGrade = grades.stream().filter(e -> String.valueOf(e.getId()).equals(su.getGrade())).findFirst();
  5006. if (oGrade != null && oGrade.isPresent()) {
  5007. userData.setGrade(oGrade.get().getName());
  5008. }
  5009. }
  5010. userData.setCollege(su.getCollege());
  5011. userData.setSpeciality(su.getSpeciality());
  5012. userData.setSchoolClass(su.getSchoolClass());
  5013. userData.setCampus(su.getCampus());
  5014. userData.setDormitoryNumber(su.getDormitoryNumber());
  5015. userData.setPhone(su.getPhone());
  5016. userData.setAffiliate(su.getAffiliate());
  5017. //查找关联人
  5018. if (su.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  5019. List<AffiliateParentVo> parents = smartUserService.queryAffiliateParents(su.getId());
  5020. if (parents != null && parents.size() > 0) {
  5021. String affiliateStr = StringUtils.join(parents.stream().map(AffiliateParentVo::getName).collect(Collectors.toList()), ",");
  5022. userData.setAffiliateName(affiliateStr);
  5023. }
  5024. } else if (su.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  5025. if (su.getAffiliate() != null) {
  5026. List<String> affiliates = Arrays.asList(su.getAffiliate().split(","));
  5027. List<SmartUser> childs = smartUserService.getSmartUserIds(affiliates);
  5028. String affiliateStr = StringUtils.join(childs.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  5029. userData.setAffiliateName(affiliateStr);
  5030. }
  5031. }
  5032. //关联人名称用逗号隔开
  5033. userData.setTitle(su.getTitle());
  5034. userData.setAddress(su.getAddress());
  5035. userData.setNation(su.getNation());
  5036. userData.setOfStudent(su.getOfStudent());
  5037. userData.setGraduate(su.getGraduate());
  5038. userData.setDuties(su.getDuties());
  5039. userData.setIsPush(su.getIsPush());
  5040. userData.setIsCancel(su.getIsCancel());
  5041. userData.setOpenId(su.getOpenId());
  5042. userData.setXOpenId(su.getXOpenId());
  5043. userData.setGzhOpenId(su.getGzhOpenId());
  5044. userData.setXwStudentUid(su.getXwStudentUid());
  5045. userData.setBsStudentNo(su.getBsStudentNo());
  5046. userData.setXwTeacherCode(su.getXwTeacherCode());
  5047. userData.setBsStaffCode(su.getBsStaffCode());
  5048. return CommonResult.ok(userData);
  5049. }
  5050. //endregion
  5051. //region 绑定学生
  5052. @Override
  5053. @DESRespondSecret(validated = true)
  5054. public CommonResult bindStudent
  5055. (bindStudentRequest
  5056. bsr, BindingResult bindingResult) {
  5057. if (bindingResult.hasErrors()) {
  5058. String st = paramUtils.getParamError(bindingResult);
  5059. return CommonResult.fail(st);
  5060. }
  5061. SmartUser parentUser = smartUserService.getSmartById(bsr.getUserId());
  5062. if (parentUser == null) {
  5063. return CommonResult.fail("当前用户信息无效,绑定失败!");
  5064. }
  5065. if (parentUser.getIdentityId().intValue() != eIdentityStatu.Parent.getValue()) {
  5066. return CommonResult.fail("当前用户身份无法进行绑定操作");
  5067. }
  5068. //查找是否存在学生数据
  5069. SmartUser studentUser = smartUserService.queryUserInfo(bsr.getName(), bsr.getCardNo(), bsr.getIdCard());
  5070. if (studentUser == null) {
  5071. return CommonResult.fail("当前学生不存在,绑定失败!");
  5072. }
  5073. //判断是否已绑定过
  5074. if (parentUser.getAffiliate() == null) {
  5075. parentUser.setAffiliate(String.valueOf(studentUser.getId()));
  5076. } else {
  5077. List<String> newAffiliates = new ArrayList<>();
  5078. List<String> affiliates = Arrays.asList(parentUser.getAffiliate().split(","));
  5079. long existCount = affiliates.stream().filter(e -> e.equals(String.valueOf(studentUser.getId()))).count();
  5080. if (existCount > 0) {
  5081. return CommonResult.fail("当前学生信息已绑定过,请勿重复操作!");
  5082. }
  5083. parentUser.setAffiliate(parentUser.getAffiliate() + "," + studentUser.getId());
  5084. }
  5085. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(studentUser.getCardNo());
  5086. if (indexs != null && indexs.size() >= 4) {
  5087. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  5088. }
  5089. int index = 0;
  5090. if (indexs != null) {
  5091. for (SmartFamilyIndex data : indexs) {
  5092. if (data.getIndexData().intValue() == index && index < 3) {
  5093. index++;
  5094. continue;
  5095. } else {
  5096. break;
  5097. }
  5098. }
  5099. }
  5100. //region 新增希沃学生家长信息
  5101. //初始化客户端
  5102. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  5103. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  5104. //响应体,MimeType为 application/json
  5105. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  5106. .build();
  5107. param.setRequestBody(requestBody);
  5108. //query
  5109. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  5110. .appId(seewoConfig.getAppId())
  5111. .schoolUid(seewoConfig.getSchoolId())
  5112. .build();
  5113. requestBody.setQuery(query);
  5114. //学生与家长列表,最大100条
  5115. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem studentParents = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  5116. .studentCode(studentUser.getCardNo())
  5117. .build();
  5118. query.setStudentParents(java.util.Collections.singletonList(studentParents));
  5119. //家长列表,最多4个
  5120. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  5121. .name(parentUser.getName())
  5122. .phone(parentUser.getPhone())
  5123. .index(index)
  5124. .build();
  5125. studentParents.setParents(java.util.Collections.singletonList(parents));
  5126. param.setRequestBody(requestBody);
  5127. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  5128. logger.info("入参:" + request);
  5129. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  5130. //request.setServerUrl("https://openapi.test.seewo.com")
  5131. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  5132. ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
  5133. logger.info("出参:" + result);
  5134. if (result == null) {
  5135. return CommonResult.fail("希沃学生家长数据添加失败!");
  5136. }
  5137. if (!result.getResponseBody().getCode().equals("000000")) {
  5138. return CommonResult.fail(result.getResponseBody().getMessage());
  5139. }
  5140. //endregion
  5141. int updateResult = smartUserService.updateSmartUser(parentUser);
  5142. return updateResult > 0 ? CommonResult.ok("绑定成功") : CommonResult.fail("绑定失败");
  5143. }
  5144. //endregion
  5145. //region 根据数据ID获取用户信息
  5146. @Override
  5147. public CommonResult queryUserData(
  5148. int id) {
  5149. SmartUserVo user = smartUserService.querySmartUserById(id);
  5150. return CommonResult.ok(user);
  5151. }
  5152. //endregion
  5153. //region 删除记录的分页数据
  5154. @Override
  5155. public CommonResult queryUserDeletePage
  5156. (int currentPage, int pageCount) {
  5157. PageUtils<UserDeleteVo> result = smartUserService.queryUserDeletePage(currentPage, pageCount);
  5158. List<SmartDepartment> departments = smartDepartmentService.list(null);
  5159. for (UserDeleteVo data : result.getList()) {
  5160. data.setIdentityStr(eIdentityStatu.stringOf(data.getIdentityId()));//身份
  5161. //获取父级部门ID
  5162. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  5163. if (department != null && department.isPresent()) {
  5164. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  5165. data.setDepartmentStr(departmentName);
  5166. }
  5167. }
  5168. return CommonResult.ok(result);
  5169. }
  5170. //endregion
  5171. //region 获取班级下的学生
  5172. @Override
  5173. public CommonResult queryClassUser(
  5174. int userId, String keyWord) {
  5175. SmartUser userData = smartUserService.getSmartById(userId);
  5176. if (userData == null) {
  5177. return CommonResult.fail("未查到用户信息,获取失败");
  5178. }
  5179. if (userData.getSchoolClass() == null) {
  5180. return CommonResult.fail("当前用户所在班级为空,获取失败");
  5181. }
  5182. SmartClass classData = smartClassService.getSmartClassById(userData.getSchoolClass());
  5183. if (classData == null) {
  5184. return CommonResult.fail("班级数据为空,获取失败");
  5185. }
  5186. List<SmartDepartment> departments = smartDepartmentService.list(null);
  5187. if (departments == null) {
  5188. return CommonResult.fail("部门数据为空,获取失败");
  5189. }
  5190. //查找部门名称
  5191. String departmentName = classData.getName().replace("年级", "") + "学生";
  5192. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  5193. if (!(department != null && department.isPresent())) {
  5194. return CommonResult.fail("部门数据为空,获取失败");
  5195. }
  5196. String departmentStr = QueryParentDepartments(department.get().getParentId(), departments, null);
  5197. ClassUserVo result = new ClassUserVo();
  5198. result.setClassId(userData.getSchoolClass());
  5199. result.setName(departmentStr);
  5200. List<ClassUserDetailVo> userDetails = new ArrayList<>();
  5201. //region 用户明细集合数据
  5202. List<SmartUser> users = smartUserService.queryUsersByClass(userData.getSchoolClass());
  5203. if (users != null && users.size() > 0) {
  5204. List<SmartTimeGroup> timeGroups = smartTimeGroupService.list(null);
  5205. for (SmartUser user : users) {
  5206. ClassUserDetailVo userDetail = new ClassUserDetailVo();
  5207. userDetail.setId(user.getId());
  5208. userDetail.setName(user.getName());
  5209. userDetail.setCardNo(user.getCardNo());
  5210. Optional<SmartTimeGroup> timeGroup = timeGroups.stream().filter(e -> e.getId().equals(user.getTimeGroupId())).findFirst();
  5211. if (timeGroup != null && timeGroup.isPresent()) {
  5212. userDetail.setTimeGroup(timeGroup.get().getName());
  5213. }
  5214. userDetails.add(userDetail);
  5215. }
  5216. if (!ObjectUtils.isEmpty(keyWord)) {
  5217. userDetails = userDetails.stream().filter(e -> (e.getName() != null && e.getName().contains(keyWord)) || (e.getTimeGroup() != null && e.getTimeGroup().contains(keyWord))).collect(Collectors.toList());
  5218. }
  5219. }
  5220. //endregion
  5221. result.setUserDetails(userDetails);
  5222. return CommonResult.ok(result);
  5223. }
  5224. //endregion
  5225. //region 批量设置学生时间组
  5226. @Override
  5227. public CommonResult setUserTimeGroup
  5228. (setUserTimeGroupRequest
  5229. isur, BindingResult bindingResult) throws
  5230. Exception {
  5231. if (bindingResult.hasErrors()) {
  5232. String st = paramUtils.getParamError(bindingResult);
  5233. return CommonResult.fail(st);
  5234. }
  5235. logger.info("批量设置时间组1" + TimeExchange.getDateMillS());
  5236. SmartTimeGroup timeGroup = smartTimeGroupService.queryTimeGroupById(isur.getTimeGroupId());
  5237. if (timeGroup == null) {
  5238. return CommonResult.fail("时间组数据无效,批量同步时间组失败!");
  5239. }
  5240. logger.info("批量设置时间组2" + TimeExchange.getDateMillS());
  5241. //region 批量更新百胜学生的时间组
  5242. List<SmartUser> users = smartUserService.getSmartUserByIds(isur.getIds());
  5243. if (users == null) {
  5244. return CommonResult.fail("用户数据无效,批量同步时间组失败!");
  5245. }
  5246. logger.info("批量设置时间组3" + TimeExchange.getDateMillS());
  5247. List<SmartGrade> grades = smartGradeService.list(null);
  5248. List<SmartClass> classes = smartClassService.list(null);
  5249. logger.info("批量设置时间组4" + TimeExchange.getDateMillS());
  5250. for (SmartUser user : users) {
  5251. user.setTimeGroupId(isur.getTimeGroupId());
  5252. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getId().equals(Integer.valueOf(user.getGrade()))).findFirst();
  5253. if (!(oGrade != null && oGrade.isPresent())) {
  5254. return CommonResult.fail("年级数据无效,批量同步时间组失败!");
  5255. }
  5256. Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
  5257. if (!(oClass != null && oClass.isPresent())) {
  5258. return CommonResult.fail("班级数据无效,批量同步时间组失败!");
  5259. }
  5260. // 开始时间
  5261. long stime = System.currentTimeMillis();
  5262. logger.info("开始循环调用百胜一次:" + TimeExchange.getDateMillS());
  5263. /**
  5264. * 学生数据的有效期是到毕业年份的8月31日
  5265. */
  5266. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  5267. String endTime = queryGraduationYear(oGrade.get().getGradeNo());
  5268. CommonResult<String> updateBsStudent = bsTUpdateStudent(user, oClass.get().getBsClassNo(), startTime, endTime);
  5269. if (!updateBsStudent.isSuccess()) {
  5270. return CommonResult.fail(updateBsStudent.getMessage());
  5271. }
  5272. // 结束时间
  5273. long etime = System.currentTimeMillis();
  5274. // 计算执行时间
  5275. logger.info("结束循环调用百胜一次,执行时长:%d 毫秒.", (etime - stime));
  5276. //endregion
  5277. }
  5278. logger.info("循环结束:" + TimeExchange.getDateMillS());
  5279. //region 批量更新学生数据
  5280. boolean updateBatch = smartUserService.updateUserBatchById(users);
  5281. logger.info("存储结束:" + TimeExchange.getDateMillS());
  5282. return updateBatch ? CommonResult.ok("批量同步成功") : CommonResult.fail("批量同步失败");
  5283. }
  5284. @Override
  5285. @DESRespondSecret(validated = true)
  5286. @PassToken
  5287. public CommonResult getPhoneUser
  5288. (String phone) {
  5289. if (ObjectUtils.isEmpty(phone)) {
  5290. return CommonResult.fail("参数异常");
  5291. }
  5292. // 通过手机号找到对应用户
  5293. SmartUser smartUser = smartUserService.getPhoneUser(phone);
  5294. return CommonResult.ok(smartUser);
  5295. }
  5296. @Override
  5297. @DESRespondSecret(validated = true)
  5298. @PassToken
  5299. public CommonResult getPhoneAffiliate(String phone) {
  5300. if (ObjectUtils.isEmpty(phone)) {
  5301. return CommonResult.fail("参数异常");
  5302. }
  5303. SmartUser smartUser = smartUserService.getPhoneUser(phone);
  5304. // 用户id,多个就用逗号隔开
  5305. String affiliate = smartUser.getAffiliate();
  5306. if (ObjectUtils.isEmpty(affiliate)) {
  5307. return CommonResult.fail("未关联学生");
  5308. }
  5309. // 通过关联人找到对应用户
  5310. List<SmartUserAffiliateVo> smartUsers = smartUserService.getAffiliateUser(affiliate);
  5311. return CommonResult.ok(smartUsers);
  5312. }
  5313. //endregion
  5314. //region 查询时间组编号
  5315. public String eGroupTime(Integer id) {
  5316. SmartTimeGroup result = smartTimeGroupService.queryTimeGroupById(id);
  5317. return result == null ? "" : result.getBsno();
  5318. }
  5319. //endregion
  5320. //region 查询时间组ID
  5321. public Integer eGroupTime(String name) {
  5322. SmartTimeGroup result = smartTimeGroupService.queryTimeGroupByName(name);
  5323. return result == null ? 0 : result.getId();
  5324. }
  5325. //endregion
  5326. //region 根据年级查询毕业年份
  5327. /**
  5328. * 根据年级查询毕业年份
  5329. *
  5330. * @return
  5331. */
  5332. public String queryGraduationYear(
  5333. int grade) {
  5334. String endTime = "";
  5335. int endYear = Year.now().getValue();
  5336. // 获取当前年份
  5337. LocalDate currentDate = LocalDate.now();
  5338. switch (grade) {
  5339. case 7:
  5340. if (currentDate.getMonthValue() < 9) {
  5341. endYear = endYear + 2;
  5342. } else {
  5343. endYear = endYear + 3;
  5344. }
  5345. break;
  5346. case 8:
  5347. if (currentDate.getMonthValue() < 9) {
  5348. endYear = endYear + 1;
  5349. } else {
  5350. endYear = endYear + 2;
  5351. }
  5352. break;
  5353. case 9:
  5354. break;
  5355. default:
  5356. break;
  5357. }
  5358. endTime = endYear + "-08-31 23:59:59";
  5359. return endTime;
  5360. }
  5361. //endregion
  5362. }