SmartUserController.java 291 KB

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