SmartUserController.java 272 KB

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