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