SmartUserController.java 263 KB

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