SmartUserController.java 313 KB

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