SmartUserController.java 421 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.Wrapper;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.fasterxml.jackson.core.JsonProcessingException;
  11. import com.fasterxml.jackson.databind.ObjectMapper;
  12. import com.qcloud.cos.utils.IOUtils;
  13. import com.seewo.open.sdk.DefaultSeewoClient;
  14. import com.seewo.open.sdk.SeewoClient;
  15. import com.seewo.open.sdk.auth.Account;
  16. import com.template.annotation.DESRespondSecret;
  17. import com.template.annotation.PassToken;
  18. import com.template.api.SmartUserControllerAPI;
  19. import com.template.common.utils.*;
  20. import com.template.config.ControlConfig;
  21. import com.template.config.SeewoConfig;
  22. import com.template.model.enumModel.*;
  23. import com.template.model.evaluate.teacher.SmartEvaluateTeacher;
  24. import com.template.model.pojo.*;
  25. import com.template.model.request.*;
  26. import com.template.model.result.CommonResult;
  27. import com.template.model.result.PageUtils;
  28. import com.template.model.seewo.*;
  29. import com.template.model.vo.*;
  30. import com.template.services.*;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.apache.poi.hssf.usermodel.HSSFRow;
  33. import org.apache.poi.hssf.usermodel.HSSFSheet;
  34. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  35. import org.apache.poi.ss.usermodel.DataFormatter;
  36. import org.apache.poi.ss.usermodel.Row;
  37. import org.apache.poi.ss.usermodel.Sheet;
  38. import org.apache.poi.ss.usermodel.Workbook;
  39. import org.apache.poi.xssf.usermodel.XSSFRow;
  40. import org.apache.poi.xssf.usermodel.XSSFSheet;
  41. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  42. import org.slf4j.Logger;
  43. import org.slf4j.LoggerFactory;
  44. import org.springframework.beans.factory.annotation.Autowired;
  45. import org.springframework.validation.BindingResult;
  46. import org.springframework.web.bind.annotation.RequestParam;
  47. import org.springframework.web.bind.annotation.RestController;
  48. import org.springframework.web.multipart.MultipartFile;
  49. import javax.annotation.Resource;
  50. import javax.servlet.http.HttpServletResponse;
  51. import java.io.*;
  52. import java.net.URLDecoder;
  53. import java.net.URLEncoder;
  54. import java.nio.charset.Charset;
  55. import java.time.LocalDate;
  56. import java.time.LocalDateTime;
  57. import java.time.Year;
  58. import java.time.format.DateTimeFormatter;
  59. import java.util.*;
  60. import java.util.stream.Collectors;
  61. import java.util.stream.Stream;
  62. import java.util.zip.ZipInputStream;
  63. import static com.template.common.utils.AesTestOne.decrypt;
  64. /**
  65. * <p>
  66. * 前端控制器
  67. * </p>
  68. *
  69. * @author ceshi
  70. * @since 2023-12-04
  71. */
  72. @RestController
  73. //返回参数加密注解
  74. @DESRespondSecret
  75. public class SmartUserController implements SmartUserControllerAPI {
  76. @Resource
  77. private SeewoConfig seewoConfig;
  78. @Resource
  79. private ControlConfig controlConfig;
  80. @Autowired
  81. private SmartUserService smartUserService;
  82. @Autowired
  83. private SmartGradeService smartGradeService;
  84. @Autowired
  85. private SmartClassService smartClassService;
  86. @Autowired
  87. private SmartUploadService smartUploadService;
  88. @Autowired
  89. private SmartDutiesService smartDutiesService;
  90. @Autowired
  91. private SmartDepartmentService smartDepartmentService;
  92. @Autowired
  93. private SmartIdentityService smartIdentityService;
  94. @Autowired
  95. private SmartTimeGroupService smartTimeGroupService;
  96. @Autowired
  97. private SmartAuthorityService smartAuthorityService;
  98. @Autowired
  99. private SmartFamilyIndexService smartFamilyIndexService;
  100. @Autowired
  101. private SmartTeachingService smartTeachingService;
  102. @Autowired
  103. private SmartAuthorGroupService smartAuthorGroupService;
  104. @Autowired
  105. private SmartSemesterService smartSemesterService;
  106. @Autowired
  107. private SmartSubjectService smartSubjectService;
  108. @Autowired
  109. private SmartEvaluateTeacherService smartEvaluateTeacherService;
  110. @Autowired
  111. private SmartOperationUserService smartOperationUserService;
  112. private static Logger logger = LoggerFactory.getLogger(SmartUserController.class);
  113. //region 开发自己导数据用的接口
  114. @Override
  115. public CommonResult testDeleteUserById(int userId) throws Exception {
  116. SmartUser user = smartUserService.getSmartById(userId);
  117. bsDeleteStudent(user);
  118. return CommonResult.ok();
  119. }
  120. @Override
  121. public CommonResult insertSmartUserPhoto() throws JsonProcessingException {
  122. Integer userType = eSeewoUserType.Student.getValue();
  123. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  124. List<SmartUser> students = smartUserService.queryStudentDatas();
  125. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  126. for (SmartUser student : students) {
  127. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  128. photo.setPhotoUrl(student.getHeadImage());
  129. photo.setUserCode(student.getCardNo());
  130. photoList.add(photo);
  131. }
  132. int num = (int) Math.ceil((double) photoList.size() / 1000);
  133. for (int count = 1; count <= num; count++) {
  134. int startIndex = (count - 1) * 1000;
  135. int endIndex = count * 1000;
  136. if (count == num) {
  137. endIndex = startIndex + (photoList.size() % 1000);
  138. }
  139. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  140. CommonResult result = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, userType);
  141. if (!result.isSuccess()) {
  142. return result;
  143. }
  144. }
  145. return CommonResult.ok("图片上传成功");
  146. }
  147. @Override
  148. public CommonResult importExcelUserBsno(MultipartFile excelFile) throws IOException {
  149. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  150. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  151. return CommonResult.fail("压缩包中的excel文件不能为空");
  152. }
  153. List<SmartUser> result = new ArrayList<>();
  154. String ContentType = excelFile.getContentType();
  155. InputStream inputStream = excelFile.getInputStream();
  156. if (ContentType.equals(eFileType.Xlsx.getValue())) {
  157. CommonResult<List<SmartUser>> resultData = readBsXlsx(inputStream);
  158. if (!resultData.isSuccess()) {
  159. return resultData;
  160. }
  161. result = resultData.getData();
  162. if (result == null) {
  163. return CommonResult.fail("文档内容为空,导入失败");
  164. }
  165. } else {
  166. return CommonResult.fail("用户导入只支持Xlsx");
  167. }
  168. List<String> gradeIds = result.stream().map(SmartUser::getGrade).distinct().collect(Collectors.toList());
  169. if (gradeIds != null && gradeIds.size() > 0) {
  170. List<SmartUser> users = smartUserService.queryStudentsByGrade(gradeIds);
  171. for (SmartUser user : users) {
  172. Optional<SmartUser> resultData = result.stream().filter(e -> e.getCardNo().equals(user.getCardNo()) && e.getName().equals(user.getName())).findFirst();
  173. if (resultData != null && resultData.isPresent()) {
  174. user.setBsStudentNo(resultData.get().getBsStudentNo());
  175. }
  176. }
  177. if (users != null && users.size() > 0) {
  178. boolean insertData = smartUserService.updateBatchById(users);
  179. if (!insertData) {
  180. return CommonResult.fail("导入失败");
  181. }
  182. }
  183. }
  184. return CommonResult.ok("导入成功");
  185. }
  186. /**
  187. * Xlsx文件读取方法ss
  188. *
  189. * @param inputStream 文件流
  190. * @return
  191. * @throws IOException
  192. */
  193. private CommonResult<List<SmartUser>> readBsXlsx(InputStream inputStream) throws IOException {
  194. List<SmartUser> users = new ArrayList<>();
  195. List<String> idCards = new ArrayList<>();
  196. List<String> cardNos = new ArrayList<>();
  197. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  198. List<SmartGrade> grades = smartGradeService.list(null); //年级
  199. //读取第一张sheet
  200. XSSFSheet sheetAt = sheets.getSheetAt(0);
  201. DataFormatter dataFormatter = new DataFormatter();
  202. try {
  203. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  204. XSSFRow row = sheetAt.getRow(rowNum);
  205. if (row != null) {
  206. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  207. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  208. //然后poi会根据字符串读取它
  209. //标题 校验
  210. if (rowNum == 0) {
  211. String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//年级
  212. if (!schoolClass.equals("年级")) {
  213. return CommonResult.fail("导入数据第一列为年级");
  214. }
  215. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  216. if (!cardNo.equals("学号")) {
  217. return CommonResult.fail("导入数据第四列为学号");
  218. }
  219. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  220. if (!name.equals("姓名")) {
  221. return CommonResult.fail("导入数据第五列为姓名");
  222. }
  223. String sex = dataFormatter.formatCellValue(row.getCell(5));//学生编码
  224. if (!sex.equals("学生编码")) {
  225. return CommonResult.fail("导入数据第六列为学生编码");
  226. }
  227. } else {
  228. SmartUser user = new SmartUser();
  229. String name = dataFormatter.formatCellValue(row.getCell(4));
  230. if (ObjectUtils.isEmpty(name)) {
  231. return CommonResult.fail("第" + (rowNum + 1) + "条数据的姓名不能为空");
  232. }
  233. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  234. if (ObjectUtils.isEmpty(schoolGrade)) {
  235. return CommonResult.fail(name + "的年级不能为空");
  236. }
  237. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  238. if (ObjectUtils.isEmpty(cardNo)) {
  239. return CommonResult.fail(name + "的学号不能为空");
  240. }
  241. //学号重复判断
  242. if (!ObjectUtils.isEmpty(cardNo)) {
  243. cardNos.add(cardNo);
  244. }
  245. if (cardNos.stream().distinct().count() != cardNos.size()) {
  246. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  247. }
  248. String studentNo = dataFormatter.formatCellValue(row.getCell(5));//学生编码
  249. if (ObjectUtils.isEmpty(studentNo)) {
  250. return CommonResult.fail(name + "的学生编码不能为空");
  251. }
  252. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(schoolGrade)).findFirst();
  253. if (oGrade != null && oGrade.isPresent()) {
  254. Integer gradeId = oGrade.get().getId();
  255. user.setGrade(String.valueOf(gradeId));
  256. } else {
  257. return CommonResult.fail(name + "的年级数据无效,导入失败");
  258. }
  259. user.setName(name);
  260. user.setBsStudentNo(studentNo);
  261. user.setCardNo(cardNo);
  262. users.add(user);
  263. }
  264. }
  265. }
  266. } catch (Exception e) {
  267. return CommonResult.fail("请按模板格式导入数据");
  268. }
  269. return CommonResult.ok(users);
  270. }
  271. @Override
  272. public CommonResult importExcelFamilys(MultipartFile excelFile) throws Exception {
  273. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  274. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  275. return CommonResult.fail("压缩包中的excel文件不能为空");
  276. }
  277. String ContentType = excelFile.getContentType();
  278. InputStream inputStream = excelFile.getInputStream();
  279. List<SmartFamilyIndex> result = new ArrayList<>();
  280. CommonResult<List<SmartFamilyIndex>> resultData = readFamilyXlsx(inputStream);
  281. if (!resultData.isSuccess()) {
  282. return resultData;
  283. }
  284. result = resultData.getData();
  285. boolean insertBatch = smartFamilyIndexService.saveBatch(result);
  286. return insertBatch ? CommonResult.ok("操作成功") : CommonResult.fail("操作失败");
  287. }
  288. /**
  289. * Xlsx文件读取方法
  290. *
  291. * @param inputStream 文件流
  292. * @return
  293. * @throws IOException
  294. */
  295. private CommonResult<List<SmartFamilyIndex>> readFamilyXlsx(InputStream inputStream) throws IOException {
  296. List<SmartFamilyIndex> result = new ArrayList<>();
  297. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  298. //读取第一张sheet
  299. XSSFSheet sheetAt = sheets.getSheetAt(0);
  300. DataFormatter dataFormatter = new DataFormatter();
  301. try {
  302. for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  303. XSSFRow row = sheetAt.getRow(rowNum);
  304. if (row != null) {
  305. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  306. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  307. //然后poi会根据字符串读取它
  308. //标题 校验
  309. if (rowNum < 3) {
  310. //不做校验处理了
  311. } else {
  312. String cardNo = dataFormatter.formatCellValue(row.getCell(4));//学号
  313. if (ObjectUtils.isEmpty(cardNo)) {
  314. continue;
  315. }
  316. String phone1 = dataFormatter.formatCellValue(row.getCell(10));//手机号1
  317. if (!ObjectUtils.isEmpty(phone1)) {
  318. SmartFamilyIndex index = new SmartFamilyIndex();
  319. index.setStudentNo(cardNo);
  320. index.setParentPhone(phone1);
  321. index.setIndexData(0);
  322. result.add(index);
  323. }
  324. String phone2 = dataFormatter.formatCellValue(row.getCell(12));//手机号1
  325. if (!ObjectUtils.isEmpty(phone1)) {
  326. SmartFamilyIndex index = new SmartFamilyIndex();
  327. index.setStudentNo(cardNo);
  328. index.setParentPhone(phone1);
  329. index.setIndexData(1);
  330. result.add(index);
  331. }
  332. }
  333. }
  334. }
  335. } catch (Exception e) {
  336. return CommonResult.fail("请按模板格式导入数据");
  337. }
  338. return CommonResult.ok(result);
  339. }
  340. /**
  341. * 批量导入压缩包用户信息
  342. * 以身份证号作为判断依据 如果存在重复数据就提示存在重复数据
  343. * 开发流程:建议先去拿到excel中的所有数据的身份证号去数据库中找一遍是否存在重复数据
  344. * 如果不存在重复数据就把附件文件夹中的附件文件上传到cos服务器上
  345. * 然后手动拼接一个人脸照片文件地址存入对应的数据中
  346. *
  347. * @param zipFile zip压缩包
  348. * @return
  349. */
  350. @Override
  351. @DESRespondSecret(validated = true)
  352. public CommonResult importZipUsers(MultipartFile zipFile) throws IOException {
  353. List<SmartUser> result = new ArrayList<>();
  354. MultipartFile excelFile = null;
  355. List<MultipartFile> multipartFileHashMap = new ArrayList<>();
  356. String excelStr = null;
  357. if (zipFile != null) {
  358. //解压压缩文件并上传文件
  359. ByteArrayOutputStream byteOut = null;
  360. ZipInputStream zipIn = null;
  361. try {
  362. java.util.zip.ZipEntry zipEntry = null;
  363. zipIn = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK"));
  364. while ((zipEntry = zipIn.getNextEntry()) != null) {
  365. String fileName = zipEntry.getName();
  366. if (fileName.contains("人脸照片") && (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg"))) {
  367. byteOut = new ByteArrayOutputStream();
  368. IOUtils.copy(zipIn, byteOut);
  369. InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
  370. MultipartFile multipartFile = FileUtils.getMultipartFile(inputStream, fileName);
  371. multipartFileHashMap.add(multipartFile);
  372. } else if (fileName.contains("人员信息采集表") && (fileName.endsWith(".xlsx") || fileName.endsWith(".xls"))) {
  373. excelStr = fileName.endsWith(".xlsx") ? "xlsx" : "xls";
  374. byteOut = new ByteArrayOutputStream();
  375. IOUtils.copy(zipIn, byteOut);
  376. InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
  377. excelFile = FileUtils.getMultipartFile(inputStream, fileName);
  378. }
  379. }
  380. } catch (Exception e) {
  381. e.printStackTrace();
  382. } finally {
  383. if (byteOut != null) {
  384. byteOut.close();
  385. }
  386. if (zipIn != null) {
  387. zipIn.close();
  388. }
  389. }
  390. }
  391. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  392. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  393. return CommonResult.fail("压缩包中的excel文件不能为空");
  394. }
  395. String ContentType = excelFile.getContentType();
  396. InputStream inputStream = excelFile.getInputStream();
  397. //xls格式文件
  398. if (excelStr.equals("xls")) {
  399. CommonResult<List<SmartUser>> resultData = readXls(inputStream);
  400. if (!resultData.isSuccess()) {
  401. return resultData;
  402. }
  403. result = resultData.getData();
  404. } else if (excelStr.equals("xlsx")) {
  405. CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
  406. if (!resultData.isSuccess()) {
  407. return resultData;
  408. }
  409. result = resultData.getData();
  410. } else {
  411. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  412. }
  413. //cos上传 返回图片地址
  414. String uploadResult = smartUploadService.upload(multipartFileHashMap.toArray(new MultipartFile[0]));
  415. List<String> uploadImages = Arrays.asList(uploadResult.split(","));
  416. for (SmartUser user : result) {
  417. Optional<String> headImage = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/headImage/" + user.getHeadImage())).findFirst();
  418. if (headImage != null && headImage.isPresent()) {
  419. user.setHeadImage(headImage.get());
  420. }
  421. }
  422. //批量存储用户信息
  423. boolean resultBool = smartUserService.saveBatch(result);
  424. return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
  425. }
  426. //endregion
  427. //region 注销账号
  428. @Override
  429. @DESRespondSecret(validated = true)
  430. public CommonResult logoffAccount(useridsRequest ur, BindingResult bindingResult) {
  431. if (bindingResult.hasErrors()) {
  432. String st = paramUtils.getParamError(bindingResult);
  433. return CommonResult.fail(st);
  434. }
  435. int user = smartUserService.getSmartUserCountByIds(ur.getUserIds());
  436. if (user != ur.getUserIds().size()) {
  437. return CommonResult.fail("用户信息已失效");
  438. }
  439. return 0 > 0 ? CommonResult.ok("注销成功") : CommonResult.fail("注销失败");
  440. }
  441. //endregion
  442. //region 移动多个用户到其他部门
  443. @Override
  444. @DESRespondSecret(validated = true)
  445. public CommonResult changeDepartment(changeDepartmentRequest cdr, BindingResult bindingResult) {
  446. if (bindingResult.hasErrors()) {
  447. String st = paramUtils.getParamError(bindingResult);
  448. return CommonResult.fail(st);
  449. }
  450. List<SmartUser> users = smartUserService.getSmartUserByIds(cdr.getUserIds());
  451. if (users == null) {
  452. return CommonResult.fail("用户信息无效,移动失败!");
  453. }
  454. if (users.size() != cdr.getUserIds().size()) {
  455. return CommonResult.fail("存在无效用户数据,移动失败!");
  456. }
  457. for (SmartUser user : users) {
  458. user.setDepartmentId(cdr.getDepartmentId());
  459. }
  460. boolean result = smartUserService.updateBatchById(users);
  461. return result ? CommonResult.ok("移动成功") : CommonResult.fail("移动失败");
  462. }
  463. //endregion
  464. //region 批量新增用户
  465. //region 批量新增用户方法
  466. @Override
  467. @DESRespondSecret(validated = true)
  468. public CommonResult importExcelUsers(MultipartFile excelFile, String headImage) throws Exception {
  469. List<SmartUser> result = new ArrayList<>();
  470. int useXw = 1;
  471. int useBs = 1;
  472. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  473. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  474. return CommonResult.fail("压缩包中的excel文件不能为空");
  475. }
  476. String ContentType = excelFile.getContentType();
  477. InputStream inputStream = excelFile.getInputStream();
  478. //xls格式文件
  479. if (ContentType.equals(eFileType.Xls.getValue())) {
  480. CommonResult<List<SmartUser>> resultData = readXls(inputStream);
  481. if (!resultData.isSuccess()) {
  482. return resultData;
  483. }
  484. result = resultData.getData();
  485. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  486. CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
  487. if (!resultData.isSuccess()) {
  488. return resultData;
  489. }
  490. result = resultData.getData();
  491. } else {
  492. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  493. }
  494. List<String> uploadImages = Arrays.asList(headImage.split(","));
  495. for (SmartUser user : result) {
  496. Optional<String> image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/" + user.getHeadImage())).findFirst();
  497. if (image != null && image.isPresent()) {
  498. user.setHeadImage(image.get());
  499. } else {
  500. if (user.getIdentityId().equals(eIdentityStatu.Student.getValue())
  501. || user.getIdentityId().equals(eIdentityStatu.Teacher.getValue())) {
  502. return CommonResult.fail(user.getName() + "头像不存在,导入失败");
  503. }
  504. }
  505. }
  506. //region 将数据加入第三方
  507. List<SmartUser> studentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
  508. if (studentDatas != null && studentDatas.size() > 0) {
  509. //判断是否存在重复数据
  510. List<String> cardNos = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  511. if (cardNos == null) {
  512. return CommonResult.fail("文档内容为空,导入失败");
  513. }
  514. if (cardNos.size() <= 0) {
  515. return CommonResult.fail("文档内容为空,导入失败");
  516. }
  517. List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
  518. if (existUsers != null && existUsers.size() > 0) {
  519. String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  520. return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
  521. }
  522. //获取班级Uid
  523. List<SmartClass> classDatas = smartClassService.getSmartClasss();
  524. if (classDatas == null) {
  525. return CommonResult.fail("班级数据无效,新增失败");
  526. }
  527. List<SmartGrade> gradeDatas = smartGradeService.getSmartGrades();
  528. if (gradeDatas == null) {
  529. return CommonResult.fail("年级数据无效,新增失败");
  530. }
  531. HashMap<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> seewoDatas = new HashMap<>();
  532. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  533. for (SmartUser student : studentDatas) {
  534. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  535. photo.setPhotoUrl(student.getHeadImage());
  536. photo.setUserCode(student.getCardNo());
  537. photoList.add(photo);
  538. //region 学生参数必填判断:年级、班级
  539. if (student.getGrade() == null) {
  540. return CommonResult.fail("学生年级不能为空");
  541. }
  542. if (student.getSchoolClass() == null) {
  543. return CommonResult.fail("学生班级不能为空");
  544. }
  545. //endregion
  546. Optional<SmartClass> oClassData = classDatas.stream().filter(e -> e.getId().equals(student.getSchoolClass())).findFirst();
  547. if (oClassData == null) {
  548. return CommonResult.fail("班级数据无效,新增失败");
  549. }
  550. Optional<SmartGrade> oGradeData = gradeDatas.stream().filter(e -> e.getId().intValue() == Integer.valueOf(student.getGrade())).findFirst();
  551. if (oGradeData == null) {
  552. return CommonResult.fail("年级数据无效,新增失败");
  553. }
  554. SmartClass classData = oClassData.get();
  555. SmartGrade gradeData = oGradeData.get();
  556. //region 凑希沃参数
  557. if (useXw == 1) {
  558. if (!seewoDatas.containsKey(classData.getClassUid())) {
  559. seewoDatas.put(classData.getClassUid(), new ArrayList<>());
  560. }
  561. StudentServiceBatchSaveClassStudentsParam.StudentInfo studentSeewo = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  562. .studentName(student.getName())
  563. .studentCode(student.getCardNo())
  564. .gender(student.getSexId())
  565. .phone(student.getPhone() == null ? "" : student.getPhone())
  566. .build();
  567. seewoDatas.get(classData.getClassUid()).add(studentSeewo);
  568. }
  569. //endregion
  570. //region 百胜新增学生信息
  571. if (useBs == 1) {
  572. /**
  573. * 学生数据的有效期是到毕业年份的8月31日
  574. */
  575. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  576. String endTime = queryGraduationYear(gradeData.getGradeNo());
  577. CommonResult<String> insertBsStudent = bsInsertStudent(student.getName(), student.getCardNo(), student.getSexId(), student.getHeadImage(), student.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, student.getIdCard());
  578. if (!insertBsStudent.isSuccess()) {
  579. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  580. }
  581. student.setBsStudentNo(insertBsStudent.getData());
  582. }
  583. //endregion
  584. }
  585. if (useXw == 1) {
  586. //初始化客户端
  587. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  588. List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultDatas = new ArrayList<>();
  589. for (Map.Entry<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> entry : seewoDatas.entrySet()) {
  590. String classUid = entry.getKey();
  591. CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> insertStudents = SeewoInsertBatchStudent(seewoClient, entry.getValue(), classUid);
  592. if (!insertStudents.isSuccess()) {
  593. return CommonResult.fail("希沃平台:" + insertStudents.getMessage());
  594. }
  595. seewoResultDatas.addAll(insertStudents.getData());
  596. }
  597. for (SmartUser student : studentDatas) {
  598. Optional<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultData = seewoResultDatas.stream().filter(e -> e.getStudentCode().equals(student.getCardNo())).findFirst();
  599. if (seewoResultData != null && seewoResultData.isPresent()) {
  600. student.setXwStudentUid(seewoResultData.get().getUserUid());
  601. }
  602. }
  603. }
  604. if (studentDatas != null && studentDatas.size() > 0) {
  605. //批量存储学生信息
  606. boolean resultBool = smartUserService.saveBatch(studentDatas);
  607. if (!resultBool) {
  608. return CommonResult.fail("导入失败");
  609. } else {
  610. // 需添加到海康平台
  611. ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
  612. for (SmartUser studentData : studentDatas) {
  613. Integer id = studentData.getId();
  614. SmartOperationUser smartOperationUser = new SmartOperationUser();
  615. smartOperationUser.setOperationId(id);
  616. smartOperationUser.setOperationMode("1");
  617. smartOperationUser.setStatus(1);
  618. smartOperationUser.setType(studentData.getIdentityId());
  619. operationUsers.add(smartOperationUser);
  620. }
  621. smartOperationUserService.saveBatch(operationUsers);
  622. }
  623. List<SmartFamilyIndex> familyIndexs = new ArrayList<>();
  624. //region 希沃新增编辑学生家长信息
  625. if (useXw == 1) {
  626. int num = (int) Math.ceil((double) studentDatas.size() / 100);
  627. for (int count = 1; count <= num; count++) {
  628. int startIndex = (count - 1) * 100;
  629. int endIndex = count * 100;
  630. if (count == num) {
  631. endIndex = startIndex + (studentDatas.size() % 100);
  632. }
  633. List<SmartUser> currentStudentDatas = studentDatas.subList(startIndex, endIndex);//结尾不包含下标100
  634. //学生与家长列表,最大100条
  635. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  636. for (SmartUser student : currentStudentDatas) {
  637. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  638. .studentCode(student.getCardNo())
  639. .build();
  640. List<SmartUser> parentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList());
  641. List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
  642. int i = 0;
  643. for (SmartUser parent : parentDatas) {
  644. SmartFamilyIndex familyIndex = new SmartFamilyIndex();
  645. familyIndex.setParentPhone(parent.getPhone());
  646. familyIndex.setStudentNo(student.getCardNo());
  647. familyIndex.setIndexData(i);
  648. familyIndexs.add(familyIndex);
  649. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  650. .name(parent.getShip())
  651. .phone(parent.getPhone())
  652. .index(i)
  653. .build();
  654. parents.add(data);
  655. ++i;
  656. }
  657. if (parents != null && parents.size() > 0) {
  658. studentParents.add(students);
  659. //家长列表,最多4个
  660. students.setParents(parents);
  661. }
  662. }
  663. //初始化客户端
  664. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  665. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  666. //响应体,MimeType为 application/json
  667. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  668. .build();
  669. param.setRequestBody(requestBody);
  670. //query
  671. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  672. .appId(seewoConfig.getAppId())
  673. .schoolUid(seewoConfig.getSchoolId())
  674. .build();
  675. requestBody.setQuery(query);
  676. query.setStudentParents(studentParents);
  677. param.setRequestBody(requestBody);
  678. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  679. String jsonString = JSON.toJSONString(request);
  680. logger.info("入参:" + request);
  681. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  682. //request.setServerUrl("https://openapi.test.seewo.com")
  683. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  684. ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request);
  685. logger.info("出参:" + parentResult);
  686. if (parentResult == null) {
  687. return CommonResult.fail("希沃学生家长数据添加失败!");
  688. }
  689. if (!parentResult.getResponseBody().getCode().equals("000000")) {
  690. return CommonResult.fail("希沃平台:" + parentResult.getResponseBody().getMessage());
  691. }
  692. }
  693. }
  694. //endregion
  695. if (familyIndexs != null && familyIndexs.size() > 0) {
  696. boolean insertBatch = smartFamilyIndexService.saveBatch(familyIndexs);
  697. if (!insertBatch) {
  698. return CommonResult.fail("导入失败!");
  699. }
  700. }
  701. }
  702. //endregion
  703. List<SmartUser> parents = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
  704. //双胞胎家长
  705. List<SmartUser> newParents = new ArrayList<>();
  706. if (cardNos != null && cardNos.size() > 0) {
  707. List<SmartUser> students = smartUserService.querySmartUserByCardNos(cardNos);
  708. for (SmartUser parent : parents) {
  709. Optional<SmartUser> student = students.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
  710. if (student != null && student.isPresent()) {
  711. //先查找是否存在
  712. Optional<SmartUser> newData = newParents.stream().filter(e -> e.getName().equals(parent.getName()) && e.getPhone().equals(parent.getPhone()) && e.getShip().equals(parent.getShip())).findFirst();
  713. if (newData != null && newData.isPresent()) {
  714. String affiliate = newData.get().getAffiliate() + "," + student.get().getId();
  715. newData.get().setAffiliate(affiliate);
  716. } else {
  717. SmartUser newParent = new SmartUser();
  718. newParent.setName(parent.getName());
  719. newParent.setDepartmentId(parent.getDepartmentId());
  720. newParent.setPhone(parent.getPhone());
  721. newParent.setIdentityId(parent.getIdentityId());
  722. newParent.setSexId(parent.getSexId());
  723. newParent.setIsCancel(parent.getIsCancel());
  724. newParent.setAffiliate(String.valueOf(student.get().getId()));
  725. newParent.setShip(parent.getShip());
  726. newParents.add(newParent);
  727. }
  728. }
  729. }
  730. if (newParents != null && newParents.size() > 0) {
  731. //批量存储家长信息
  732. boolean resultBool = smartUserService.saveBatch(newParents);
  733. if (!resultBool) {
  734. return CommonResult.fail("导入失败!");
  735. }
  736. }
  737. //region 最后上传学生图片 这样能保证图片上传失败也不影响数据导入
  738. if (useXw == 1) {
  739. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  740. int num = (int) Math.ceil((double) photoList.size() / 1000);
  741. for (int count = 1; count <= num; count++) {
  742. int startIndex = (count - 1) * 1000;
  743. int endIndex = count * 1000;
  744. if (count == num) {
  745. endIndex = startIndex + (photoList.size() % 1000);
  746. }
  747. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  748. CommonResult photoResult = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, eSeewoUserType.Student.getValue());
  749. if (!photoResult.isSuccess()) {
  750. return photoResult;
  751. }
  752. }
  753. }
  754. //endregion
  755. }
  756. } else {
  757. List<SmartUser> teacherDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()).collect(Collectors.toList());
  758. //判断是否存在重复数据
  759. List<String> cardNos = teacherDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  760. if (cardNos == null) {
  761. return CommonResult.fail("文档内容为空,导入失败");
  762. }
  763. if (cardNos.size() <= 0) {
  764. return CommonResult.fail("文档内容为空,导入失败");
  765. }
  766. List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
  767. if (existUsers != null && existUsers.size() > 0) {
  768. String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  769. return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
  770. }
  771. //获取班级Uid
  772. List<SmartClass> classDatas = smartClassService.getSmartClasss();
  773. List<SmartDepartment> departmentDatas = smartDepartmentService.list(null);
  774. //region
  775. //region 希沃添加教师数据
  776. if (useXw == 1) {
  777. int num = (int) Math.ceil((double) teacherDatas.size() / 100);
  778. for (int count = 1; count <= num; count++) {
  779. int startIndex = (count - 1) * 100;
  780. int endIndex = count * 100;
  781. if (count == num) {
  782. endIndex = startIndex + (teacherDatas.size() % 100);
  783. }
  784. List<SmartUser> currentStudentDatas = teacherDatas.subList(startIndex, endIndex);//结尾不包含下标100
  785. //初始化客户端
  786. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  787. //上传图片
  788. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  789. // 老师列表
  790. List<TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery> teachers = new ArrayList<>();
  791. for (SmartUser teacher : currentStudentDatas) {
  792. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teacherData = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  793. .account(teacher.getPhone())//用户账号
  794. .name(teacher.getName())//用户名字
  795. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  796. .teacherCode(teacher.getCardNo())//教师工号
  797. .photoUrl(teacher.getHeadImage())//图片链接
  798. .build();
  799. teachers.add(teacherData);
  800. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  801. photo.setPhotoUrl(teacher.getHeadImage());
  802. photo.setUserCode(teacher.getPhone());
  803. photoList.add(photo);
  804. }
  805. CommonResult<List<TeacherServiceBatchSaveOrUpdateTeacherResult.TeacherBaseInfoDto>> insertTeacher = SeewoInsertBatchTeacher(seewoClient, teachers);
  806. if (!insertTeacher.isSuccess()) {
  807. return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
  808. }
  809. CommonResult insertPhotoResult = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  810. if (!insertPhotoResult.isSuccess()) {
  811. return insertPhotoResult;
  812. }
  813. for (SmartUser teacher : teacherDatas) {
  814. if (teacher.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  815. Optional<SmartClass> oClass = classDatas.stream().filter(e -> e.getId().equals(teacher.getSchoolClass())).findFirst();
  816. if (oClass != null && oClass.isPresent()) {
  817. //获取班级Uid
  818. //region 将班主任推送到希沃
  819. if (useXw == 1) {
  820. CommonResult pushMaster = SeewoPushMaster(seewoClient, teacher.getPhone(), oClass.get().getClassUid());
  821. if (!pushMaster.isSuccess()) {
  822. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  823. }
  824. }
  825. //endregion
  826. } else {
  827. return CommonResult.fail(teacher.getName() + "班级数据无效,导入失败");
  828. }
  829. }
  830. }
  831. }
  832. }
  833. //endregion
  834. //region 百胜添加教师数据
  835. if (useBs == 1) {
  836. for (SmartUser teacher : teacherDatas) {
  837. Optional<SmartDepartment> oDepartment = departmentDatas.stream().filter(e -> e.getId().equals(teacher.getDepartmentId())).findFirst();
  838. if (!(oDepartment != null && oDepartment.isPresent())) {
  839. return CommonResult.fail(teacher.getName() + "的部门数据无效,导入失败");
  840. }
  841. /**
  842. * 教师数据的有效期是20年
  843. */
  844. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  845. String endTime = TimeExchange.addYear(20);
  846. if (ObjectUtils.isEmpty(teacher.getBsStaffCode())) {
  847. CommonResult<String> insertBsTeacher = bsInsertTeacher(teacher, oDepartment.get().getBsDepartmentNo(), startTime, endTime);
  848. if (!insertBsTeacher.isSuccess()) {
  849. return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
  850. }
  851. teacher.setBsStaffCode(insertBsTeacher.getData());
  852. } else {
  853. CommonResult<String> bsUpdateTeacher = updateBsTeacher(teacher, oDepartment.get().getBsDepartmentNo(), startTime, endTime);
  854. if (!bsUpdateTeacher.isSuccess()) {
  855. return CommonResult.fail("百胜平台:" + bsUpdateTeacher.getMessage());
  856. }
  857. teacher.setBsStaffCode(bsUpdateTeacher.getData());
  858. }
  859. }
  860. }
  861. //endregion
  862. if (teacherDatas != null && teacherDatas.size() > 0) {
  863. //批量存储老师信息
  864. boolean resultBool = smartUserService.saveBatch(teacherDatas);
  865. if (!resultBool) {
  866. return CommonResult.fail("导入失败");
  867. } else {
  868. // 需添加到海康平台
  869. ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
  870. for (SmartUser teacherData : teacherDatas) {
  871. Integer id = teacherData.getId();
  872. SmartOperationUser smartOperationUser = new SmartOperationUser();
  873. smartOperationUser.setOperationId(id);
  874. smartOperationUser.setOperationMode("1");
  875. smartOperationUser.setStatus(1);
  876. smartOperationUser.setType(teacherData.getIdentityId());
  877. operationUsers.add(smartOperationUser);
  878. }
  879. smartOperationUserService.saveBatch(operationUsers);
  880. }
  881. //region 批量存储综合评价
  882. List<SmartEvaluateTeacher> insertETeachers = new ArrayList<>();
  883. List<SmartSemester> semesters = smartSemesterService.list(null);
  884. List<SmartClass> classes = smartClassService.list(null);
  885. List<SmartGrade> grades = smartGradeService.list(null);
  886. for (SmartUser teacher : teacherDatas) {
  887. for (SmartSemester semester : semesters) {
  888. //<0 : A < B
  889. //=0 : A = B
  890. //>0 : A > B
  891. if (semester.getEndTime().compareTo(teacher.getCreateTime()) >= 0) {//说明在半学期创建的老师
  892. SmartEvaluateTeacher set = new SmartEvaluateTeacher();
  893. set.setCardNo(teacher.getCardNo());
  894. set.setName(teacher.getName());
  895. set.setUserId(teacher.getId());
  896. set.setTermId(semester.getId());
  897. set.setTerm(semester.getName());
  898. if (teacher.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {//班主任才有年级和班级
  899. set.setGradeId(Integer.valueOf(teacher.getGrade()));
  900. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getId().equals(set.getGradeId())).findFirst();
  901. if (oGrade != null && oGrade.isPresent()) {
  902. set.setGradeName(oGrade.get().getName());
  903. }
  904. set.setClassId(teacher.getSchoolClass());
  905. Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(set.getClassId())).findFirst();
  906. if (oClass != null && oClass.isPresent()) {
  907. set.setClassName(oClass.get().getName());
  908. }
  909. }
  910. set.setTotalScore(0.0);
  911. set.setLowingScore(0.0);
  912. insertETeachers.add(set);
  913. }
  914. }
  915. }
  916. if (insertETeachers != null && insertETeachers.size() > 0) {
  917. boolean insertEteacher = smartEvaluateTeacherService.saveBatch(insertETeachers);
  918. if (!insertEteacher) {
  919. return CommonResult.fail("导入失败");
  920. }
  921. }
  922. //endregion
  923. }
  924. }
  925. return CommonResult.ok("导入成功");
  926. }
  927. //endregion
  928. //region 批量新增Xlsx文件读取方法
  929. /**
  930. * Xlsx文件读取方法
  931. *
  932. * @param inputStream 文件流
  933. * @return
  934. * @throws IOException
  935. */
  936. private CommonResult<List<SmartUser>> readXlsx(InputStream inputStream) throws IOException {
  937. List<String> idCards = new ArrayList<>();
  938. List<String> cardNos = new ArrayList<>();
  939. List<SmartUser> result = new ArrayList<>();
  940. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  941. List<SmartDepartment> departments = smartDepartmentService.list(null);
  942. List<SmartGrade> grades = smartGradeService.list(null); //年级
  943. List<SmartClass> classs = smartClassService.list(null);//班级
  944. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  945. //读取第一张sheet
  946. XSSFSheet sheetAt = sheets.getSheetAt(0);
  947. DataFormatter dataFormatter = new DataFormatter();
  948. //region 判断是老师还是学生导入
  949. boolean isTeacher = false;
  950. XSSFRow checkRow = sheetAt.getRow(0);
  951. if (checkRow != null) {
  952. String firstCow = dataFormatter.formatCellValue(checkRow.getCell(0));//第一列 学生是年级 老师是 学校名称
  953. if (firstCow.equals("学校名称")) {
  954. isTeacher = true;
  955. }
  956. }
  957. //endregion
  958. try {
  959. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  960. XSSFRow row = sheetAt.getRow(rowNum);
  961. if (row != null) {
  962. if (!isTeacher) {
  963. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  964. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  965. //然后poi会根据字符串读取它
  966. //标题 校验
  967. if (rowNum == 0) {
  968. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  969. if (!schoolGrade.equals("年级")) {
  970. return CommonResult.fail("导入数据第一列为年级");
  971. }
  972. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  973. if (!schoolClass.equals("班级")) {
  974. return CommonResult.fail("导入数据第一列为班级");
  975. }
  976. String departmentNo = dataFormatter.formatCellValue(row.getCell(2));//部门
  977. if (!departmentNo.equals("部门")) {
  978. return CommonResult.fail("导入数据第二列为部门");
  979. }
  980. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  981. if (!cardNo.equals("学号")) {
  982. return CommonResult.fail("导入数据第二列为学号");
  983. }
  984. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  985. if (!name.equals("姓名")) {
  986. return CommonResult.fail("导入数据第三列为姓名");
  987. }
  988. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  989. if (!sex.equals("性别")) {
  990. return CommonResult.fail("导入数据第四列为性别");
  991. }
  992. String nation = dataFormatter.formatCellValue(row.getCell(6));//民族
  993. if (!nation.equals("民族")) {
  994. return CommonResult.fail("导入数据第五列为民族");
  995. }
  996. String cardId = dataFormatter.formatCellValue(row.getCell(7));//身份证
  997. if (!cardId.equals("身份证")) {
  998. return CommonResult.fail("导入数据第六列为身份证");
  999. }
  1000. String headImage = dataFormatter.formatCellValue(row.getCell(8));//照片
  1001. if (!headImage.equals("照片")) {
  1002. return CommonResult.fail("导入数据第七列为照片");
  1003. }
  1004. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));//常规时间组
  1005. if (!timeGroup.equals("常规时间组")) {
  1006. return CommonResult.fail("导入数据第八列为常规时间组");
  1007. }
  1008. String address = dataFormatter.formatCellValue(row.getCell(10));//住址
  1009. if (!address.equals("住址")) {
  1010. return CommonResult.fail("导入数据第九列为住址");
  1011. }
  1012. String phone = dataFormatter.formatCellValue(row.getCell(11));//联系电话
  1013. if (!phone.equals("联系电话")) {
  1014. return CommonResult.fail("导入数据第十列为联系电话");
  1015. }
  1016. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  1017. if (!family.equals("家属")) {
  1018. return CommonResult.fail("导入数据第十一列为家属");
  1019. }
  1020. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  1021. if (!familyShip.equals("家属与本人关系")) {
  1022. return CommonResult.fail("导入数据第十二列为家属与本人关系");
  1023. }
  1024. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  1025. if (!phoneTwo.equals("联系电话2")) {
  1026. return CommonResult.fail("导入数据第十三列为联系电话2");
  1027. }
  1028. String familyTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  1029. if (!familyTwo.equals("家属2")) {
  1030. return CommonResult.fail("导入数据第十四列为家属2");
  1031. }
  1032. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  1033. if (!familyShipTwo.equals("家属与本人关系2")) {
  1034. return CommonResult.fail("导入数据第十五列为家属与本人关系2");
  1035. }
  1036. } else {
  1037. SmartUser user = new SmartUser();
  1038. String name = dataFormatter.formatCellValue(row.getCell(4));
  1039. // if (ObjectUtils.isEmpty(name)) {
  1040. // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
  1041. // }
  1042. if (ObjectUtils.isEmpty(name)) {
  1043. continue;
  1044. }
  1045. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  1046. if (ObjectUtils.isEmpty(schoolGrade)) {
  1047. return CommonResult.fail(name + "的年级不能为空");
  1048. }
  1049. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1050. if (ObjectUtils.isEmpty(schoolClass)) {
  1051. return CommonResult.fail(name + "的班级不能为空");
  1052. }
  1053. //不判断重复性 因为会出现双胞胎
  1054. String phone = dataFormatter.formatCellValue(row.getCell(11));
  1055. // if (!ObjectUtils.isEmpty(phone)) {
  1056. // phones.add(phone);
  1057. // }
  1058. // if (phones.stream().distinct().count() != phones.size()) {
  1059. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  1060. // }
  1061. //性别是否为空判断
  1062. String sex = dataFormatter.formatCellValue(row.getCell(5));
  1063. if (ObjectUtils.isEmpty(sex)) {
  1064. return CommonResult.fail(name + "的性别不能为空");
  1065. }
  1066. //家庭住址是否为空判断
  1067. String address = dataFormatter.formatCellValue(row.getCell(10));
  1068. //民族是否为空判断
  1069. String nation = dataFormatter.formatCellValue(row.getCell(6));
  1070. if (ObjectUtils.isEmpty(nation)) {
  1071. return CommonResult.fail(name + "的民族不能为空");
  1072. }
  1073. //部门是否为空判断
  1074. String department = dataFormatter.formatCellValue(row.getCell(2));
  1075. if (ObjectUtils.isEmpty(nation)) {
  1076. return CommonResult.fail(name + "的部门不能为空");
  1077. }
  1078. Integer parentDid = null;
  1079. Integer departmentId = null;
  1080. String[] departmentStrs = department.split("/");
  1081. for (int i = 0; i < departmentStrs.length; i++) {
  1082. String departmentName = departmentStrs[i];
  1083. Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  1084. if (oD != null && oD.isPresent()) {
  1085. parentDid = oD.get().getId();
  1086. } else {
  1087. String bsDepartment = insertDepartmentToBs(departmentName);
  1088. if (bsDepartment == null) {
  1089. return CommonResult.fail(name + "的部门添加到百胜失败");
  1090. }
  1091. SmartDepartment sdParent = new SmartDepartment();
  1092. sdParent.setParentId(parentDid);
  1093. sdParent.setName(departmentName);
  1094. sdParent.setBsDepartmentNo(bsDepartment);
  1095. int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
  1096. departmentId = departmentData;
  1097. parentDid = departmentData;
  1098. }
  1099. }
  1100. //学号重复判断
  1101. String cardNo = dataFormatter.formatCellValue(row.getCell(3));
  1102. if (!ObjectUtils.isEmpty(cardNo)) {
  1103. cardNos.add(cardNo);
  1104. }
  1105. if (cardNos.stream().distinct().count() != cardNos.size()) {
  1106. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  1107. }
  1108. //身份证重复判断
  1109. String idCard = dataFormatter.formatCellValue(row.getCell(7));
  1110. if (!ObjectUtils.isEmpty(idCard)) {
  1111. idCards.add(idCard);
  1112. }
  1113. if (idCards.stream().distinct().count() != idCards.size()) {
  1114. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  1115. }
  1116. user.setCardNo(cardNo == null ? "" : cardNo);
  1117. user.setName(name == null ? "" : name);
  1118. user.setIdentityId(eIdentityStatu.Student.getValue());
  1119. user.setIdCard(idCard == null ? "" : idCard);
  1120. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1121. user.setDepartmentId(departmentId);
  1122. String cellImage = dataFormatter.formatCellValue(row.getCell(8));
  1123. user.setHeadImage(cellImage);
  1124. user.setDormitoryNumber("");
  1125. String grade = schoolGrade == null ? "" : schoolGrade;
  1126. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  1127. if (oGrade != null && oGrade.isPresent()) {
  1128. Integer gradeId = oGrade.get().getId();
  1129. user.setGrade(String.valueOf(gradeId));
  1130. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  1131. if (oClass != null && oClass.isPresent()) {
  1132. user.setSchoolClass(oClass.get().getId());
  1133. } else {
  1134. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1135. }
  1136. } else {
  1137. return CommonResult.fail(name + "的年级数据无效,导入失败");
  1138. }
  1139. user.setCollege("");
  1140. user.setSpeciality("");
  1141. user.setCampus("");
  1142. user.setPhone("");
  1143. user.setAffiliate("");
  1144. user.setTitle("");
  1145. user.setAddress(address == null ? "" : address);
  1146. user.setNation(nation == null ? "" : nation);
  1147. user.setOfStudent("");
  1148. user.setGraduate("");
  1149. user.setDuties(null);
  1150. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));
  1151. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1152. if (groupData != null && groupData.isPresent()) {
  1153. user.setTimeGroupId(groupData.get().getId());
  1154. } else {
  1155. user.setTimeGroupId(0);
  1156. }
  1157. user.setIsCancel(eLogOff.Unlogout.getValue());
  1158. result.add(user);
  1159. //部门是否为空判断
  1160. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  1161. Integer familyDepartmentId = null;
  1162. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  1163. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  1164. familyDepartmentId = familyDepartModel.get().getId();
  1165. } else {
  1166. familyDepartmentId = 16;
  1167. }
  1168. //region 家属
  1169. if (!ObjectUtils.isEmpty(phone)) {
  1170. if (phone.length() != 11) {
  1171. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1172. }
  1173. SmartUser familyOne = new SmartUser();
  1174. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  1175. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  1176. familyOne.setDepartmentId(familyDepartmentId);
  1177. familyOne.setPhone(phone);
  1178. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  1179. familyOne.setSexId(eSexStatu.Man.getValue());
  1180. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  1181. familyOne.setAffiliate(user.getCardNo());
  1182. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  1183. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  1184. result.add(familyOne);
  1185. }
  1186. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  1187. if (!ObjectUtils.isEmpty(phoneTwo)) {
  1188. if (phoneTwo.length() != 11) {
  1189. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1190. }
  1191. SmartUser familyTwo = new SmartUser();
  1192. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  1193. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  1194. familyTwo.setDepartmentId(familyDepartmentId);
  1195. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  1196. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  1197. familyTwo.setSexId(eSexStatu.Man.getValue());
  1198. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  1199. familyTwo.setAffiliate(user.getCardNo());
  1200. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  1201. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  1202. result.add(familyTwo);
  1203. }
  1204. //endregion
  1205. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  1206. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(14)))) {
  1207. if (phone.equals(dataFormatter.formatCellValue(row.getCell(14)))) {
  1208. return CommonResult.fail(name + "的学生家长手机号不可重复");
  1209. }
  1210. }
  1211. //endregion
  1212. }
  1213. } else {
  1214. //教师导入
  1215. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1216. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1217. //然后poi会根据字符串读取它
  1218. //标题 校验
  1219. if (rowNum == 0) {
  1220. String schoolName = dataFormatter.formatCellValue(row.getCell(0));//学校名称
  1221. if (!schoolName.equals("学校名称")) {
  1222. return CommonResult.fail("导入数据第一列为学校名称");
  1223. }
  1224. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1225. if (!departmentNo.equals("部门编码")) {
  1226. return CommonResult.fail("导入数据第二列为部门编码");
  1227. }
  1228. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1229. if (!departmentName.equals("部门名称")) {
  1230. return CommonResult.fail("导入数据第三列为部门名称");
  1231. }
  1232. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1233. if (!teacherNo.equals("教师编码")) {
  1234. return CommonResult.fail("导入数据第四列为教师编码");
  1235. }
  1236. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1237. if (!name.equals("姓名")) {
  1238. return CommonResult.fail("导入数据第五列为姓名");
  1239. }
  1240. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1241. if (!sex.equals("性别")) {
  1242. return CommonResult.fail("导入数据第六列为性别");
  1243. }
  1244. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1245. if (!phone.equals("联系电话")) {
  1246. return CommonResult.fail("导入数据第七列为联系电话");
  1247. }
  1248. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//管理班级
  1249. if (!schoolClass.equals("管理班级")) {
  1250. return CommonResult.fail("导入数据第八列为身份证");
  1251. }
  1252. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1253. if (!nation.equals("民族")) {
  1254. return CommonResult.fail("导入数据第九列为民族");
  1255. }
  1256. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1257. if (!card.equals("身份证(允许为空)")) {
  1258. return CommonResult.fail("导入数据第十列为身份证");
  1259. }
  1260. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1261. if (!photo.equals("照片")) {
  1262. return CommonResult.fail("导入数据第十一列为照片");
  1263. }
  1264. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1265. if (!timeGroup.equals("常规时间组")) {
  1266. return CommonResult.fail("导入数据第十二列为常规时间组");
  1267. }
  1268. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1269. if (!address.equals("住址")) {
  1270. return CommonResult.fail("导入数据第十三列为住址");
  1271. }
  1272. } else {
  1273. SmartUser user = new SmartUser();
  1274. user.setIdentityId(eIdentityStatu.Teacher.getValue());
  1275. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1276. if (ObjectUtils.isEmpty(name)) {
  1277. continue;
  1278. }
  1279. user.setName(name);
  1280. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1281. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1282. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1283. if (ObjectUtils.isEmpty(departmentName)) {
  1284. return CommonResult.fail(name + "的部门名称不能为空");
  1285. }
  1286. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1287. if (ObjectUtils.isEmpty(departmentNo)) {
  1288. return CommonResult.fail(name + "的部门编码不能为空");
  1289. }
  1290. Optional<SmartDepartment> oDepartment = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  1291. if (!(oDepartment != null && oDepartment.isPresent())) {
  1292. return CommonResult.fail(departmentName + "部门数据在系统中不存在");
  1293. }
  1294. user.setDepartmentId(oDepartment.get().getId());
  1295. if (departmentName.equals("班主任")) {
  1296. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//班级
  1297. if (ObjectUtils.isEmpty(schoolClass)) {
  1298. return CommonResult.fail(name + "的管理班级不能为空");
  1299. }
  1300. //班级和年级
  1301. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  1302. if (!(oClass != null && oClass.isPresent())) {
  1303. return CommonResult.fail(schoolClass + "的班级数据在系统中不存在");
  1304. }
  1305. user.setSchoolClass(oClass.get().getId());
  1306. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  1307. user.setDuties(eDuties.ClassTeacher.getValue());
  1308. } else {
  1309. user.setDuties(5);//任课老师
  1310. }
  1311. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1312. if (!ObjectUtils.isEmpty(teacherNo)) {
  1313. user.setCardNo(teacherNo);
  1314. }
  1315. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1316. if (ObjectUtils.isEmpty(phone)) {
  1317. return CommonResult.fail(name + "的手机号不能为空");
  1318. }
  1319. user.setPhone(phone);
  1320. user.setXwTeacherCode(phone);
  1321. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1322. if (!ObjectUtils.isEmpty(nation)) {
  1323. user.setNation(nation);
  1324. }
  1325. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1326. if (!ObjectUtils.isEmpty(card)) {
  1327. user.setIdCard(card);
  1328. }
  1329. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1330. if (!ObjectUtils.isEmpty(photo)) {
  1331. user.setHeadImage(photo);
  1332. }
  1333. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1334. if (!ObjectUtils.isEmpty(timeGroup)) {
  1335. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1336. if (groupData != null && groupData.isPresent()) {
  1337. user.setTimeGroupId(groupData.get().getId());
  1338. }
  1339. }
  1340. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1341. if (!ObjectUtils.isEmpty(address)) {
  1342. user.setAddress(address);
  1343. }
  1344. user.setIsCancel(eLogOff.Unlogout.getValue());
  1345. result.add(user);
  1346. }
  1347. }
  1348. }
  1349. }
  1350. } catch (Exception e) {
  1351. return CommonResult.fail("请按模板格式导入数据");
  1352. }
  1353. return CommonResult.ok(result);
  1354. }
  1355. //endregion
  1356. //region 批量新增Xls文件读取方法
  1357. /**
  1358. * Xls文件读取方法
  1359. *
  1360. * @param inputStream 文件流
  1361. * @return
  1362. * @throws IOException
  1363. */
  1364. private CommonResult<List<SmartUser>> readXls(InputStream inputStream) throws IOException {
  1365. List<String> idCards = new ArrayList<>();
  1366. List<String> cardNos = new ArrayList<>();
  1367. List<SmartUser> result = new ArrayList<>();
  1368. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  1369. List<SmartDepartment> departments = smartDepartmentService.list(null);
  1370. List<SmartGrade> grades = smartGradeService.list(null); //年级
  1371. List<SmartClass> classs = smartClassService.list(null);//班级
  1372. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  1373. //读取第一张sheet
  1374. HSSFSheet sheetAt = sheets.getSheetAt(0);
  1375. DataFormatter dataFormatter = new DataFormatter();
  1376. //region 判断是老师还是学生导入
  1377. boolean isTeacher = false;
  1378. HSSFRow checkRow = sheetAt.getRow(0);
  1379. if (checkRow != null) {
  1380. String firstCow = dataFormatter.formatCellValue(checkRow.getCell(0));//第一列 学生是年级 老师是 学校名称
  1381. if (firstCow.equals("学校名称")) {
  1382. isTeacher = true;
  1383. }
  1384. }
  1385. //endregion
  1386. try {
  1387. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  1388. HSSFRow row = sheetAt.getRow(rowNum);
  1389. if (row != null) {
  1390. if (!isTeacher) {
  1391. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1392. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1393. //然后poi会根据字符串读取它
  1394. //标题 校验
  1395. if (rowNum == 0) {
  1396. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  1397. if (!schoolGrade.equals("年级")) {
  1398. return CommonResult.fail("导入数据第一列为年级");
  1399. }
  1400. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1401. if (!schoolClass.equals("班级")) {
  1402. return CommonResult.fail("导入数据第一列为班级");
  1403. }
  1404. String departmentNo = dataFormatter.formatCellValue(row.getCell(2));//部门
  1405. if (!departmentNo.equals("部门")) {
  1406. return CommonResult.fail("导入数据第二列为部门");
  1407. }
  1408. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  1409. if (!cardNo.equals("学号")) {
  1410. return CommonResult.fail("导入数据第二列为学号");
  1411. }
  1412. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1413. if (!name.equals("姓名")) {
  1414. return CommonResult.fail("导入数据第三列为姓名");
  1415. }
  1416. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1417. if (!sex.equals("性别")) {
  1418. return CommonResult.fail("导入数据第四列为性别");
  1419. }
  1420. String nation = dataFormatter.formatCellValue(row.getCell(6));//民族
  1421. if (!nation.equals("民族")) {
  1422. return CommonResult.fail("导入数据第五列为民族");
  1423. }
  1424. String cardId = dataFormatter.formatCellValue(row.getCell(7));//身份证
  1425. if (!cardId.equals("身份证")) {
  1426. return CommonResult.fail("导入数据第六列为身份证");
  1427. }
  1428. String headImage = dataFormatter.formatCellValue(row.getCell(8));//照片
  1429. if (!headImage.equals("照片")) {
  1430. return CommonResult.fail("导入数据第七列为照片");
  1431. }
  1432. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));//常规时间组
  1433. if (!timeGroup.equals("常规时间组")) {
  1434. return CommonResult.fail("导入数据第八列为常规时间组");
  1435. }
  1436. String address = dataFormatter.formatCellValue(row.getCell(10));//住址
  1437. if (!address.equals("住址")) {
  1438. return CommonResult.fail("导入数据第九列为住址");
  1439. }
  1440. String phone = dataFormatter.formatCellValue(row.getCell(11));//联系电话
  1441. if (!phone.equals("联系电话")) {
  1442. return CommonResult.fail("导入数据第十列为联系电话");
  1443. }
  1444. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  1445. if (!family.equals("家属")) {
  1446. return CommonResult.fail("导入数据第十一列为家属");
  1447. }
  1448. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  1449. if (!familyShip.equals("家属与本人关系")) {
  1450. return CommonResult.fail("导入数据第十二列为家属与本人关系");
  1451. }
  1452. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  1453. if (!phoneTwo.equals("联系电话2")) {
  1454. return CommonResult.fail("导入数据第十三列为联系电话2");
  1455. }
  1456. String familyTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  1457. if (!familyTwo.equals("家属2")) {
  1458. return CommonResult.fail("导入数据第十四列为家属2");
  1459. }
  1460. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  1461. if (!familyShipTwo.equals("家属与本人关系2")) {
  1462. return CommonResult.fail("导入数据第十五列为家属与本人关系2");
  1463. }
  1464. } else {
  1465. SmartUser user = new SmartUser();
  1466. String name = dataFormatter.formatCellValue(row.getCell(4));
  1467. // if (ObjectUtils.isEmpty(name)) {
  1468. // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
  1469. // }
  1470. if (ObjectUtils.isEmpty(name)) {
  1471. continue;
  1472. }
  1473. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  1474. if (ObjectUtils.isEmpty(schoolGrade)) {
  1475. return CommonResult.fail(name + "的年级不能为空");
  1476. }
  1477. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1478. if (ObjectUtils.isEmpty(schoolClass)) {
  1479. return CommonResult.fail(name + "的班级不能为空");
  1480. }
  1481. //不判断重复性 因为会出现双胞胎
  1482. String phone = dataFormatter.formatCellValue(row.getCell(11));
  1483. // if (!ObjectUtils.isEmpty(phone)) {
  1484. // phones.add(phone);
  1485. // }
  1486. // if (phones.stream().distinct().count() != phones.size()) {
  1487. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  1488. // }
  1489. //性别是否为空判断
  1490. String sex = dataFormatter.formatCellValue(row.getCell(5));
  1491. if (ObjectUtils.isEmpty(sex)) {
  1492. return CommonResult.fail(name + "的性别不能为空");
  1493. }
  1494. //家庭住址是否为空判断
  1495. String address = dataFormatter.formatCellValue(row.getCell(10));
  1496. //民族是否为空判断
  1497. String nation = dataFormatter.formatCellValue(row.getCell(6));
  1498. if (ObjectUtils.isEmpty(nation)) {
  1499. return CommonResult.fail(name + "的民族不能为空");
  1500. }
  1501. //部门是否为空判断
  1502. String department = dataFormatter.formatCellValue(row.getCell(2));
  1503. if (ObjectUtils.isEmpty(nation)) {
  1504. return CommonResult.fail(name + "的部门不能为空");
  1505. }
  1506. Integer parentDid = null;
  1507. Integer departmentId = null;
  1508. String[] departmentStrs = department.split("/");
  1509. for (int i = 0; i < departmentStrs.length; i++) {
  1510. String departmentName = departmentStrs[i];
  1511. Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  1512. if (oD != null && oD.isPresent()) {
  1513. parentDid = oD.get().getId();
  1514. } else {
  1515. String bsDepartment = insertDepartmentToBs(departmentName);
  1516. if (bsDepartment == null) {
  1517. return CommonResult.fail(name + "的部门添加到百胜失败");
  1518. }
  1519. SmartDepartment sdParent = new SmartDepartment();
  1520. sdParent.setParentId(parentDid);
  1521. sdParent.setName(departmentName);
  1522. sdParent.setBsDepartmentNo(bsDepartment);
  1523. int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
  1524. departmentId = departmentData;
  1525. parentDid = departmentData;
  1526. }
  1527. }
  1528. //学号重复判断
  1529. String cardNo = dataFormatter.formatCellValue(row.getCell(3));
  1530. if (!ObjectUtils.isEmpty(cardNo)) {
  1531. cardNos.add(cardNo);
  1532. }
  1533. if (cardNos.stream().distinct().count() != cardNos.size()) {
  1534. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  1535. }
  1536. //身份证重复判断
  1537. String idCard = dataFormatter.formatCellValue(row.getCell(7));
  1538. if (!ObjectUtils.isEmpty(idCard)) {
  1539. idCards.add(idCard);
  1540. }
  1541. if (idCards.stream().distinct().count() != idCards.size()) {
  1542. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  1543. }
  1544. user.setCardNo(cardNo == null ? "" : cardNo);
  1545. user.setName(name == null ? "" : name);
  1546. user.setIdentityId(eIdentityStatu.Student.getValue());
  1547. user.setIdCard(idCard == null ? "" : idCard);
  1548. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1549. user.setDepartmentId(departmentId);
  1550. String cellImage = dataFormatter.formatCellValue(row.getCell(8));
  1551. user.setHeadImage(cellImage);
  1552. user.setDormitoryNumber("");
  1553. String grade = schoolGrade == null ? "" : schoolGrade;
  1554. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  1555. if (oGrade != null && oGrade.isPresent()) {
  1556. Integer gradeId = oGrade.get().getId();
  1557. user.setGrade(String.valueOf(gradeId));
  1558. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  1559. if (oClass != null && oClass.isPresent()) {
  1560. user.setSchoolClass(oClass.get().getId());
  1561. } else {
  1562. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1563. }
  1564. } else {
  1565. return CommonResult.fail(name + "的年级数据无效,导入失败");
  1566. }
  1567. user.setCollege("");
  1568. user.setSpeciality("");
  1569. user.setCampus("");
  1570. user.setPhone("");
  1571. user.setAffiliate("");
  1572. user.setTitle("");
  1573. user.setAddress(address == null ? "" : address);
  1574. user.setNation(nation == null ? "" : nation);
  1575. user.setOfStudent("");
  1576. user.setGraduate("");
  1577. user.setDuties(null);
  1578. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));
  1579. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1580. if (groupData != null && groupData.isPresent()) {
  1581. user.setTimeGroupId(groupData.get().getId());
  1582. } else {
  1583. user.setTimeGroupId(0);
  1584. }
  1585. user.setIsCancel(eLogOff.Unlogout.getValue());
  1586. result.add(user);
  1587. //部门是否为空判断
  1588. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  1589. Integer familyDepartmentId = null;
  1590. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  1591. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  1592. familyDepartmentId = familyDepartModel.get().getId();
  1593. } else {
  1594. familyDepartmentId = 16;
  1595. }
  1596. //region 家属
  1597. if (!ObjectUtils.isEmpty(phone)) {
  1598. if (phone.length() != 11) {
  1599. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1600. }
  1601. SmartUser familyOne = new SmartUser();
  1602. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  1603. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  1604. familyOne.setDepartmentId(familyDepartmentId);
  1605. familyOne.setPhone(phone);
  1606. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  1607. familyOne.setSexId(eSexStatu.Man.getValue());
  1608. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  1609. familyOne.setAffiliate(user.getCardNo());
  1610. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  1611. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  1612. result.add(familyOne);
  1613. }
  1614. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  1615. if (!ObjectUtils.isEmpty(phoneTwo)) {
  1616. if (phoneTwo.length() != 11) {
  1617. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1618. }
  1619. SmartUser familyTwo = new SmartUser();
  1620. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  1621. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  1622. familyTwo.setDepartmentId(familyDepartmentId);
  1623. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  1624. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  1625. familyTwo.setSexId(eSexStatu.Man.getValue());
  1626. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  1627. familyTwo.setAffiliate(user.getCardNo());
  1628. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  1629. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  1630. result.add(familyTwo);
  1631. }
  1632. //endregion
  1633. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  1634. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(14)))) {
  1635. if (phone.equals(dataFormatter.formatCellValue(row.getCell(14)))) {
  1636. return CommonResult.fail(name + "的学生家长手机号不可重复");
  1637. }
  1638. }
  1639. //endregion
  1640. }
  1641. } else {
  1642. //教师导入
  1643. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1644. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1645. //然后poi会根据字符串读取它
  1646. //标题 校验
  1647. if (rowNum == 0) {
  1648. String schoolName = dataFormatter.formatCellValue(row.getCell(0));//学校名称
  1649. if (!schoolName.equals("学校名称")) {
  1650. return CommonResult.fail("导入数据第一列为学校名称");
  1651. }
  1652. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1653. if (!departmentNo.equals("部门编码")) {
  1654. return CommonResult.fail("导入数据第二列为部门编码");
  1655. }
  1656. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1657. if (!departmentName.equals("部门名称")) {
  1658. return CommonResult.fail("导入数据第三列为部门名称");
  1659. }
  1660. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1661. if (!teacherNo.equals("教师编码")) {
  1662. return CommonResult.fail("导入数据第四列为教师编码");
  1663. }
  1664. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1665. if (!name.equals("姓名")) {
  1666. return CommonResult.fail("导入数据第五列为姓名");
  1667. }
  1668. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1669. if (!sex.equals("性别")) {
  1670. return CommonResult.fail("导入数据第六列为性别");
  1671. }
  1672. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1673. if (!phone.equals("联系电话")) {
  1674. return CommonResult.fail("导入数据第七列为联系电话");
  1675. }
  1676. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//管理班级
  1677. if (!schoolClass.equals("管理班级")) {
  1678. return CommonResult.fail("导入数据第八列为身份证");
  1679. }
  1680. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1681. if (!nation.equals("民族")) {
  1682. return CommonResult.fail("导入数据第九列为民族");
  1683. }
  1684. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1685. if (!card.equals("身份证(允许为空)")) {
  1686. return CommonResult.fail("导入数据第十列为身份证");
  1687. }
  1688. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1689. if (!photo.equals("照片")) {
  1690. return CommonResult.fail("导入数据第十一列为照片");
  1691. }
  1692. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1693. if (!timeGroup.equals("常规时间组")) {
  1694. return CommonResult.fail("导入数据第十二列为常规时间组");
  1695. }
  1696. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1697. if (!address.equals("住址")) {
  1698. return CommonResult.fail("导入数据第十三列为住址");
  1699. }
  1700. } else {
  1701. SmartUser user = new SmartUser();
  1702. user.setIdentityId(eIdentityStatu.Teacher.getValue());
  1703. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  1704. if (ObjectUtils.isEmpty(name)) {
  1705. continue;
  1706. }
  1707. user.setName(name);
  1708. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  1709. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1710. String departmentName = dataFormatter.formatCellValue(row.getCell(2));//部门名称
  1711. if (ObjectUtils.isEmpty(departmentName)) {
  1712. return CommonResult.fail(name + "的部门名称不能为空");
  1713. }
  1714. String departmentNo = dataFormatter.formatCellValue(row.getCell(1));//部门编码
  1715. if (ObjectUtils.isEmpty(departmentNo)) {
  1716. return CommonResult.fail(name + "的部门编码不能为空");
  1717. }
  1718. Optional<SmartDepartment> oDepartment = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  1719. if (!(oDepartment != null && oDepartment.isPresent())) {
  1720. return CommonResult.fail(departmentName + "部门数据在系统中不存在");
  1721. }
  1722. user.setDepartmentId(oDepartment.get().getId());
  1723. if (departmentName.equals("班主任")) {
  1724. String schoolClass = dataFormatter.formatCellValue(row.getCell(7));//班级
  1725. if (ObjectUtils.isEmpty(schoolClass)) {
  1726. return CommonResult.fail(name + "的管理班级不能为空");
  1727. }
  1728. //班级和年级
  1729. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  1730. if (!(oClass != null && oClass.isPresent())) {
  1731. return CommonResult.fail(schoolClass + "的班级数据在系统中不存在");
  1732. }
  1733. user.setSchoolClass(oClass.get().getId());
  1734. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  1735. user.setDuties(eDuties.ClassTeacher.getValue());
  1736. } else {
  1737. user.setDuties(5);//任课老师
  1738. }
  1739. String teacherNo = dataFormatter.formatCellValue(row.getCell(3));//教师编码
  1740. if (!ObjectUtils.isEmpty(teacherNo)) {
  1741. //user.setBsStaffCode(teacherNo);
  1742. user.setCardNo(teacherNo);
  1743. }
  1744. String phone = dataFormatter.formatCellValue(row.getCell(6));//联系电话
  1745. if (ObjectUtils.isEmpty(phone)) {
  1746. return CommonResult.fail(name + "的手机号不能为空");
  1747. }
  1748. user.setPhone(phone);
  1749. user.setXwTeacherCode(phone);
  1750. String nation = dataFormatter.formatCellValue(row.getCell(8));//民族
  1751. if (!ObjectUtils.isEmpty(nation)) {
  1752. user.setNation(nation);
  1753. }
  1754. String card = dataFormatter.formatCellValue(row.getCell(9));//身份证
  1755. if (!ObjectUtils.isEmpty(card)) {
  1756. user.setIdCard(card);
  1757. }
  1758. String photo = dataFormatter.formatCellValue(row.getCell(10));//照片
  1759. if (!ObjectUtils.isEmpty(photo)) {
  1760. user.setHeadImage(photo);
  1761. }
  1762. String timeGroup = dataFormatter.formatCellValue(row.getCell(11));//常规时间组
  1763. if (!ObjectUtils.isEmpty(timeGroup)) {
  1764. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1765. if (groupData != null && groupData.isPresent()) {
  1766. user.setTimeGroupId(groupData.get().getId());
  1767. }
  1768. }
  1769. String address = dataFormatter.formatCellValue(row.getCell(12));//住址
  1770. if (!ObjectUtils.isEmpty(address)) {
  1771. user.setAddress(address);
  1772. }
  1773. user.setIsCancel(eLogOff.Unlogout.getValue());
  1774. result.add(user);
  1775. }
  1776. }
  1777. }
  1778. }
  1779. } catch (Exception e) {
  1780. return CommonResult.fail("请按模板格式导入数据");
  1781. }
  1782. return CommonResult.ok(result);
  1783. }
  1784. //endregion
  1785. public String insertDepartmentToBs(String name) throws Exception {
  1786. //region 百胜添加部门数据
  1787. String appId = controlConfig.getAppId();
  1788. String schoolno = controlConfig.getSchoolCode();
  1789. String timestamp = TimeExchange.DateNowTimeStamo();
  1790. String appSecret = controlConfig.getAppSecret();
  1791. String url = controlConfig.getUrl() + "department/create";
  1792. JSONObject jsonobject = new JSONObject();
  1793. jsonobject.put("appid", appId);
  1794. String str = "{\"department_name\":\"" + name + "\"}";
  1795. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  1796. jsonobject.put("data", aesStr);
  1797. jsonobject.put("schoolno", schoolno);
  1798. jsonobject.put("timestamp", timestamp);
  1799. String md5Str = "appid=" + appId + "&data={\"department_name\":\"" + name + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  1800. String sign = CommonUtil.MD5(md5Str);
  1801. //sign签名
  1802. jsonobject.put("sign", sign);
  1803. //返回的结果中 code为1表示成功
  1804. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  1805. if (bsResult.contains("添加成功")) {
  1806. ObjectMapper objectMapper = new ObjectMapper();
  1807. BsDepartmentVo department = objectMapper.readValue(bsResult, BsDepartmentVo.class);
  1808. // URL解码
  1809. String decodedUrl = URLDecoder.decode(department.getData(), "UTF-8");
  1810. BsDepartmentNoVo departmentData = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsDepartmentNoVo.class);
  1811. return departmentData.getDepartment_no();
  1812. }
  1813. //endregion
  1814. return null;
  1815. }
  1816. //endregion
  1817. //region 批量更新用户
  1818. //region 批量更新用户方法
  1819. /**
  1820. * 只更新 姓名 班级 时间组
  1821. *
  1822. * @param excelFile excel文件
  1823. * @return
  1824. * @throws IOException
  1825. */
  1826. @Override
  1827. public CommonResult importExcelUpdateUsers(MultipartFile excelFile, String headImage) throws Exception {
  1828. List<SmartUser> result = new ArrayList<>();
  1829. int useXw = 1;
  1830. int useBs = 1;
  1831. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  1832. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  1833. return CommonResult.fail("excel文件不能为空");
  1834. }
  1835. String ContentType = excelFile.getContentType();
  1836. InputStream inputStream = excelFile.getInputStream();
  1837. //xls格式文件
  1838. if (ContentType.equals(eFileType.Xls.getValue())) {
  1839. CommonResult<List<SmartUser>> resultData = readUpdateXls(inputStream);
  1840. if (!resultData.isSuccess()) {
  1841. return resultData;
  1842. }
  1843. result = resultData.getData();
  1844. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  1845. CommonResult<List<SmartUser>> resultData = readUpdateXlsx(inputStream);
  1846. if (!resultData.isSuccess()) {
  1847. return resultData;
  1848. }
  1849. result = resultData.getData();
  1850. } else {
  1851. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  1852. }
  1853. //获取导入学生的相关数据
  1854. List<String> cardNos = result.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  1855. if (cardNos == null) {
  1856. return CommonResult.fail("文档内容为空,批量更新失败");
  1857. }
  1858. List<SmartGrade> grades = smartGradeService.list(null);
  1859. List<SmartClass> classes = smartClassService.list(null);
  1860. List<SmartUser> insertStudent = new ArrayList<>();
  1861. List<SmartUser> updateStudent = new ArrayList<>();
  1862. List<SmartUser> updateStudents = result.stream().filter(e -> e.getId() != null && e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
  1863. for (SmartUser studentData : updateStudents) {
  1864. studentData.setName(studentData.getName());//姓名
  1865. studentData.setSchoolClass(studentData.getSchoolClass());//班级
  1866. studentData.setGrade(studentData.getGrade());//可能会变年级
  1867. studentData.setTimeGroupId(studentData.getTimeGroupId());//时间组
  1868. updateStudent.add(studentData);
  1869. Optional<SmartGrade> oGrade = grades.stream().filter(e -> String.valueOf(e.getId()).equals(studentData.getGrade())).findFirst();
  1870. if (oGrade != null && oGrade.isPresent()) {
  1871. Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(studentData.getSchoolClass())).findFirst();
  1872. if (oClass != null && oClass.isPresent()) {
  1873. if (useXw == 1) {
  1874. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1875. CommonResult updateSwStudent = SeewoUpdateStudent(seewoClient, studentData);
  1876. if (!updateSwStudent.isSuccess()) {
  1877. return CommonResult.fail("希沃平台:" + updateSwStudent.getMessage());
  1878. }
  1879. if (!studentData.getOldClassUid().equals(oClass.get().getClassUid())) {
  1880. CommonResult changeClass = SeewoChangeClass(seewoClient, seewoConfig.getSchoolId(), studentData.getXwStudentUid(), studentData.getOldClassUid(), oClass.get().getClassUid());
  1881. if (!changeClass.isSuccess()) {
  1882. //return CommonResult.fail("希沃平台:" + changeClass.getMessage());
  1883. }
  1884. }
  1885. }
  1886. if (useBs == 1) {
  1887. /**
  1888. * 学生数据的有效期是到毕业年份的8月31日
  1889. */
  1890. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1891. String endTime = queryGraduationYear(oGrade.get().getGradeNo());
  1892. CommonResult<String> updateBsStudent = bsEUpdateStudent(studentData, oClass.get().getBsClassNo(), startTime, endTime);
  1893. if (!updateBsStudent.isSuccess()) {
  1894. return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
  1895. }
  1896. }
  1897. } else {
  1898. return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的班级数据无效,无法进行更新操作");
  1899. }
  1900. } else {
  1901. return CommonResult.fail("学号为:" + studentData.getCardNo() + "的" + studentData.getName() + "的年级数据无效,无法进行更新操作");
  1902. }
  1903. }
  1904. //更新家长
  1905. List<SmartUser> updateParents = result.stream().filter(e -> e.getId() != null && e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
  1906. if(updateParents != null && updateParents.size() > 0){
  1907. boolean updateBatch = smartUserService.updateBatchById(updateParents);
  1908. if (!updateBatch) {
  1909. return CommonResult.fail("系统批量更新家长出错,导入失败");
  1910. }
  1911. }
  1912. //新增家长
  1913. List<SmartUser> insertParentDatas = new ArrayList<>();
  1914. List<SmartUser> insertParents = result.stream().filter(e -> e.getId() == null && e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
  1915. if(insertParents != null && insertParents.size() > 0){
  1916. List<String> familyCardNos = updateStudents.stream().map(SmartUser::getCardNo).distinct().collect(Collectors.toList());
  1917. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(familyCardNos);
  1918. List<SmartFamilyIndex> familyIndexs = new ArrayList<>();
  1919. //region 希沃新增编辑学生家长信息
  1920. if (useXw == 1) {
  1921. int num = (int) Math.ceil((double) updateStudents.size() / 100);
  1922. for (int count = 1; count <= num; count++) {
  1923. int startIndex = (count - 1) * 100;
  1924. int endIndex = count * 100;
  1925. if (count == num) {
  1926. endIndex = startIndex + (updateStudents.size() % 100);
  1927. }
  1928. List<SmartUser> currentStudentDatas = updateStudents.subList(startIndex, endIndex);//结尾不包含下标100
  1929. //学生与家长列表,最大100条
  1930. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  1931. for (SmartUser student : currentStudentDatas) {
  1932. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  1933. .studentCode(student.getCardNo())
  1934. .build();
  1935. List<SmartUser> parentDatas = insertParents.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList());
  1936. List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
  1937. long indexCount = indexs.stream().filter(e -> e.getStudentNo().equals(student.getCardNo())).count();
  1938. int i = (indexCount<= 0 ? 0 : (int)indexCount);
  1939. for (SmartUser parent : parentDatas) {
  1940. insertParentDatas.add(parent);
  1941. SmartFamilyIndex familyIndex = new SmartFamilyIndex();
  1942. familyIndex.setParentPhone(parent.getPhone());
  1943. familyIndex.setStudentNo(student.getCardNo());
  1944. familyIndex.setIndexData(i);
  1945. familyIndexs.add(familyIndex);
  1946. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  1947. .name(parent.getShip())
  1948. .phone(parent.getPhone())
  1949. .index(i)
  1950. .build();
  1951. parents.add(data);
  1952. ++i;
  1953. }
  1954. if (parents != null && parents.size() > 0) {
  1955. studentParents.add(students);
  1956. //家长列表,最多4个
  1957. students.setParents(parents);
  1958. }
  1959. }
  1960. //初始化客户端
  1961. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1962. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  1963. //响应体,MimeType为 application/json
  1964. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  1965. .build();
  1966. param.setRequestBody(requestBody);
  1967. //query
  1968. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  1969. .appId(seewoConfig.getAppId())
  1970. .schoolUid(seewoConfig.getSchoolId())
  1971. .build();
  1972. requestBody.setQuery(query);
  1973. query.setStudentParents(studentParents);
  1974. param.setRequestBody(requestBody);
  1975. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  1976. String jsonString = JSON.toJSONString(request);
  1977. logger.info("入参:" + request);
  1978. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  1979. //request.setServerUrl("https://openapi.test.seewo.com")
  1980. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  1981. ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request);
  1982. logger.info("出参:" + parentResult);
  1983. if (parentResult == null) {
  1984. return CommonResult.fail("希沃学生家长数据添加失败!");
  1985. }
  1986. if (!parentResult.getResponseBody().getCode().equals("000000")) {
  1987. return CommonResult.fail("希沃平台:" + parentResult.getResponseBody().getMessage());
  1988. }
  1989. }
  1990. }
  1991. //endregion
  1992. if (familyIndexs != null && familyIndexs.size() > 0) {
  1993. boolean insertBatch = smartFamilyIndexService.saveBatch(familyIndexs);
  1994. if (!insertBatch) {
  1995. return CommonResult.fail("导入失败!");
  1996. }
  1997. }
  1998. List<SmartUser> newParents = new ArrayList<>();
  1999. if(insertParentDatas != null && insertParentDatas.size() > 0){
  2000. for (SmartUser parent : insertParentDatas) {
  2001. Optional<SmartUser> student = updateStudents.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
  2002. if (student != null && student.isPresent()) {
  2003. //先查找是否存在
  2004. Optional<SmartUser> newData = newParents.stream().filter(e -> e.getName().equals(parent.getName()) && e.getPhone().equals(parent.getPhone()) && e.getShip().equals(parent.getShip())).findFirst();
  2005. if (newData != null && newData.isPresent()) {
  2006. String affiliate = newData.get().getAffiliate() + "," + student.get().getId();
  2007. newData.get().setAffiliate(affiliate);
  2008. } else {
  2009. SmartUser newParent = new SmartUser();
  2010. newParent.setName(parent.getName());
  2011. newParent.setDepartmentId(parent.getDepartmentId());
  2012. newParent.setPhone(parent.getPhone());
  2013. newParent.setIdentityId(parent.getIdentityId());
  2014. newParent.setSexId(parent.getSexId());
  2015. newParent.setIsCancel(parent.getIsCancel());
  2016. newParent.setAffiliate(String.valueOf(student.get().getId()));
  2017. newParent.setShip(parent.getShip());
  2018. newParents.add(newParent);
  2019. }
  2020. }
  2021. }
  2022. boolean insertBatch = smartUserService.saveBatch(newParents);
  2023. if (!insertBatch) {
  2024. return CommonResult.fail("批量新增家长失败!");
  2025. }
  2026. }
  2027. }
  2028. if (updateStudent != null && updateStudent.size() > 0) {
  2029. boolean updateBatch = smartUserService.updateBatchById(updateStudent);
  2030. if (!updateBatch) {
  2031. return CommonResult.fail("系统批量更新出错,导入失败");
  2032. } else {
  2033. //修改需同步到海康平台
  2034. for (SmartUser su : updateStudent) {
  2035. Integer identityId = su.getIdentityId();
  2036. if (2 == identityId || identityId == 3) {
  2037. Integer id = su.getId();
  2038. SmartOperationUser smartOperationUser = new SmartOperationUser();
  2039. smartOperationUser.setOperationId(id);
  2040. smartOperationUser.setOperationMode("2");
  2041. smartOperationUser.setStatus(1);
  2042. smartOperationUser.setType(identityId);
  2043. smartOperationUserService.save(smartOperationUser);
  2044. }
  2045. }
  2046. }
  2047. }
  2048. List<SmartUser> insertStudents = result.stream().filter(e -> e.getId() == null).collect(Collectors.toList());
  2049. if (insertStudents != null && insertStudents.size() > 0) {
  2050. if(headImage == null){
  2051. return CommonResult.fail("更新数据文档中存在新增数据,头像不能为空");
  2052. }
  2053. List<String> uploadImages = Arrays.asList(headImage.split(","));
  2054. for (SmartUser user : insertStudents) {
  2055. Optional<String> image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/" + user.getHeadImage())).findFirst();
  2056. if (image != null && image.isPresent()) {
  2057. user.setHeadImage(image.get());
  2058. } else {
  2059. if (user.getIdentityId().equals(eIdentityStatu.Student.getValue())
  2060. || user.getIdentityId().equals(eIdentityStatu.Teacher.getValue())) {
  2061. return CommonResult.fail(user.getName() + "头像不存在,导入失败");
  2062. }
  2063. }
  2064. }
  2065. //region 将数据加入第三方
  2066. List<SmartUser> studentDatas = insertStudents.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
  2067. List<String> newCardNos = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  2068. if (newCardNos == null) {
  2069. return CommonResult.fail("文档内容为空,批量更新失败");
  2070. }
  2071. if (studentDatas != null && studentDatas.size() > 0) {
  2072. //判断是否存在重复数据
  2073. List<String> cardNoDatas = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  2074. if (cardNoDatas == null) {
  2075. return CommonResult.fail("文档内容为空,导入失败");
  2076. }
  2077. if (cardNoDatas.size() <= 0) {
  2078. return CommonResult.fail("文档内容为空,导入失败");
  2079. }
  2080. List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNoDatas);
  2081. if (existUsers != null && existUsers.size() > 0) {
  2082. String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  2083. return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
  2084. }
  2085. //获取班级Uid
  2086. List<SmartClass> classDatas = smartClassService.getSmartClasss();
  2087. if (classDatas == null) {
  2088. return CommonResult.fail("班级数据无效,新增失败");
  2089. }
  2090. List<SmartGrade> gradeDatas = smartGradeService.getSmartGrades();
  2091. if (gradeDatas == null) {
  2092. return CommonResult.fail("年级数据无效,新增失败");
  2093. }
  2094. HashMap<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> seewoDatas = new HashMap<>();
  2095. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  2096. for (SmartUser student : studentDatas) {
  2097. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  2098. photo.setPhotoUrl(student.getHeadImage());
  2099. photo.setUserCode(student.getCardNo());
  2100. photoList.add(photo);
  2101. //region 学生参数必填判断:年级、班级
  2102. if (student.getGrade() == null) {
  2103. return CommonResult.fail("学生年级不能为空");
  2104. }
  2105. if (student.getSchoolClass() == null) {
  2106. return CommonResult.fail("学生班级不能为空");
  2107. }
  2108. //endregion
  2109. Optional<SmartClass> oClassData = classDatas.stream().filter(e -> e.getId().equals(student.getSchoolClass())).findFirst();
  2110. if (oClassData == null) {
  2111. return CommonResult.fail("班级数据无效,新增失败");
  2112. }
  2113. Optional<SmartGrade> oGradeData = gradeDatas.stream().filter(e -> e.getId().intValue() == Integer.valueOf(student.getGrade())).findFirst();
  2114. if (oGradeData == null) {
  2115. return CommonResult.fail("年级数据无效,新增失败");
  2116. }
  2117. SmartClass classData = oClassData.get();
  2118. SmartGrade gradeData = oGradeData.get();
  2119. //region 凑希沃参数
  2120. if (useXw == 1) {
  2121. if (!seewoDatas.containsKey(classData.getClassUid())) {
  2122. seewoDatas.put(classData.getClassUid(), new ArrayList<>());
  2123. }
  2124. StudentServiceBatchSaveClassStudentsParam.StudentInfo studentSeewo = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  2125. .studentName(student.getName())
  2126. .studentCode(student.getCardNo())
  2127. .gender(student.getSexId())
  2128. .phone(student.getPhone() == null ? "" : student.getPhone())
  2129. .build();
  2130. seewoDatas.get(classData.getClassUid()).add(studentSeewo);
  2131. }
  2132. //endregion
  2133. //region 百胜新增学生信息
  2134. if (useBs == 1) {
  2135. /**
  2136. * 学生数据的有效期是到毕业年份的8月31日
  2137. */
  2138. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  2139. String endTime = queryGraduationYear(gradeData.getGradeNo());
  2140. CommonResult<String> insertBsStudent = bsInsertStudent(student.getName(), student.getCardNo(), student.getSexId(), student.getHeadImage(), student.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, student.getIdCard());
  2141. if (!insertBsStudent.isSuccess()) {
  2142. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  2143. }
  2144. student.setBsStudentNo(insertBsStudent.getData());
  2145. }
  2146. //endregion
  2147. }
  2148. if (useXw == 1) {
  2149. //初始化客户端
  2150. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2151. List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultDatas = new ArrayList<>();
  2152. for (Map.Entry<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> entry : seewoDatas.entrySet()) {
  2153. String classUid = entry.getKey();
  2154. CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> insertStudentsws = SeewoInsertBatchStudent(seewoClient, entry.getValue(), classUid);
  2155. if (!insertStudentsws.isSuccess()) {
  2156. return CommonResult.fail("希沃平台:" + insertStudentsws.getMessage());
  2157. }
  2158. seewoResultDatas.addAll(insertStudentsws.getData());
  2159. }
  2160. for (SmartUser student : studentDatas) {
  2161. Optional<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultData = seewoResultDatas.stream().filter(e -> e.getStudentCode().equals(student.getCardNo())).findFirst();
  2162. if (seewoResultData != null && seewoResultData.isPresent()) {
  2163. student.setXwStudentUid(seewoResultData.get().getUserUid());
  2164. }
  2165. }
  2166. }
  2167. if (studentDatas != null && studentDatas.size() > 0) {
  2168. //批量存储学生信息
  2169. boolean resultBool = smartUserService.saveBatch(studentDatas);
  2170. if (!resultBool) {
  2171. return CommonResult.fail("导入失败");
  2172. } else {
  2173. // 需添加到海康平台
  2174. ArrayList<SmartOperationUser> operationUsers = new ArrayList<>();
  2175. for (SmartUser studentData1 : studentDatas) {
  2176. Integer id = studentData1.getId();
  2177. SmartOperationUser smartOperationUser = new SmartOperationUser();
  2178. smartOperationUser.setOperationId(id);
  2179. smartOperationUser.setOperationMode("1");
  2180. smartOperationUser.setStatus(1);
  2181. smartOperationUser.setType(studentData1.getIdentityId());
  2182. operationUsers.add(smartOperationUser);
  2183. }
  2184. smartOperationUserService.saveBatch(operationUsers);
  2185. }
  2186. List<SmartFamilyIndex> familyIndexs = new ArrayList<>();
  2187. //region 希沃新增编辑学生家长信息
  2188. if (useXw == 1) {
  2189. int num = (int) Math.ceil((double) studentDatas.size() / 100);
  2190. for (int count = 1; count <= num; count++) {
  2191. int startIndex = (count - 1) * 100;
  2192. int endIndex = count * 100;
  2193. if (count == num) {
  2194. endIndex = startIndex + (studentDatas.size() % 100);
  2195. }
  2196. List<SmartUser> currentStudentDatas = studentDatas.subList(startIndex, endIndex);//结尾不包含下标100
  2197. //学生与家长列表,最大100条
  2198. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  2199. for (SmartUser student : currentStudentDatas) {
  2200. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  2201. .studentCode(student.getCardNo())
  2202. .build();
  2203. List<SmartUser> parentDatas = insertStudents.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList());
  2204. List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
  2205. int i = 0;
  2206. for (SmartUser parent : parentDatas) {
  2207. SmartFamilyIndex familyIndex = new SmartFamilyIndex();
  2208. familyIndex.setParentPhone(parent.getPhone());
  2209. familyIndex.setStudentNo(student.getCardNo());
  2210. familyIndex.setIndexData(i);
  2211. familyIndexs.add(familyIndex);
  2212. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  2213. .name(parent.getShip())
  2214. .phone(parent.getPhone())
  2215. .index(i)
  2216. .build();
  2217. parents.add(data);
  2218. ++i;
  2219. }
  2220. if (parents != null && parents.size() > 0) {
  2221. studentParents.add(students);
  2222. //家长列表,最多4个
  2223. students.setParents(parents);
  2224. }
  2225. }
  2226. //初始化客户端
  2227. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2228. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  2229. //响应体,MimeType为 application/json
  2230. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  2231. .build();
  2232. param.setRequestBody(requestBody);
  2233. //query
  2234. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  2235. .appId(seewoConfig.getAppId())
  2236. .schoolUid(seewoConfig.getSchoolId())
  2237. .build();
  2238. requestBody.setQuery(query);
  2239. query.setStudentParents(studentParents);
  2240. param.setRequestBody(requestBody);
  2241. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  2242. String jsonString = JSON.toJSONString(request);
  2243. logger.info("入参:" + request);
  2244. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2245. //request.setServerUrl("https://openapi.test.seewo.com")
  2246. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2247. ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request);
  2248. logger.info("出参:" + parentResult);
  2249. if (parentResult == null) {
  2250. return CommonResult.fail("希沃学生家长数据添加失败!");
  2251. }
  2252. if (!parentResult.getResponseBody().getCode().equals("000000")) {
  2253. return CommonResult.fail("希沃平台:" + parentResult.getResponseBody().getMessage());
  2254. }
  2255. }
  2256. }
  2257. //endregion
  2258. if (familyIndexs != null && familyIndexs.size() > 0) {
  2259. boolean insertBatch = smartFamilyIndexService.saveBatch(familyIndexs);
  2260. if (!insertBatch) {
  2261. return CommonResult.fail("导入失败!");
  2262. }
  2263. }
  2264. }
  2265. //endregion
  2266. List<SmartUser> parents = insertStudents.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
  2267. //双胞胎家长
  2268. List<SmartUser> newParents = new ArrayList<>();
  2269. if (newCardNos != null && newCardNos.size() > 0) {
  2270. List<SmartUser> students = smartUserService.querySmartUserByCardNos(newCardNos);
  2271. for (SmartUser parent : parents) {
  2272. Optional<SmartUser> student = students.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
  2273. if (student != null && student.isPresent()) {
  2274. //先查找是否存在
  2275. Optional<SmartUser> newData = newParents.stream().filter(e -> e.getName().equals(parent.getName()) && e.getPhone().equals(parent.getPhone()) && e.getShip().equals(parent.getShip())).findFirst();
  2276. if (newData != null && newData.isPresent()) {
  2277. String affiliate = newData.get().getAffiliate() + "," + student.get().getId();
  2278. newData.get().setAffiliate(affiliate);
  2279. } else {
  2280. SmartUser newParent = new SmartUser();
  2281. newParent.setName(parent.getName());
  2282. newParent.setDepartmentId(parent.getDepartmentId());
  2283. newParent.setPhone(parent.getPhone());
  2284. newParent.setIdentityId(parent.getIdentityId());
  2285. newParent.setSexId(parent.getSexId());
  2286. newParent.setIsCancel(parent.getIsCancel());
  2287. newParent.setAffiliate(String.valueOf(student.get().getId()));
  2288. newParent.setShip(parent.getShip());
  2289. newParents.add(newParent);
  2290. }
  2291. }
  2292. }
  2293. if (newParents != null && newParents.size() > 0) {
  2294. //批量存储家长信息
  2295. boolean resultBool = smartUserService.saveBatch(newParents);
  2296. if (!resultBool) {
  2297. return CommonResult.fail("导入失败!");
  2298. }
  2299. }
  2300. //region 最后上传学生图片 这样能保证图片上传失败也不影响数据导入
  2301. if (useXw == 1) {
  2302. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2303. int num = (int) Math.ceil((double) photoList.size() / 1000);
  2304. for (int count = 1; count <= num; count++) {
  2305. int startIndex = (count - 1) * 1000;
  2306. int endIndex = count * 1000;
  2307. if (count == num) {
  2308. endIndex = startIndex + (photoList.size() % 1000);
  2309. }
  2310. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  2311. CommonResult photoResult = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, eSeewoUserType.Student.getValue());
  2312. if (!photoResult.isSuccess()) {
  2313. return photoResult;
  2314. }
  2315. }
  2316. }
  2317. //endregion
  2318. }
  2319. }
  2320. }
  2321. return CommonResult.ok("导入成功");
  2322. }
  2323. //endregion
  2324. //region Xls文件读取方法
  2325. /**
  2326. * Xls文件读取方法
  2327. *
  2328. * @param inputStream 文件流
  2329. * @return
  2330. * @throws IOException
  2331. */
  2332. private CommonResult<List<SmartUser>> readUpdateXls(InputStream inputStream) throws IOException {
  2333. List<String> idCards = new ArrayList<>();
  2334. List<String> cardNos = new ArrayList<>();
  2335. List<SmartUser> result = new ArrayList<>();
  2336. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  2337. List<SmartGrade> grades = smartGradeService.list(null);//年级
  2338. List<SmartClass> classs = smartClassService.list(null);//班级
  2339. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  2340. List<SmartDepartment> departments = smartDepartmentService.list(null);
  2341. List<Integer> ids = new ArrayList<>();
  2342. for (int i = Year.now().getValue() - 2; i <= Year.now().getValue(); i++) {
  2343. String strName = (i + "级");
  2344. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(strName)).findFirst();
  2345. if (oGrade != null && oGrade.isPresent()) {
  2346. ids.add(oGrade.get().getId());
  2347. }
  2348. }
  2349. //读取第一张sheet
  2350. HSSFSheet sheetAt = sheets.getSheetAt(0);
  2351. DataFormatter dataFormatter = new DataFormatter();
  2352. List<SmartUser> users = smartUserService.queryStudentDatas(eIdentityStatu.Student.getValue(), ids);
  2353. List<SmartUser> parents = smartUserService.getSmartUserByIdentity(eIdentityStatu.Parent.getValue());
  2354. try {
  2355. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  2356. HSSFRow row = sheetAt.getRow(rowNum);
  2357. if (row != null) {
  2358. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  2359. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  2360. //然后poi会根据字符串读取它
  2361. //标题 校验
  2362. if (rowNum == 0) {
  2363. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  2364. if (!schoolGrade.equals("年级")) {
  2365. return CommonResult.fail("导入数据第一列为年级");
  2366. }
  2367. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  2368. if (!schoolClass.equals("班级")) {
  2369. return CommonResult.fail("导入数据第二列为班级");
  2370. }
  2371. String departmentNo = dataFormatter.formatCellValue(row.getCell(2));//部门
  2372. if (!departmentNo.equals("部门")) {
  2373. return CommonResult.fail("导入数据第三列为部门");
  2374. }
  2375. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  2376. if (!cardNo.equals("学号")) {
  2377. return CommonResult.fail("导入数据第四列为学号");
  2378. }
  2379. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  2380. if (!name.equals("姓名")) {
  2381. return CommonResult.fail("导入数据第五列为姓名");
  2382. }
  2383. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  2384. if (!sex.equals("性别")) {
  2385. return CommonResult.fail("导入数据第六列为性别");
  2386. }
  2387. String nation = dataFormatter.formatCellValue(row.getCell(6));//民族
  2388. if (!nation.equals("民族")) {
  2389. return CommonResult.fail("导入数据第七列为民族");
  2390. }
  2391. String cardId = dataFormatter.formatCellValue(row.getCell(7));//身份证
  2392. if (!cardId.equals("身份证")) {
  2393. return CommonResult.fail("导入数据第八列为身份证");
  2394. }
  2395. String headImage = dataFormatter.formatCellValue(row.getCell(8));//照片
  2396. if (!headImage.equals("照片")) {
  2397. return CommonResult.fail("导入数据第九列为照片");
  2398. }
  2399. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));//常规时间组
  2400. if (!timeGroup.equals("常规时间组")) {
  2401. return CommonResult.fail("导入数据第十列为常规时间组");
  2402. }
  2403. String address = dataFormatter.formatCellValue(row.getCell(10));//住址
  2404. if (!address.equals("住址")) {
  2405. return CommonResult.fail("导入数据第十一列为住址");
  2406. }
  2407. String phone = dataFormatter.formatCellValue(row.getCell(11));//联系电话
  2408. if (!phone.equals("联系电话")) {
  2409. return CommonResult.fail("导入数据第十二列为联系电话");
  2410. }
  2411. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  2412. if (!family.equals("家属")) {
  2413. return CommonResult.fail("导入数据第十三列为家属");
  2414. }
  2415. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  2416. if (!familyShip.equals("家属与本人关系")) {
  2417. return CommonResult.fail("导入数据第十四列为家属与本人关系");
  2418. }
  2419. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  2420. if (!phoneTwo.equals("联系电话2")) {
  2421. return CommonResult.fail("导入数据第十五列为联系电话2");
  2422. }
  2423. String familyTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  2424. if (!familyTwo.equals("家属2")) {
  2425. return CommonResult.fail("导入数据第十六列为家属2");
  2426. }
  2427. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  2428. if (!familyShipTwo.equals("家属与本人关系2")) {
  2429. return CommonResult.fail("导入数据第十七列为家属与本人关系2");
  2430. }
  2431. } else {
  2432. SmartUser user = new SmartUser();
  2433. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  2434. if (ObjectUtils.isEmpty(cardNo)) {
  2435. return CommonResult.fail("第" + (rowNum) + "条数据的学号不能为空");
  2436. }
  2437. Optional<SmartUser> oUser = users.stream().filter(e -> e.getCardNo().equals(cardNo)).findFirst();
  2438. if (oUser != null && oUser.isPresent()) {
  2439. user = oUser.get();
  2440. Optional<SmartClass> oldClass = classs.stream().filter(e -> e.getId().equals(oUser.get().getSchoolClass())).findFirst();
  2441. if (oldClass != null && oldClass.isPresent()) {
  2442. user.setOldClassUid(oldClass.get().getClassUid());
  2443. }
  2444. //学号重复判断
  2445. if (!ObjectUtils.isEmpty(cardNo)) {
  2446. cardNos.add(cardNo);
  2447. }
  2448. if (cardNos.stream().distinct().count() != cardNos.size()) {
  2449. return CommonResult.fail("导入的Excel中," + user.getName() + "的学号:" + cardNo + "存在重复数据");
  2450. }
  2451. //身份证重复判断
  2452. String idCard = dataFormatter.formatCellValue(row.getCell(7));
  2453. if (!ObjectUtils.isEmpty(idCard)) {
  2454. idCards.add(idCard);
  2455. }
  2456. if (idCards.stream().distinct().count() != idCards.size()) {
  2457. return CommonResult.fail("导入的Excel中," + user.getName() + "的身份证号:" + idCard + "存在重复数据");
  2458. }
  2459. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  2460. if (ObjectUtils.isEmpty(name)) {
  2461. return CommonResult.fail("第" + (rowNum) + "条数据的姓名不能为空");
  2462. }
  2463. String department = dataFormatter.formatCellValue(row.getCell(2));//部门
  2464. if (ObjectUtils.isEmpty(department)) {
  2465. return CommonResult.fail(name + "的部门不能为空");
  2466. }
  2467. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  2468. if (ObjectUtils.isEmpty(schoolClass)) {
  2469. return CommonResult.fail(name + "的班级不能为空");
  2470. }
  2471. String group = dataFormatter.formatCellValue(row.getCell(9));//时间组
  2472. if (ObjectUtils.isEmpty(group)) {
  2473. return CommonResult.fail(name + "的时间组不能为空");
  2474. }
  2475. Integer parentDid = null;
  2476. Integer departmentId = null;
  2477. String[] departmentStrs = department.split("/");
  2478. for (int i = 0; i < departmentStrs.length; i++) {
  2479. String departmentName = departmentStrs[i];
  2480. Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  2481. if (oD != null && oD.isPresent()) {
  2482. parentDid = oD.get().getId();
  2483. } else {
  2484. String bsDepartment = insertDepartmentToBs(departmentName);
  2485. if (bsDepartment == null) {
  2486. return CommonResult.fail(name + "的部门添加到百胜失败");
  2487. }
  2488. SmartDepartment sdParent = new SmartDepartment();
  2489. sdParent.setParentId(parentDid);
  2490. sdParent.setName(departmentName);
  2491. sdParent.setBsDepartmentNo(bsDepartment);
  2492. int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
  2493. departmentId = departmentData;
  2494. parentDid = departmentData;
  2495. }
  2496. }
  2497. //性别是否为空判断
  2498. String sex = dataFormatter.formatCellValue(row.getCell(5));
  2499. if (ObjectUtils.isEmpty(sex)) {
  2500. return CommonResult.fail(name + "的性别不能为空");
  2501. }
  2502. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  2503. user.setDepartmentId(departmentId == null ? parentDid : departmentId);
  2504. user.setCardNo(cardNo == null ? "" : cardNo);
  2505. user.setName(name == null ? "" : name);
  2506. user.setIdentityId(eIdentityStatu.Student.getValue());
  2507. String cardId = dataFormatter.formatCellValue(row.getCell(7));//身份证
  2508. user.setIdCard(cardId == null ? user.getIdCard() : cardId);
  2509. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  2510. if (oClass != null && oClass.isPresent()) {
  2511. user.setSchoolClass(oClass.get().getId());
  2512. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  2513. } else {
  2514. return CommonResult.fail(name + "的班级数据无效,导入失败");
  2515. }
  2516. Optional<SmartTimeGroup> oGroup = timeGroups.stream().filter(e -> e.getName().equals(group)).findFirst();
  2517. if (oGroup != null && oGroup.isPresent()) {
  2518. user.setTimeGroupId(oGroup.get().getId());
  2519. }
  2520. result.add(user);
  2521. //不判断重复性 因为会出现双胞胎
  2522. String phone = dataFormatter.formatCellValue(row.getCell(11));
  2523. //部门是否为空判断
  2524. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  2525. Integer familyDepartmentId = null;
  2526. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  2527. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  2528. familyDepartmentId = familyDepartModel.get().getId();
  2529. } else {
  2530. familyDepartmentId = 16;
  2531. }
  2532. //region 家属
  2533. if (!ObjectUtils.isEmpty(phone)) {
  2534. if (phone.length() != 11) {
  2535. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  2536. }
  2537. SmartUser familyOne = new SmartUser();
  2538. Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phone)).findFirst();
  2539. if(oneParent != null && oneParent.isPresent()){
  2540. familyOne = oneParent.get();
  2541. }else{
  2542. familyOne.setAffiliate(user.getCardNo());
  2543. }
  2544. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  2545. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  2546. familyOne.setDepartmentId(familyDepartmentId);
  2547. familyOne.setPhone(phone);
  2548. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  2549. familyOne.setSexId(eSexStatu.Man.getValue());
  2550. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  2551. familyOne.setAffiliate(user.getCardNo());
  2552. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  2553. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  2554. result.add(familyOne);
  2555. }
  2556. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  2557. if (!ObjectUtils.isEmpty(phoneTwo)) {
  2558. if (phoneTwo.length() != 11) {
  2559. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  2560. }
  2561. SmartUser familyTwo = new SmartUser();
  2562. Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phoneTwo)).findFirst();
  2563. if(oneParent != null && oneParent.isPresent()){
  2564. familyTwo = oneParent.get();
  2565. }else{
  2566. familyTwo.setAffiliate(user.getCardNo());
  2567. }
  2568. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  2569. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  2570. familyTwo.setDepartmentId(familyDepartmentId);
  2571. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  2572. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  2573. familyTwo.setSexId(eSexStatu.Man.getValue());
  2574. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  2575. familyTwo.setAffiliate(user.getCardNo());
  2576. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  2577. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  2578. result.add(familyTwo);
  2579. }
  2580. //endregion
  2581. } else {
  2582. String name = dataFormatter.formatCellValue(row.getCell(4));
  2583. // if (ObjectUtils.isEmpty(name)) {
  2584. // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
  2585. // }
  2586. if (ObjectUtils.isEmpty(name)) {
  2587. continue;
  2588. }
  2589. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  2590. if (ObjectUtils.isEmpty(schoolGrade)) {
  2591. return CommonResult.fail(name + "的年级不能为空");
  2592. }
  2593. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  2594. if (ObjectUtils.isEmpty(schoolClass)) {
  2595. return CommonResult.fail(name + "的班级不能为空");
  2596. }
  2597. //不判断重复性 因为会出现双胞胎
  2598. String phone = dataFormatter.formatCellValue(row.getCell(11));
  2599. // if (!ObjectUtils.isEmpty(phone)) {
  2600. // phones.add(phone);
  2601. // }
  2602. // if (phones.stream().distinct().count() != phones.size()) {
  2603. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  2604. // }
  2605. //性别是否为空判断
  2606. String sex = dataFormatter.formatCellValue(row.getCell(5));
  2607. if (ObjectUtils.isEmpty(sex)) {
  2608. return CommonResult.fail(name + "的性别不能为空");
  2609. }
  2610. //家庭住址是否为空判断
  2611. String address = dataFormatter.formatCellValue(row.getCell(10));
  2612. //民族是否为空判断
  2613. String nation = dataFormatter.formatCellValue(row.getCell(6));
  2614. if (ObjectUtils.isEmpty(nation)) {
  2615. return CommonResult.fail(name + "的民族不能为空");
  2616. }
  2617. //部门是否为空判断
  2618. String department = dataFormatter.formatCellValue(row.getCell(2));
  2619. if (ObjectUtils.isEmpty(nation)) {
  2620. return CommonResult.fail(name + "的部门不能为空");
  2621. }
  2622. Integer parentDid = null;
  2623. Integer departmentId = null;
  2624. String[] departmentStrs = department.split("/");
  2625. for (int i = 0; i < departmentStrs.length; i++) {
  2626. String departmentName = departmentStrs[i];
  2627. Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  2628. if (oD != null && oD.isPresent()) {
  2629. parentDid = oD.get().getId();
  2630. } else {
  2631. String bsDepartment = insertDepartmentToBs(departmentName);
  2632. if (bsDepartment == null) {
  2633. return CommonResult.fail(name + "的部门添加到百胜失败");
  2634. }
  2635. SmartDepartment sdParent = new SmartDepartment();
  2636. sdParent.setParentId(parentDid);
  2637. sdParent.setName(departmentName);
  2638. sdParent.setBsDepartmentNo(bsDepartment);
  2639. int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
  2640. departmentId = departmentData;
  2641. parentDid = departmentData;
  2642. }
  2643. }
  2644. //学号重复判断
  2645. if (!ObjectUtils.isEmpty(cardNo)) {
  2646. cardNos.add(cardNo);
  2647. }
  2648. if (cardNos.stream().distinct().count() != cardNos.size()) {
  2649. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  2650. }
  2651. //身份证重复判断
  2652. String idCard = dataFormatter.formatCellValue(row.getCell(7));
  2653. if (!ObjectUtils.isEmpty(idCard)) {
  2654. idCards.add(idCard);
  2655. }
  2656. if (idCards.stream().distinct().count() != idCards.size()) {
  2657. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  2658. }
  2659. user.setCardNo(cardNo == null ? "" : cardNo);
  2660. user.setName(name == null ? "" : name);
  2661. user.setIdentityId(eIdentityStatu.Student.getValue());
  2662. user.setIdCard(idCard == null ? "" : idCard);
  2663. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  2664. user.setDepartmentId(departmentId == null ? parentDid : departmentId);
  2665. String cellImage = dataFormatter.formatCellValue(row.getCell(8));
  2666. user.setHeadImage(cellImage);
  2667. user.setDormitoryNumber("");
  2668. String grade = schoolGrade == null ? "" : schoolGrade;
  2669. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  2670. if (oGrade != null && oGrade.isPresent()) {
  2671. Integer gradeId = oGrade.get().getId();
  2672. user.setGrade(String.valueOf(gradeId));
  2673. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  2674. if (oClass != null && oClass.isPresent()) {
  2675. user.setSchoolClass(oClass.get().getId());
  2676. } else {
  2677. return CommonResult.fail(name + "的班级数据无效,导入失败");
  2678. }
  2679. } else {
  2680. return CommonResult.fail(name + "的年级数据无效,导入失败");
  2681. }
  2682. user.setCollege("");
  2683. user.setSpeciality("");
  2684. user.setCampus("");
  2685. user.setPhone("");
  2686. user.setAffiliate("");
  2687. user.setTitle("");
  2688. user.setAddress(address == null ? "" : address);
  2689. user.setNation(nation == null ? "" : nation);
  2690. user.setOfStudent("");
  2691. user.setGraduate("");
  2692. user.setDuties(null);
  2693. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));
  2694. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  2695. if (groupData != null && groupData.isPresent()) {
  2696. user.setTimeGroupId(groupData.get().getId());
  2697. } else {
  2698. user.setTimeGroupId(0);
  2699. }
  2700. user.setIsCancel(eLogOff.Unlogout.getValue());
  2701. result.add(user);
  2702. //部门是否为空判断
  2703. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  2704. Integer familyDepartmentId = null;
  2705. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  2706. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  2707. familyDepartmentId = familyDepartModel.get().getId();
  2708. } else {
  2709. familyDepartmentId = 16;
  2710. }
  2711. //region 家属
  2712. if (!ObjectUtils.isEmpty(phone)) {
  2713. if (phone.length() != 11) {
  2714. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  2715. }
  2716. SmartUser familyOne = new SmartUser();
  2717. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  2718. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  2719. familyOne.setDepartmentId(familyDepartmentId);
  2720. familyOne.setPhone(phone);
  2721. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  2722. familyOne.setSexId(eSexStatu.Man.getValue());
  2723. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  2724. familyOne.setAffiliate(user.getCardNo());
  2725. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  2726. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  2727. result.add(familyOne);
  2728. }
  2729. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  2730. if (!ObjectUtils.isEmpty(phoneTwo)) {
  2731. if (phoneTwo.length() != 11) {
  2732. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  2733. }
  2734. SmartUser familyTwo = new SmartUser();
  2735. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  2736. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  2737. familyTwo.setDepartmentId(familyDepartmentId);
  2738. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  2739. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  2740. familyTwo.setSexId(eSexStatu.Man.getValue());
  2741. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  2742. familyTwo.setAffiliate(user.getCardNo());
  2743. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  2744. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  2745. result.add(familyTwo);
  2746. }
  2747. //endregion
  2748. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  2749. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(14)))) {
  2750. if (phone.equals(dataFormatter.formatCellValue(row.getCell(14)))) {
  2751. return CommonResult.fail(name + "的学生家长手机号不可重复");
  2752. }
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. } catch (Exception e) {
  2759. return CommonResult.fail("请按模板格式导入数据");
  2760. }
  2761. return CommonResult.ok(result);
  2762. }
  2763. //endregion
  2764. //region Xlsx文件读取方法
  2765. /**
  2766. * Xlsx文件读取方法
  2767. *
  2768. * @param inputStream 文件流
  2769. * @return
  2770. * @throws IOException
  2771. */
  2772. private CommonResult<List<SmartUser>> readUpdateXlsx(InputStream inputStream) throws IOException {
  2773. List<String> idCards = new ArrayList<>();
  2774. List<String> cardNos = new ArrayList<>();
  2775. List<SmartUser> result = new ArrayList<>();
  2776. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  2777. List<SmartGrade> grades = smartGradeService.list(null);//年级
  2778. List<SmartClass> classs = smartClassService.list(null);//班级
  2779. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  2780. List<SmartDepartment> departments = smartDepartmentService.list(null);
  2781. List<Integer> ids = new ArrayList<>();
  2782. for (int i = Year.now().getValue() - 2; i <= Year.now().getValue(); i++) {
  2783. String strName = (i + "级");
  2784. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(strName)).findFirst();
  2785. if (oGrade != null && oGrade.isPresent()) {
  2786. ids.add(oGrade.get().getId());
  2787. }
  2788. }
  2789. //读取第一张sheet
  2790. XSSFSheet sheetAt = sheets.getSheetAt(0);
  2791. DataFormatter dataFormatter = new DataFormatter();
  2792. List<SmartUser> users = smartUserService.queryStudentDatas(eIdentityStatu.Student.getValue(), ids);
  2793. List<SmartUser> parents = smartUserService.getSmartUserByIdentity(eIdentityStatu.Parent.getValue());
  2794. try {
  2795. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  2796. XSSFRow row = sheetAt.getRow(rowNum);
  2797. if (row != null) {
  2798. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  2799. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  2800. //然后poi会根据字符串读取它
  2801. //标题 校验
  2802. if (rowNum == 0) {
  2803. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  2804. if (!schoolGrade.equals("年级")) {
  2805. return CommonResult.fail("导入数据第一列为年级");
  2806. }
  2807. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  2808. if (!schoolClass.equals("班级")) {
  2809. return CommonResult.fail("导入数据第二列为班级");
  2810. }
  2811. String departmentNo = dataFormatter.formatCellValue(row.getCell(2));//部门
  2812. if (!departmentNo.equals("部门")) {
  2813. return CommonResult.fail("导入数据第三列为部门");
  2814. }
  2815. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  2816. if (!cardNo.equals("学号")) {
  2817. return CommonResult.fail("导入数据第四列为学号");
  2818. }
  2819. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  2820. if (!name.equals("姓名")) {
  2821. return CommonResult.fail("导入数据第五列为姓名");
  2822. }
  2823. String sex = dataFormatter.formatCellValue(row.getCell(5));//性别
  2824. if (!sex.equals("性别")) {
  2825. return CommonResult.fail("导入数据第六列为性别");
  2826. }
  2827. String nation = dataFormatter.formatCellValue(row.getCell(6));//民族
  2828. if (!nation.equals("民族")) {
  2829. return CommonResult.fail("导入数据第七列为民族");
  2830. }
  2831. String cardId = dataFormatter.formatCellValue(row.getCell(7));//身份证
  2832. if (!cardId.equals("身份证")) {
  2833. return CommonResult.fail("导入数据第八列为身份证");
  2834. }
  2835. String headImage = dataFormatter.formatCellValue(row.getCell(8));//照片
  2836. if (!headImage.equals("照片")) {
  2837. return CommonResult.fail("导入数据第九列为照片");
  2838. }
  2839. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));//常规时间组
  2840. if (!timeGroup.equals("常规时间组")) {
  2841. return CommonResult.fail("导入数据第十列为常规时间组");
  2842. }
  2843. String address = dataFormatter.formatCellValue(row.getCell(10));//住址
  2844. if (!address.equals("住址")) {
  2845. return CommonResult.fail("导入数据第十一列为住址");
  2846. }
  2847. String phone = dataFormatter.formatCellValue(row.getCell(11));//联系电话
  2848. if (!phone.equals("联系电话")) {
  2849. return CommonResult.fail("导入数据第十二列为联系电话");
  2850. }
  2851. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  2852. if (!family.equals("家属")) {
  2853. return CommonResult.fail("导入数据第十三列为家属");
  2854. }
  2855. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  2856. if (!familyShip.equals("家属与本人关系")) {
  2857. return CommonResult.fail("导入数据第十四列为家属与本人关系");
  2858. }
  2859. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  2860. if (!phoneTwo.equals("联系电话2")) {
  2861. return CommonResult.fail("导入数据第十五列为联系电话2");
  2862. }
  2863. String familyTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  2864. if (!familyTwo.equals("家属2")) {
  2865. return CommonResult.fail("导入数据第十六列为家属2");
  2866. }
  2867. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  2868. if (!familyShipTwo.equals("家属与本人关系2")) {
  2869. return CommonResult.fail("导入数据第十七列为家属与本人关系2");
  2870. }
  2871. } else {
  2872. SmartUser user = new SmartUser();
  2873. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  2874. if (ObjectUtils.isEmpty(cardNo)) {
  2875. return CommonResult.fail("第" + (rowNum) + "条数据的学号不能为空");
  2876. }
  2877. Optional<SmartUser> oUser = users.stream().filter(e -> e.getCardNo().equals(cardNo)).findFirst();
  2878. if (oUser != null && oUser.isPresent()) {
  2879. user = oUser.get();
  2880. Optional<SmartClass> oldClass = classs.stream().filter(e -> e.getId().equals(oUser.get().getSchoolClass())).findFirst();
  2881. if (oldClass != null && oldClass.isPresent()) {
  2882. user.setOldClassUid(oldClass.get().getClassUid());
  2883. }
  2884. //学号重复判断
  2885. if (!ObjectUtils.isEmpty(cardNo)) {
  2886. cardNos.add(cardNo);
  2887. }
  2888. if (cardNos.stream().distinct().count() != cardNos.size()) {
  2889. return CommonResult.fail("导入的Excel中," + user.getName() + "的学号:" + cardNo + "存在重复数据");
  2890. }
  2891. //身份证重复判断
  2892. String idCard = dataFormatter.formatCellValue(row.getCell(7));
  2893. if (!ObjectUtils.isEmpty(idCard)) {
  2894. idCards.add(idCard);
  2895. }
  2896. if (idCards.stream().distinct().count() != idCards.size()) {
  2897. return CommonResult.fail("导入的Excel中," + user.getName() + "的身份证号:" + idCard + "存在重复数据");
  2898. }
  2899. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  2900. if (ObjectUtils.isEmpty(name)) {
  2901. return CommonResult.fail("第" + (rowNum) + "条数据的姓名不能为空");
  2902. }
  2903. String department = dataFormatter.formatCellValue(row.getCell(2));//部门
  2904. if (ObjectUtils.isEmpty(department)) {
  2905. return CommonResult.fail(name + "的部门不能为空");
  2906. }
  2907. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  2908. if (ObjectUtils.isEmpty(schoolClass)) {
  2909. return CommonResult.fail(name + "的班级不能为空");
  2910. }
  2911. String group = dataFormatter.formatCellValue(row.getCell(9));//时间组
  2912. if (ObjectUtils.isEmpty(group)) {
  2913. return CommonResult.fail(name + "的时间组不能为空");
  2914. }
  2915. Integer parentDid = null;
  2916. Integer departmentId = null;
  2917. String[] departmentStrs = department.split("/");
  2918. for (int i = 0; i < departmentStrs.length; i++) {
  2919. String departmentName = departmentStrs[i];
  2920. Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  2921. if (oD != null && oD.isPresent()) {
  2922. parentDid = oD.get().getId();
  2923. } else {
  2924. String bsDepartment = insertDepartmentToBs(departmentName);
  2925. if (bsDepartment == null) {
  2926. return CommonResult.fail(name + "的部门添加到百胜失败");
  2927. }
  2928. SmartDepartment sdParent = new SmartDepartment();
  2929. sdParent.setParentId(parentDid);
  2930. sdParent.setName(departmentName);
  2931. sdParent.setBsDepartmentNo(bsDepartment);
  2932. int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
  2933. departmentId = departmentData;
  2934. parentDid = departmentData;
  2935. }
  2936. }
  2937. //性别是否为空判断
  2938. String sex = dataFormatter.formatCellValue(row.getCell(5));
  2939. if (ObjectUtils.isEmpty(sex)) {
  2940. return CommonResult.fail(name + "的性别不能为空");
  2941. }
  2942. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  2943. user.setDepartmentId(departmentId == null ? parentDid : departmentId);
  2944. user.setCardNo(cardNo == null ? "" : cardNo);
  2945. user.setName(name == null ? "" : name);
  2946. user.setIdentityId(eIdentityStatu.Student.getValue());
  2947. String cardId = dataFormatter.formatCellValue(row.getCell(7));//身份证
  2948. user.setIdCard(cardId == null ? user.getIdCard() : cardId);
  2949. String address = dataFormatter.formatCellValue(row.getCell(10));//住址
  2950. user.setAddress(address == null ? user.getAddress() : address);
  2951. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
  2952. if (oClass != null && oClass.isPresent()) {
  2953. user.setSchoolClass(oClass.get().getId());
  2954. user.setGrade(String.valueOf(oClass.get().getGradeId()));
  2955. } else {
  2956. return CommonResult.fail(name + "的班级数据无效,导入失败");
  2957. }
  2958. Optional<SmartTimeGroup> oGroup = timeGroups.stream().filter(e -> e.getName().equals(group)).findFirst();
  2959. if (oGroup != null && oGroup.isPresent()) {
  2960. user.setTimeGroupId(oGroup.get().getId());
  2961. }
  2962. result.add(user);
  2963. //不判断重复性 因为会出现双胞胎
  2964. String phone = dataFormatter.formatCellValue(row.getCell(11));
  2965. //部门是否为空判断
  2966. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  2967. Integer familyDepartmentId = null;
  2968. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  2969. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  2970. familyDepartmentId = familyDepartModel.get().getId();
  2971. } else {
  2972. familyDepartmentId = 16;
  2973. }
  2974. //region 家属
  2975. if(user.getName().equals("张宇霏")){
  2976. String sdsd ="";
  2977. }
  2978. if (!ObjectUtils.isEmpty(phone)) {
  2979. if (phone.length() != 11) {
  2980. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  2981. }
  2982. SmartUser familyOne = new SmartUser();
  2983. Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phone)).findFirst();
  2984. if(oneParent != null && oneParent.isPresent()){
  2985. familyOne = oneParent.get();
  2986. }else{
  2987. familyOne.setAffiliate(user.getCardNo());
  2988. }
  2989. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  2990. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  2991. familyOne.setDepartmentId(familyDepartmentId);
  2992. familyOne.setPhone(phone);
  2993. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  2994. familyOne.setSexId(eSexStatu.Man.getValue());
  2995. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  2996. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  2997. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  2998. result.add(familyOne);
  2999. }
  3000. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  3001. if (!ObjectUtils.isEmpty(phoneTwo)) {
  3002. if (phoneTwo.length() != 11) {
  3003. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  3004. }
  3005. SmartUser familyTwo = new SmartUser();
  3006. Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phoneTwo)).findFirst();
  3007. if(oneParent != null && oneParent.isPresent()){
  3008. familyTwo = oneParent.get();
  3009. }else{
  3010. familyTwo.setAffiliate(user.getCardNo());
  3011. }
  3012. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  3013. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  3014. familyTwo.setDepartmentId(familyDepartmentId);
  3015. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  3016. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  3017. familyTwo.setSexId(eSexStatu.Man.getValue());
  3018. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  3019. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  3020. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  3021. result.add(familyTwo);
  3022. }
  3023. //endregion
  3024. } else {
  3025. String name = dataFormatter.formatCellValue(row.getCell(4));
  3026. // if (ObjectUtils.isEmpty(name)) {
  3027. // return CommonResult.fail("第" + (rowNum + 1) + "条数据的名称不能为空");
  3028. // }
  3029. if (ObjectUtils.isEmpty(name)) {
  3030. continue;
  3031. }
  3032. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  3033. if (ObjectUtils.isEmpty(schoolGrade)) {
  3034. return CommonResult.fail(name + "的年级不能为空");
  3035. }
  3036. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  3037. if (ObjectUtils.isEmpty(schoolClass)) {
  3038. return CommonResult.fail(name + "的班级不能为空");
  3039. }
  3040. //不判断重复性 因为会出现双胞胎
  3041. String phone = dataFormatter.formatCellValue(row.getCell(11));
  3042. // if (!ObjectUtils.isEmpty(phone)) {
  3043. // phones.add(phone);
  3044. // }
  3045. // if (phones.stream().distinct().count() != phones.size()) {
  3046. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  3047. // }
  3048. //性别是否为空判断
  3049. String sex = dataFormatter.formatCellValue(row.getCell(5));
  3050. if (ObjectUtils.isEmpty(sex)) {
  3051. return CommonResult.fail(name + "的性别不能为空");
  3052. }
  3053. //家庭住址是否为空判断
  3054. String address = dataFormatter.formatCellValue(row.getCell(10));
  3055. //民族是否为空判断
  3056. String nation = dataFormatter.formatCellValue(row.getCell(6));
  3057. if (ObjectUtils.isEmpty(nation)) {
  3058. return CommonResult.fail(name + "的民族不能为空");
  3059. }
  3060. //部门是否为空判断
  3061. String department = dataFormatter.formatCellValue(row.getCell(2));
  3062. if (ObjectUtils.isEmpty(nation)) {
  3063. return CommonResult.fail(name + "的部门不能为空");
  3064. }
  3065. Integer parentDid = null;
  3066. Integer departmentId = null;
  3067. String[] departmentStrs = department.split("/");
  3068. for (int i = 0; i < departmentStrs.length; i++) {
  3069. String departmentName = departmentStrs[i];
  3070. Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  3071. if (oD != null && oD.isPresent()) {
  3072. parentDid = oD.get().getId();
  3073. } else {
  3074. String bsDepartment = insertDepartmentToBs(departmentName);
  3075. if (bsDepartment == null) {
  3076. return CommonResult.fail(name + "的部门添加到百胜失败");
  3077. }
  3078. SmartDepartment sdParent = new SmartDepartment();
  3079. sdParent.setParentId(parentDid);
  3080. sdParent.setName(departmentName);
  3081. sdParent.setBsDepartmentNo(bsDepartment);
  3082. int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
  3083. departmentId = departmentData;
  3084. parentDid = departmentData;
  3085. }
  3086. }
  3087. //学号重复判断
  3088. if (!ObjectUtils.isEmpty(cardNo)) {
  3089. cardNos.add(cardNo);
  3090. }
  3091. if (cardNos.stream().distinct().count() != cardNos.size()) {
  3092. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  3093. }
  3094. //身份证重复判断
  3095. String idCard = dataFormatter.formatCellValue(row.getCell(7));
  3096. if (!ObjectUtils.isEmpty(idCard)) {
  3097. idCards.add(idCard);
  3098. }
  3099. if (idCards.stream().distinct().count() != idCards.size()) {
  3100. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  3101. }
  3102. user.setCardNo(cardNo == null ? "" : cardNo);
  3103. user.setName(name == null ? "" : name);
  3104. user.setIdentityId(eIdentityStatu.Student.getValue());
  3105. user.setIdCard(idCard == null ? "" : idCard);
  3106. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  3107. user.setDepartmentId(departmentId == null ? parentDid : departmentId);
  3108. String cellImage = dataFormatter.formatCellValue(row.getCell(8));
  3109. user.setHeadImage(cellImage);
  3110. user.setDormitoryNumber("");
  3111. String grade = schoolGrade == null ? "" : schoolGrade;
  3112. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  3113. if (oGrade != null && oGrade.isPresent()) {
  3114. Integer gradeId = oGrade.get().getId();
  3115. user.setGrade(String.valueOf(gradeId));
  3116. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  3117. if (oClass != null && oClass.isPresent()) {
  3118. user.setSchoolClass(oClass.get().getId());
  3119. } else {
  3120. return CommonResult.fail(name + "的班级数据无效,导入失败");
  3121. }
  3122. } else {
  3123. return CommonResult.fail(name + "的年级数据无效,导入失败");
  3124. }
  3125. user.setCollege("");
  3126. user.setSpeciality("");
  3127. user.setCampus("");
  3128. user.setPhone("");
  3129. user.setAffiliate("");
  3130. user.setTitle("");
  3131. user.setAddress(address == null ? "" : address);
  3132. user.setNation(nation == null ? "" : nation);
  3133. user.setOfStudent("");
  3134. user.setGraduate("");
  3135. user.setDuties(null);
  3136. String timeGroup = dataFormatter.formatCellValue(row.getCell(9));
  3137. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  3138. if (groupData != null && groupData.isPresent()) {
  3139. user.setTimeGroupId(groupData.get().getId());
  3140. } else {
  3141. user.setTimeGroupId(0);
  3142. }
  3143. user.setIsCancel(eLogOff.Unlogout.getValue());
  3144. result.add(user);
  3145. //部门是否为空判断
  3146. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  3147. Integer familyDepartmentId = null;
  3148. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  3149. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  3150. familyDepartmentId = familyDepartModel.get().getId();
  3151. } else {
  3152. familyDepartmentId = 16;
  3153. }
  3154. //region 家属
  3155. if (!ObjectUtils.isEmpty(phone)) {
  3156. if (phone.length() != 11) {
  3157. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  3158. }
  3159. SmartUser familyOne = new SmartUser();
  3160. String family = dataFormatter.formatCellValue(row.getCell(12));//家属
  3161. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  3162. familyOne.setDepartmentId(familyDepartmentId);
  3163. familyOne.setPhone(phone);
  3164. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  3165. familyOne.setSexId(eSexStatu.Man.getValue());
  3166. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  3167. familyOne.setAffiliate(user.getCardNo());
  3168. String familyShip = dataFormatter.formatCellValue(row.getCell(13));//家属与本人关系
  3169. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  3170. result.add(familyOne);
  3171. }
  3172. String phoneTwo = dataFormatter.formatCellValue(row.getCell(14));//联系电话2
  3173. if (!ObjectUtils.isEmpty(phoneTwo)) {
  3174. if (phoneTwo.length() != 11) {
  3175. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  3176. }
  3177. SmartUser familyTwo = new SmartUser();
  3178. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
  3179. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  3180. familyTwo.setDepartmentId(familyDepartmentId);
  3181. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  3182. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  3183. familyTwo.setSexId(eSexStatu.Man.getValue());
  3184. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  3185. familyTwo.setAffiliate(user.getCardNo());
  3186. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(16));//家属与本人关系2
  3187. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  3188. result.add(familyTwo);
  3189. }
  3190. //endregion
  3191. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  3192. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(14)))) {
  3193. if (phone.equals(dataFormatter.formatCellValue(row.getCell(14)))) {
  3194. return CommonResult.fail(name + "的学生家长手机号不可重复");
  3195. }
  3196. }
  3197. }
  3198. }
  3199. }
  3200. }
  3201. } catch (Exception e) {
  3202. return CommonResult.fail("请按模板格式导入数据");
  3203. }
  3204. return CommonResult.ok(result);
  3205. }
  3206. //endregion
  3207. //endregion
  3208. //region 时间组数据集合
  3209. @Override
  3210. @DESRespondSecret(validated = true)
  3211. public CommonResult timeGroups() throws Exception {
  3212. List<TimeGroupVo> result = new ArrayList<>();
  3213. //region 获取百胜的时间组
  3214. String appId = controlConfig.getAppId();
  3215. String schoolno = controlConfig.getSchoolCode();
  3216. String timestamp = TimeExchange.DateNowTimeStamo();
  3217. String appSecret = controlConfig.getAppSecret();
  3218. String url = controlConfig.getUrl() + "timegroup/searchtimegroup";
  3219. JSONObject jsonobject = new JSONObject();
  3220. jsonobject.put("appid", appId);
  3221. String str = "{\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}";
  3222. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  3223. jsonobject.put("data", aesStr);
  3224. jsonobject.put("schoolno", schoolno);
  3225. jsonobject.put("timestamp", timestamp);
  3226. String md5Str = "appid=" + appId + "&data={\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  3227. String sign = CommonUtil.MD5(md5Str);
  3228. //sign签名
  3229. jsonobject.put("sign", sign);
  3230. //返回的结果中 code为1表示成功
  3231. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  3232. ObjectMapper objectMapper = new ObjectMapper();
  3233. BsTimeGroupVo bsDataResult = objectMapper.readValue(bsResult, BsTimeGroupVo.class);
  3234. if (!bsResult.contains("查询成功")) {
  3235. return CommonResult.fail(bsDataResult.getMsg());
  3236. }
  3237. // URL解码
  3238. String decodedUrl = URLDecoder.decode(bsDataResult.getData(), "UTF-8");
  3239. BsTimeGroupNoVo timeGroupNos = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsTimeGroupNoVo.class);
  3240. //endregion
  3241. List<SmartTimeGroup> groups = smartTimeGroupService.queryTimeGroups();
  3242. List<SmartTimeGroup> newGroups = new ArrayList<>();
  3243. List<SmartTimeGroup> oldGroups = new ArrayList<>();
  3244. if (timeGroupNos.getData() != null) {
  3245. for (BsTimeGroupNoListVo timeGroup : timeGroupNos.getData()) {
  3246. Optional<SmartTimeGroup> oGroup = groups == null ? null : groups.stream().filter(e -> e.getBsno().equals(timeGroup.getTg_no())).findFirst();
  3247. if (oGroup != null && oGroup.isPresent()) {
  3248. SmartTimeGroup oldData = new SmartTimeGroup();
  3249. oldData.setId(oGroup.get().getId());
  3250. oldData.setBsno(timeGroup.getTg_no());
  3251. oldData.setName(timeGroup.getTg_name());
  3252. oldData.setRemark(timeGroup.getTg_remark());
  3253. oldGroups.add(oldData);
  3254. } else {
  3255. SmartTimeGroup newData = new SmartTimeGroup();
  3256. newData.setBsno(timeGroup.getTg_no());
  3257. newData.setName(timeGroup.getTg_name());
  3258. newData.setRemark(timeGroup.getTg_remark());
  3259. newGroups.add(newData);
  3260. }
  3261. }
  3262. }
  3263. if (oldGroups != null && oldGroups.size() > 0) {
  3264. boolean updateGroup = smartTimeGroupService.updateSmartTimeGroups(oldGroups);
  3265. if (!updateGroup) {
  3266. return CommonResult.fail("获取时间组失败");
  3267. }
  3268. }
  3269. if (newGroups != null && newGroups.size() > 0) {
  3270. boolean insertGroup = smartTimeGroupService.insertSmartTimeGroups(newGroups);
  3271. if (!insertGroup) {
  3272. return CommonResult.fail("获取时间组失败");
  3273. }
  3274. }
  3275. //oldData集合不在newDatas集合中的内容
  3276. List<Integer> newDatas = oldGroups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
  3277. List<Integer> oldDatas = groups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
  3278. List<Integer> deleteIds = oldDatas.stream().filter(item -> !newDatas.contains(item)).collect(Collectors.toList());//需要删除的id
  3279. if (deleteIds.size() > 0) {
  3280. int deleted = smartTimeGroupService.deletedTimeGroupByIds(deleteIds);
  3281. if (deleted <= 0) {
  3282. throw new Exception("获取时间组失败!");
  3283. }
  3284. }
  3285. List<SmartTimeGroup> groupDatas = smartTimeGroupService.queryTimeGroups();
  3286. for (SmartTimeGroup groupData : groupDatas) {
  3287. TimeGroupVo data = new TimeGroupVo();
  3288. data.setId(groupData.getId());
  3289. data.setName(groupData.getName());
  3290. data.setRemark(groupData.getRemark());
  3291. result.add(data);
  3292. }
  3293. return CommonResult.ok(result);
  3294. }
  3295. //endregion
  3296. //region 新增用户
  3297. /**
  3298. * 新增用户
  3299. *
  3300. * @param isur 用户数据
  3301. * @param bindingResult
  3302. * @return
  3303. */
  3304. @Override
  3305. @DESRespondSecret(validated = true)
  3306. public CommonResult insertSmartUser(insertSmartUserRequest isur, BindingResult bindingResult) throws Exception {
  3307. if (bindingResult.hasErrors()) {
  3308. String st = paramUtils.getParamError(bindingResult);
  3309. return CommonResult.fail(st);
  3310. }
  3311. int useBs = 1;
  3312. int useXw = 1;
  3313. SmartGrade gradeData = null;
  3314. SmartClass classData = null;
  3315. if (org.springframework.util.StringUtils.hasText(isur.getCardNo())) {
  3316. //重复性判断
  3317. int existCount = smartUserService.querySmartUserByCardNo(isur.getCardNo());
  3318. if (existCount > 0) {
  3319. return CommonResult.fail("当前学号已存在,请勿重复添加");
  3320. }
  3321. }
  3322. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3323. SmartUser su = new SmartUser();
  3324. su.setTimeGroupId(isur.getTimeGroupId());
  3325. su.setCardNo(isur.getCardNo());
  3326. su.setName(isur.getName());
  3327. su.setIdentityId(isur.getIdentityId());
  3328. su.setIdCard(isur.getIdCard());
  3329. su.setSexId(isur.getSexId());
  3330. su.setDepartmentId(isur.getDepartmentId());
  3331. su.setHeadImage(isur.getHeadImage());
  3332. su.setGrade(isur.getGrade());
  3333. su.setCollege(isur.getCollege());
  3334. su.setSpeciality(isur.getSpeciality());
  3335. su.setSchoolClass(isur.getSchoolClass());
  3336. su.setCampus(isur.getCampus());
  3337. su.setDormitoryNumber(isur.getDormitoryNumber());
  3338. su.setPhone(isur.getPhone());
  3339. su.setAffiliate(StringUtils.join(isur.getAffiliate(), ","));
  3340. su.setTitle(isur.getTitle());
  3341. su.setAddress(isur.getAddress());
  3342. su.setNation(isur.getNation());
  3343. su.setOfStudent(isur.getOfStudent());
  3344. su.setGraduate(isur.getGraduate());
  3345. su.setDuties(isur.getDuties());
  3346. su.setIsCancel(eLogOff.Unlogout.getValue());
  3347. //region 人员信息加入到第三方api
  3348. //要将用户数据加入到希沃和百胜中
  3349. //希沃和百胜的老师、学生数据添加是不一样的,所以按身份添加
  3350. if (isur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  3351. //region 家长参数必填判断:手机号
  3352. if (isur.getPhone() == null) {
  3353. return CommonResult.fail("家长手机号不能为空");
  3354. }
  3355. //endregion
  3356. //查找家长身份是否存在用了该手机号的用户
  3357. int existCount = smartUserService.queryParentByCount(isur.getPhone());
  3358. if (existCount > 0) {
  3359. return CommonResult.fail("当前手机号已被其他家长使用");
  3360. }
  3361. //拿到被关联学生的信息去获取对应的卡号
  3362. //有多个学生就循环学生
  3363. if (isur.getAffiliate() == null) {
  3364. return CommonResult.fail("被关联人不能为空");
  3365. }
  3366. if (isur.getAffiliate().size() <= 0) {
  3367. return CommonResult.fail("被关联人不能为空");
  3368. }
  3369. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(isur.getAffiliate());
  3370. //region 希沃新增编辑学生家长信息
  3371. if (useXw == 1) {
  3372. CommonResult insertOrUpdateStudent = insertOrUpdateStudentParent(seewoClient, studentDatas, "其他", isur.getPhone(), true);
  3373. if (!insertOrUpdateStudent.isSuccess()) {
  3374. return CommonResult.fail("希沃平台:" + insertOrUpdateStudent.getMessage());
  3375. }
  3376. }
  3377. //endregion
  3378. } else if (isur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  3379. //region 学生参数必填判断:年级、班级
  3380. if (isur.getGrade() == null) {
  3381. return CommonResult.fail("学生年级不能为空");
  3382. }
  3383. if (isur.getSchoolClass() == null) {
  3384. return CommonResult.fail("学生班级不能为空");
  3385. }
  3386. //endregion
  3387. //获取班级Uid
  3388. classData = smartClassService.getSmartClassById(isur.getSchoolClass());
  3389. if (classData == null) {
  3390. return CommonResult.fail("班级数据无效,新增失败");
  3391. }
  3392. gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(isur.getGrade()));
  3393. if (gradeData == null) {
  3394. return CommonResult.fail("年级数据无效,新增失败");
  3395. }
  3396. //region 希沃新增学生信息
  3397. if (useXw == 1) {
  3398. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getPhone(), classData.getClassUid());
  3399. if (!insertStudent.isSuccess()) {
  3400. return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
  3401. }
  3402. su.setXwStudentUid(insertStudent.getData());
  3403. //上传图片
  3404. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  3405. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  3406. photo.setPhotoUrl(su.getHeadImage());
  3407. photo.setUserCode(su.getCardNo());
  3408. photoList.add(photo);
  3409. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  3410. if (!result.isSuccess()) {
  3411. return result;
  3412. }
  3413. }
  3414. //endregion
  3415. //region 百胜新增学生信息
  3416. if (useBs == 1) {
  3417. /**
  3418. * 学生数据的有效期是到毕业年份的8月31日
  3419. */
  3420. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  3421. String endTime = queryGraduationYear(gradeData.getGradeNo());
  3422. CommonResult<String> insertBsStudent = bsInsertStudent(isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getHeadImage(), isur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, isur.getIdCard());
  3423. if (!insertBsStudent.isSuccess()) {
  3424. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  3425. }
  3426. su.setBsStudentNo(insertBsStudent.getData());
  3427. }
  3428. //endregion
  3429. } else if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//老师
  3430. //region 老师参数必填判断:职称、手机号
  3431. if (isur.getTitle() == null) {
  3432. return CommonResult.fail("老师职称不能为空");
  3433. }
  3434. if (isur.getPhone() == null) {
  3435. return CommonResult.fail("老师手机号不能为空");
  3436. }
  3437. //endregion
  3438. //region 希沃添加教师数据
  3439. if (useXw == 1) {
  3440. CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, isur.getPhone(), isur.getName(), isur.getHeadImage());
  3441. if (!insertTeacher.isSuccess()) {
  3442. return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
  3443. }
  3444. su.setXwTeacherCode(insertTeacher.getData());
  3445. //上传图片
  3446. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  3447. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  3448. photo.setPhotoUrl(su.getHeadImage());
  3449. photo.setUserCode(su.getPhone());
  3450. photoList.add(photo);
  3451. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  3452. if (!result.isSuccess()) {
  3453. return result;
  3454. }
  3455. }
  3456. //endregion
  3457. if (isur.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  3458. //获取班级Uid
  3459. classData = smartClassService.getSmartClassById(isur.getSchoolClass());
  3460. if (classData == null) {
  3461. return CommonResult.fail("班级数据无效,新增失败");
  3462. }
  3463. //region 将班主任推送到希沃
  3464. if (useXw == 1) {
  3465. CommonResult pushMaster = SeewoPushMaster(seewoClient, isur.getPhone(), classData.getClassUid());
  3466. if (!pushMaster.isSuccess()) {
  3467. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  3468. }
  3469. }
  3470. //endregion
  3471. }
  3472. SmartDepartment departmentData = smartDepartmentService.getSmartById(isur.getDepartmentId());
  3473. if (departmentData == null) {
  3474. return CommonResult.fail("部门数据无效,新增教师失败");
  3475. }
  3476. String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
  3477. if (departmentNo == null) {
  3478. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  3479. }
  3480. //region 百胜添加教师数据
  3481. if (useBs == 1) {
  3482. /**
  3483. * 教师数据的有效期是20年
  3484. */
  3485. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  3486. String endTime = TimeExchange.addYear(20);
  3487. CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
  3488. if (!insertBsTeacher.isSuccess()) {
  3489. return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
  3490. }
  3491. su.setBsStaffCode(insertBsTeacher.getData());
  3492. }
  3493. //endregion
  3494. }
  3495. //endregion
  3496. //最后都要把数据加入到数据库中
  3497. if (org.springframework.util.StringUtils.hasText(isur.getPhone())) {
  3498. //多身份
  3499. List<SmartUser> users = smartUserService.getPhoneUsers(isur.getPhone());
  3500. if (users != null && users.size() > 0) {
  3501. Optional<SmartUser> ownerUser = users.stream().filter(e -> org.springframework.util.StringUtils.hasText(e.getXOpenId())).findFirst();
  3502. if (ownerUser != null && ownerUser.isPresent()) {
  3503. su.setXOpenId(ownerUser.get().getXOpenId());
  3504. }
  3505. }
  3506. }
  3507. int result = smartUserService.insertSmartUser(su);
  3508. if (result > 0) {
  3509. // 将添加的用户同步到海康平台
  3510. Integer identityId = su.getIdentityId();
  3511. if (2 == identityId || identityId == 3) {
  3512. Integer id = su.getId();
  3513. SmartOperationUser smartOperationUser = new SmartOperationUser();
  3514. smartOperationUser.setOperationId(id);
  3515. smartOperationUser.setOperationMode("1");
  3516. smartOperationUser.setStatus(1);
  3517. smartOperationUser.setType(identityId);
  3518. smartOperationUserService.save(smartOperationUser);
  3519. }
  3520. if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  3521. if (isur.getIsr() != null && isur.getIsr().size() > 0) {
  3522. List<SmartTeaching> teachings = new ArrayList<>();
  3523. for (isrRequest sv : isur.getIsr()) {
  3524. if (sv.getIds() != null && sv.getIds().size() > 0) {
  3525. SmartTeaching st = new SmartTeaching();
  3526. st.setUserId(result);
  3527. st.setSubjectId(sv.getIds().size() > 0 ? sv.getIds().get(0) : 0);
  3528. st.setGradeId(sv.getIds().size() > 1 ? sv.getIds().get(1) : 0);
  3529. st.setClassId(sv.getIds().size() > 2 ? sv.getIds().get(2) : 0);
  3530. teachings.add(st);
  3531. }
  3532. }
  3533. if (teachings != null && teachings.size() > 0) {
  3534. boolean insertBatch = smartTeachingService.saveBatch(teachings);
  3535. if (!insertBatch) {
  3536. return CommonResult.fail("任课数据添加失败");
  3537. }
  3538. }
  3539. }
  3540. //region 新增用户的时候同步新增教师综合评价数据
  3541. List<SmartSemester> semesters = smartSemesterService.querySemesterByTime(new Date());
  3542. gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(isur.getGrade()));
  3543. if (semesters != null && semesters.size() > 0) {
  3544. List<SmartEvaluateTeacher> eTeachers = new ArrayList<>();
  3545. for (SmartSemester semester : semesters) {
  3546. SmartEvaluateTeacher set = new SmartEvaluateTeacher();
  3547. set.setCardNo(su.getCardNo());
  3548. set.setName(su.getName());
  3549. set.setUserId(su.getId());
  3550. set.setTermId(semester.getId());
  3551. set.setTerm(semester.getName());
  3552. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {//班主任才有年级和班级
  3553. set.setGradeId(Integer.valueOf(su.getGrade()));
  3554. if (gradeData != null) {
  3555. set.setGradeName(gradeData.getName());
  3556. }
  3557. set.setClassId(su.getSchoolClass());
  3558. if (classData != null) {
  3559. set.setClassName(classData.getName());
  3560. }
  3561. }
  3562. set.setTotalScore(0.0);
  3563. set.setLowingScore(0.0);
  3564. eTeachers.add(set);
  3565. }
  3566. if (eTeachers != null && eTeachers.size() > 0) {
  3567. boolean insertEteacher = smartEvaluateTeacherService.saveBatch(eTeachers);
  3568. if (!insertEteacher) {
  3569. return CommonResult.fail("添加失败");
  3570. }
  3571. }
  3572. }
  3573. //endregion
  3574. }
  3575. }
  3576. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  3577. }
  3578. //endregion
  3579. @Override
  3580. @DESRespondSecret(validated = true)
  3581. @PassToken
  3582. public CommonResult updateTest(int departmentId) throws Exception {
  3583. List<Integer> departmentIds = new ArrayList<>();
  3584. departmentIds.add(81);
  3585. departmentIds.add(82);
  3586. departmentIds.add(83);
  3587. departmentIds.add(84);
  3588. departmentIds.add(85);
  3589. departmentIds.add(86);
  3590. departmentIds.add(87);
  3591. departmentIds.add(88);
  3592. departmentIds.add(89);
  3593. departmentIds.add(90);
  3594. departmentIds.add(91);
  3595. departmentIds.add(92);
  3596. departmentIds.add(93);
  3597. departmentIds.add(94);
  3598. departmentIds.add(95);
  3599. departmentIds.add(96);
  3600. departmentIds.add(97);
  3601. departmentIds.add(98);
  3602. List<SmartUser> users = smartUserService.queryDatasByDepartments(departmentIds);
  3603. for (SmartUser usur:users) {
  3604. if(usur.getName().equals("张玉玲")){
  3605. String sdsd = "";
  3606. }
  3607. int useXw = 1;
  3608. int useBs = 1;
  3609. //更新的同时将百胜用户信息同步过去或者同步过来?
  3610. SmartUser su = smartUserService.getSmartById(usur.getId());
  3611. if (su == null) {
  3612. return CommonResult.fail("用户数据已失效,修改失败!");
  3613. }
  3614. //是否转换身份
  3615. boolean changeIdentity = false;
  3616. Integer oldIdentity = null;
  3617. String oldAffiliate = su.getAffiliate();
  3618. Integer oldSchoolClass = su.getSchoolClass();
  3619. String oldStaffNo = su.getBsStaffCode();
  3620. String oldCardNo = su.getCardNo();
  3621. if (usur.getIdentityId().intValue() != su.getIdentityId().intValue()) {
  3622. changeIdentity = true;
  3623. oldIdentity = su.getIdentityId().intValue();
  3624. }
  3625. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3626. su.setTimeGroupId(usur.getTimeGroupId());
  3627. su.setCardNo(usur.getCardNo());
  3628. su.setName(usur.getName());
  3629. su.setIdentityId(usur.getIdentityId());
  3630. su.setIdCard(usur.getIdCard());
  3631. su.setSexId(usur.getSexId());
  3632. su.setDepartmentId(usur.getDepartmentId());
  3633. su.setHeadImage(usur.getHeadImage());
  3634. su.setGrade(usur.getGrade());
  3635. su.setCollege(usur.getCollege());
  3636. su.setSpeciality(usur.getSpeciality());
  3637. su.setSchoolClass(usur.getSchoolClass());
  3638. su.setCampus(usur.getCampus());
  3639. su.setDormitoryNumber(usur.getDormitoryNumber());
  3640. su.setPhone(usur.getPhone());
  3641. su.setAffiliate(StringUtils.join(usur.getAffiliate(), ","));
  3642. su.setTitle(usur.getTitle());
  3643. su.setAddress(usur.getAddress());
  3644. su.setNation(usur.getNation());
  3645. su.setOfStudent(usur.getOfStudent());
  3646. su.setGraduate(usur.getGraduate());
  3647. su.setDuties(usur.getDuties());
  3648. su.setIsCancel(eLogOff.Unlogout.getValue());
  3649. if (usur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  3650. //拿到被关联学生的信息去获取对应的卡号
  3651. //有多个学生就循环学生
  3652. if (usur.getAffiliate() == null) {
  3653. return CommonResult.fail("被关联人不能为空");
  3654. }
  3655. List<String> affiliates = Arrays.asList(usur.getAffiliate().split(","));
  3656. if (affiliates.size() <= 0) {
  3657. return CommonResult.fail("被关联人不能为空");
  3658. }
  3659. SmartUser oldUser = smartUserService.queryParentByPhone(usur.getPhone());
  3660. if (oldUser != null && oldUser.getId().intValue() != usur.getId().intValue()) {
  3661. //return CommonResult.fail("当前手机号已被其他家长使用");
  3662. }
  3663. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(affiliates);
  3664. if(studentDatas.size() <= 0){
  3665. smartUserService.deleteSmartUserById(usur.getId());
  3666. continue;
  3667. }
  3668. if (!changeIdentity) {
  3669. //region 希沃新增编辑学生家长信息
  3670. if (useXw == 1) {
  3671. //学生与家长列表,最大100条
  3672. CommonResult insertOrUpdateResult = insertOrUpdateStudentParent(seewoClient, studentDatas, "其他", usur.getPhone(), false);
  3673. if (!insertOrUpdateResult.isSuccess()) {
  3674. return CommonResult.fail("希沃平台:" + insertOrUpdateResult.getMessage());
  3675. }
  3676. }
  3677. //endregion
  3678. } else {
  3679. if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  3680. //region 希沃删除学生
  3681. //获取班级Uid
  3682. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  3683. if (classData == null) {
  3684. return CommonResult.fail("班级数据无效,更新失败");
  3685. }
  3686. if (useXw == 1) {
  3687. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  3688. if (!deleteStudent.isSuccess()) {
  3689. return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
  3690. }
  3691. }
  3692. //endregion
  3693. //region 百胜删除学生
  3694. if (useBs == 1) {
  3695. CommonResult deleteBsStudent = bsDeleteStudent(su);
  3696. if (!deleteBsStudent.isSuccess()) {
  3697. return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
  3698. }
  3699. }
  3700. //endregion
  3701. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  3702. //获取班级Uid
  3703. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  3704. if (classData == null) {
  3705. return CommonResult.fail("班级数据无效,更新失败");
  3706. }
  3707. //region 希沃删除教师
  3708. if (useXw == 1) {
  3709. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  3710. if (!deleteTeacher.isSuccess()) {
  3711. return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
  3712. }
  3713. }
  3714. //endregion
  3715. //region 希沃删除班主任
  3716. if (useXw == 1) {
  3717. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
  3718. if (deleteTeacherMaster.isSuccess()) {
  3719. return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
  3720. }
  3721. }
  3722. //endregion
  3723. //region 百胜删除教师
  3724. if (useBs == 1) {
  3725. CommonResult bsDeleteTeacher = bsDeleteTeacher(oldStaffNo);
  3726. if (!bsDeleteTeacher.isSuccess()) {
  3727. return CommonResult.fail("百胜平台:" + bsDeleteTeacher.getMessage());
  3728. }
  3729. }
  3730. //endregion
  3731. }
  3732. //region 希沃新增编辑学生家长信息
  3733. if (useXw == 1) {
  3734. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(su.getCardNo());
  3735. if (indexs != null && indexs.size() >= 4) {
  3736. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  3737. }
  3738. CommonResult insertOrUpdate = insertOrUpdateStudentParent(seewoClient, studentDatas, su.getShip(), su.getPhone(), true);
  3739. if (!insertOrUpdate.isSuccess()) {
  3740. return CommonResult.fail("希沃平台:" + insertOrUpdate.getMessage());
  3741. }
  3742. }
  3743. //endregion
  3744. }
  3745. }
  3746. }
  3747. return CommonResult.ok();
  3748. }
  3749. //region 更新用户
  3750. /**
  3751. * 更新用户
  3752. *
  3753. * @param usur 更新用户数据
  3754. * @param bindingResult
  3755. * @return
  3756. */
  3757. @Override
  3758. @DESRespondSecret(validated = true)
  3759. public CommonResult updateSmartUserById(updateSmartUserRequest usur, BindingResult bindingResult) throws Exception {
  3760. if (bindingResult.hasErrors()) {
  3761. String st = paramUtils.getParamError(bindingResult);
  3762. return CommonResult.fail(st);
  3763. }
  3764. //region 参数判断
  3765. if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  3766. if (usur.getTimeGroupId() == null) {
  3767. return CommonResult.fail("学生时间组不能为空");
  3768. }
  3769. if (usur.getCardNo() == null) {
  3770. return CommonResult.fail("学生编号不能为空");
  3771. }
  3772. if (usur.getHeadImage() == null) {
  3773. return CommonResult.fail("学生人脸照片不能为空");
  3774. }
  3775. }
  3776. //endregion
  3777. int useXw = 1;
  3778. int useBs = 1;
  3779. //更新的同时将百胜用户信息同步过去或者同步过来?
  3780. SmartUser su = smartUserService.getSmartById(usur.getId());
  3781. if (su == null) {
  3782. return CommonResult.fail("用户数据已失效,修改失败!");
  3783. }
  3784. //是否转换身份
  3785. boolean changeIdentity = false;
  3786. Integer oldIdentity = null;
  3787. String oldAffiliate = su.getAffiliate();
  3788. Integer oldSchoolClass = su.getSchoolClass();
  3789. String oldStaffNo = su.getBsStaffCode();
  3790. String oldCardNo = su.getCardNo();
  3791. if (usur.getIdentityId().intValue() != su.getIdentityId().intValue()) {
  3792. changeIdentity = true;
  3793. oldIdentity = su.getIdentityId().intValue();
  3794. }
  3795. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3796. su.setTimeGroupId(usur.getTimeGroupId());
  3797. su.setCardNo(usur.getCardNo());
  3798. su.setName(usur.getName());
  3799. su.setIdentityId(usur.getIdentityId());
  3800. su.setIdCard(usur.getIdCard());
  3801. su.setSexId(usur.getSexId());
  3802. su.setDepartmentId(usur.getDepartmentId());
  3803. su.setHeadImage(usur.getHeadImage());
  3804. su.setGrade(usur.getGrade());
  3805. su.setCollege(usur.getCollege());
  3806. su.setSpeciality(usur.getSpeciality());
  3807. su.setSchoolClass(usur.getSchoolClass());
  3808. su.setCampus(usur.getCampus());
  3809. su.setDormitoryNumber(usur.getDormitoryNumber());
  3810. su.setPhone(usur.getPhone());
  3811. su.setAffiliate(StringUtils.join(usur.getAffiliate(), ","));
  3812. su.setTitle(usur.getTitle());
  3813. su.setAddress(usur.getAddress());
  3814. su.setNation(usur.getNation());
  3815. su.setOfStudent(usur.getOfStudent());
  3816. su.setGraduate(usur.getGraduate());
  3817. su.setDuties(usur.getDuties());
  3818. su.setIsCancel(eLogOff.Unlogout.getValue());
  3819. if (usur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  3820. //拿到被关联学生的信息去获取对应的卡号
  3821. //有多个学生就循环学生
  3822. if (usur.getAffiliate() == null) {
  3823. return CommonResult.fail("被关联人不能为空");
  3824. }
  3825. if (usur.getAffiliate().size() <= 0) {
  3826. return CommonResult.fail("被关联人不能为空");
  3827. }
  3828. SmartUser oldUser = smartUserService.queryParentByPhone(usur.getPhone());
  3829. if (oldUser != null && oldUser.getId().intValue() != usur.getId().intValue()) {
  3830. return CommonResult.fail("当前手机号已被其他家长使用");
  3831. }
  3832. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(usur.getAffiliate());
  3833. if (!changeIdentity) {
  3834. //region 希沃新增编辑学生家长信息
  3835. if (useXw == 1) {
  3836. //学生与家长列表,最大100条
  3837. CommonResult insertOrUpdateResult = insertOrUpdateStudentParent(seewoClient, studentDatas, "其他", usur.getPhone(), false);
  3838. if (!insertOrUpdateResult.isSuccess()) {
  3839. return CommonResult.fail("希沃平台:" + insertOrUpdateResult.getMessage());
  3840. }
  3841. }
  3842. //endregion
  3843. } else {
  3844. if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  3845. //region 希沃删除学生
  3846. //获取班级Uid
  3847. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  3848. if (classData == null) {
  3849. return CommonResult.fail("班级数据无效,更新失败");
  3850. }
  3851. if (useXw == 1) {
  3852. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  3853. if (!deleteStudent.isSuccess()) {
  3854. return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
  3855. }
  3856. }
  3857. //endregion
  3858. //region 百胜删除学生
  3859. if (useBs == 1) {
  3860. CommonResult deleteBsStudent = bsDeleteStudent(su);
  3861. if (!deleteBsStudent.isSuccess()) {
  3862. return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
  3863. }
  3864. }
  3865. //endregion
  3866. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  3867. //获取班级Uid
  3868. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  3869. if (classData == null) {
  3870. return CommonResult.fail("班级数据无效,更新失败");
  3871. }
  3872. //region 希沃删除教师
  3873. if (useXw == 1) {
  3874. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  3875. if (!deleteTeacher.isSuccess()) {
  3876. return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
  3877. }
  3878. }
  3879. //endregion
  3880. //region 希沃删除班主任
  3881. if (useXw == 1) {
  3882. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
  3883. if (deleteTeacherMaster.isSuccess()) {
  3884. return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
  3885. }
  3886. }
  3887. //endregion
  3888. //region 百胜删除教师
  3889. if (useBs == 1) {
  3890. CommonResult bsDeleteTeacher = bsDeleteTeacher(oldStaffNo);
  3891. if (!bsDeleteTeacher.isSuccess()) {
  3892. return CommonResult.fail("百胜平台:" + bsDeleteTeacher.getMessage());
  3893. }
  3894. }
  3895. //endregion
  3896. }
  3897. //region 希沃新增编辑学生家长信息
  3898. if (useXw == 1) {
  3899. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(su.getCardNo());
  3900. if (indexs != null && indexs.size() >= 4) {
  3901. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  3902. }
  3903. CommonResult insertOrUpdate = insertOrUpdateStudentParent(seewoClient, studentDatas, su.getShip(), su.getPhone(), true);
  3904. if (!insertOrUpdate.isSuccess()) {
  3905. return CommonResult.fail("希沃平台:" + insertOrUpdate.getMessage());
  3906. }
  3907. }
  3908. //endregion
  3909. }
  3910. } else if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  3911. //region 年级和班级不能为空
  3912. if (usur.getGrade() == null) {
  3913. return CommonResult.fail("学生年级不能为空");
  3914. }
  3915. if (usur.getSchoolClass() == null) {
  3916. return CommonResult.fail("学生班级不能为空");
  3917. }
  3918. //endregion
  3919. //获取班级Uid
  3920. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  3921. if (classData == null) {
  3922. return CommonResult.fail("班级数据无效,更新失败");
  3923. }
  3924. //获取年级Uid
  3925. SmartGrade gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(su.getGrade()));
  3926. if (gradeData == null) {
  3927. return CommonResult.fail("年级数据无效,新增失败");
  3928. }
  3929. if (!changeIdentity) {
  3930. //region 更新希沃学生信息
  3931. if (useXw == 1) {
  3932. CommonResult updateStudent = SeewoUpdateStudent(seewoClient, su);
  3933. if (!updateStudent.isSuccess()) {
  3934. if (updateStudent.getMessage().equals("学生不存在")) {
  3935. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
  3936. if (!insertStudent.isSuccess()) {
  3937. return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
  3938. }
  3939. }
  3940. } else {
  3941. if (!su.getSchoolClass().equals(oldSchoolClass)) {
  3942. //获取班级Uid
  3943. SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
  3944. if (oldClassData == null) {
  3945. return CommonResult.fail("班级数据无效,更新失败");
  3946. }
  3947. CommonResult changeClass = SeewoChangeClass(seewoClient, seewoConfig.getSchoolId(), su.getXwStudentUid(), oldClassData.getClassUid(), classData.getClassUid());
  3948. if(!changeClass.isSuccess()){
  3949. return CommonResult.fail("希沃平台:" + changeClass.getMessage());
  3950. }
  3951. }
  3952. }
  3953. //上传图片
  3954. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  3955. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  3956. photo.setPhotoUrl(su.getHeadImage());
  3957. photo.setUserCode(su.getCardNo());
  3958. photoList.add(photo);
  3959. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  3960. if (!result.isSuccess()) {
  3961. return result;
  3962. }
  3963. }
  3964. //endregion
  3965. //region 更新百胜学生信息
  3966. if (useBs == 1) {
  3967. /**
  3968. * 学生数据的有效期是到毕业年份的8月31日
  3969. */
  3970. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  3971. String endTime = queryGraduationYear(gradeData.getGradeNo());
  3972. CommonResult updateBsStudent = bsUpdateStudent(su, classData.getBsClassNo() ,startTime, endTime);
  3973. if (!updateBsStudent.isSuccess()) {
  3974. if (updateBsStudent.getMessage().equals("人员不存在或已删除")) {
  3975. //region 百胜新增学生信息
  3976. CommonResult<String> insertBsStudent = bsInsertStudent(usur.getName(), usur.getCardNo(), usur.getSexId(), usur.getHeadImage(), usur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, usur.getIdCard());
  3977. if (!insertBsStudent.isSuccess()) {
  3978. return CommonResult.fail("百胜平台:" + insertBsStudent.getMessage());
  3979. }
  3980. su.setBsStudentNo(insertBsStudent.getData());
  3981. //endregion
  3982. } else {
  3983. return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
  3984. }
  3985. }
  3986. }
  3987. //endregion
  3988. } else {
  3989. if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
  3990. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
  3991. //region 希沃删除原有的家长关系
  3992. if (useXw == 1) {
  3993. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
  3994. if (!deleteResult.isSuccess()) {
  3995. return CommonResult.fail("希沃平台:" + deleteResult.getMessage());
  3996. }
  3997. smartFamilyIndexService.deleteSmartFamilyByPhone(su.getPhone());
  3998. }
  3999. //endregion
  4000. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  4001. //获取班级Uid
  4002. SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
  4003. if (oldClassData == null) {
  4004. return CommonResult.fail("班级数据无效,更新失败");
  4005. }
  4006. //region 希沃删除教师
  4007. if (useXw == 1) {
  4008. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  4009. if (!deleteTeacher.isSuccess()) {
  4010. return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
  4011. }
  4012. }
  4013. //endregion
  4014. //region 希沃删除班主任
  4015. if (useXw == 1) {
  4016. CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
  4017. if (!deleteMaster.isSuccess()) {
  4018. return CommonResult.fail("希沃平台:" + deleteMaster.getMessage());
  4019. }
  4020. }
  4021. //endregion
  4022. //region 百胜删除教师
  4023. if (useBs == 1) {
  4024. CommonResult deleteBsTeacher = bsDeleteTeacher(oldStaffNo);
  4025. if (!deleteBsTeacher.isSuccess()) {
  4026. return CommonResult.fail("百胜平台:" + deleteBsTeacher.getMessage());
  4027. }
  4028. }
  4029. //endregion
  4030. }
  4031. //region 希沃新增学生信息
  4032. if (useXw == 1) {
  4033. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
  4034. if (!insertStudent.isSuccess()) {
  4035. return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
  4036. } else {
  4037. su.setXwStudentUid(insertStudent.getData());
  4038. }
  4039. //上传图片
  4040. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  4041. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  4042. photo.setPhotoUrl(su.getHeadImage());
  4043. photo.setUserCode(su.getCardNo());
  4044. photoList.add(photo);
  4045. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  4046. if (!result.isSuccess()) {
  4047. return result;
  4048. }
  4049. }
  4050. //endregion
  4051. //region 百胜新增学生信息
  4052. if (useBs == 1) {
  4053. /**
  4054. * 学生数据的有效期是到毕业年份的8月31日
  4055. */
  4056. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  4057. String endTime = queryGraduationYear(gradeData.getGradeNo());
  4058. CommonResult<String> insertBsStudent = bsInsertStudent(su.getName(), su.getCardNo(), su.getSexId(), su.getHeadImage(), su.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime, su.getIdCard());
  4059. if (insertBsStudent.isSuccess()) {
  4060. su.setBsStudentNo(insertBsStudent.getData());
  4061. } else {
  4062. //region 希沃删除学生
  4063. //百胜数据插入失败后需要把已插入到希沃的数据删除
  4064. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  4065. if (!deleteStudent.isSuccess()) {
  4066. return CommonResult.fail("百胜平台:" + deleteStudent.getMessage());
  4067. }
  4068. //endregion
  4069. return CommonResult.fail("切换身份后," + insertBsStudent.getMessage() + ",百胜无法插入学生数据");
  4070. }
  4071. }
  4072. //endregion
  4073. }
  4074. } else if (usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//教师
  4075. if (!changeIdentity) {
  4076. //region 希沃更新教师数据
  4077. if (useXw == 1) {
  4078. CommonResult<String> updateTeacher = SeewoUpdateTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
  4079. if (!updateTeacher.isSuccess()) {
  4080. return CommonResult.fail("希沃平台:" + updateTeacher.getMessage());
  4081. }
  4082. su.setXwTeacherCode(updateTeacher.getData());
  4083. //上传图片
  4084. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  4085. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  4086. photo.setPhotoUrl(su.getHeadImage());
  4087. photo.setUserCode(su.getPhone());
  4088. photoList.add(photo);
  4089. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  4090. if (!result.isSuccess()) {
  4091. return result;
  4092. }
  4093. }
  4094. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4095. //获取班级Uid
  4096. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  4097. if (classData == null) {
  4098. return CommonResult.fail("班级数据无效,新增失败");
  4099. }
  4100. if (useXw == 1) {
  4101. //获取班级Uid
  4102. SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
  4103. if (oldClassData == null) {
  4104. return CommonResult.fail("班级数据无效,更新失败");
  4105. }
  4106. CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
  4107. if (!deleteMaster.isSuccess()) {
  4108. return CommonResult.fail("希沃平台:" + deleteMaster.getMessage());
  4109. }
  4110. }
  4111. //region 将班主任推送到希沃
  4112. if (useXw == 1) {
  4113. CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
  4114. if (!pushMaster.isSuccess()) {
  4115. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  4116. }
  4117. }
  4118. //endregion
  4119. }
  4120. //endregion
  4121. SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
  4122. if (departmentData == null) {
  4123. return CommonResult.fail("部门数据无效,更新教师失败");
  4124. }
  4125. String departmentNo = departmentData.getBsDepartmentNo();
  4126. if (departmentNo == null) {
  4127. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  4128. }
  4129. //region 百胜更新教师数据
  4130. if (useBs == 1) {
  4131. /**
  4132. * 教师数据的有效期是20年
  4133. */
  4134. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  4135. String endTime = TimeExchange.addYear(20);
  4136. CommonResult<String> bsUpdateTeacher = updateBsTeacher(su, departmentNo, startTime, endTime);
  4137. if (!bsUpdateTeacher.isSuccess()) {
  4138. return CommonResult.fail("百胜平台:" + bsUpdateTeacher.getMessage());
  4139. }
  4140. su.setBsStaffCode(bsUpdateTeacher.getData());
  4141. }
  4142. //endregion
  4143. } else {
  4144. if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
  4145. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
  4146. //region 希沃删除原有的家长关系
  4147. if (useXw == 1) {
  4148. CommonResult deleteOldShip = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
  4149. if (!deleteOldShip.isSuccess()) {
  4150. return CommonResult.fail("希沃平台:" + deleteOldShip.getMessage());
  4151. }
  4152. smartFamilyIndexService.deleteSmartFamilyByPhone(su.getPhone());
  4153. }
  4154. //endregion
  4155. } else if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  4156. //获取班级Uid
  4157. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  4158. if (classData == null) {
  4159. return CommonResult.fail("班级数据无效,更新失败");
  4160. }
  4161. //region 希沃删除学生
  4162. if (useXw == 1) {
  4163. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  4164. if (!deleteStudent.isSuccess()) {
  4165. return CommonResult.fail("希沃平台:" + deleteStudent.getMessage());
  4166. }
  4167. }
  4168. //endregion
  4169. //region 百胜删除学生
  4170. if (useBs == 1) {
  4171. CommonResult deleteBsStudent = bsDeleteStudent(su);
  4172. if (!deleteBsStudent.isSuccess()) {
  4173. return CommonResult.fail("百胜平台:" + deleteBsStudent.getMessage());
  4174. }
  4175. }
  4176. //endregion
  4177. }
  4178. //region 希沃添加教师数据
  4179. if (useXw == 1) {
  4180. CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
  4181. if (!insertTeacher.isSuccess()) {
  4182. return CommonResult.fail("希沃平台:" + insertTeacher.getMessage());
  4183. }
  4184. su.setXwTeacherCode(insertTeacher.getData());
  4185. //上传图片
  4186. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  4187. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  4188. photo.setPhotoUrl(su.getHeadImage());
  4189. photo.setUserCode(su.getPhone());
  4190. photoList.add(photo);
  4191. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  4192. if (!result.isSuccess()) {
  4193. return result;
  4194. }
  4195. }
  4196. //endregion
  4197. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4198. //获取班级Uid
  4199. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  4200. if (classData == null) {
  4201. return CommonResult.fail("班级数据无效,新增失败");
  4202. }
  4203. //region 将班主任推送到希沃
  4204. if (useXw == 1) {
  4205. CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
  4206. if (!pushMaster.isSuccess()) {
  4207. return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  4208. }
  4209. }
  4210. //endregion
  4211. }
  4212. SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
  4213. if (departmentData == null) {
  4214. return CommonResult.fail("部门数据无效,新增教师失败");
  4215. }
  4216. String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
  4217. if (departmentNo == null) {
  4218. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  4219. }
  4220. //region 百胜添加教师数据
  4221. if (useBs == 1) {
  4222. /**
  4223. * 教师数据的有效期是20年
  4224. */
  4225. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  4226. String endTime = TimeExchange.addYear(20);
  4227. CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
  4228. if (!insertBsTeacher.isSuccess()) {
  4229. return CommonResult.fail("百胜平台:" + insertBsTeacher.getMessage());
  4230. }
  4231. su.setBsStaffCode(insertBsTeacher.getData());
  4232. }
  4233. //endregion
  4234. }
  4235. }
  4236. int result = smartUserService.updateSmartUser(su);
  4237. // 修改需同步到海康平台
  4238. if (result > 0) {
  4239. Integer identityId = su.getIdentityId();
  4240. if (2 == identityId || identityId == 3) {
  4241. Integer id = su.getId();
  4242. SmartOperationUser smartOperationUser = new SmartOperationUser();
  4243. smartOperationUser.setOperationId(id);
  4244. smartOperationUser.setOperationMode("2");
  4245. smartOperationUser.setStatus(1);
  4246. smartOperationUser.setType(identityId);
  4247. smartOperationUserService.save(smartOperationUser);
  4248. }
  4249. }
  4250. //region 任课数据
  4251. if (result > 0 && usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  4252. smartTeachingService.deleteByUserId(su.getId());
  4253. if (usur.getUsr() != null && usur.getUsr().size() > 0) {
  4254. List<SmartTeaching> teachings = new ArrayList<>();
  4255. for (isrRequest sv : usur.getUsr()) {
  4256. if (sv.getIds() != null && sv.getIds().size() > 0) {
  4257. SmartTeaching st = new SmartTeaching();
  4258. st.setUserId(su.getId());
  4259. st.setSubjectId(sv.getIds().size() > 0 ? sv.getIds().get(0) : 0);
  4260. st.setGradeId(sv.getIds().size() > 1 ? sv.getIds().get(1) : 0);
  4261. st.setClassId(sv.getIds().size() > 2 ? sv.getIds().get(2) : 0);
  4262. teachings.add(st);
  4263. }
  4264. }
  4265. if (teachings != null && teachings.size() > 0) {
  4266. boolean insertBatch = smartTeachingService.saveBatch(teachings);
  4267. if (!insertBatch) {
  4268. return CommonResult.fail("任课数据添加失败");
  4269. }
  4270. }
  4271. }
  4272. List<SmartEvaluateTeacher> eTeachers = smartEvaluateTeacherService.queryEvaluateTeachersByUserId(usur.getId());
  4273. List<SmartSemester> semesters = smartSemesterService.querySemesterByTime(su.getCreateTime());
  4274. List<SmartEvaluateTeacher> newTeachers = new ArrayList<>();
  4275. List<SmartEvaluateTeacher> updateTeachers = new ArrayList<>();
  4276. SmartClass classData = null;
  4277. SmartGrade gradeData = null;
  4278. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4279. classData = smartClassService.getSmartClassById(su.getSchoolClass());
  4280. gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(su.getGrade()));
  4281. }
  4282. if (eTeachers != null && eTeachers.size() > 0) {
  4283. for (SmartSemester semester : semesters) {
  4284. Optional<SmartEvaluateTeacher> oTeacher = eTeachers.stream().filter(e -> e.getTermId().equals(semester.getId())).findFirst();
  4285. if (oTeacher != null && oTeacher.isPresent()) {
  4286. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  4287. oTeacher.get().setGradeId(gradeData.getId());
  4288. oTeacher.get().setGradeName(gradeData.getName());
  4289. oTeacher.get().setClassId(classData.getId());
  4290. oTeacher.get().setClassName(classData.getName());
  4291. updateTeachers.add(oTeacher.get());
  4292. }
  4293. } else {
  4294. SmartEvaluateTeacher set = new SmartEvaluateTeacher();
  4295. set.setCardNo(su.getCardNo());
  4296. set.setName(su.getName());
  4297. set.setUserId(su.getId());
  4298. set.setTermId(semester.getId());
  4299. set.setTerm(semester.getName());
  4300. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {//班主任才有年级和班级
  4301. set.setGradeId(gradeData.getId());
  4302. set.setGradeName(gradeData.getName());
  4303. set.setClassId(classData.getId());
  4304. set.setClassName(classData.getName());
  4305. }
  4306. set.setTotalScore(0.0);
  4307. set.setLowingScore(0.0);
  4308. newTeachers.add(set);
  4309. }
  4310. }
  4311. } else {
  4312. for (SmartSemester semester : semesters) {
  4313. SmartEvaluateTeacher set = new SmartEvaluateTeacher();
  4314. set.setCardNo(su.getCardNo());
  4315. set.setName(su.getName());
  4316. set.setUserId(su.getId());
  4317. set.setTermId(semester.getId());
  4318. set.setTerm(semester.getName());
  4319. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {//班主任才有年级和班级
  4320. set.setGradeId(gradeData.getId());
  4321. set.setGradeName(gradeData.getName());
  4322. set.setClassId(classData.getId());
  4323. set.setClassName(classData.getName());
  4324. }
  4325. set.setTotalScore(0.0);
  4326. set.setLowingScore(0.0);
  4327. newTeachers.add(set);
  4328. }
  4329. }
  4330. if (newTeachers != null && newTeachers.size() > 0) {
  4331. boolean insertEteacher = smartEvaluateTeacherService.saveBatch(newTeachers);
  4332. if (!insertEteacher) {
  4333. return CommonResult.fail("修改失败");
  4334. }
  4335. }
  4336. if (updateTeachers != null && updateTeachers.size() > 0) {
  4337. boolean updateEteacher = smartEvaluateTeacherService.updateBatchById(updateTeachers);
  4338. if (!updateEteacher) {
  4339. return CommonResult.fail("修改失败");
  4340. }
  4341. }
  4342. }
  4343. //endregion
  4344. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  4345. }
  4346. //endregion
  4347. //region 希沃增删改查方法
  4348. //region 希沃换班
  4349. public CommonResult SeewoChangeClass(SeewoClient seewoClient, String schoolUid, String studentUid, String oldC, String newC) throws JsonProcessingException {
  4350. //初始化客户端
  4351. MdmStudentApiStudentChangeClassParam requestParam = new MdmStudentApiStudentChangeClassParam();
  4352. //请求体,MimeType为 application/json
  4353. MdmStudentApiStudentChangeClassParam.JSONRequestBody requestBody = MdmStudentApiStudentChangeClassParam.JSONRequestBody.builder()
  4354. .build();
  4355. requestParam.setRequestBody(requestBody);
  4356. //
  4357. MdmStudentApiStudentChangeClassParam.StudentChangeClassReqDto reqDto = MdmStudentApiStudentChangeClassParam.StudentChangeClassReqDto.builder()
  4358. .orgUid(schoolUid)
  4359. .studentUid(studentUid)
  4360. .oldClassUid(oldC)
  4361. .newClassUid(newC)
  4362. .build();
  4363. requestBody.setReqDto(reqDto);
  4364. MdmStudentApiStudentChangeClassRequest request = new MdmStudentApiStudentChangeClassRequest(requestParam);
  4365. System.out.println("入参:" + request);
  4366. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4367. MdmStudentApiStudentChangeClassResult result = seewoClient.invoke(request);
  4368. System.out.println("出参:" + result);
  4369. ObjectMapper objectMapper = new ObjectMapper();
  4370. XwBodyVo xwResult = objectMapper.readValue(result.getBody(), XwBodyVo.class);
  4371. if (!xwResult.getCode().equals("000000")) {
  4372. return CommonResult.fail("希沃平台:" + xwResult.getMessage());
  4373. }
  4374. return CommonResult.ok("换班成功");
  4375. }
  4376. //endregion
  4377. //region 希沃批量上传头像
  4378. /**
  4379. * 希沃批量上传头像 如果当前用户已存在图片 会进行覆盖
  4380. *
  4381. * @param seewoClient 链接配置
  4382. * @param photoList 头像集合
  4383. * @param userType 用户类型
  4384. * @return
  4385. * @throws JsonProcessingException
  4386. */
  4387. public CommonResult SeewoInsertBatchPhoto(SeewoClient seewoClient, List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList, Integer userType) throws
  4388. JsonProcessingException {
  4389. //region 希沃上传第三方图片信息
  4390. //初始化客户端
  4391. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4392. PhotoServiceSavePhotosParam param = new PhotoServiceSavePhotosParam();
  4393. //请求体,MimeType为 application/json
  4394. PhotoServiceSavePhotosParam.JSONRequestBody requestBody = PhotoServiceSavePhotosParam.JSONRequestBody.builder()
  4395. .build();
  4396. param.setRequestBody(requestBody);
  4397. //
  4398. PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery query = PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery.builder()
  4399. .appId(seewoConfig.getAppId())
  4400. .unitUid(seewoConfig.getSchoolId())
  4401. .userType(userType)
  4402. .build();
  4403. requestBody.setQuery(query);
  4404. // 图片保存列表
  4405. query.setPhotoList(photoList);
  4406. PhotoServiceSavePhotosRequest request = new PhotoServiceSavePhotosRequest(param);
  4407. // 该接口需要数据权限,请将授权资源id替换至下方,请妥善保管好授权资源id,避免泄露
  4408. // permissionId位置: 控制台 -> 应用详情 -> 我申请的 -> 已通过的接口 -> 调用范围 -> 审批信息 中查看授权资源的「学校id」或「区域id」
  4409. //request.setPermissionId(seewoConfig.getSchoolId());
  4410. logger.info("入参:" + request);
  4411. logger.info("入参:" + JSON.toJSON(request));
  4412. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4413. PhotoServiceSavePhotosResult result = seewoClient.invoke(request);
  4414. logger.info("出参:" + result);
  4415. ObjectMapper objectMapper = new ObjectMapper();
  4416. XwBodyVo xwResult = objectMapper.readValue(result.getBody(), XwBodyVo.class);
  4417. if (!xwResult.getCode().equals("000000")) {
  4418. return CommonResult.fail("希沃平台:" + result.getMessage());
  4419. }
  4420. //endregion
  4421. return CommonResult.ok("200", "图片添加成功");
  4422. }
  4423. //endregion
  4424. //region 希沃批量新增学生信息
  4425. public CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> SeewoInsertBatchStudent
  4426. (SeewoClient seewoClient, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo> students, String
  4427. classUid) {
  4428. //region 希沃新增学生信息
  4429. //初始化客户端
  4430. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4431. StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
  4432. //请求体,MimeType为 application/json
  4433. StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
  4434. .build();
  4435. param.setRequestBody(requestBody);
  4436. //查询条件
  4437. StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
  4438. .appId(seewoConfig.getAppId())
  4439. .schoolUid(seewoConfig.getSchoolId())
  4440. .classUid(classUid)
  4441. .build();
  4442. requestBody.setQuery(query);
  4443. // 学生列表
  4444. query.setStudents(students);
  4445. query.setInPlaceOld(false);// 是否删除旧学生再保存
  4446. param.setRequestBody(requestBody);
  4447. StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
  4448. logger.info("入参:" + request);
  4449. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4450. //request.setServerUrl("https://openapi.test.seewo.com")
  4451. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4452. StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
  4453. logger.info("出参:" + result);
  4454. if (result == null) {
  4455. return CommonResult.fail("希沃学生数据新增失败!");
  4456. }
  4457. if (!result.getResponseBody().getCode().equals("000000")) {
  4458. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4459. }
  4460. return CommonResult.ok("200", "添加成功", result.getResponseBody().getData());
  4461. //endregion
  4462. }
  4463. //endregion
  4464. //region 希沃新增学生信息
  4465. public CommonResult<String> SeewoInsertStudent(SeewoClient seewoClient, String name, String cardNo, Integer
  4466. sexId, String Phone, String classUid) {
  4467. //region 希沃新增学生信息
  4468. //初始化客户端
  4469. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4470. StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
  4471. //请求体,MimeType为 application/json
  4472. StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
  4473. .build();
  4474. param.setRequestBody(requestBody);
  4475. //查询条件
  4476. StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
  4477. .appId(seewoConfig.getAppId())
  4478. .schoolUid(seewoConfig.getSchoolId())
  4479. .classUid(classUid)
  4480. .build();
  4481. requestBody.setQuery(query);
  4482. // 学生列表
  4483. StudentServiceBatchSaveClassStudentsParam.StudentInfo students = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  4484. .studentName(name)
  4485. .studentCode(cardNo)
  4486. .gender(sexId)
  4487. .phone(Phone == null ? "" : Phone)
  4488. .build();
  4489. query.setStudents(java.util.Collections.singletonList(students));
  4490. query.setInPlaceOld(false);// 是否删除旧学生再保存
  4491. param.setRequestBody(requestBody);
  4492. StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
  4493. logger.info("入参:" + request);
  4494. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4495. //request.setServerUrl("https://openapi.test.seewo.com")
  4496. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4497. StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
  4498. logger.info("出参:" + result);
  4499. if (result == null) {
  4500. return CommonResult.fail("希沃学生数据新增失败!");
  4501. }
  4502. if (!result.getResponseBody().getCode().equals("000000")) {
  4503. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4504. }
  4505. return CommonResult.ok("200", "添加成功", result.getResponseBody().getData().get(0).getUserUid());
  4506. //endregion
  4507. }
  4508. //endregion
  4509. //region 希沃更新学生信息
  4510. public CommonResult SeewoUpdateStudent(SeewoClient seewoClient, SmartUser su) {
  4511. //region 更新希沃学生信息
  4512. //初始化客户端
  4513. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4514. StudentServiceUpdateStudentInfoParam param = new StudentServiceUpdateStudentInfoParam();
  4515. //响应体,MimeType为 application/json
  4516. StudentServiceUpdateStudentInfoParam.RequestBody requestBody = StudentServiceUpdateStudentInfoParam.RequestBody.builder()
  4517. .build();
  4518. param.setRequestBody(requestBody);
  4519. //query
  4520. StudentServiceUpdateStudentInfoParam.Query query = StudentServiceUpdateStudentInfoParam.Query.builder()
  4521. .appId(seewoConfig.getAppId())
  4522. .schoolUid(seewoConfig.getSchoolId())
  4523. .studentUid(su.getXwStudentUid())
  4524. .studentCode(su.getCardNo())
  4525. .studentName(su.getName())
  4526. .build();
  4527. requestBody.setQuery(query);
  4528. param.setRequestBody(requestBody);
  4529. StudentServiceUpdateStudentInfoRequest request = new StudentServiceUpdateStudentInfoRequest(param);
  4530. logger.info("入参:" + request);
  4531. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4532. //request.setServerUrl("https://openapi.test.seewo.com")
  4533. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4534. StudentServiceUpdateStudentInfoResult result = seewoClient.invoke(request);
  4535. logger.info("出参:" + result);
  4536. if (result == null) {
  4537. return CommonResult.fail("希沃学生数据更新失败!");
  4538. }
  4539. if (!result.getResponseBody().getCode().equals("000000")) {
  4540. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4541. }
  4542. return CommonResult.ok("更新成功");
  4543. //endregion
  4544. }
  4545. //endregion
  4546. //region 希沃删除学生
  4547. public CommonResult SeewoDeleteStudent(SeewoClient seewoClient, String ClassUid, String CardNo) {
  4548. //初始化客户端
  4549. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4550. StudentServiceRemoveClassStudentsParam deleteParam = new StudentServiceRemoveClassStudentsParam();
  4551. //请求体,MimeType为 application/json
  4552. StudentServiceRemoveClassStudentsParam.JSONRequestBody deleteRequestBody = StudentServiceRemoveClassStudentsParam.JSONRequestBody.builder()
  4553. .build();
  4554. deleteParam.setRequestBody(deleteRequestBody);
  4555. //查询条件
  4556. StudentServiceRemoveClassStudentsParam.UnbindStudentQuery deleteQuery = StudentServiceRemoveClassStudentsParam.UnbindStudentQuery.builder()
  4557. .appId(seewoConfig.getAppId())
  4558. .schoolUid(seewoConfig.getSchoolId())
  4559. .classUid(ClassUid)
  4560. .studentCodes(java.util.Collections.singletonList(CardNo))
  4561. .build();
  4562. deleteRequestBody.setQuery(deleteQuery);
  4563. deleteParam.setRequestBody(deleteRequestBody);
  4564. StudentServiceRemoveClassStudentsRequest deleteRequest = new StudentServiceRemoveClassStudentsRequest(deleteParam);
  4565. logger.info("入参:" + deleteRequest);
  4566. //如果想要调用沙箱环境,请通过设置 deleteRequest 对象的 serverUrl 属性,如:
  4567. //deleteRequest.setServerUrl("https://openapi.test.seewo.com")
  4568. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4569. StudentServiceRemoveClassStudentsResult deleteResult = seewoClient.invoke(deleteRequest);
  4570. logger.info("出参:" + deleteResult);
  4571. if (deleteResult == null) {
  4572. return CommonResult.fail("希沃删除学生数据失败!");
  4573. }
  4574. if (!deleteResult.getResponseBody().getCode().equals("000000")) {
  4575. return CommonResult.fail("希沃平台:" + deleteResult.getResponseBody().getMessage());
  4576. }
  4577. return CommonResult.ok("删除成功");
  4578. }
  4579. //endregion
  4580. //region 希沃添加老师数据
  4581. //老师数据会根据手机号判断新增不新增
  4582. //手机号相同的情况下更新不新增
  4583. public CommonResult<String> SeewoInsertTeacher(SeewoClient seewoClient, String phone, String name, String
  4584. headImage) {
  4585. //region 希沃添加教师数据
  4586. //初始化客户端
  4587. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4588. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  4589. //请求体,MimeType为 application/json
  4590. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  4591. .build();
  4592. param.setRequestBody(requestBody);
  4593. //老师信息
  4594. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  4595. .appId(seewoConfig.getAppId())
  4596. .schoolUid(seewoConfig.getSchoolId())
  4597. .build();
  4598. requestBody.setQuery(query);
  4599. // 老师列表
  4600. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  4601. .account(phone)//用户账号
  4602. .name(name)//用户名字
  4603. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  4604. .teacherCode(phone)//教师工号
  4605. .photoUrl(headImage)//图片链接
  4606. .build();
  4607. query.setTeachers(java.util.Collections.singletonList(teachers));
  4608. param.setRequestBody(requestBody);
  4609. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  4610. logger.info("入参:" + request);
  4611. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4612. //request.setServerUrl("https://openapi.test.seewo.com")
  4613. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4614. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  4615. logger.info("出参:" + result);
  4616. if (result == null) {
  4617. return CommonResult.fail("希沃教师数据新增失败!");
  4618. }
  4619. if (!result.getResponseBody().getCode().equals("000000")) {
  4620. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4621. }
  4622. String teacherCode = phone;
  4623. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  4624. teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
  4625. }
  4626. return CommonResult.ok("200", "操作成功", teacherCode);
  4627. //endregion
  4628. }
  4629. //endregion
  4630. //region 希沃批量添加老师数据
  4631. //老师数据会根据手机号判断新增不新增
  4632. //手机号相同的情况下更新不新增
  4633. public CommonResult<List<TeacherServiceBatchSaveOrUpdateTeacherResult.TeacherBaseInfoDto>> SeewoInsertBatchTeacher
  4634. (SeewoClient seewoClient, List<TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery> teachers) {
  4635. //region 希沃添加教师数据
  4636. //初始化客户端
  4637. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4638. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  4639. //请求体,MimeType为 application/json
  4640. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  4641. .build();
  4642. param.setRequestBody(requestBody);
  4643. //老师信息
  4644. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  4645. .appId(seewoConfig.getAppId())
  4646. .schoolUid(seewoConfig.getSchoolId())
  4647. .build();
  4648. requestBody.setQuery(query);
  4649. query.setTeachers(teachers);
  4650. param.setRequestBody(requestBody);
  4651. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  4652. logger.info("入参:" + request);
  4653. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4654. //request.setServerUrl("https://openapi.test.seewo.com")
  4655. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4656. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  4657. logger.info("出参:" + result);
  4658. if (result == null) {
  4659. return CommonResult.fail("希沃教师数据新增失败!");
  4660. }
  4661. if (!result.getResponseBody().getCode().equals("000000")) {
  4662. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4663. }
  4664. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  4665. return CommonResult.ok("200", "操作成功", result.getResponseBody().getData());
  4666. }
  4667. return CommonResult.ok("200", "操作成功", null);
  4668. //endregion
  4669. }
  4670. //endregion
  4671. //region 希沃更新教师
  4672. public CommonResult<String> SeewoUpdateTeacher(SeewoClient seewoClient, String phone, String name, String
  4673. headImage) {
  4674. //region 希沃更新教师数据
  4675. //初始化客户端
  4676. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4677. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  4678. //请求体,MimeType为 application/json
  4679. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  4680. .build();
  4681. param.setRequestBody(requestBody);
  4682. //老师信息
  4683. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  4684. .appId(seewoConfig.getAppId())
  4685. .schoolUid(seewoConfig.getSchoolId())
  4686. .build();
  4687. requestBody.setQuery(query);
  4688. // 老师列表
  4689. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  4690. .account(phone)//用户账号
  4691. .name(name)//用户名字
  4692. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  4693. .teacherCode(phone)//教师工号
  4694. .photoUrl(headImage)//图片链接
  4695. .build();
  4696. query.setTeachers(java.util.Collections.singletonList(teachers));
  4697. param.setRequestBody(requestBody);
  4698. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  4699. logger.info("入参:" + request);
  4700. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4701. //request.setServerUrl("https://openapi.test.seewo.com")
  4702. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4703. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  4704. logger.info("出参:" + result);
  4705. if (result == null) {
  4706. return CommonResult.fail("希沃教师数据更新失败!");
  4707. }
  4708. if (!result.getResponseBody().getCode().equals("000000")) {
  4709. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4710. }
  4711. String teacherCode = phone;
  4712. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  4713. teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
  4714. }
  4715. return CommonResult.ok("200", "操作成功", teacherCode);
  4716. //endregion
  4717. }
  4718. //endregion
  4719. //region 希沃删除教师
  4720. public CommonResult SeewoDeleteTeacher(SeewoClient seewoClient, String phone) {
  4721. //region 希沃删除教师
  4722. //初始化客户端
  4723. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4724. TeacherServiceBatchRemoveTeachersParam param = new TeacherServiceBatchRemoveTeachersParam();
  4725. //响应体,MimeType为 application/json
  4726. TeacherServiceBatchRemoveTeachersParam.RequestBody requestBody = TeacherServiceBatchRemoveTeachersParam.RequestBody.builder()
  4727. .build();
  4728. param.setRequestBody(requestBody);
  4729. //query
  4730. TeacherServiceBatchRemoveTeachersParam.Query query = TeacherServiceBatchRemoveTeachersParam.Query.builder()
  4731. .appId(seewoConfig.getAppId())
  4732. .schoolUid(seewoConfig.getSchoolId())
  4733. .phones(java.util.Collections.singletonList(phone))
  4734. .build();
  4735. requestBody.setQuery(query);
  4736. param.setRequestBody(requestBody);
  4737. TeacherServiceBatchRemoveTeachersRequest request = new TeacherServiceBatchRemoveTeachersRequest(param);
  4738. logger.info("入参:" + request);
  4739. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4740. //request.setServerUrl("https://openapi.test.seewo.com")
  4741. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4742. TeacherServiceBatchRemoveTeachersResult result = seewoClient.invoke(request);
  4743. logger.info("出参:" + result);
  4744. if (result == null) {
  4745. return CommonResult.fail("希沃教师数据删除失败!");
  4746. }
  4747. if (!result.getResponseBody().getCode().equals("000000")) {
  4748. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4749. }
  4750. return CommonResult.ok("删除成功");
  4751. //endregion
  4752. }
  4753. //endregion
  4754. //region 希沃删除班主任
  4755. public CommonResult SeewoDeleteTeacherMaster(SeewoClient seewoClient, String classUid, String phone) {
  4756. //region 希沃删除班主任
  4757. //初始化客户端
  4758. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4759. TeacherServiceBatchRemoveClassMastersParam mastersParam = new TeacherServiceBatchRemoveClassMastersParam();
  4760. //响应体,MimeType为 application/json
  4761. TeacherServiceBatchRemoveClassMastersParam.RequestBody mastersRequestBody = TeacherServiceBatchRemoveClassMastersParam.RequestBody.builder()
  4762. .build();
  4763. mastersParam.setRequestBody(mastersRequestBody);
  4764. //query
  4765. TeacherServiceBatchRemoveClassMastersParam.Query mastersQuery = TeacherServiceBatchRemoveClassMastersParam.Query.builder()
  4766. .appId(seewoConfig.getAppId())
  4767. .schoolUid(seewoConfig.getSchoolId())
  4768. .classUid(classUid)
  4769. .userPhones(java.util.Collections.singletonList(phone))
  4770. .build();
  4771. mastersRequestBody.setQuery(mastersQuery);
  4772. mastersParam.setRequestBody(mastersRequestBody);
  4773. TeacherServiceBatchRemoveClassMastersRequest mastersRequest = new TeacherServiceBatchRemoveClassMastersRequest(mastersParam);
  4774. logger.info("入参:" + mastersRequest);
  4775. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4776. //request.setServerUrl("https://openapi.test.seewo.com")
  4777. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4778. TeacherServiceBatchRemoveClassMastersResult masterResult = seewoClient.invoke(mastersRequest);
  4779. logger.info("出参:" + masterResult);
  4780. if (masterResult == null) {
  4781. return CommonResult.fail("希沃教师数据删除失败!");
  4782. }
  4783. if (!masterResult.getResponseBody().getCode().equals("000000")) {
  4784. return CommonResult.fail("希沃平台:" + masterResult.getResponseBody().getMessage());
  4785. }
  4786. return CommonResult.ok("删除成功");
  4787. //endregion
  4788. }
  4789. //endregion
  4790. //region 希沃推送班主任
  4791. public CommonResult SeewoPushMaster(SeewoClient seewoClient, String phone, String classUid) {
  4792. //region 将班主任推送到希沃
  4793. //初始化客户端
  4794. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4795. TeacherServiceBatchSetClassMastersParam teacherClassParam = new TeacherServiceBatchSetClassMastersParam();
  4796. //响应体,MimeType为 application/json
  4797. TeacherServiceBatchSetClassMastersParam.RequestBody teacherClassRequestBody = TeacherServiceBatchSetClassMastersParam.RequestBody.builder()
  4798. .build();
  4799. teacherClassParam.setRequestBody(teacherClassRequestBody);
  4800. //query
  4801. List<String> teacherPhones = new ArrayList<>();
  4802. teacherPhones.add(phone);
  4803. TeacherServiceBatchSetClassMastersParam.Query teacherClassQuery = TeacherServiceBatchSetClassMastersParam.Query.builder()
  4804. .appId(seewoConfig.getAppId())
  4805. .schoolUid(seewoConfig.getSchoolId())
  4806. .classUid(classUid)
  4807. .userPhones(teacherPhones)
  4808. .build();
  4809. teacherClassRequestBody.setQuery(teacherClassQuery);
  4810. teacherClassParam.setRequestBody(teacherClassRequestBody);
  4811. TeacherServiceBatchSetClassMastersRequest teacherClassRequest = new TeacherServiceBatchSetClassMastersRequest(teacherClassParam);
  4812. logger.info("入参:" + teacherClassRequest);
  4813. //如果想要调用沙箱环境,请通过设置 teacherClassRequest 对象的 serverUrl 属性,如:
  4814. //request.setServerUrl("https://openapi.test.seewo.com")
  4815. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4816. TeacherServiceBatchSetClassMastersResult teacherClassResult = seewoClient.invoke(teacherClassRequest);
  4817. logger.info("出参:" + teacherClassResult);
  4818. if (teacherClassResult == null) {
  4819. return CommonResult.fail("希沃教师数据新增失败!");
  4820. }
  4821. if (!teacherClassResult.getResponseBody().getCode().equals("000000")) {
  4822. return CommonResult.fail("希沃平台:" + teacherClassResult.getResponseBody().getMessage());
  4823. }
  4824. return CommonResult.ok("添加成功");
  4825. //endregion
  4826. }
  4827. //endregion
  4828. //region 希沃新增编辑学生家长信息
  4829. public CommonResult insertOrUpdateStudentParent(SeewoClient seewoClient, List<SmartUser> studentDatas, String name, String phone, boolean isInsert) {
  4830. //region 希沃新增编辑学生家长信息
  4831. //学生与家长列表,最大100条
  4832. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  4833. List<SmartFamilyIndex> insertIndexs = new ArrayList<>();
  4834. for (SmartUser student : studentDatas) {
  4835. int index = 0;
  4836. if (isInsert) {
  4837. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(student.getCardNo());
  4838. if (indexs != null && indexs.size() >= 4) {
  4839. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  4840. }
  4841. if (indexs != null) {
  4842. long existCount = indexs.stream().filter(e -> e.getParentPhone().equals(phone)).count();
  4843. if (existCount > 0) {
  4844. return CommonResult.fail("当前家长手机号已绑定该学生,请勿重复绑定");
  4845. }
  4846. for (SmartFamilyIndex data : indexs) {
  4847. if (data.getIndexData().intValue() == index && index < 3) {
  4848. index++;
  4849. continue;
  4850. } else {
  4851. break;
  4852. }
  4853. }
  4854. }
  4855. SmartFamilyIndex insertFamily = new SmartFamilyIndex();
  4856. insertFamily.setParentPhone(phone);
  4857. insertFamily.setStudentNo(student.getCardNo());
  4858. insertFamily.setIndexData(index);
  4859. insertIndexs.add(insertFamily);
  4860. } else {
  4861. SmartFamilyIndex familyIndex = smartFamilyIndexService.queryFamilyByPhoneCardNo(phone, student.getCardNo());
  4862. if (familyIndex == null) {
  4863. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(student.getCardNo());
  4864. if (indexs != null && indexs.size() >= 4) {
  4865. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  4866. }
  4867. if (indexs != null) {
  4868. for (SmartFamilyIndex data : indexs) {
  4869. if (data.getIndexData().intValue() == index && index < 3) {
  4870. index++;
  4871. continue;
  4872. } else {
  4873. break;
  4874. }
  4875. }
  4876. }
  4877. SmartFamilyIndex insertFamily = new SmartFamilyIndex();
  4878. insertFamily.setParentPhone(phone);
  4879. insertFamily.setStudentNo(student.getCardNo());
  4880. insertFamily.setIndexData(index);
  4881. insertIndexs.add(insertFamily);
  4882. } else {
  4883. familyIndex.setStudentNo(student.getCardNo());
  4884. familyIndex.setParentPhone(phone);
  4885. index = familyIndex.getIndexData();
  4886. int updateFamily = smartFamilyIndexService.updateSmartFamily(familyIndex);
  4887. if (updateFamily <= 0) {
  4888. return CommonResult.fail("绑定失败");
  4889. }
  4890. }
  4891. }
  4892. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  4893. .studentCode(student.getCardNo())
  4894. .build();
  4895. studentParents.add(students);
  4896. //家长列表,最多4个
  4897. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  4898. .name(name)
  4899. .phone(phone)
  4900. .index(index)
  4901. .build();
  4902. students.setParents(java.util.Collections.singletonList(parents));
  4903. }
  4904. if (insertIndexs != null && insertIndexs.size() > 0) {
  4905. smartFamilyIndexService.saveBatch(insertIndexs);
  4906. }
  4907. //初始化客户端
  4908. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4909. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  4910. //响应体,MimeType为 application/json
  4911. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  4912. .build();
  4913. param.setRequestBody(requestBody);
  4914. //query
  4915. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  4916. .appId(seewoConfig.getAppId())
  4917. .schoolUid(seewoConfig.getSchoolId())
  4918. .build();
  4919. requestBody.setQuery(query);
  4920. query.setStudentParents(studentParents);
  4921. param.setRequestBody(requestBody);
  4922. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  4923. logger.info("入参:" + request);
  4924. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  4925. //request.setServerUrl("https://openapi.test.seewo.com")
  4926. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4927. ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
  4928. logger.info("出参:" + result);
  4929. if (result == null) {
  4930. return CommonResult.fail("希沃学生家长数据更新失败!");
  4931. }
  4932. if (!result.getResponseBody().getCode().equals("000000")) {
  4933. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  4934. }
  4935. return CommonResult.ok("新增成功");
  4936. //endregion
  4937. }
  4938. //endregion
  4939. //region 希沃删除学生原有的家长关系
  4940. public CommonResult deleteOldStudentParentShip(SeewoClient seewoClient, String cardNo, List<String> phones) throws
  4941. JsonProcessingException {
  4942. //region 删除原有的家长关系
  4943. //初始化客户端
  4944. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4945. ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
  4946. //请求体,MimeType为 application/json
  4947. ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
  4948. .build();
  4949. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  4950. //
  4951. ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
  4952. .appId(seewoConfig.getAppId())
  4953. .schoolUid(seewoConfig.getSchoolId())
  4954. //.studentCodes(java.util.Collections.singletonList(cardNo))//传卡号会把该学生的家长都删掉
  4955. .parentPhones(phones)
  4956. .build();
  4957. deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
  4958. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  4959. ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
  4960. logger.info("入参:" + deleteOldFamilyRequest);
  4961. //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
  4962. //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
  4963. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  4964. ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
  4965. logger.info("出参:" + deleteOldFamilyResult);
  4966. if (deleteOldFamilyResult == null) {
  4967. return CommonResult.fail("希沃家长数据删除失败!");
  4968. }
  4969. if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
  4970. ObjectMapper objectMapper = new ObjectMapper();
  4971. XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
  4972. if (!result.getCode().equals("000000")) {
  4973. return CommonResult.fail("希沃平台:" + result.getMessage());
  4974. }
  4975. } else {
  4976. if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
  4977. return CommonResult.fail("希沃平台:" + deleteOldFamilyResult.getResponseBody().getResult().getMessage());
  4978. }
  4979. }
  4980. return CommonResult.ok("删除成功");
  4981. //endregion
  4982. }
  4983. //endregion
  4984. //region 希沃删除原有的家长关系
  4985. public CommonResult deleteOldParentShip(SeewoClient seewoClient, List<SmartUser> studentDatas, String phone) throws
  4986. JsonProcessingException {
  4987. //region 删除原有的家长关系
  4988. //初始化客户端
  4989. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  4990. ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
  4991. //请求体,MimeType为 application/json
  4992. ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
  4993. .build();
  4994. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  4995. //
  4996. ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
  4997. .appId(seewoConfig.getAppId())
  4998. .schoolUid(seewoConfig.getSchoolId())
  4999. //.studentCodes(studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList()))//不能传卡号 传了卡号会把该学生的家长都删掉
  5000. .parentPhones(java.util.Collections.singletonList(phone))
  5001. .build();
  5002. deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
  5003. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  5004. ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
  5005. logger.info("入参:" + deleteOldFamilyRequest);
  5006. logger.info("入参:" + JSON.toJSON(deleteOldFamilyRequest));
  5007. //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
  5008. //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
  5009. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  5010. ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
  5011. logger.info("出参:" + deleteOldFamilyResult);
  5012. if (deleteOldFamilyResult == null) {
  5013. return CommonResult.fail("希沃家长数据删除失败!");
  5014. }
  5015. if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
  5016. ObjectMapper objectMapper = new ObjectMapper();
  5017. XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
  5018. if (!result.getCode().equals("000000")) {
  5019. return CommonResult.fail("希沃平台:" + result.getMessage());
  5020. }
  5021. } else {
  5022. if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
  5023. return CommonResult.fail("希沃平台:" + deleteOldFamilyResult.getResponseBody().getResult().getMessage());
  5024. }
  5025. }
  5026. return CommonResult.ok("删除成功");
  5027. //endregion
  5028. }
  5029. //endregion
  5030. //endregion
  5031. //region 百胜增删改查方法
  5032. //region 百胜更新学生信息 给批量导入用的
  5033. public CommonResult bsEUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws
  5034. Exception {
  5035. //region 更新百胜学生信息
  5036. String appId = controlConfig.getAppId();
  5037. String schoolno = controlConfig.getSchoolCode();
  5038. String timestamp = TimeExchange.DateNowTimeStamo();
  5039. String appSecret = controlConfig.getAppSecret();
  5040. String url = controlConfig.getUrl() + "student/update";
  5041. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
  5042. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  5043. JSONObject jsonobject = new JSONObject();
  5044. jsonobject.put("appid", appId);
  5045. 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 + "\"}";
  5046. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5047. jsonobject.put("data", aesStr);
  5048. jsonobject.put("schoolno", schoolno);
  5049. jsonobject.put("timestamp", timestamp);
  5050. 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;
  5051. String sign = CommonUtil.MD5(md5Str);
  5052. //sign签名
  5053. jsonobject.put("sign", sign);
  5054. //返回的结果中 code为1表示成功
  5055. String bsResult = RequestUtils.httpPosts(url, jsonobject.toJSONString());
  5056. ObjectMapper objectMapper = new ObjectMapper();
  5057. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  5058. if (!bsResult.contains("更新成功")) {
  5059. return CommonResult.fail("百胜平台:" + result.getMsg());
  5060. }
  5061. return CommonResult.ok("更新成功");
  5062. //endregion
  5063. }
  5064. //endregion
  5065. //region 百胜更新学生信息 给设置时间组接口用的
  5066. public CommonResult bsTUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws
  5067. Exception {
  5068. //region 更新百胜学生信息
  5069. String appId = controlConfig.getAppId();
  5070. String schoolno = controlConfig.getSchoolCode();
  5071. String timestamp = TimeExchange.DateNowTimeStamo();
  5072. String appSecret = controlConfig.getAppSecret();
  5073. String url = controlConfig.getUrl() + "student/update";
  5074. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
  5075. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  5076. JSONObject jsonobject = new JSONObject();
  5077. jsonobject.put("appid", appId);
  5078. 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 + "\"}";
  5079. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5080. jsonobject.put("data", aesStr);
  5081. jsonobject.put("schoolno", schoolno);
  5082. jsonobject.put("timestamp", timestamp);
  5083. 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;
  5084. String sign = CommonUtil.MD5(md5Str);
  5085. //sign签名
  5086. jsonobject.put("sign", sign);
  5087. //返回的结果中 code为1表示成功
  5088. String bsResult = RequestUtils.httpPosts(url, jsonobject.toJSONString());
  5089. ObjectMapper objectMapper = new ObjectMapper();
  5090. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  5091. if (!bsResult.contains("更新成功")) {
  5092. return CommonResult.fail("百胜平台:" + result.getMsg());
  5093. }
  5094. return CommonResult.ok("更新成功");
  5095. //endregion
  5096. }
  5097. //endregion
  5098. //region 百胜更新学生信息
  5099. public CommonResult bsUpdateStudent(SmartUser su, String bsClassNo, String startDate, String endDate) throws Exception {
  5100. //region 更新百胜学生信息
  5101. String appId = controlConfig.getAppId();
  5102. String schoolno = controlConfig.getSchoolCode();
  5103. String timestamp = TimeExchange.DateNowTimeStamo();
  5104. String appSecret = controlConfig.getAppSecret();
  5105. String url = controlConfig.getUrl() + "student/update";
  5106. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"student_idcard\":\"" + su.getIdCard() : "\",\"student_idcard\":\"" + "";
  5107. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  5108. JSONObject jsonobject = new JSONObject();
  5109. jsonobject.put("appid", appId);
  5110. 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 + "\"}";
  5111. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5112. jsonobject.put("data", aesStr);
  5113. jsonobject.put("schoolno", schoolno);
  5114. jsonobject.put("timestamp", timestamp);
  5115. 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;
  5116. String sign = CommonUtil.MD5(md5Str);
  5117. //sign签名
  5118. jsonobject.put("sign", sign);
  5119. //返回的结果中 code为1表示成功
  5120. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  5121. ObjectMapper objectMapper = new ObjectMapper();
  5122. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  5123. if (!bsResult.contains("更新成功")) {
  5124. return CommonResult.fail("百胜平台:" + result.getMsg());
  5125. }
  5126. return CommonResult.ok("更新成功");
  5127. //endregion
  5128. }
  5129. //endregion
  5130. //region 百胜新增学生
  5131. public CommonResult<String> bsInsertStudent(String name, String cardNo, Integer sexId, String
  5132. headImage, Integer timeGroupId, String bsClassNo, String startDate, String endDate, String idCard) throws
  5133. Exception {
  5134. //region 百胜新增学生信息
  5135. String appId = controlConfig.getAppId();
  5136. String schoolno = controlConfig.getSchoolCode();
  5137. String timestamp = TimeExchange.DateNowTimeStamo();
  5138. String appSecret = controlConfig.getAppSecret();
  5139. String url = controlConfig.getUrl() + "student/create";
  5140. String idCardStr = org.springframework.util.StringUtils.hasText(idCard) ? "\",\"student_idcard\":\"" + idCard : "\",\"student_idcard\":\"" + "";
  5141. String bsGroupNo = eGroupTime(timeGroupId);
  5142. JSONObject jsonobject = new JSONObject();
  5143. jsonobject.put("appid", appId);
  5144. 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 + "\"}";
  5145. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5146. jsonobject.put("data", aesStr);
  5147. jsonobject.put("schoolno", schoolno);
  5148. jsonobject.put("timestamp", timestamp);
  5149. 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;
  5150. String sign = CommonUtil.MD5(md5Str);
  5151. //sign签名
  5152. jsonobject.put("sign", sign);
  5153. //返回的结果中 code为1表示成功
  5154. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  5155. ObjectMapper objectMapper = new ObjectMapper();
  5156. BsStudentVo grade = objectMapper.readValue(bsResult, BsStudentVo.class);
  5157. if (!bsResult.contains("添加成功")) {
  5158. return CommonResult.fail("百胜平台:" + grade.getMsg());
  5159. }
  5160. // URL解码
  5161. String decodedUrl = URLDecoder.decode(grade.getData(), "UTF-8");
  5162. BsStudentNoVo studentNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStudentNoVo.class);
  5163. return CommonResult.ok("200", "新增成功", studentNo.getStudent_no());
  5164. //endregion
  5165. }
  5166. //endregion
  5167. //region 百胜删除学生
  5168. public CommonResult bsDeleteStudent(SmartUser su) throws Exception {
  5169. //region 百胜删除学生
  5170. String appId = controlConfig.getAppId();
  5171. String schoolno = controlConfig.getSchoolCode();
  5172. String timestamp = TimeExchange.DateNowTimeStamo();
  5173. String appSecret = controlConfig.getAppSecret();
  5174. String url = controlConfig.getUrl() + "student/delete";
  5175. JSONObject jsonobject = new JSONObject();
  5176. jsonobject.put("appid", appId);
  5177. String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\"}";
  5178. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5179. jsonobject.put("data", aesStr);
  5180. jsonobject.put("schoolno", schoolno);
  5181. jsonobject.put("timestamp", timestamp);
  5182. String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  5183. String sign = CommonUtil.MD5(md5Str);
  5184. //sign签名
  5185. jsonobject.put("sign", sign);
  5186. //返回的结果中 code为1表示成功
  5187. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  5188. ObjectMapper objectMapper = new ObjectMapper();
  5189. BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
  5190. if (!bsResult.contains("删除学生成功")) {
  5191. return CommonResult.fail("百胜平台:" + result.getMsg());
  5192. }
  5193. return CommonResult.ok("操作成功");
  5194. //endregion
  5195. }
  5196. //endregion
  5197. //region 百胜添加教师
  5198. public CommonResult<String> bsInsertTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
  5199. Exception {
  5200. //region 百胜添加教师数据
  5201. String appId = controlConfig.getAppId();
  5202. String schoolno = controlConfig.getSchoolCode();
  5203. String timestamp = TimeExchange.DateNowTimeStamo();
  5204. String appSecret = controlConfig.getAppSecret();
  5205. String url = controlConfig.getUrl() + "staff/create";
  5206. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"staff_idcard\":\"" + su.getIdCard() : "\",\"staff_idcard\":\"" + "";
  5207. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  5208. JSONObject jsonobject = new JSONObject();
  5209. jsonobject.put("appid", appId);
  5210. 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 + "\"}";
  5211. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5212. jsonobject.put("data", aesStr);
  5213. jsonobject.put("schoolno", schoolno);
  5214. jsonobject.put("timestamp", timestamp);
  5215. 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;
  5216. String sign = CommonUtil.MD5(md5Str);
  5217. //sign签名
  5218. jsonobject.put("sign", sign);
  5219. //返回的结果中 code为1表示成功
  5220. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  5221. ObjectMapper objectMapper = new ObjectMapper();
  5222. BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
  5223. if (!bsResult.contains("添加成功")) {
  5224. return CommonResult.fail("百胜平台:" + staff.getMsg());
  5225. }
  5226. // URL解码
  5227. String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
  5228. BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
  5229. su.setBsStaffCode(staffNo.getStaff_no());
  5230. return CommonResult.ok("200", "新增成功", staffNo.getStaff_no());
  5231. //endregion
  5232. }
  5233. //endregion
  5234. //region 百胜更新教师
  5235. public CommonResult<String> updateBsTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
  5236. Exception {
  5237. //region 百胜更新教师数据
  5238. String appId = controlConfig.getAppId();
  5239. String schoolno = controlConfig.getSchoolCode();
  5240. String timestamp = TimeExchange.DateNowTimeStamo();
  5241. String appSecret = controlConfig.getAppSecret();
  5242. String url = controlConfig.getUrl() + "staff/update";
  5243. String idCardStr = org.springframework.util.StringUtils.hasText(su.getIdCard()) ? "\",\"staff_idcard\":\"" + su.getIdCard() : "\",\"staff_idcard\":\"" + "";
  5244. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  5245. JSONObject jsonobject = new JSONObject();
  5246. jsonobject.put("appid", appId);
  5247. 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 + "\"}";
  5248. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5249. jsonobject.put("data", aesStr);
  5250. jsonobject.put("schoolno", schoolno);
  5251. jsonobject.put("timestamp", timestamp);
  5252. 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;
  5253. String sign = CommonUtil.MD5(md5Str);
  5254. //sign签名
  5255. jsonobject.put("sign", sign);
  5256. //返回的结果中 code为1表示成功
  5257. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  5258. ObjectMapper objectMapper = new ObjectMapper();
  5259. BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
  5260. if (!bsResult.contains("更新成功")) {
  5261. return CommonResult.fail("百胜平台:" + staff.getMsg());
  5262. }
  5263. // URL解码
  5264. String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
  5265. BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
  5266. return CommonResult.ok("200", "操作成功", staffNo.getStaff_no());
  5267. //endregion
  5268. }
  5269. //endregion
  5270. //region百胜删除教师
  5271. public CommonResult bsDeleteTeacher(String staffNo) throws Exception {
  5272. //region 百胜删除教师
  5273. String appId = controlConfig.getAppId();
  5274. String schoolno = controlConfig.getSchoolCode();
  5275. String timestamp = TimeExchange.DateNowTimeStamo();
  5276. String appSecret = controlConfig.getAppSecret();
  5277. String url = controlConfig.getUrl() + "staff/delete";
  5278. JSONObject jsonobject = new JSONObject();
  5279. jsonobject.put("appid", appId);
  5280. String str = "{\"staff_no\":\"" + staffNo + "\"}";
  5281. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  5282. jsonobject.put("data", aesStr);
  5283. jsonobject.put("schoolno", schoolno);
  5284. jsonobject.put("timestamp", timestamp);
  5285. String md5Str = "appid=" + appId + "&data={\"staff_no\":\"" + staffNo + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  5286. String sign = CommonUtil.MD5(md5Str);
  5287. //sign签名
  5288. jsonobject.put("sign", sign);
  5289. //返回的结果中 code为1表示成功
  5290. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  5291. ObjectMapper objectMapper = new ObjectMapper();
  5292. BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
  5293. if (!bsResult.contains("删除员工成功")) {
  5294. return CommonResult.fail("百胜平台:" + result.getMsg());
  5295. }
  5296. return CommonResult.ok("删除成功");
  5297. //endregion
  5298. }
  5299. //endregion
  5300. //endregion
  5301. //region 用户分页数据
  5302. /**
  5303. * 用户分页数据查询
  5304. *
  5305. * @param currentPage 当前页数
  5306. * @param pageCount 一页数据条数
  5307. * @param departmentId 部门ID
  5308. * @return
  5309. */
  5310. @Override
  5311. @DESRespondSecret(validated = true)
  5312. public CommonResult queryPageSmartUser(int currentPage, int pageCount, Integer departmentId, String
  5313. name, String userhead) {
  5314. //region 角色判断
  5315. String userID = AesUtils.decrypt(userhead);
  5316. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  5317. if (operateData == null) {
  5318. return CommonResult.fail("用户信息不合法,无法查看");
  5319. }
  5320. QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
  5321. queryWrapper.eq("user_id", operateData.getId());
  5322. List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
  5323. if (authorities == null) {
  5324. return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
  5325. }
  5326. if (authorities.size() <= 0) {
  5327. return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
  5328. }
  5329. List<String> viewAuthors = new ArrayList<>();//部门查看权限
  5330. List<String> manageAuthors = new ArrayList<>();//部门管理权限
  5331. for (SmartAuthority author : authorities) {
  5332. List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
  5333. if (views != null && views.size() > 0) {
  5334. viewAuthors.addAll(views);
  5335. }
  5336. List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
  5337. if (manages != null && manages.size() > 0) {
  5338. manageAuthors.addAll(manages);
  5339. }
  5340. }
  5341. List<String> AllAuths = new ArrayList<>();
  5342. AllAuths.addAll(viewAuthors);
  5343. AllAuths.addAll(manageAuthors);
  5344. AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
  5345. //endregion
  5346. //获取该部门下的所有子级部门ID
  5347. List<Integer> childDepartmentIds = new ArrayList<>();
  5348. List<SmartDepartment> departments = smartDepartmentService.list(null);
  5349. childDepartmentIds.add(departmentId);
  5350. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  5351. if (departmentId == null) {
  5352. childDepartmentIds = null;
  5353. }
  5354. List<Integer> authDepartments = new ArrayList<>();
  5355. for (Integer child : childDepartmentIds) {
  5356. if (AllAuths.contains(String.valueOf(child))) {
  5357. authDepartments.add(child);
  5358. }
  5359. }
  5360. PageUtils<UserVo> result = null;
  5361. if (authDepartments != null && authDepartments.size() > 0) {
  5362. result = smartUserService.querySmartUserPages(currentPage, pageCount, authDepartments, name);
  5363. } else {
  5364. IPage<UserVo> userData = new Page<>();
  5365. result = new PageUtils<UserVo>(userData);
  5366. }
  5367. if (result != null && result.getList() != null) {
  5368. List<Integer> studentIds = new ArrayList<>();
  5369. List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
  5370. for (String studentStr : studentStrs) {
  5371. if (!ObjectUtils.isEmpty(studentStr)) {
  5372. studentIds.add(Integer.valueOf(studentStr));
  5373. }
  5374. }
  5375. List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
  5376. List<SmartClass> classs = smartClassService.list(null);
  5377. List<SmartIdentity> idnetitys = smartIdentityService.list(null);
  5378. List<SmartTimeGroup> timeGroups = smartTimeGroupService.list(null);
  5379. List<Integer> userIds = result.getList().stream().map(UserVo::getId).collect(Collectors.toList());
  5380. List<UserSubjectVo> teachings = smartTeachingService.querySmartTeachings(userIds);
  5381. for (UserVo data : result.getList()) {
  5382. //region 任课数据
  5383. List<UserSubjectVo> ownerTeachings = teachings.stream().filter(e -> e.getUserId().equals(data.getId())).collect(Collectors.toList());
  5384. if (ownerTeachings != null && ownerTeachings.size() > 0) {
  5385. List<isrRequest> subjectVos = new ArrayList<>();
  5386. for (UserSubjectVo ownerTeaching : ownerTeachings) {
  5387. isrRequest ir = new isrRequest();
  5388. Integer[] ids = new Integer[3];
  5389. //用这种方式能避免重复引用
  5390. //简单说,重复引用就是一个集合/对象中的多个元素/属性同时引用同一对象,循环引用就是集合/对象中的多个元素/属性存在相互引用导致循环。
  5391. Integer subjectId = new Integer(ownerTeaching.getSubjectId());
  5392. ids[0] = subjectId;
  5393. Integer gradeId = new Integer(ownerTeaching.getGradeId());
  5394. ids[1] = gradeId;
  5395. Integer classId = new Integer(ownerTeaching.getClassId());
  5396. ids[2] = classId;
  5397. ir.setIds(Arrays.asList(ids));
  5398. subjectVos.add(ir);
  5399. }
  5400. data.setSubjectVos(subjectVos);
  5401. }
  5402. //endregion
  5403. //时间组
  5404. Optional<SmartTimeGroup> oTimeGroup = timeGroups.stream().filter(e -> e.getId().equals(data.getTimeGroupId())).findFirst();
  5405. if (oTimeGroup != null && oTimeGroup.isPresent()) {
  5406. data.setTimeGroupName(oTimeGroup.get().getName());
  5407. }
  5408. Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
  5409. if (identityData != null && identityData.isPresent()) {
  5410. data.setIdentity(identityData.get().getName());
  5411. }
  5412. data.setSex(eSexStatu.stringOf(data.getSexId()));
  5413. Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  5414. if (departmentData != null && departmentData.isPresent()) {
  5415. data.setDepartment(departmentData.get().getName());
  5416. }
  5417. Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
  5418. if (nowClass != null && nowClass.isPresent()) {
  5419. data.setClassStr(nowClass.get().getName());
  5420. }
  5421. List<AffiliateUserVo> datas = new ArrayList<>();
  5422. if (data.getAffiliate() != null) {
  5423. List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
  5424. for (String a : affiliates) {
  5425. if (!ObjectUtils.isEmpty(a)) {
  5426. Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
  5427. if (student != null && student.isPresent()) {
  5428. AffiliateUserVo affiliate = new AffiliateUserVo();
  5429. affiliate.setId(student.get().getId());
  5430. affiliate.setName(student.get().getName());
  5431. affiliate.setCardNo(student.get().getCardNo());
  5432. affiliate.setDepartmentId(student.get().getDepartmentId());
  5433. datas.add(affiliate);
  5434. }
  5435. }
  5436. }
  5437. }
  5438. data.setAffiliates(datas);
  5439. }
  5440. }
  5441. return CommonResult.ok(result);
  5442. }
  5443. //endregion
  5444. //region 用户分页数据
  5445. /**
  5446. * 用户分页数据查询
  5447. *
  5448. * @param currentPage 当前页数
  5449. * @param pageCount 一页数据条数
  5450. * @param departmentId 部门ID
  5451. * @return
  5452. */
  5453. @Override
  5454. @DESRespondSecret(validated = true)
  5455. public CommonResult queryPageSmartUserNoAuth(int currentPage, int pageCount, Integer departmentId, String
  5456. name, String userhead) {
  5457. //region 角色判断
  5458. String userID = AesUtils.decrypt(userhead);
  5459. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  5460. if (operateData == null) {
  5461. return CommonResult.fail("用户信息不合法,无法查看");
  5462. }
  5463. //endregion
  5464. //获取该部门下的所有子级部门ID
  5465. List<Integer> childDepartmentIds = new ArrayList<>();
  5466. List<SmartDepartment> departments = smartDepartmentService.list(null);
  5467. childDepartmentIds.add(departmentId);
  5468. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  5469. if (departmentId == null) {
  5470. childDepartmentIds = null;
  5471. }
  5472. PageUtils<UserVo> result = null;
  5473. if (childDepartmentIds != null && childDepartmentIds.size() > 0) {
  5474. result = smartUserService.querySmartUserPages(currentPage, pageCount, childDepartmentIds, name);
  5475. } else {
  5476. IPage<UserVo> userData = new Page<>();
  5477. result = new PageUtils<UserVo>(userData);
  5478. }
  5479. if (result != null && result.getList() != null) {
  5480. List<Integer> studentIds = new ArrayList<>();
  5481. List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
  5482. for (String studentStr : studentStrs) {
  5483. if (!ObjectUtils.isEmpty(studentStr)) {
  5484. studentIds.add(Integer.valueOf(studentStr));
  5485. }
  5486. }
  5487. List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
  5488. List<SmartClass> classs = smartClassService.list(null);
  5489. List<SmartIdentity> idnetitys = smartIdentityService.list(null);
  5490. for (UserVo data : result.getList()) {
  5491. data.setTimeGroupName(eGroupTime(data.getTimeGroupId()));
  5492. Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
  5493. if (identityData != null && identityData.isPresent()) {
  5494. data.setIdentity(identityData.get().getName());
  5495. }
  5496. data.setSex(eSexStatu.stringOf(data.getSexId()));
  5497. Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  5498. if (departmentData != null && departmentData.isPresent()) {
  5499. data.setDepartment(departmentData.get().getName());
  5500. }
  5501. Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
  5502. if (nowClass != null && nowClass.isPresent()) {
  5503. data.setClassStr(nowClass.get().getName());
  5504. }
  5505. List<AffiliateUserVo> datas = new ArrayList<>();
  5506. if (data.getAffiliate() != null) {
  5507. List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
  5508. for (String a : affiliates) {
  5509. if (!ObjectUtils.isEmpty(a)) {
  5510. Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
  5511. if (student != null && student.isPresent()) {
  5512. AffiliateUserVo affiliate = new AffiliateUserVo();
  5513. affiliate.setId(student.get().getId());
  5514. affiliate.setName(student.get().getName());
  5515. affiliate.setCardNo(student.get().getCardNo());
  5516. affiliate.setDepartmentId(student.get().getDepartmentId());
  5517. datas.add(affiliate);
  5518. }
  5519. }
  5520. }
  5521. }
  5522. data.setAffiliates(datas);
  5523. }
  5524. }
  5525. return CommonResult.ok(result);
  5526. }
  5527. //endregion
  5528. //region 导出表头列表集合
  5529. @Override
  5530. @DESRespondSecret(validated = false)
  5531. public CommonResult gauageOutfit() {
  5532. int i = 1;
  5533. List<gauageOutfitVo> govs = new ArrayList<>();
  5534. //region 学号
  5535. gauageOutfitVo cardNo = new gauageOutfitVo();
  5536. cardNo.setId(i);
  5537. cardNo.setName("学号");
  5538. govs.add(cardNo);
  5539. i++;
  5540. //endregion
  5541. //region 姓名
  5542. gauageOutfitVo name = new gauageOutfitVo();
  5543. name.setId(i);
  5544. name.setName("姓名");
  5545. govs.add(name);
  5546. i++;
  5547. //endregion
  5548. //region 身份
  5549. gauageOutfitVo identity = new gauageOutfitVo();
  5550. identity.setId(i);
  5551. identity.setName("身份");
  5552. govs.add(identity);
  5553. i++;
  5554. //endregion
  5555. //region 职务
  5556. gauageOutfitVo duties = new gauageOutfitVo();
  5557. duties.setId(i);
  5558. duties.setName("职务");
  5559. govs.add(duties);
  5560. i++;
  5561. //endregion
  5562. //region 身份证号
  5563. gauageOutfitVo idcard = new gauageOutfitVo();
  5564. idcard.setId(i);
  5565. idcard.setName("身份证号");
  5566. govs.add(idcard);
  5567. i++;
  5568. //endregion
  5569. //region 性别
  5570. gauageOutfitVo sex = new gauageOutfitVo();
  5571. sex.setId(i);
  5572. sex.setName("性别");
  5573. govs.add(sex);
  5574. i++;
  5575. //endregion
  5576. //region 部门
  5577. gauageOutfitVo department = new gauageOutfitVo();
  5578. department.setId(i);
  5579. department.setName("部门");
  5580. govs.add(department);
  5581. i++;
  5582. //endregion
  5583. //region 人脸照片
  5584. gauageOutfitVo iamge = new gauageOutfitVo();
  5585. iamge.setId(i);
  5586. iamge.setName("人脸照片");
  5587. govs.add(iamge);
  5588. i++;
  5589. //endregion
  5590. //region 年级
  5591. gauageOutfitVo grade = new gauageOutfitVo();
  5592. grade.setId(i);
  5593. grade.setName("年级");
  5594. govs.add(grade);
  5595. i++;
  5596. //endregion
  5597. //region 班级
  5598. gauageOutfitVo classes = new gauageOutfitVo();
  5599. classes.setId(i);
  5600. classes.setName("班级");
  5601. govs.add(classes);
  5602. i++;
  5603. //endregion
  5604. //region 时间组
  5605. gauageOutfitVo timeGroup = new gauageOutfitVo();
  5606. timeGroup.setId(i);
  5607. timeGroup.setName("时间组");
  5608. govs.add(timeGroup);
  5609. i++;
  5610. //endregion
  5611. //region 学院
  5612. gauageOutfitVo college = new gauageOutfitVo();
  5613. college.setId(i);
  5614. college.setName("学院");
  5615. govs.add(college);
  5616. i++;
  5617. //endregion
  5618. //region 专业
  5619. gauageOutfitVo speciality = new gauageOutfitVo();
  5620. speciality.setId(i);
  5621. speciality.setName("专业");
  5622. govs.add(speciality);
  5623. i++;
  5624. //endregion
  5625. //region 校区
  5626. gauageOutfitVo campus = new gauageOutfitVo();
  5627. campus.setId(i);
  5628. campus.setName("校区");
  5629. govs.add(campus);
  5630. i++;
  5631. //endregion
  5632. //region 宿舍号
  5633. gauageOutfitVo dormitory = new gauageOutfitVo();
  5634. dormitory.setId(i);
  5635. dormitory.setName("宿舍号");
  5636. govs.add(dormitory);
  5637. i++;
  5638. //endregion
  5639. //region 手机号
  5640. gauageOutfitVo phone = new gauageOutfitVo();
  5641. phone.setId(i);
  5642. phone.setName("手机号");
  5643. govs.add(phone);
  5644. i++;
  5645. //endregion
  5646. //region 关联人
  5647. gauageOutfitVo affiliate = new gauageOutfitVo();
  5648. affiliate.setId(i);
  5649. affiliate.setName("关联人");
  5650. govs.add(affiliate);
  5651. i++;
  5652. //endregion
  5653. //region 职称
  5654. gauageOutfitVo title = new gauageOutfitVo();
  5655. title.setId(i);
  5656. title.setName("职称");
  5657. govs.add(title);
  5658. i++;
  5659. //endregion
  5660. //region 家庭地址
  5661. gauageOutfitVo address = new gauageOutfitVo();
  5662. address.setId(i);
  5663. address.setName("家庭地址");
  5664. govs.add(address);
  5665. i++;
  5666. //endregion
  5667. //region 民族
  5668. gauageOutfitVo nation = new gauageOutfitVo();
  5669. nation.setId(i);
  5670. nation.setName("民族");
  5671. govs.add(nation);
  5672. i++;
  5673. //endregion
  5674. //region 生源地
  5675. gauageOutfitVo student = new gauageOutfitVo();
  5676. student.setId(i);
  5677. student.setName("生源地");
  5678. govs.add(student);
  5679. i++;
  5680. //endregion
  5681. //region 毕业学院
  5682. gauageOutfitVo graduate = new gauageOutfitVo();
  5683. graduate.setId(i);
  5684. graduate.setName("毕业学院");
  5685. govs.add(graduate);
  5686. //endregion
  5687. return CommonResult.ok(govs);
  5688. }
  5689. @Override
  5690. @DESRespondSecret(validated = true)
  5691. public CommonResult getPage(int currentPage, int pageCount, String keyWord, String schoolClass) {
  5692. PageUtils<SmartUserPageVo> pageUtils = smartUserService.getPage(currentPage, pageCount, keyWord, schoolClass);
  5693. return CommonResult.ok(pageUtils);
  5694. }
  5695. @Override
  5696. @DESRespondSecret(validated = true)
  5697. @PassToken
  5698. public CommonResult studentSelect(String keyWord) {
  5699. if (ObjectUtils.isEmpty(keyWord)) {
  5700. return CommonResult.fail();
  5701. }
  5702. List<StudentSelectVo> list = smartUserService.studentSelect(keyWord);
  5703. return CommonResult.ok(list);
  5704. }
  5705. @Override
  5706. @DESRespondSecret(validated = true)
  5707. public CommonResult statisticsCampus(Integer classId, String dateTime) {
  5708. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  5709. LocalDateTime startTime = LocalDateTime.parse(dateTime, dateTimeFormatter1);
  5710. LocalDateTime endTime = startTime.plusDays(1);
  5711. // 正常
  5712. Set<StatisticsCampusVo> vos = new HashSet<>();
  5713. // 查找门禁记录
  5714. List<StatisticsCampusVo> accessVos = smartUserService.getAccessStatisticsCampus(classId, startTime, endTime);
  5715. for (StatisticsCampusVo accessVo : accessVos) {
  5716. vos.add(accessVo);
  5717. }
  5718. // 查找打卡记录
  5719. List<StatisticsCampusVo> attendanceVos = smartUserService.getAttendanceStatisticsCampus(classId, startTime, endTime);
  5720. for (StatisticsCampusVo attendanceVo : attendanceVos) {
  5721. vos.add(attendanceVo);
  5722. }
  5723. // 查找人脸记录
  5724. List<StatisticsCampusVo> faceDiscernVos = smartUserService.getFaceDiscernStatisticsCampus(classId, startTime, endTime);
  5725. for (StatisticsCampusVo faceDiscernVo : faceDiscernVos) {
  5726. vos.add(faceDiscernVo);
  5727. }
  5728. // 查找请假记录
  5729. List<StatisticsCampusVo> ackVos = smartUserService.getAckStatisticsCampus(classId, startTime, endTime);
  5730. for (StatisticsCampusVo ackVo : ackVos) {
  5731. vos.add(ackVo);
  5732. }
  5733. // 查找该班级下的所有人
  5734. List<StatisticsCampusVo> campusVos = smartUserService.getClassStudent(classId);
  5735. // 不在正常记录里面的就是异常记录
  5736. ArrayList<StatisticsCampusVo> abnormalVos = new ArrayList<>();
  5737. for (StatisticsCampusVo campusVo : campusVos) {
  5738. if (!vos.contains(campusVo)) {
  5739. abnormalVos.add(campusVo);
  5740. }
  5741. }
  5742. HashMap<String, Object> normal = new HashMap<>();
  5743. normal.put("date", vos);
  5744. normal.put("count", vos.size());
  5745. HashMap<String, Object> ack = new HashMap<>();
  5746. ack.put("date", ackVos);
  5747. ack.put("count", ackVos.size());
  5748. HashMap<String, Object> abnormal = new HashMap<>();
  5749. abnormal.put("date", abnormalVos);
  5750. abnormal.put("count", abnormalVos.size());
  5751. JSONObject jsonObject = new JSONObject();
  5752. jsonObject.put("normal", normal);
  5753. jsonObject.put("ack", ack);
  5754. jsonObject.put("abnormal", abnormal);
  5755. return CommonResult.ok(jsonObject);
  5756. }
  5757. @Override
  5758. @DESRespondSecret(validated = true)
  5759. public CommonResult addressBook(Integer userId) {
  5760. // 获取学生信息
  5761. SmartUser smartById = smartUserService.getSmartById(userId);
  5762. // 获取家长信息
  5763. List<SmartUser> list = smartUserService.getAddressBook(userId);
  5764. HashMap<String, Object> map = new HashMap<>();
  5765. map.put("student", smartById);
  5766. map.put("patriarch", list);
  5767. return CommonResult.ok(map);
  5768. }
  5769. /**
  5770. * 在校统计 逻辑说明:
  5771. * 监听包含请假、门禁、打卡、人脸
  5772. */
  5773. @Override
  5774. @DESRespondSecret(validated = true)
  5775. public CommonResult statisticsCampusManage(Integer gradeId, Integer classId, String dateTime, Integer type, String keyWord) {
  5776. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  5777. LocalDateTime startTime = LocalDateTime.parse(dateTime, dateTimeFormatter1);
  5778. LocalDateTime endTime = startTime.plusDays(1);
  5779. //正常
  5780. Set<StatisticsCampusManageVo> vos = new HashSet<>();
  5781. //请假
  5782. //查找请假记录
  5783. List<StatisticsCampusManageVo> ackVos = smartUserService.getAckStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5784. if (ObjectUtils.isNotEmpty(ackVos) && ackVos.size() > 0) {
  5785. for (StatisticsCampusManageVo ackVo : ackVos) {
  5786. vos.add(ackVo);
  5787. }
  5788. }
  5789. //查找门禁记录
  5790. List<StatisticsCampusManageVo> accessVos = smartUserService.getAccessStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5791. for (StatisticsCampusManageVo accessVo : accessVos) {
  5792. vos.add(accessVo);
  5793. }
  5794. //查找打卡记录
  5795. List<StatisticsCampusManageVo> attendanceVos = smartUserService.getAttendanceStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5796. for (StatisticsCampusManageVo attendanceVo : attendanceVos) {
  5797. vos.add(attendanceVo);
  5798. }
  5799. //查找人脸记录
  5800. List<StatisticsCampusManageVo> faceDiscernVos = smartUserService.getFaceDiscernStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5801. for (StatisticsCampusManageVo faceDiscernVo : faceDiscernVos) {
  5802. vos.add(faceDiscernVo);
  5803. }
  5804. //异常
  5805. //查找该班级下的所有人
  5806. List<StatisticsCampusManageVo> campusVos = smartUserService.getClassStudentManage(gradeId, classId, keyWord);
  5807. //不在正常记录里面的就是异常记录
  5808. ArrayList<StatisticsCampusManageVo> abnormalVos = new ArrayList<>();
  5809. for (StatisticsCampusManageVo campusVo : campusVos) {
  5810. if (!vos.contains(campusVo)) {
  5811. abnormalVos.add(campusVo);
  5812. }
  5813. }
  5814. JSONObject jsonObject = new JSONObject();
  5815. jsonObject.put("abnormal", abnormalVos.size());//未监听
  5816. jsonObject.put("normal", vos.size());//监听
  5817. jsonObject.put("ack", ackVos.size());//请假
  5818. if (1 == type) {
  5819. jsonObject.put("data", abnormalVos);
  5820. return CommonResult.ok(jsonObject);
  5821. } else if (2 == type) {
  5822. jsonObject.put("data", vos);
  5823. return CommonResult.ok(jsonObject);
  5824. } else if (3 == type) {
  5825. jsonObject.put("data", ackVos);
  5826. return CommonResult.ok(jsonObject);
  5827. } else {
  5828. return CommonResult.fail("状态异常");
  5829. }
  5830. }
  5831. @Override
  5832. @PassToken
  5833. public void statisticsCampusManageExport(HttpServletResponse response, Integer gradeId, Integer classId, String dateTime, Integer type, String keyWord) {
  5834. //导出
  5835. Workbook workbook = new XSSFWorkbook();
  5836. Sheet sheet = workbook.createSheet("在校统计");
  5837. Row headerRow = sheet.createRow(0);
  5838. headerRow.createCell(0).setCellValue("序号");
  5839. headerRow.createCell(1).setCellValue("年级");
  5840. headerRow.createCell(2).setCellValue("班级");
  5841. headerRow.createCell(3).setCellValue("姓名");
  5842. headerRow.createCell(4).setCellValue("学号");
  5843. headerRow.createCell(5).setCellValue("类型");
  5844. headerRow.createCell(6).setCellValue("时间");
  5845. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  5846. LocalDateTime startTime = LocalDateTime.parse(dateTime, dateTimeFormatter1);
  5847. LocalDateTime endTime = startTime.plusDays(1);
  5848. // 正常
  5849. Set<StatisticsCampusManageVo> vos = new HashSet<>();
  5850. // 查找请假记录
  5851. List<StatisticsCampusManageVo> ackVos = smartUserService.getAckStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5852. if (ObjectUtils.isNotEmpty(ackVos) && ackVos.size() > 0) {
  5853. for (StatisticsCampusManageVo ackVo : ackVos) {
  5854. vos.add(ackVo);
  5855. }
  5856. }
  5857. // 查找门禁记录
  5858. List<StatisticsCampusManageVo> accessVos = smartUserService.getAccessStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5859. for (StatisticsCampusManageVo accessVo : accessVos) {
  5860. vos.add(accessVo);
  5861. }
  5862. // 查找打卡记录
  5863. List<StatisticsCampusManageVo> attendanceVos = smartUserService.getAttendanceStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5864. for (StatisticsCampusManageVo attendanceVo : attendanceVos) {
  5865. vos.add(attendanceVo);
  5866. }
  5867. // 查找人脸记录
  5868. List<StatisticsCampusManageVo> faceDiscernVos = smartUserService.getFaceDiscernStatisticsCampusManage(gradeId, classId, startTime, endTime, keyWord);
  5869. for (StatisticsCampusManageVo faceDiscernVo : faceDiscernVos) {
  5870. vos.add(faceDiscernVo);
  5871. }
  5872. // 异常
  5873. // 查找该班级下的所有人
  5874. List<StatisticsCampusManageVo> campusVos = smartUserService.getClassStudentManage(gradeId, classId, keyWord);
  5875. // 不在正常记录里面的就是异常记录
  5876. ArrayList<StatisticsCampusManageVo> abnormalVos = new ArrayList<>();
  5877. for (StatisticsCampusManageVo campusVo : campusVos) {
  5878. if (!vos.contains(campusVo)) {
  5879. abnormalVos.add(campusVo);
  5880. }
  5881. }
  5882. String[] s = dateTime.split(" ");
  5883. String s1 = s[0];
  5884. int count = 0;
  5885. for (int i = 0; i < abnormalVos.size(); i++) {
  5886. StatisticsCampusManageVo vo = abnormalVos.get(i);
  5887. count = count + 1;
  5888. Row dataRow = sheet.createRow(count);
  5889. dataRow.createCell(0).setCellValue(count);
  5890. dataRow.createCell(1).setCellValue(vo.getGradeName());
  5891. dataRow.createCell(2).setCellValue(vo.getClassName());
  5892. dataRow.createCell(3).setCellValue(vo.getName());
  5893. dataRow.createCell(4).setCellValue(vo.getCardNo());
  5894. dataRow.createCell(5).setCellValue("异常");
  5895. dataRow.createCell(6).setCellValue(s1);
  5896. }
  5897. for (int i = 0; i < ackVos.size(); i++) {
  5898. StatisticsCampusManageVo vo = ackVos.get(i);
  5899. count = count + 1;
  5900. Row dataRow = sheet.createRow(count);
  5901. dataRow.createCell(0).setCellValue(count);
  5902. dataRow.createCell(1).setCellValue(vo.getGradeName());
  5903. dataRow.createCell(2).setCellValue(vo.getClassName());
  5904. dataRow.createCell(3).setCellValue(vo.getName());
  5905. dataRow.createCell(4).setCellValue(vo.getCardNo());
  5906. dataRow.createCell(5).setCellValue("请假");
  5907. dataRow.createCell(6).setCellValue(s1);
  5908. }
  5909. for (StatisticsCampusManageVo vo : vos) {
  5910. count = count + 1;
  5911. Row dataRow = sheet.createRow(count);
  5912. dataRow.createCell(0).setCellValue(count);
  5913. dataRow.createCell(1).setCellValue(vo.getGradeName());
  5914. dataRow.createCell(2).setCellValue(vo.getClassName());
  5915. dataRow.createCell(3).setCellValue(vo.getName());
  5916. dataRow.createCell(4).setCellValue(vo.getCardNo());
  5917. dataRow.createCell(5).setCellValue("正常");
  5918. dataRow.createCell(6).setCellValue(s1);
  5919. }
  5920. // 将工作簿写入文件
  5921. ExcelUtils.excelDownload(workbook, s1 + ":在校统计.xlsx", response);
  5922. }
  5923. @Override
  5924. @DESRespondSecret(validated = false)
  5925. public CommonResult statisticsStatementManag(String dateTime) {
  5926. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  5927. LocalDateTime startTime = LocalDateTime.parse(dateTime, dateTimeFormatter1);
  5928. LocalDateTime endTime = startTime.plusDays(1);
  5929. Integer totalAbnormal = 0;
  5930. Integer totalNormal = 0;
  5931. Integer totalAck = 0;
  5932. // 获取年级
  5933. List<SmartGrade> smartGrades = smartGradeService.list(new LambdaQueryWrapper<>());
  5934. // 获取每个班的请假人数
  5935. List<StatisticsStatement> ackList = smartUserService.getUserAckTotal(startTime, endTime);
  5936. // 获取每个班级的人数
  5937. List<StatisticsStatement> totalList = smartUserService.getUserClassTotal();
  5938. // 获取每个班级的正常人数
  5939. List<StatisticsStatement> normalList = smartUserService.getUserNormalTotal(startTime, endTime);
  5940. ArrayList<StatisticsStatementVo> vos = new ArrayList<>();
  5941. for (StatisticsStatement statisticsStatement : totalList) {
  5942. StatisticsStatementVo vo = new StatisticsStatementVo();
  5943. Integer classId = statisticsStatement.getClassId();
  5944. Integer gradeId = statisticsStatement.getGradeId();
  5945. vo.setGradeId(gradeId);
  5946. vo.setClassId(classId);
  5947. vo.setGradeName(statisticsStatement.getGradeName());
  5948. vo.setClassName(statisticsStatement.getClassName());
  5949. // 总数
  5950. Integer total = statisticsStatement.getCount();
  5951. Integer normal = 0;
  5952. Integer ack = 0;
  5953. for (StatisticsStatement statement : normalList) {
  5954. Integer classId1 = statement.getClassId();
  5955. Integer gradeId1 = statement.getGradeId();
  5956. if (classId.equals(classId1) && gradeId.equals(gradeId1)) {
  5957. normal = statement.getCount();
  5958. break;
  5959. }
  5960. }
  5961. for (StatisticsStatement statement : ackList) {
  5962. Integer classId1 = statement.getClassId();
  5963. Integer gradeId1 = statement.getGradeId();
  5964. if (classId.equals(classId1) && gradeId.equals(gradeId1)) {
  5965. // 请假数量
  5966. ack = statement.getCount();
  5967. break;
  5968. }
  5969. }
  5970. Integer abnormal = total - normal;
  5971. vo.setAck(ack);
  5972. vo.setNormal(normal);
  5973. vo.setAbnormal(abnormal);
  5974. totalAbnormal = totalAbnormal + abnormal;
  5975. totalNormal = totalNormal + normal;
  5976. totalAck = totalAck + ack;
  5977. vos.add(vo);
  5978. }
  5979. ArrayList<StatisticsStatementManagVo> ssmVos = new ArrayList<>();
  5980. for (SmartGrade smartGrade : smartGrades) {
  5981. StatisticsStatementManagVo vo = new StatisticsStatementManagVo();
  5982. Integer id = smartGrade.getId();
  5983. vo.setGradeName(smartGrade.getName());
  5984. List<StatisticsStatementVo> ownerClasses = vos.stream().filter(e -> e.getGradeId().equals(id)).collect(Collectors.toList());
  5985. if (ownerClasses != null && ownerClasses.size() > 0) {
  5986. vo.setVos(ownerClasses);
  5987. }
  5988. ssmVos.add(vo);
  5989. }
  5990. JSONObject jsonObject = new JSONObject();
  5991. jsonObject.put("list", ssmVos);
  5992. jsonObject.put("totalAbnormal", totalAbnormal);
  5993. jsonObject.put("totalNormal", totalNormal);
  5994. jsonObject.put("totalAck", totalAck);
  5995. return CommonResult.ok(jsonObject);
  5996. }
  5997. @Override
  5998. public void statisticsStatementManagExport(HttpServletResponse response, String dateTime) {
  5999. //导出
  6000. Workbook workbook = new XSSFWorkbook();
  6001. Sheet sheet = workbook.createSheet("统计报表");
  6002. Row headerRow = sheet.createRow(0);
  6003. headerRow.createCell(0).setCellValue("序号");
  6004. headerRow.createCell(1).setCellValue("年级");
  6005. headerRow.createCell(2).setCellValue("班级");
  6006. headerRow.createCell(3).setCellValue("监听");
  6007. headerRow.createCell(4).setCellValue("未监听");
  6008. headerRow.createCell(5).setCellValue("请假");
  6009. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  6010. LocalDateTime startTime = LocalDateTime.parse(dateTime, dateTimeFormatter1);
  6011. LocalDateTime endTime = startTime.plusDays(1);
  6012. // 获取每个班的请假人数
  6013. List<StatisticsStatement> ackList = smartUserService.getUserAckTotal(startTime, endTime);
  6014. // 获取每个班级的人数
  6015. List<StatisticsStatement> totalList = smartUserService.getUserClassTotal();
  6016. // 获取每个班级的正常人数
  6017. List<StatisticsStatement> normalList = smartUserService.getUserNormalTotal(startTime, endTime);
  6018. ArrayList<StatisticsStatementVo> vos = new ArrayList<>();
  6019. for (StatisticsStatement statisticsStatement : totalList) {
  6020. StatisticsStatementVo vo = new StatisticsStatementVo();
  6021. Integer classId = statisticsStatement.getClassId();
  6022. Integer gradeId = statisticsStatement.getGradeId();
  6023. vo.setGradeId(gradeId);
  6024. vo.setClassId(classId);
  6025. vo.setGradeName(statisticsStatement.getGradeName());
  6026. vo.setClassName(statisticsStatement.getClassName());
  6027. // 总数
  6028. Integer total = statisticsStatement.getCount();
  6029. Integer normal = 0;
  6030. Integer ack = 0;
  6031. for (StatisticsStatement statement : normalList) {
  6032. Integer classId1 = statement.getClassId();
  6033. Integer gradeId1 = statement.getGradeId();
  6034. if (classId.equals(classId1) && gradeId.equals(gradeId1)) {
  6035. normal = statement.getCount();
  6036. break;
  6037. }
  6038. }
  6039. for (StatisticsStatement statement : ackList) {
  6040. Integer classId1 = statement.getClassId();
  6041. Integer gradeId1 = statement.getGradeId();
  6042. if (classId.equals(classId1) && gradeId.equals(gradeId1)) {
  6043. // 请假数量
  6044. ack = statement.getCount();
  6045. break;
  6046. }
  6047. }
  6048. Integer abnormal = total - normal;
  6049. vo.setAck(ack);
  6050. vo.setNormal(normal);
  6051. vo.setAbnormal(abnormal);
  6052. vos.add(vo);
  6053. }
  6054. String[] s = dateTime.split(" ");
  6055. String s1 = s[0];
  6056. for (int i = 0; i < vos.size(); i++) {
  6057. StatisticsStatementVo vo = vos.get(i);
  6058. Row dataRow = sheet.createRow(i + 1);
  6059. dataRow.createCell(0).setCellValue(i + 1);
  6060. dataRow.createCell(1).setCellValue(vo.getGradeName());
  6061. dataRow.createCell(2).setCellValue(vo.getClassName());
  6062. dataRow.createCell(3).setCellValue(vo.getNormal());
  6063. dataRow.createCell(4).setCellValue(vo.getAbnormal());
  6064. dataRow.createCell(5).setCellValue(vo.getAck());
  6065. }
  6066. ExcelUtils.excelDownload(workbook, s1 + ":统计报表.xlsx", response);
  6067. }
  6068. @Override
  6069. @PassToken
  6070. public CommonResult lostBan(String teacherUid, String classUid) {
  6071. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  6072. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classUid, teacherUid);
  6073. if (deleteTeacherMaster.isSuccess()) {
  6074. return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
  6075. }
  6076. // CommonResult pushMaster = SeewoPushMaster(seewoClient, teacherUid, classUid);
  6077. // if (!pushMaster.isSuccess()) {
  6078. // return CommonResult.fail("希沃平台:" + pushMaster.getMessage());
  6079. // }
  6080. return CommonResult.ok();
  6081. }
  6082. public CommonResult seeWoLostBan(SeewoClient seewoClient,String schoolUid, String classUid, String teacherUid){
  6083. MdmTeacherClassApiTeacherLeaveClassParam requestParam = new MdmTeacherClassApiTeacherLeaveClassParam();
  6084. //请求体,MimeType为 application/json
  6085. MdmTeacherClassApiTeacherLeaveClassParam.JSONRequestBody requestBody = MdmTeacherClassApiTeacherLeaveClassParam.JSONRequestBody.builder()
  6086. .build();
  6087. requestParam.setRequestBody(requestBody);
  6088. //
  6089. List<String> teacherIds = new ArrayList<>();
  6090. teacherIds.add(teacherUid);
  6091. MdmTeacherClassApiTeacherLeaveClassParam.TeacherLeaveClassReqDto reqDto = MdmTeacherClassApiTeacherLeaveClassParam.TeacherLeaveClassReqDto.builder()
  6092. .orgUid(schoolUid)
  6093. .classUid(classUid)
  6094. .teacherUids(teacherIds)
  6095. .positionCode("CLASS_MASTER")
  6096. .build();
  6097. requestBody.setReqDto(reqDto);
  6098. MdmTeacherClassApiTeacherLeaveClassRequest request = new MdmTeacherClassApiTeacherLeaveClassRequest(requestParam);
  6099. System.out.println("入参:" +request);
  6100. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  6101. MdmTeacherClassApiTeacherLeaveClassResult result = seewoClient.invoke(request);
  6102. System.out.println("出参:" +result);
  6103. if (result == null) {
  6104. return CommonResult.fail("希沃教师数据删除失败!");
  6105. }
  6106. if (!result.getResponseBody().getCode().equals("000000")) {
  6107. return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
  6108. }
  6109. return CommonResult.ok("删除成功");
  6110. }
  6111. //endregion
  6112. //region 用户导出
  6113. /**
  6114. * @param response 响应头
  6115. * @param userhead 请求头
  6116. * @param sure 请求参数
  6117. */
  6118. @Override
  6119. @DESRespondSecret(validated = false)
  6120. public CommonResult smartUserExport(HttpServletResponse response, String userhead, smartUserExportRequest sure) {
  6121. if (sure.getGauageOutfitVos() == null) {
  6122. return CommonResult.fail("表头数据为空");
  6123. }
  6124. if (sure.getGauageOutfitVos().size() <= 0) {
  6125. return CommonResult.fail("表头数据为空");
  6126. }
  6127. //region 角色判断
  6128. String userID = AesUtils.decrypt(userhead);
  6129. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  6130. if (operateData != null && sure != null && sure.getGauageOutfitVos() != null && sure.getGauageOutfitVos().size() > 0) {
  6131. QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
  6132. queryWrapper.eq("user_id", operateData.getId());
  6133. List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
  6134. if (authorities != null && authorities.size() > 0) {
  6135. List<String> viewAuthors = new ArrayList<>();//部门查看权限
  6136. List<String> manageAuthors = new ArrayList<>();//部门管理权限
  6137. for (SmartAuthority author : authorities) {
  6138. List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
  6139. if (views != null && views.size() > 0) {
  6140. viewAuthors.addAll(views);
  6141. }
  6142. List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
  6143. if (manages != null && manages.size() > 0) {
  6144. manageAuthors.addAll(manages);
  6145. }
  6146. }
  6147. List<String> AllAuths = new ArrayList<>();
  6148. AllAuths.addAll(viewAuthors);
  6149. AllAuths.addAll(manageAuthors);
  6150. AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
  6151. //endregion
  6152. //获取该部门下的所有子级部门ID
  6153. List<Integer> childDepartmentIds = new ArrayList<>();
  6154. List<SmartDepartment> departments = smartDepartmentService.list(null);
  6155. Integer departmentId = sure != null ? sure.getDepartmentId() : null;
  6156. childDepartmentIds.add(departmentId);
  6157. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  6158. if (departmentId == null) {
  6159. childDepartmentIds = null;
  6160. }
  6161. List<Integer> authDepartments = new ArrayList<>();
  6162. for (Integer child : childDepartmentIds) {
  6163. if (AllAuths.contains(String.valueOf(child))) {
  6164. authDepartments.add(child);
  6165. }
  6166. }
  6167. String name = sure != null ? sure.getName() : null;
  6168. List<SmartUser> users = smartUserService.querySmartUsers(authDepartments, name);
  6169. List<String> affiliates = new ArrayList<>();
  6170. List<String> affiliateStr = users.stream().map(SmartUser::getAffiliate).distinct().collect(Collectors.toList());
  6171. for (String datas : affiliateStr) {
  6172. if (!ObjectUtils.isEmpty(datas)) {
  6173. String[] dataArray = datas.split(",");
  6174. for (int i = 0; i < dataArray.length; i++) {
  6175. affiliates.add(dataArray[i]);
  6176. }
  6177. }
  6178. }
  6179. List<SmartUser> affiliateDatas = affiliates != null && affiliates.size() > 0 ? smartUserService.getSmartUserIds(affiliates) : null;
  6180. List<Integer> dutieIds = users != null && users.size() > 0 ? users.stream().map(SmartUser::getDuties).collect(Collectors.toList()) : null;
  6181. //职务数据
  6182. List<SmartDuties> duties = dutieIds != null && dutieIds.size() > 0 ? smartDutiesService.queryDutiesByIds(dutieIds) : null;
  6183. //年级
  6184. List<SmartGrade> grades = smartGradeService.list(null);
  6185. //班级
  6186. List<SmartClass> classes = smartClassService.list(null);
  6187. //导出
  6188. Workbook workbook = new XSSFWorkbook();
  6189. Sheet sheet = workbook.createSheet("用户信息管理");
  6190. Row headerRow = sheet.createRow(0);
  6191. int exportIndex = 1;
  6192. List<String> gauageStrs = sure.getGauageOutfitVos().stream().map(gauageOutfitVo::getName).collect(Collectors.toList());
  6193. headerRow.createCell(0).setCellValue("序号");
  6194. if (gauageStrs.contains("学号")) {
  6195. headerRow.createCell(exportIndex).setCellValue("学号");
  6196. exportIndex++;
  6197. }
  6198. if (gauageStrs.contains("姓名")) {
  6199. headerRow.createCell(exportIndex).setCellValue("姓名");
  6200. exportIndex++;
  6201. }
  6202. if (gauageStrs.contains("身份")) {
  6203. headerRow.createCell(exportIndex).setCellValue("身份");
  6204. exportIndex++;
  6205. }
  6206. if (gauageStrs.contains("职务")) {
  6207. headerRow.createCell(exportIndex).setCellValue("职务");
  6208. exportIndex++;
  6209. }
  6210. if (gauageStrs.contains("身份证号")) {
  6211. headerRow.createCell(exportIndex).setCellValue("身份证号");
  6212. exportIndex++;
  6213. }
  6214. if (gauageStrs.contains("性别")) {
  6215. headerRow.createCell(exportIndex).setCellValue("性别");
  6216. exportIndex++;
  6217. }
  6218. if (gauageStrs.contains("部门")) {
  6219. headerRow.createCell(exportIndex).setCellValue("部门");
  6220. exportIndex++;
  6221. }
  6222. if (gauageStrs.contains("人脸照片")) {
  6223. headerRow.createCell(exportIndex).setCellValue("人脸照片");
  6224. exportIndex++;
  6225. }
  6226. if (gauageStrs.contains("年级")) {
  6227. headerRow.createCell(exportIndex).setCellValue("年级");
  6228. exportIndex++;
  6229. }
  6230. if (gauageStrs.contains("班级")) {
  6231. headerRow.createCell(exportIndex).setCellValue("班级");
  6232. exportIndex++;
  6233. }
  6234. if (gauageStrs.contains("时间组")) {
  6235. headerRow.createCell(exportIndex).setCellValue("时间组");
  6236. exportIndex++;
  6237. }
  6238. if (gauageStrs.contains("学院")) {
  6239. headerRow.createCell(exportIndex).setCellValue("学院");
  6240. exportIndex++;
  6241. }
  6242. if (gauageStrs.contains("专业")) {
  6243. headerRow.createCell(exportIndex).setCellValue("专业");
  6244. exportIndex++;
  6245. }
  6246. if (gauageStrs.contains("校区")) {
  6247. headerRow.createCell(exportIndex).setCellValue("校区");
  6248. exportIndex++;
  6249. }
  6250. if (gauageStrs.contains("宿舍号")) {
  6251. headerRow.createCell(exportIndex).setCellValue("宿舍号");
  6252. exportIndex++;
  6253. }
  6254. if (gauageStrs.contains("手机号")) {
  6255. headerRow.createCell(exportIndex).setCellValue("手机号");
  6256. exportIndex++;
  6257. }
  6258. if (gauageStrs.contains("关联人")) {
  6259. headerRow.createCell(exportIndex).setCellValue("关联人");
  6260. exportIndex++;
  6261. }
  6262. if (gauageStrs.contains("职称")) {
  6263. headerRow.createCell(exportIndex).setCellValue("职称");
  6264. exportIndex++;
  6265. }
  6266. if (gauageStrs.contains("家庭住址")) {
  6267. headerRow.createCell(exportIndex).setCellValue("家庭住址");
  6268. exportIndex++;
  6269. }
  6270. if (gauageStrs.contains("民族")) {
  6271. headerRow.createCell(exportIndex).setCellValue("民族");
  6272. exportIndex++;
  6273. }
  6274. if (gauageStrs.contains("生源地")) {
  6275. headerRow.createCell(exportIndex).setCellValue("生源地");
  6276. exportIndex++;
  6277. }
  6278. if (gauageStrs.contains("毕业学院")) {
  6279. headerRow.createCell(exportIndex).setCellValue("毕业学院");
  6280. exportIndex++;
  6281. }
  6282. List<SmartTimeGroup> timeGroups = new ArrayList<>();
  6283. if (gauageStrs.contains("时间组")) {
  6284. timeGroups = smartTimeGroupService.list(null);
  6285. }
  6286. for (int i = 0; i < users.size(); i++) {
  6287. int valueIndex = 1;
  6288. SmartUser user = users.get(i);
  6289. Row dataRow = sheet.createRow(i + 1);
  6290. dataRow.createCell(0).setCellValue(i + 1);//序号
  6291. if (gauageStrs.contains("学号")) {
  6292. dataRow.createCell(valueIndex).setCellValue(user.getCardNo());//学号
  6293. valueIndex++;
  6294. }
  6295. if (gauageStrs.contains("姓名")) {
  6296. dataRow.createCell(valueIndex).setCellValue(user.getName());//姓名
  6297. valueIndex++;
  6298. }
  6299. if (gauageStrs.contains("身份")) {
  6300. dataRow.createCell(valueIndex).setCellValue(eIdentityStatu.stringOf(user.getIdentityId()));//身份
  6301. valueIndex++;
  6302. }
  6303. if (gauageStrs.contains("职务")) {
  6304. String dutieStr = "";
  6305. if (duties != null && duties.size() > 0 && user.getDuties() != null) {
  6306. Optional<SmartDuties> oduty = duties.stream().filter(e -> e.getId().equals(user.getDuties())).findFirst();
  6307. if (oduty != null && oduty.isPresent()) {
  6308. dutieStr = oduty.get().getName();
  6309. }
  6310. }
  6311. dataRow.createCell(valueIndex).setCellValue(dutieStr);//职务
  6312. valueIndex++;
  6313. }
  6314. if (gauageStrs.contains("身份证号")) {
  6315. dataRow.createCell(valueIndex).setCellValue(user.getIdCard());//身份证号
  6316. valueIndex++;
  6317. }
  6318. if (gauageStrs.contains("性别")) {
  6319. dataRow.createCell(valueIndex).setCellValue(eSexStatu.stringOf(user.getSexId()));//性别
  6320. valueIndex++;
  6321. }
  6322. if (gauageStrs.contains("部门")) {
  6323. //获取父级部门ID
  6324. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(user.getDepartmentId())).findFirst();
  6325. if (department != null && department.isPresent()) {
  6326. dataRow.createCell(valueIndex).setCellValue(QueryParentDepartments(department.get().getParentId(), departments, null));//部门
  6327. }
  6328. valueIndex++;
  6329. }
  6330. if (gauageStrs.contains("人脸照片")) {
  6331. dataRow.createCell(valueIndex).setCellValue(user.getHeadImage() == null ? "" : user.getHeadImage());//人脸
  6332. valueIndex++;
  6333. }
  6334. if (gauageStrs.contains("年级")) {
  6335. String grade = "";
  6336. Optional<SmartGrade> gradeData = grades == null ? null : grades.stream().filter(e -> e.getId().toString().equals(user.getGrade())).findFirst();
  6337. if (gradeData != null && gradeData.isPresent()) {
  6338. grade = gradeData.get().getName();
  6339. }
  6340. dataRow.createCell(valueIndex).setCellValue(grade);//年级
  6341. valueIndex++;
  6342. }
  6343. if (gauageStrs.contains("班级")) {
  6344. String classStr = "";
  6345. Optional<SmartClass> classData = classes == null ? null : classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
  6346. if (classData != null && classData.isPresent()) {
  6347. classStr = classData.get().getName();
  6348. }
  6349. dataRow.createCell(valueIndex).setCellValue(classStr);//班级
  6350. valueIndex++;
  6351. }
  6352. if (gauageStrs.contains("时间组")) {
  6353. Optional<SmartTimeGroup> oTime = timeGroups != null && timeGroups.size() > 0 && user.getTimeGroupId() != null ? timeGroups.stream().filter(e -> e.getId().equals(user.getTimeGroupId())).findFirst() : null;
  6354. String timeStr = "";
  6355. if (oTime != null && oTime.isPresent()) {
  6356. timeStr = oTime.get().getName();
  6357. }
  6358. dataRow.createCell(valueIndex).setCellValue(timeStr);//时间组
  6359. valueIndex++;
  6360. }
  6361. if (gauageStrs.contains("学院")) {
  6362. dataRow.createCell(valueIndex).setCellValue(user.getCollege() == null ? "" : user.getCollege());//学院
  6363. valueIndex++;
  6364. }
  6365. if (gauageStrs.contains("专业")) {
  6366. dataRow.createCell(valueIndex).setCellValue(user.getSpeciality() == null ? "" : user.getSpeciality());//专业
  6367. valueIndex++;
  6368. }
  6369. if (gauageStrs.contains("校区")) {
  6370. dataRow.createCell(valueIndex).setCellValue(user.getCampus() == null ? "" : user.getCampus());//校区
  6371. valueIndex++;
  6372. }
  6373. if (gauageStrs.contains("宿舍号")) {
  6374. dataRow.createCell(valueIndex).setCellValue(user.getDormitoryNumber() == null ? "" : user.getDormitoryNumber());//宿舍号
  6375. valueIndex++;
  6376. }
  6377. if (gauageStrs.contains("手机号")) {
  6378. dataRow.createCell(valueIndex).setCellValue(user.getPhone() == null ? "" : user.getPhone());//手机号
  6379. valueIndex++;
  6380. }
  6381. if (gauageStrs.contains("关联人")) {
  6382. List<String> affiliateCellStrs = new ArrayList<>();
  6383. if (user.getAffiliate() != null && affiliateDatas != null) {
  6384. String[] affArrayStr = user.getAffiliate().split(",");
  6385. for (int j = 0; j < affArrayStr.length; j++) {
  6386. String affArrayIndex = affArrayStr[j];
  6387. Optional<SmartUser> affUser = affiliateDatas.stream().filter(e -> e.getId().toString().equals(affArrayIndex)).findFirst();
  6388. if (affUser != null && affUser.isPresent()) {
  6389. affiliateCellStrs.add(affUser.get().getName());
  6390. }
  6391. }
  6392. }
  6393. dataRow.createCell(valueIndex).setCellValue(StringUtils.join(affiliateCellStrs, ","));//关联人
  6394. valueIndex++;
  6395. }
  6396. if (gauageStrs.contains("职称")) {
  6397. dataRow.createCell(valueIndex).setCellValue(user.getTitle() == null ? "" : user.getTitle());//职称
  6398. valueIndex++;
  6399. }
  6400. if (gauageStrs.contains("家庭住址")) {
  6401. dataRow.createCell(valueIndex).setCellValue(user.getAddress() == null ? "" : user.getAddress());//家庭住址
  6402. valueIndex++;
  6403. }
  6404. if (gauageStrs.contains("民族")) {
  6405. dataRow.createCell(valueIndex).setCellValue(user.getNation() == null ? "" : user.getNation());//民族
  6406. valueIndex++;
  6407. }
  6408. if (gauageStrs.contains("生源地")) {
  6409. dataRow.createCell(valueIndex).setCellValue(user.getOfStudent() == null ? "" : user.getOfStudent());//生源地
  6410. valueIndex++;
  6411. }
  6412. if (gauageStrs.contains("毕业学院")) {
  6413. dataRow.createCell(valueIndex).setCellValue(user.getGraduate() == null ? "" : user.getGraduate());//毕业学校
  6414. valueIndex++;
  6415. }
  6416. }
  6417. // 将工作簿写入文件
  6418. ExcelUtils.excelDownload(workbook, "用户信息.xlsx", response);
  6419. }
  6420. }
  6421. return CommonResult.ok("导出成功");
  6422. }
  6423. //endregion
  6424. //region 根据父级ID获取树形数据
  6425. /**
  6426. * 根据父级ID获取树形数据
  6427. *
  6428. * @param parentID 父级ID
  6429. * @param lists 数据集合
  6430. * @return
  6431. */
  6432. private List<DepartmentTreeVo> QueryDepartmentTreeRecords
  6433. (Integer
  6434. parentID, List<SmartDepartment> lists, List<Integer> departmentIds) {
  6435. List<DepartmentTreeVo> newTrees = new ArrayList<>();
  6436. List<SmartDepartment> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
  6437. for (SmartDepartment data : datas) {
  6438. departmentIds.add(data.getId());
  6439. QueryDepartmentTreeRecords(data.getId(), lists, departmentIds);
  6440. }
  6441. return newTrees;
  6442. }
  6443. //endregion
  6444. //region 根据父级ID往上查找父级数据
  6445. /**
  6446. * 根据父级ID获取父级数据
  6447. *
  6448. * @param parentID 子级ID
  6449. * @param lists 数据集合
  6450. * @return
  6451. */
  6452. private String QueryParentDepartments
  6453. (Integer
  6454. parentID, List<SmartDepartment> lists, String
  6455. departmentStr) {
  6456. Optional<SmartDepartment> data = lists.stream().filter(e -> e.getId().equals(parentID)).findFirst();
  6457. if (data != null && data.isPresent()) {
  6458. departmentStr = departmentStr == null ? data.get().getName() : data.get().getName() + "/" + departmentStr;
  6459. departmentStr = QueryParentDepartments(data.get().getParentId(), lists, departmentStr);
  6460. }
  6461. return departmentStr;
  6462. }
  6463. //endregion
  6464. //region 根据数据ID删除用户数据(旧的)
  6465. @Override
  6466. @DESRespondSecret(validated = true)
  6467. public CommonResult deleteSmartUserByIdOld
  6468. (useridsRequest ur, BindingResult
  6469. bindingResult) throws Exception {
  6470. if (bindingResult.hasErrors()) {
  6471. String st = paramUtils.getParamError(bindingResult);
  6472. return CommonResult.fail(st);
  6473. }
  6474. List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
  6475. if (users.size() != ur.getUserIds().size()) {
  6476. return CommonResult.fail("存在无效用户数据,删除失败!");
  6477. }
  6478. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  6479. for (SmartUser user : users) {
  6480. if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
  6481. List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
  6482. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
  6483. //region 删除原有的家长关系
  6484. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
  6485. if (!deleteResult.isSuccess()) {
  6486. return CommonResult.fail(deleteResult.getMessage());
  6487. }
  6488. //endregion
  6489. } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  6490. //查找家长
  6491. List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
  6492. //获取班级Uid
  6493. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  6494. if (classData == null) {
  6495. return CommonResult.fail("班级数据无效,更新失败");
  6496. }
  6497. //region 百胜删除学生
  6498. CommonResult deleteBsStudent = bsDeleteStudent(user);
  6499. if (!deleteBsStudent.isSuccess()) {
  6500. return CommonResult.fail(deleteBsStudent.getMessage());
  6501. }
  6502. //endregion
  6503. //region 希沃删除学生
  6504. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
  6505. if (!deleteStudent.isSuccess()) {
  6506. return CommonResult.fail(deleteStudent.getMessage());
  6507. }
  6508. //endregion
  6509. if (parents != null) {
  6510. //region 删除原有的家长关系
  6511. CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
  6512. if (!deleteResult.isSuccess()) {
  6513. return CommonResult.fail(deleteResult.getMessage());
  6514. }
  6515. //endregion
  6516. }
  6517. } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  6518. //region 希沃删除教师
  6519. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
  6520. if (!deleteTeacher.isSuccess()) {
  6521. return CommonResult.fail(deleteTeacher.getMessage());
  6522. }
  6523. //endregion
  6524. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  6525. if (user.getSchoolClass() == null) {
  6526. return CommonResult.fail("班级数据无效,删除失败");
  6527. }
  6528. //获取班级Uid
  6529. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  6530. if (classData == null) {
  6531. return CommonResult.fail("班级数据无效,删除失败");
  6532. }
  6533. //region 希沃删除班主任
  6534. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  6535. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
  6536. if (deleteTeacherMaster.isSuccess()) {
  6537. return CommonResult.fail(deleteTeacherMaster.getMessage());
  6538. }
  6539. }
  6540. //endregion
  6541. }
  6542. //region 百胜删除教师
  6543. CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
  6544. if (!bsDeleteTeacher.isSuccess()) {
  6545. return CommonResult.fail(bsDeleteTeacher.getMessage());
  6546. }
  6547. //endregion
  6548. }
  6549. }
  6550. int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
  6551. if (result > 0) {
  6552. smartTeachingService.deleteByUserIds(ur.getUserIds());
  6553. }
  6554. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  6555. }
  6556. //endregion
  6557. //region 根据数据ID删除用户数据
  6558. @Override
  6559. public CommonResult deleteSmartUserById
  6560. (useridsRequest ur, BindingResult
  6561. bindingResult) throws Exception {
  6562. if (bindingResult.hasErrors()) {
  6563. String st = paramUtils.getParamError(bindingResult);
  6564. return CommonResult.fail(st);
  6565. }
  6566. List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
  6567. if (users.size() != ur.getUserIds().size()) {
  6568. return CommonResult.fail("存在无效用户数据,删除失败!");
  6569. }
  6570. //先删除咱自己数据库里的用户数据
  6571. int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
  6572. if (result <= 0) {
  6573. return CommonResult.fail("删除失败");
  6574. } else {
  6575. // 删除同步到海康平台
  6576. for (SmartUser user : users) {
  6577. Integer identityId = user.getIdentityId();
  6578. if (2 == identityId || identityId == 3) {
  6579. Integer id = user.getId();
  6580. SmartOperationUser smartOperationUser = new SmartOperationUser();
  6581. smartOperationUser.setOperationId(id);
  6582. smartOperationUser.setOperationMode("3");
  6583. smartOperationUser.setStatus(1);
  6584. smartOperationUser.setType(identityId);
  6585. smartOperationUserService.save(smartOperationUser);
  6586. }
  6587. }
  6588. }
  6589. List<deleteUserVo> deleteUsers = new ArrayList<>();
  6590. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  6591. for (SmartUser user : users) {
  6592. deleteUserVo deleteUser = new deleteUserVo();
  6593. deleteUser.setId(user.getId());
  6594. if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
  6595. List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
  6596. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
  6597. //region 删除原有的家长关系
  6598. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
  6599. if (!deleteResult.isSuccess()) {
  6600. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败:" + deleteResult.getMessage() + ";";
  6601. deleteUser.setReason(reason);
  6602. //return CommonResult.fail(deleteResult.getMessage());
  6603. }
  6604. //endregion
  6605. //删除家长 根据家长手机号删除下标数据
  6606. smartFamilyIndexService.deleteSmartFamilyByPhone(user.getPhone());
  6607. } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  6608. //查找家长
  6609. List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
  6610. //获取班级Uid
  6611. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  6612. if (classData == null) {
  6613. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;";
  6614. deleteUser.setReason(reason);
  6615. //return CommonResult.fail("班级数据无效,更新失败");
  6616. }
  6617. //region 百胜删除学生
  6618. CommonResult deleteBsStudent = bsDeleteStudent(user);
  6619. if (!deleteBsStudent.isSuccess()) {
  6620. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除学生失败;" + deleteBsStudent.getMessage() + ";";
  6621. deleteUser.setReason(reason);
  6622. //return CommonResult.fail(deleteBsStudent.getMessage());
  6623. }
  6624. //endregion
  6625. //region 希沃删除学生
  6626. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
  6627. if (!deleteStudent.isSuccess()) {
  6628. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除学生失败;" + deleteStudent.getMessage() + ";";
  6629. ;
  6630. deleteUser.setReason(reason);
  6631. //return CommonResult.fail(deleteStudent.getMessage());
  6632. }
  6633. //endregion
  6634. if (parents != null) {
  6635. //region 删除原有的家长关系
  6636. CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
  6637. if (!deleteResult.isSuccess()) {
  6638. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败;" + deleteResult.getMessage() + ";";
  6639. ;
  6640. deleteUser.setReason(reason);
  6641. //return CommonResult.fail(deleteResult.getMessage());
  6642. }
  6643. //endregion
  6644. //删除学生 根据学生学号删除下标数据
  6645. smartFamilyIndexService.deleteSmartFamilyByCardNo(user.getCardNo());
  6646. }
  6647. } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  6648. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  6649. if (user.getSchoolClass() == null) {
  6650. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,希沃删除班主任失败;";
  6651. deleteUser.setReason(reason);
  6652. } else {
  6653. //获取班级Uid
  6654. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  6655. if (classData == null) {
  6656. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,希沃删除教师失败;";
  6657. deleteUser.setReason(reason);
  6658. //return CommonResult.fail("班级数据无效,更新失败");
  6659. }
  6660. //region 希沃删除班主任
  6661. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
  6662. if (!deleteTeacherMaster.isSuccess()) {
  6663. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除班主任失败;" + deleteTeacherMaster.getMessage() + ";";
  6664. deleteUser.setReason(reason);
  6665. //return CommonResult.fail(deleteTeacherMaster.getMessage());
  6666. }
  6667. //endregion
  6668. }
  6669. }
  6670. //region 希沃删除教师
  6671. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
  6672. if (!deleteTeacher.isSuccess()) {
  6673. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + deleteTeacher.getMessage() + ";";
  6674. deleteUser.setReason(reason);
  6675. //return CommonResult.fail(deleteTeacher.getMessage());
  6676. }
  6677. //endregion
  6678. //region 百胜删除教师
  6679. CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
  6680. if (!bsDeleteTeacher.isSuccess()) {
  6681. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + bsDeleteTeacher.getMessage() + ";";
  6682. deleteUser.setReason(reason);
  6683. //return CommonResult.fail(bsDeleteTeacher.getMessage());
  6684. }
  6685. //endregion
  6686. }
  6687. if (deleteUser.getReason() != null) {
  6688. deleteUsers.add(deleteUser);
  6689. }
  6690. }
  6691. if (deleteUsers != null && deleteUsers.size() > 0) {
  6692. int deleteUser = smartUserService.deleteUserBatch(deleteUsers);
  6693. if (deleteUser > 0) {
  6694. List<SmartAuthorGroup> allDatas = new ArrayList<>();//要被更新的权限组数据
  6695. List<Integer> deleteGroupId = new ArrayList<>();//要被删除的权限组
  6696. List<Integer> deleteUserId = new ArrayList<>();//要被删除的管理组权限
  6697. for (deleteUserVo dUser : deleteUsers) {
  6698. deleteUserId.add(dUser.getId());
  6699. List<SmartAuthorGroup> authGroups = smartAuthorGroupService.smartAuthorGroup(dUser.getId());
  6700. for (SmartAuthorGroup authGroup : authGroups) {
  6701. List<String> newUserId = new ArrayList<>();
  6702. List<String> userIds = Arrays.asList(authGroup.getUserId().split(","));
  6703. for (String userId : userIds) {
  6704. if (!userId.equals(String.valueOf(dUser.getId()))) {
  6705. newUserId.add(userId);
  6706. }
  6707. }
  6708. if (newUserId != null && newUserId.size() > 0) {
  6709. authGroup.setUserId(StringUtils.join(newUserId, ","));
  6710. allDatas.add(authGroup);
  6711. } else {
  6712. deleteGroupId.add(authGroup.getId());
  6713. }
  6714. }
  6715. }
  6716. if (allDatas != null && allDatas.size() > 0) {//更新权限组
  6717. smartAuthorGroupService.saveBatch(allDatas);
  6718. }
  6719. if (deleteGroupId != null && deleteGroupId.size() > 0) {//删除权限组
  6720. smartAuthorGroupService.deleteSmartAuthorGroupByIds(deleteGroupId);
  6721. }
  6722. if (deleteUserId != null && deleteUserId.size() > 0) {//删除管理组权限
  6723. smartAuthorityService.deleteAuthorityByUserIds(deleteUserId);
  6724. }
  6725. } else {
  6726. return CommonResult.fail("删除失败");
  6727. }
  6728. }
  6729. return CommonResult.ok("删除成功");
  6730. }
  6731. //endregion
  6732. //region 根据当前用户ID获取受访学生数据
  6733. @Override
  6734. @DESRespondSecret(validated = true)
  6735. public CommonResult queryAffiliateUserById
  6736. (int id) {
  6737. List<AffiliateUserVo> result = smartUserService.queryAffiliateUserById(id);
  6738. if (result != null && result.size() > 0) {
  6739. List<SmartDepartment> departments = smartDepartmentService.list(null);
  6740. for (AffiliateUserVo data : result) {
  6741. //获取父级部门ID
  6742. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  6743. if (department != null && department.isPresent()) {
  6744. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  6745. data.setDepartmentName(departmentName);
  6746. }
  6747. }
  6748. }
  6749. return CommonResult.ok(result);
  6750. }
  6751. //endregion
  6752. //region 导出人员Excel模板
  6753. @Override
  6754. @DESRespondSecret(validated = true)
  6755. public CommonResult downloadUserExcel
  6756. () {
  6757. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/人员信息表.xlsx");
  6758. }
  6759. //endregion
  6760. //region 导出教师模板
  6761. @Override
  6762. @DESRespondSecret(validated = true)
  6763. public CommonResult downloadTeacherExcel
  6764. () {
  6765. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/教师信息表.xlsx");
  6766. }
  6767. //endregion
  6768. //region 导出更新人员Excel模板
  6769. @Override
  6770. @DESRespondSecret(validated = true)
  6771. public CommonResult downloadUpdateUserExcel
  6772. () {
  6773. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/更新信息表.xlsx");
  6774. }
  6775. //endregion
  6776. //region 根据用户ID查询学生
  6777. @Override
  6778. @DESRespondSecret(validated = true)
  6779. public CommonResult queryStudents(
  6780. int userId) {
  6781. List<SmartUser> students = new ArrayList<>();
  6782. SmartUser user = smartUserService.getSmartById(userId);
  6783. if (user == null) {
  6784. return CommonResult.fail("用户信息为空,获取学生列表数据失败");
  6785. }
  6786. if (user.getAffiliate() == null) {
  6787. return CommonResult.ok(students);
  6788. }
  6789. List<Integer> affiliateIds = new ArrayList<>();
  6790. List<String> affiliates = Arrays.asList(user.getAffiliate().split(","));
  6791. for (String affiliate : affiliates) {
  6792. affiliateIds.add(Integer.valueOf(affiliate));
  6793. }
  6794. students = smartUserService.getSmartUserByIds(affiliateIds);
  6795. List<ParentOfStudentsVo> result = new ArrayList<>();
  6796. for (SmartUser student : students) {
  6797. ParentOfStudentsVo data = new ParentOfStudentsVo();
  6798. data.setId(student.getId());
  6799. data.setName(student.getName());
  6800. data.setCardNo(student.getCardNo());
  6801. data.setDepartmentId(student.getDepartmentId());
  6802. result.add(data);
  6803. }
  6804. return CommonResult.ok(result);
  6805. }
  6806. //endregion
  6807. //region 根据数据ID获取用户信息
  6808. @Override
  6809. @DESRespondSecret(validated = true)
  6810. public CommonResult queryInfoData(
  6811. int id) {
  6812. SmartUser su = smartUserService.getSmartById(id);
  6813. if (su == null) {
  6814. return CommonResult.fail("用户信息失效,获取用户信息失败");
  6815. }
  6816. //部门数据集合
  6817. List<SmartDepartment> departments = smartDepartmentService.list(null);
  6818. //年级数据
  6819. List<SmartGrade> grades = smartGradeService.list(null);
  6820. WechatUserVo userData = new WechatUserVo();
  6821. userData.setId(su.getId());
  6822. userData.setCardNo(su.getCardNo());
  6823. userData.setTimeGroupId(su.getTimeGroupId());
  6824. userData.setName(su.getName());
  6825. userData.setIdentityId(su.getIdentityId());
  6826. userData.setIdCard(su.getIdCard());
  6827. userData.setSexId(su.getSexId());
  6828. userData.setDepartmentId(su.getDepartmentId());
  6829. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(su.getDepartmentId())).findFirst();
  6830. if (department != null && department.isPresent()) {
  6831. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  6832. userData.setDepartmentName(departmentName == null ? "" : departmentName + "/" + department.get().getName());
  6833. }
  6834. userData.setHeadImage(su.getHeadImage());
  6835. if (org.springframework.util.StringUtils.hasText(su.getGrade())) {
  6836. Optional<SmartGrade> oGrade = grades.stream().filter(e -> String.valueOf(e.getId()).equals(su.getGrade())).findFirst();
  6837. if (oGrade != null && oGrade.isPresent()) {
  6838. userData.setGrade(oGrade.get().getName());
  6839. }
  6840. }
  6841. userData.setCollege(su.getCollege());
  6842. userData.setSpeciality(su.getSpeciality());
  6843. userData.setSchoolClass(su.getSchoolClass());
  6844. userData.setCampus(su.getCampus());
  6845. userData.setDormitoryNumber(su.getDormitoryNumber());
  6846. userData.setPhone(su.getPhone());
  6847. userData.setAffiliate(su.getAffiliate());
  6848. //查找关联人
  6849. if (su.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  6850. List<AffiliateParentVo> parents = smartUserService.queryAffiliateParents(su.getId());
  6851. if (parents != null && parents.size() > 0) {
  6852. String affiliateStr = StringUtils.join(parents.stream().map(AffiliateParentVo::getName).collect(Collectors.toList()), ",");
  6853. userData.setAffiliateName(affiliateStr);
  6854. }
  6855. } else if (su.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  6856. if (su.getAffiliate() != null) {
  6857. List<String> affiliates = Arrays.asList(su.getAffiliate().split(","));
  6858. List<SmartUser> childs = smartUserService.getSmartUserIds(affiliates);
  6859. String affiliateStr = StringUtils.join(childs.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  6860. userData.setAffiliateName(affiliateStr);
  6861. }
  6862. }
  6863. //关联人名称用逗号隔开
  6864. userData.setTitle(su.getTitle());
  6865. userData.setAddress(su.getAddress());
  6866. userData.setNation(su.getNation());
  6867. userData.setOfStudent(su.getOfStudent());
  6868. userData.setGraduate(su.getGraduate());
  6869. userData.setDuties(su.getDuties());
  6870. userData.setIsPush(su.getIsPush());
  6871. userData.setIsCancel(su.getIsCancel());
  6872. userData.setOpenId(su.getOpenId());
  6873. userData.setXOpenId(su.getXOpenId());
  6874. userData.setGzhOpenId(su.getGzhOpenId());
  6875. userData.setXwStudentUid(su.getXwStudentUid());
  6876. userData.setBsStudentNo(su.getBsStudentNo());
  6877. userData.setXwTeacherCode(su.getXwTeacherCode());
  6878. userData.setBsStaffCode(su.getBsStaffCode());
  6879. return CommonResult.ok(userData);
  6880. }
  6881. //endregion
  6882. //region 绑定学生
  6883. @Override
  6884. @DESRespondSecret(validated = true)
  6885. public CommonResult bindStudent
  6886. (bindStudentRequest
  6887. bsr, BindingResult bindingResult) {
  6888. if (bindingResult.hasErrors()) {
  6889. String st = paramUtils.getParamError(bindingResult);
  6890. return CommonResult.fail(st);
  6891. }
  6892. SmartUser parentUser = smartUserService.getSmartById(bsr.getUserId());
  6893. if (parentUser == null) {
  6894. return CommonResult.fail("当前用户信息无效,绑定失败!");
  6895. }
  6896. if (parentUser.getIdentityId().intValue() != eIdentityStatu.Parent.getValue()) {
  6897. return CommonResult.fail("当前用户身份无法进行绑定操作");
  6898. }
  6899. //查找是否存在学生数据
  6900. SmartUser studentUser = smartUserService.queryUserInfo(bsr.getName(), bsr.getCardNo(), bsr.getIdCard());
  6901. if (studentUser == null) {
  6902. return CommonResult.fail("当前学生不存在,绑定失败!");
  6903. }
  6904. //判断是否已绑定过
  6905. if (parentUser.getAffiliate() == null) {
  6906. parentUser.setAffiliate(String.valueOf(studentUser.getId()));
  6907. } else {
  6908. List<String> newAffiliates = new ArrayList<>();
  6909. List<String> affiliates = Arrays.asList(parentUser.getAffiliate().split(","));
  6910. long existCount = affiliates.stream().filter(e -> e.equals(String.valueOf(studentUser.getId()))).count();
  6911. if (existCount > 0) {
  6912. return CommonResult.fail("当前学生信息已绑定过,请勿重复操作!");
  6913. }
  6914. parentUser.setAffiliate(parentUser.getAffiliate() + "," + studentUser.getId());
  6915. }
  6916. List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(studentUser.getCardNo());
  6917. if (indexs != null && indexs.size() >= 4) {
  6918. return CommonResult.fail("绑定失败,希沃学生家长最多绑定四个家长");
  6919. }
  6920. int index = 0;
  6921. if (indexs != null) {
  6922. for (SmartFamilyIndex data : indexs) {
  6923. if (data.getIndexData().intValue() == index && index < 3) {
  6924. index++;
  6925. continue;
  6926. } else {
  6927. break;
  6928. }
  6929. }
  6930. }
  6931. //region 新增希沃学生家长信息
  6932. //初始化客户端
  6933. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  6934. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  6935. //响应体,MimeType为 application/json
  6936. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  6937. .build();
  6938. param.setRequestBody(requestBody);
  6939. //query
  6940. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  6941. .appId(seewoConfig.getAppId())
  6942. .schoolUid(seewoConfig.getSchoolId())
  6943. .build();
  6944. requestBody.setQuery(query);
  6945. //学生与家长列表,最大100条
  6946. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem studentParents = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  6947. .studentCode(studentUser.getCardNo())
  6948. .build();
  6949. query.setStudentParents(java.util.Collections.singletonList(studentParents));
  6950. //家长列表,最多4个
  6951. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  6952. .name(parentUser.getName())
  6953. .phone(parentUser.getPhone())
  6954. .index(index)
  6955. .build();
  6956. studentParents.setParents(java.util.Collections.singletonList(parents));
  6957. param.setRequestBody(requestBody);
  6958. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  6959. logger.info("入参:" + request);
  6960. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  6961. //request.setServerUrl("https://openapi.test.seewo.com")
  6962. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  6963. ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
  6964. logger.info("出参:" + result);
  6965. if (result == null) {
  6966. return CommonResult.fail("希沃学生家长数据添加失败!");
  6967. }
  6968. if (!result.getResponseBody().getCode().equals("000000")) {
  6969. return CommonResult.fail(result.getResponseBody().getMessage());
  6970. }
  6971. //endregion
  6972. int updateResult = smartUserService.updateSmartUser(parentUser);
  6973. return updateResult > 0 ? CommonResult.ok("绑定成功") : CommonResult.fail("绑定失败");
  6974. }
  6975. //endregion
  6976. //region 根据数据ID获取用户信息
  6977. @Override
  6978. public CommonResult queryUserData(
  6979. int id) {
  6980. SmartUserVo user = smartUserService.querySmartUserById(id);
  6981. return CommonResult.ok(user);
  6982. }
  6983. //endregion
  6984. //region 删除记录的分页数据
  6985. @Override
  6986. public CommonResult queryUserDeletePage
  6987. (int currentPage, int pageCount) {
  6988. PageUtils<UserDeleteVo> result = smartUserService.queryUserDeletePage(currentPage, pageCount);
  6989. List<SmartDepartment> departments = smartDepartmentService.list(null);
  6990. for (UserDeleteVo data : result.getList()) {
  6991. data.setIdentityStr(eIdentityStatu.stringOf(data.getIdentityId()));//身份
  6992. //获取父级部门ID
  6993. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  6994. if (department != null && department.isPresent()) {
  6995. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  6996. data.setDepartmentStr(departmentName);
  6997. }
  6998. }
  6999. return CommonResult.ok(result);
  7000. }
  7001. //endregion
  7002. //region 获取班级下的学生
  7003. @Override
  7004. public CommonResult queryClassUser(
  7005. int userId, String keyWord) {
  7006. SmartUser userData = smartUserService.getSmartById(userId);
  7007. if (userData == null) {
  7008. return CommonResult.fail("未查到用户信息,获取失败");
  7009. }
  7010. if (userData.getSchoolClass() == null) {
  7011. return CommonResult.fail("当前用户所在班级为空,获取失败");
  7012. }
  7013. SmartClass classData = smartClassService.getSmartClassById(userData.getSchoolClass());
  7014. if (classData == null) {
  7015. return CommonResult.fail("班级数据为空,获取失败");
  7016. }
  7017. List<SmartDepartment> departments = smartDepartmentService.list(null);
  7018. if (departments == null) {
  7019. return CommonResult.fail("部门数据为空,获取失败");
  7020. }
  7021. //查找部门名称
  7022. String departmentName = classData.getName().replace("年级", "") + "学生";
  7023. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
  7024. if (!(department != null && department.isPresent())) {
  7025. return CommonResult.fail("部门数据为空,获取失败");
  7026. }
  7027. String departmentStr = QueryParentDepartments(department.get().getParentId(), departments, null);
  7028. ClassUserVo result = new ClassUserVo();
  7029. result.setClassId(userData.getSchoolClass());
  7030. result.setName(departmentStr);
  7031. List<ClassUserDetailVo> userDetails = new ArrayList<>();
  7032. //region 用户明细集合数据
  7033. List<SmartUser> users = smartUserService.queryUsersByClass(userData.getSchoolClass());
  7034. if (users != null && users.size() > 0) {
  7035. List<SmartTimeGroup> timeGroups = smartTimeGroupService.list(null);
  7036. for (SmartUser user : users) {
  7037. ClassUserDetailVo userDetail = new ClassUserDetailVo();
  7038. userDetail.setId(user.getId());
  7039. userDetail.setName(user.getName());
  7040. userDetail.setCardNo(user.getCardNo());
  7041. Optional<SmartTimeGroup> timeGroup = timeGroups.stream().filter(e -> e.getId().equals(user.getTimeGroupId())).findFirst();
  7042. if (timeGroup != null && timeGroup.isPresent()) {
  7043. userDetail.setTimeGroup(timeGroup.get().getName());
  7044. }
  7045. userDetails.add(userDetail);
  7046. }
  7047. if (!ObjectUtils.isEmpty(keyWord)) {
  7048. userDetails = userDetails.stream().filter(e -> (e.getName() != null && e.getName().contains(keyWord)) || (e.getTimeGroup() != null && e.getTimeGroup().contains(keyWord))).collect(Collectors.toList());
  7049. }
  7050. }
  7051. //endregion
  7052. result.setUserDetails(userDetails);
  7053. return CommonResult.ok(result);
  7054. }
  7055. //endregion
  7056. //region 批量设置学生时间组
  7057. @Override
  7058. public CommonResult setUserTimeGroup
  7059. (setUserTimeGroupRequest
  7060. isur, BindingResult bindingResult) throws
  7061. Exception {
  7062. if (bindingResult.hasErrors()) {
  7063. String st = paramUtils.getParamError(bindingResult);
  7064. return CommonResult.fail(st);
  7065. }
  7066. logger.info("批量设置时间组1" + TimeExchange.getDateMillS());
  7067. SmartTimeGroup timeGroup = smartTimeGroupService.queryTimeGroupById(isur.getTimeGroupId());
  7068. if (timeGroup == null) {
  7069. return CommonResult.fail("时间组数据无效,批量同步时间组失败!");
  7070. }
  7071. logger.info("批量设置时间组2" + TimeExchange.getDateMillS());
  7072. //region 批量更新百胜学生的时间组
  7073. List<SmartUser> users = smartUserService.getSmartUserByIds(isur.getIds());
  7074. if (users == null) {
  7075. return CommonResult.fail("用户数据无效,批量同步时间组失败!");
  7076. }
  7077. logger.info("批量设置时间组3" + TimeExchange.getDateMillS());
  7078. List<SmartGrade> grades = smartGradeService.list(null);
  7079. List<SmartClass> classes = smartClassService.list(null);
  7080. logger.info("批量设置时间组4" + TimeExchange.getDateMillS());
  7081. for (SmartUser user : users) {
  7082. user.setTimeGroupId(isur.getTimeGroupId());
  7083. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getId().equals(Integer.valueOf(user.getGrade()))).findFirst();
  7084. if (!(oGrade != null && oGrade.isPresent())) {
  7085. return CommonResult.fail("年级数据无效,批量同步时间组失败!");
  7086. }
  7087. Optional<SmartClass> oClass = classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
  7088. if (!(oClass != null && oClass.isPresent())) {
  7089. return CommonResult.fail("班级数据无效,批量同步时间组失败!");
  7090. }
  7091. // 开始时间
  7092. long stime = System.currentTimeMillis();
  7093. logger.info("开始循环调用百胜一次:" + TimeExchange.getDateMillS());
  7094. /**
  7095. * 学生数据的有效期是到毕业年份的8月31日
  7096. */
  7097. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  7098. String endTime = queryGraduationYear(oGrade.get().getGradeNo());
  7099. CommonResult<String> updateBsStudent = bsTUpdateStudent(user, oClass.get().getBsClassNo(), startTime, endTime);
  7100. if (!updateBsStudent.isSuccess()) {
  7101. return CommonResult.fail(updateBsStudent.getMessage());
  7102. }
  7103. // 结束时间
  7104. long etime = System.currentTimeMillis();
  7105. // 计算执行时间
  7106. logger.info("结束循环调用百胜一次,执行时长:%d 毫秒.", (etime - stime));
  7107. //endregion
  7108. }
  7109. logger.info("循环结束:" + TimeExchange.getDateMillS());
  7110. //region 批量更新学生数据
  7111. boolean updateBatch = smartUserService.updateBatchById(users);
  7112. logger.info("存储结束:" + TimeExchange.getDateMillS());
  7113. return updateBatch ? CommonResult.ok("批量同步成功") : CommonResult.fail("批量同步失败");
  7114. }
  7115. @Override
  7116. @DESRespondSecret(validated = true)
  7117. @PassToken
  7118. public CommonResult getPhoneUser
  7119. (String phone) {
  7120. if (ObjectUtils.isEmpty(phone)) {
  7121. return CommonResult.fail("参数异常");
  7122. }
  7123. // 通过手机号找到对应用户
  7124. SmartUser smartUser = smartUserService.getPhoneUser(phone);
  7125. return CommonResult.ok(smartUser);
  7126. }
  7127. @Override
  7128. @DESRespondSecret(validated = true)
  7129. @PassToken
  7130. public CommonResult getPhoneAffiliate(String phone) {
  7131. if (ObjectUtils.isEmpty(phone)) {
  7132. return CommonResult.fail("参数异常");
  7133. }
  7134. SmartUser smartUser = smartUserService.getPhoneUser(phone);
  7135. // 用户id,多个就用逗号隔开
  7136. String affiliate = smartUser.getAffiliate();
  7137. if (ObjectUtils.isEmpty(affiliate)) {
  7138. return CommonResult.fail("未关联学生");
  7139. }
  7140. // 通过关联人找到对应用户
  7141. List<SmartUserAffiliateVo> smartUsers = smartUserService.getAffiliateUser(affiliate);
  7142. return CommonResult.ok(smartUsers);
  7143. }
  7144. //endregion
  7145. //region 查询时间组编号
  7146. public String eGroupTime(Integer id) {
  7147. SmartTimeGroup result = smartTimeGroupService.queryTimeGroupById(id);
  7148. return result == null ? "" : result.getBsno();
  7149. }
  7150. //endregion
  7151. //region 查询时间组ID
  7152. public Integer eGroupTime(String name) {
  7153. SmartTimeGroup result = smartTimeGroupService.queryTimeGroupByName(name);
  7154. return result == null ? 0 : result.getId();
  7155. }
  7156. //endregion
  7157. //region 根据年级查询毕业年份
  7158. /**
  7159. * 根据年级查询毕业年份
  7160. *
  7161. * @return
  7162. */
  7163. public String queryGraduationYear(
  7164. int grade) {
  7165. String endTime = "";
  7166. int endYear = Year.now().getValue();
  7167. // 获取当前年份
  7168. LocalDate currentDate = LocalDate.now();
  7169. switch (grade) {
  7170. case 7:
  7171. if (currentDate.getMonthValue() < 9) {
  7172. endYear = endYear + 2;
  7173. } else {
  7174. endYear = endYear + 3;
  7175. }
  7176. break;
  7177. case 8:
  7178. if (currentDate.getMonthValue() < 9) {
  7179. endYear = endYear + 1;
  7180. } else {
  7181. endYear = endYear + 2;
  7182. }
  7183. break;
  7184. case 9:
  7185. break;
  7186. default:
  7187. break;
  7188. }
  7189. endTime = endYear + "-08-31 23:59:59";
  7190. return endTime;
  7191. }
  7192. //endregion
  7193. }