SmartUserController.java 262 KB

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