SmartUserController.java 193 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857
  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.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.validation.BindingResult;
  38. import org.springframework.web.bind.annotation.RestController;
  39. import org.springframework.web.multipart.MultipartFile;
  40. import javax.annotation.Resource;
  41. import javax.servlet.http.HttpServletResponse;
  42. import java.io.*;
  43. import java.net.URLDecoder;
  44. import java.net.URLEncoder;
  45. import java.nio.charset.Charset;
  46. import java.time.LocalDate;
  47. import java.time.Year;
  48. import java.util.*;
  49. import java.util.stream.Collectors;
  50. import java.util.stream.Stream;
  51. import java.util.zip.ZipInputStream;
  52. import static com.template.common.utils.AesTestOne.decrypt;
  53. /**
  54. * <p>
  55. * 前端控制器
  56. * </p>
  57. *
  58. * @author ceshi
  59. * @since 2023-12-04
  60. */
  61. @RestController
  62. //返回参数加密注解
  63. @DESRespondSecret
  64. public class SmartUserController implements SmartUserControllerAPI {
  65. @Resource
  66. private SeewoConfig seewoConfig;
  67. @Resource
  68. private ControlConfig controlConfig;
  69. @Autowired
  70. private SmartUserService smartUserService;
  71. @Autowired
  72. private SmartGradeService smartGradeService;
  73. @Autowired
  74. private SmartClassService smartClassService;
  75. @Autowired
  76. private SmartUploadService smartUploadService;
  77. @Autowired
  78. private SmartDutiesService smartDutiesService;
  79. @Autowired
  80. private SmartDepartmentService smartDepartmentService;
  81. @Autowired
  82. private SmartIdentityService smartIdentityService;
  83. @Autowired
  84. private SmartTimeGroupService smartTimeGroupService;
  85. @Autowired
  86. private SmartAuthorityService smartAuthorityService;
  87. @Override
  88. @DESRespondSecret(validated = true)
  89. public CommonResult logoffAccount(useridsRequest ur, BindingResult bindingResult) {
  90. if (bindingResult.hasErrors()) {
  91. String st = paramUtils.getParamError(bindingResult);
  92. return CommonResult.fail(st);
  93. }
  94. int user = smartUserService.getSmartUserCountByIds(ur.getUserIds());
  95. if (user != ur.getUserIds().size()) {
  96. return CommonResult.fail("用户信息已失效");
  97. }
  98. // for (:) {
  99. //
  100. // }
  101. // user.setIsCancel(eLogOff.Logout.getValue());
  102. //
  103. // int updateResult = smartUserService.updateSmartUser(user);
  104. return 0 > 0 ? CommonResult.ok("注销成功") : CommonResult.fail("注销失败");
  105. }
  106. @Override
  107. @DESRespondSecret(validated = true)
  108. public CommonResult changeDepartment(changeDepartmentRequest cdr, BindingResult bindingResult) {
  109. if (bindingResult.hasErrors()) {
  110. String st = paramUtils.getParamError(bindingResult);
  111. return CommonResult.fail(st);
  112. }
  113. List<SmartUser> users = smartUserService.getSmartUserByIds(cdr.getUserIds());
  114. if (users == null) {
  115. return CommonResult.fail("用户信息无效,移动失败!");
  116. }
  117. if (users.size() != cdr.getUserIds().size()) {
  118. return CommonResult.fail("存在无效用户数据,移动失败!");
  119. }
  120. for (SmartUser user : users) {
  121. user.setDepartmentId(cdr.getDepartmentId());
  122. }
  123. boolean result = smartUserService.updateUserBatchById(users);
  124. return result ? CommonResult.ok("移动成功") : CommonResult.fail("移动失败");
  125. }
  126. @Override
  127. public CommonResult importExcelUserBsno(MultipartFile excelFile) throws IOException {
  128. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  129. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  130. return CommonResult.fail("压缩包中的excel文件不能为空");
  131. }
  132. List<SmartUser> result = new ArrayList<>();
  133. String ContentType = excelFile.getContentType();
  134. InputStream inputStream = excelFile.getInputStream();
  135. if (ContentType.equals(eFileType.Xlsx.getValue())) {
  136. CommonResult<List<SmartUser>> resultData = readBsXlsx(inputStream);
  137. if (!resultData.isSuccess()) {
  138. return resultData;
  139. }
  140. result = resultData.getData();
  141. if (result == null) {
  142. return CommonResult.fail("文档内容为空,导入失败");
  143. }
  144. } else {
  145. return CommonResult.fail("用户导入只支持Xlsx");
  146. }
  147. List<String> gradeIds = result.stream().map(SmartUser::getGrade).distinct().collect(Collectors.toList());
  148. if (gradeIds != null && gradeIds.size() > 0) {
  149. List<SmartUser> users = smartUserService.queryStudentsByGrade(gradeIds);
  150. for (SmartUser user : users) {
  151. Optional<SmartUser> resultData = result.stream().filter(e -> e.getCardNo().equals(user.getCardNo()) && e.getName().equals(user.getName())).findFirst();
  152. if (resultData != null && resultData.isPresent()) {
  153. user.setBsStudentNo(resultData.get().getBsStudentNo());
  154. }
  155. }
  156. if (users != null && users.size() > 0) {
  157. boolean insertData = smartUserService.updateUserBatchById(users);
  158. if (!insertData) {
  159. return CommonResult.fail("导入失败");
  160. }
  161. }
  162. }
  163. return CommonResult.ok("导入成功");
  164. }
  165. /**
  166. * Xlsx文件读取方法ss
  167. *
  168. * @param inputStream 文件流
  169. * @return
  170. * @throws IOException
  171. */
  172. private CommonResult<List<SmartUser>> readBsXlsx(InputStream inputStream) throws IOException {
  173. List<SmartUser> users = new ArrayList<>();
  174. List<String> idCards = new ArrayList<>();
  175. List<String> cardNos = new ArrayList<>();
  176. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  177. List<SmartGrade> grades = smartGradeService.list(null); //年级
  178. //读取第一张sheet
  179. XSSFSheet sheetAt = sheets.getSheetAt(0);
  180. DataFormatter dataFormatter = new DataFormatter();
  181. try {
  182. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  183. XSSFRow row = sheetAt.getRow(rowNum);
  184. if (row != null) {
  185. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  186. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  187. //然后poi会根据字符串读取它
  188. //标题 校验
  189. if (rowNum == 0) {
  190. String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//年级
  191. if (!schoolClass.equals("年级")) {
  192. return CommonResult.fail("导入数据第一列为年级");
  193. }
  194. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  195. if (!cardNo.equals("学号")) {
  196. return CommonResult.fail("导入数据第四列为学号");
  197. }
  198. String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
  199. if (!name.equals("姓名")) {
  200. return CommonResult.fail("导入数据第五列为姓名");
  201. }
  202. String sex = dataFormatter.formatCellValue(row.getCell(5));//学生编码
  203. if (!sex.equals("学生编码")) {
  204. return CommonResult.fail("导入数据第六列为学生编码");
  205. }
  206. } else {
  207. SmartUser user = new SmartUser();
  208. String name = dataFormatter.formatCellValue(row.getCell(4));
  209. if (ObjectUtils.isEmpty(name)) {
  210. return CommonResult.fail("第" + (rowNum + 2) + "条数据的姓名不能为空");
  211. }
  212. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  213. if (ObjectUtils.isEmpty(schoolGrade)) {
  214. return CommonResult.fail(name + "的年级不能为空");
  215. }
  216. String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
  217. if (ObjectUtils.isEmpty(cardNo)) {
  218. return CommonResult.fail(name + "的学号不能为空");
  219. }
  220. //学号重复判断
  221. if (!ObjectUtils.isEmpty(cardNo)) {
  222. cardNos.add(cardNo);
  223. }
  224. if (cardNos.stream().distinct().count() != cardNos.size()) {
  225. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  226. }
  227. String studentNo = dataFormatter.formatCellValue(row.getCell(5));//学生编码
  228. if (ObjectUtils.isEmpty(studentNo)) {
  229. return CommonResult.fail(name + "的学生编码不能为空");
  230. }
  231. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(schoolGrade)).findFirst();
  232. if (oGrade != null && oGrade.isPresent()) {
  233. Integer gradeId = oGrade.get().getId();
  234. user.setGrade(String.valueOf(gradeId));
  235. } else {
  236. return CommonResult.fail(name + "的年级数据无效,导入失败");
  237. }
  238. user.setName(name);
  239. user.setBsStudentNo(studentNo);
  240. user.setCardNo(cardNo);
  241. users.add(user);
  242. }
  243. }
  244. }
  245. } catch (Exception e) {
  246. return CommonResult.fail("请按模板格式导入数据");
  247. }
  248. return CommonResult.ok(users);
  249. }
  250. @Override
  251. @DESRespondSecret(validated = true)
  252. public CommonResult importExcelUsers(MultipartFile excelFile, String headImage) throws Exception {
  253. List<SmartUser> result = new ArrayList<>();
  254. int useXw = 1;
  255. int useBs = 1;
  256. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  257. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  258. return CommonResult.fail("压缩包中的excel文件不能为空");
  259. }
  260. String ContentType = excelFile.getContentType();
  261. InputStream inputStream = excelFile.getInputStream();
  262. //xls格式文件
  263. if (ContentType.equals(eFileType.Xls.getValue())) {
  264. CommonResult<List<SmartUser>> resultData = readXls(inputStream);
  265. if (!resultData.isSuccess()) {
  266. return resultData;
  267. }
  268. result = resultData.getData();
  269. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  270. CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
  271. if (!resultData.isSuccess()) {
  272. return resultData;
  273. }
  274. result = resultData.getData();
  275. } else {
  276. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  277. }
  278. List<String> uploadImages = Arrays.asList(headImage.split(","));
  279. for (SmartUser user : result) {
  280. Optional<String> image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/" + user.getHeadImage())).findFirst();
  281. if (image != null && image.isPresent()) {
  282. user.setHeadImage(image.get());
  283. } else {
  284. if (user.getIdentityId().equals(eIdentityStatu.Student.getValue())) {
  285. return CommonResult.fail(user.getName() + "头像不存在,导入失败");
  286. }
  287. }
  288. }
  289. //region 将数据加入第三方
  290. List<SmartUser> studentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
  291. //判断是否存在重复数据
  292. List<String> cardNos = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList());
  293. if (cardNos == null) {
  294. return CommonResult.fail("文档内容为空,导入失败");
  295. }
  296. if (cardNos.size() <= 0) {
  297. return CommonResult.fail("文档内容为空,导入失败");
  298. }
  299. List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
  300. if (existUsers != null && existUsers.size() > 0) {
  301. String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  302. return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
  303. }
  304. //获取班级Uid
  305. List<SmartClass> classDatas = smartClassService.getSmartClasss();
  306. if (classDatas == null) {
  307. return CommonResult.fail("班级数据无效,新增失败");
  308. }
  309. List<SmartGrade> gradeDatas = smartGradeService.getSmartGrades();
  310. if (gradeDatas == null) {
  311. return CommonResult.fail("年级数据无效,新增失败");
  312. }
  313. HashMap<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> seewoDatas = new HashMap<>();
  314. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  315. for (SmartUser student : studentDatas) {
  316. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  317. photo.setPhotoUrl(student.getHeadImage());
  318. photo.setUserCode(student.getCardNo());
  319. photoList.add(photo);
  320. //region 学生参数必填判断:年级、班级
  321. if (student.getGrade() == null) {
  322. return CommonResult.fail("学生年级不能为空");
  323. }
  324. if (student.getSchoolClass() == null) {
  325. return CommonResult.fail("学生班级不能为空");
  326. }
  327. //endregion
  328. Optional<SmartClass> oClassData = classDatas.stream().filter(e -> e.getId().equals(student.getSchoolClass())).findFirst();
  329. if (oClassData == null) {
  330. return CommonResult.fail("班级数据无效,新增失败");
  331. }
  332. Optional<SmartGrade> oGradeData = gradeDatas.stream().filter(e -> e.getId().intValue() == Integer.valueOf(student.getGrade())).findFirst();
  333. if (oGradeData == null) {
  334. return CommonResult.fail("年级数据无效,新增失败");
  335. }
  336. SmartClass classData = oClassData.get();
  337. SmartGrade gradeData = oGradeData.get();
  338. //region 凑希沃参数
  339. if (useXw == 1) {
  340. if (!seewoDatas.containsKey(classData.getClassUid())) {
  341. seewoDatas.put(classData.getClassUid(), new ArrayList<>());
  342. }
  343. StudentServiceBatchSaveClassStudentsParam.StudentInfo studentSeewo = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  344. .studentName(student.getName())
  345. .studentCode(student.getCardNo())
  346. .gender(student.getSexId())
  347. .phone(student.getPhone() == null ? "" : student.getPhone())
  348. .build();
  349. seewoDatas.get(classData.getClassUid()).add(studentSeewo);
  350. }
  351. //endregion
  352. //region 希沃新增学生信息
  353. // if (useXw == 1) {
  354. // //初始化客户端
  355. // SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  356. // CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, student.getName(), student.getCardNo(), student.getSexId(), student.getPhone(), classData.getClassUid());
  357. // if (!insertStudent.isSuccess()) {
  358. // return CommonResult.fail(insertStudent.getMessage());
  359. // }
  360. //
  361. // student.setXwStudentUid(insertStudent.getData());
  362. // }
  363. //endregion
  364. //region 百胜新增学生信息
  365. if (useBs == 1) {
  366. /**
  367. * 学生数据的有效期是到毕业年份的8月31日
  368. */
  369. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  370. String endTime = queryGraduationYear(gradeData.getGradeNo());
  371. CommonResult<String> insertBsStudent = bsInsertStudent(student.getName(), student.getCardNo(), student.getSexId(), student.getHeadImage(), student.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime);
  372. if (!insertBsStudent.isSuccess()) {
  373. return CommonResult.fail(insertBsStudent.getMessage());
  374. }
  375. student.setBsStudentNo(insertBsStudent.getData());
  376. }
  377. //endregion
  378. }
  379. if (useXw == 1) {
  380. //初始化客户端
  381. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  382. List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultDatas = new ArrayList<>();
  383. for (Map.Entry<String, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo>> entry : seewoDatas.entrySet()) {
  384. String classUid = entry.getKey();
  385. CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> insertStudents = SeewoInsertBatchStudent(seewoClient, entry.getValue(), classUid);
  386. if (!insertStudents.isSuccess()) {
  387. return CommonResult.fail(insertStudents.getMessage());
  388. }
  389. seewoResultDatas.addAll(insertStudents.getData());
  390. }
  391. for (SmartUser student : studentDatas) {
  392. Optional<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto> seewoResultData = seewoResultDatas.stream().filter(e -> e.getStudentCode().equals(student.getCardNo())).findFirst();
  393. if (seewoResultData != null && seewoResultData.isPresent()) {
  394. student.setXwStudentUid(seewoResultData.get().getUserUid());
  395. }
  396. }
  397. }
  398. if (studentDatas != null && studentDatas.size() > 0) {
  399. //批量存储学生信息
  400. boolean resultBool = smartUserService.saveBatch(studentDatas);
  401. if (!resultBool) {
  402. return CommonResult.fail("导入失败");
  403. }
  404. //region 希沃新增编辑学生家长信息
  405. if (useXw == 1) {
  406. int num = (int) Math.ceil((double) studentDatas.size() / 100);
  407. for (int count = 1; count <= num; count++) {
  408. int startIndex = (count - 1) * 100;
  409. int endIndex = count * 100;
  410. if (count == num) {
  411. endIndex = startIndex + (studentDatas.size() % 100);
  412. }
  413. List<SmartUser> currentStudentDatas = studentDatas.subList(startIndex, endIndex);//结尾不包含下标100
  414. //学生与家长列表,最大100条
  415. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  416. for (SmartUser student : currentStudentDatas) {
  417. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  418. .studentCode(student.getCardNo())
  419. .build();
  420. List<SmartUser> parentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList());
  421. List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
  422. int i = 0;
  423. for (SmartUser parent : parentDatas) {
  424. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  425. .name(parent.getName())
  426. .phone(parent.getPhone())
  427. .index(i)
  428. .build();
  429. parents.add(data);
  430. ++i;
  431. }
  432. if (parents != null && parents.size() > 0) {
  433. studentParents.add(students);
  434. //家长列表,最多4个
  435. students.setParents(parents);
  436. }
  437. }
  438. //初始化客户端
  439. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  440. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  441. //响应体,MimeType为 application/json
  442. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  443. .build();
  444. param.setRequestBody(requestBody);
  445. //query
  446. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  447. .appId(seewoConfig.getAppId())
  448. .schoolUid(seewoConfig.getSchoolId())
  449. .build();
  450. requestBody.setQuery(query);
  451. query.setStudentParents(studentParents);
  452. param.setRequestBody(requestBody);
  453. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  454. String jsonString = JSON.toJSONString(request);
  455. System.out.println("入参:" + request);
  456. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  457. //request.setServerUrl("https://openapi.test.seewo.com")
  458. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  459. ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request);
  460. System.out.println("出参:" + parentResult);
  461. if (parentResult == null) {
  462. return CommonResult.fail("希沃学生家长数据添加失败!");
  463. }
  464. if (!parentResult.getResponseBody().getCode().equals("000000")) {
  465. return CommonResult.fail(parentResult.getResponseBody().getMessage());
  466. }
  467. }
  468. }
  469. //endregion
  470. }
  471. //endregion
  472. List<SmartUser> parents = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
  473. //双胞胎家长
  474. List<SmartUser> newParents = new ArrayList<>();
  475. if (cardNos != null && cardNos.size() > 0) {
  476. List<SmartUser> students = smartUserService.querySmartUserByCardNos(cardNos);
  477. for (SmartUser parent : parents) {
  478. Optional<SmartUser> student = students.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
  479. if (student != null && student.isPresent()) {
  480. //先查找是否存在
  481. Optional<SmartUser> newData = newParents.stream().filter(e -> e.getName().equals(parent.getName()) && e.getPhone().equals(parent.getPhone()) && e.getShip().equals(parent.getShip())).findFirst();
  482. if (newData != null && newData.isPresent()) {
  483. String affiliate = newData.get().getAffiliate() + "," + student.get().getId();
  484. newData.get().setAffiliate(affiliate);
  485. } else {
  486. SmartUser newParent = new SmartUser();
  487. newParent.setName(parent.getName());
  488. newParent.setDepartmentId(parent.getDepartmentId());
  489. newParent.setPhone(parent.getPhone());
  490. newParent.setIdentityId(parent.getIdentityId());
  491. newParent.setSexId(parent.getSexId());
  492. newParent.setIsCancel(parent.getIsCancel());
  493. newParent.setAffiliate(String.valueOf(student.get().getId()));
  494. newParent.setShip(parent.getShip());
  495. newParents.add(newParent);
  496. }
  497. }
  498. }
  499. if (newParents != null && newParents.size() > 0) {
  500. //批量存储家长信息
  501. boolean resultBool = smartUserService.saveBatch(newParents);
  502. if (!resultBool) {
  503. return CommonResult.fail("导入失败!");
  504. }
  505. }
  506. //region 最后上传学生图片 这样能保证图片上传失败也不影响数据导入
  507. if (useXw == 1) {
  508. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  509. int num = (int) Math.ceil((double) photoList.size() / 1000);
  510. for (int count = 1; count <= num; count++) {
  511. int startIndex = (count - 1) * 1000;
  512. int endIndex = count * 1000;
  513. if (count == num) {
  514. endIndex = startIndex + (photoList.size() % 1000);
  515. }
  516. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  517. CommonResult photoResult = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, eSeewoUserType.Student.getValue());
  518. if (!photoResult.isSuccess()) {
  519. return photoResult;
  520. }
  521. }
  522. }
  523. //endregion
  524. }
  525. return CommonResult.ok("导入成功");
  526. }
  527. @Override
  528. public CommonResult importExcelUpdateUsers(MultipartFile excelFile) {
  529. return null;
  530. }
  531. /**
  532. * 批量导入用户信息
  533. * 以身份证号作为判断依据 如果存在重复数据就提示存在重复数据
  534. * 开发流程:建议先去拿到excel中的所有数据的身份证号去数据库中找一遍是否存在重复数据
  535. * 如果不存在重复数据就把附件文件夹中的附件文件上传到cos服务器上
  536. * 然后手动拼接一个人脸照片文件地址存入对应的数据中
  537. *
  538. * @param zipFile zip压缩包
  539. * @return
  540. */
  541. @Override
  542. @DESRespondSecret(validated = true)
  543. public CommonResult importZipUsers(MultipartFile zipFile) throws IOException {
  544. List<SmartUser> result = new ArrayList<>();
  545. MultipartFile excelFile = null;
  546. List<MultipartFile> multipartFileHashMap = new ArrayList<>();
  547. String excelStr = null;
  548. if (zipFile != null) {
  549. //解压压缩文件并上传文件
  550. ByteArrayOutputStream byteOut = null;
  551. ZipInputStream zipIn = null;
  552. try {
  553. java.util.zip.ZipEntry zipEntry = null;
  554. zipIn = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK"));
  555. while ((zipEntry = zipIn.getNextEntry()) != null) {
  556. String fileName = zipEntry.getName();
  557. if (fileName.contains("人脸照片") && (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg"))) {
  558. byteOut = new ByteArrayOutputStream();
  559. IOUtils.copy(zipIn, byteOut);
  560. InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
  561. MultipartFile multipartFile = FileUtils.getMultipartFile(inputStream, fileName);
  562. multipartFileHashMap.add(multipartFile);
  563. } else if (fileName.contains("人员信息采集表") && (fileName.endsWith(".xlsx") || fileName.endsWith(".xls"))) {
  564. excelStr = fileName.endsWith(".xlsx") ? "xlsx" : "xls";
  565. byteOut = new ByteArrayOutputStream();
  566. IOUtils.copy(zipIn, byteOut);
  567. InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray());
  568. excelFile = FileUtils.getMultipartFile(inputStream, fileName);
  569. }
  570. }
  571. } catch (Exception e) {
  572. e.printStackTrace();
  573. } finally {
  574. if (byteOut != null) {
  575. byteOut.close();
  576. }
  577. if (zipIn != null) {
  578. zipIn.close();
  579. }
  580. }
  581. }
  582. //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像
  583. if (excelFile.isEmpty() || excelFile.getSize() == 0) {
  584. return CommonResult.fail("压缩包中的excel文件不能为空");
  585. }
  586. String ContentType = excelFile.getContentType();
  587. InputStream inputStream = excelFile.getInputStream();
  588. //xls格式文件
  589. if (excelStr.equals("xls")) {
  590. CommonResult<List<SmartUser>> resultData = readXls(inputStream);
  591. if (!resultData.isSuccess()) {
  592. return resultData;
  593. }
  594. result = resultData.getData();
  595. } else if (excelStr.equals("xlsx")) {
  596. CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
  597. if (!resultData.isSuccess()) {
  598. return resultData;
  599. }
  600. result = resultData.getData();
  601. } else {
  602. return CommonResult.fail("用户导入只支持Xls、Xlsx");
  603. }
  604. //cos上传 返回图片地址
  605. String uploadResult = smartUploadService.upload(multipartFileHashMap.toArray(new MultipartFile[0]));
  606. List<String> uploadImages = Arrays.asList(uploadResult.split(","));
  607. for (SmartUser user : result) {
  608. Optional<String> headImage = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/headImage/" + user.getHeadImage())).findFirst();
  609. if (headImage != null && headImage.isPresent()) {
  610. user.setHeadImage(headImage.get());
  611. }
  612. }
  613. //批量存储用户信息
  614. boolean resultBool = smartUserService.saveBatch(result);
  615. return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
  616. }
  617. @Override
  618. public CommonResult insertSmartUserPhoto() throws JsonProcessingException {
  619. Integer userType = eSeewoUserType.Student.getValue();
  620. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  621. List<SmartUser> students = smartUserService.queryStudentDatas();
  622. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  623. for (SmartUser student : students) {
  624. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  625. photo.setPhotoUrl(student.getHeadImage());
  626. photo.setUserCode(student.getCardNo());
  627. photoList.add(photo);
  628. }
  629. int num = (int) Math.ceil((double) photoList.size() / 1000);
  630. for (int count = 1; count <= num; count++) {
  631. int startIndex = (count - 1) * 1000;
  632. int endIndex = count * 1000;
  633. if (count == num) {
  634. endIndex = startIndex + (photoList.size() % 1000);
  635. }
  636. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> currentPhotoList = photoList.subList(startIndex, endIndex);//结尾不包含下标1000
  637. CommonResult result = SeewoInsertBatchPhoto(seewoClient, currentPhotoList, userType);
  638. if (!result.isSuccess()) {
  639. return result;
  640. }
  641. }
  642. return CommonResult.ok("图片上传成功");
  643. }
  644. /**
  645. * Xlsx文件读取方法ss
  646. *
  647. * @param inputStream 文件流
  648. * @return
  649. * @throws IOException
  650. */
  651. private CommonResult<List<SmartUser>> readXlsx(InputStream inputStream) throws IOException {
  652. List<String> phones = new ArrayList<>();
  653. List<String> idCards = new ArrayList<>();
  654. List<String> cardNos = new ArrayList<>();
  655. List<SmartUser> result = new ArrayList<>();
  656. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  657. List<SmartDepartment> departments = smartDepartmentService.list(null);
  658. List<SmartGrade> grades = smartGradeService.list(null); //年级
  659. List<SmartClass> classs = smartClassService.list(null);//班级
  660. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  661. //读取第一张sheet
  662. XSSFSheet sheetAt = sheets.getSheetAt(0);
  663. DataFormatter dataFormatter = new DataFormatter();
  664. try {
  665. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  666. XSSFRow row = sheetAt.getRow(rowNum);
  667. if (row != null) {
  668. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  669. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  670. //然后poi会根据字符串读取它
  671. //标题 校验
  672. if (rowNum == 0) {
  673. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  674. if (!schoolGrade.equals("年级")) {
  675. return CommonResult.fail("导入数据第一列为年级");
  676. }
  677. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  678. if (!schoolClass.equals("班级")) {
  679. return CommonResult.fail("导入数据第一列为班级");
  680. }
  681. String cardNo = dataFormatter.formatCellValue(row.getCell(2));//学号
  682. if (!cardNo.equals("学号")) {
  683. return CommonResult.fail("导入数据第二列为学号");
  684. }
  685. String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
  686. if (!name.equals("姓名")) {
  687. return CommonResult.fail("导入数据第三列为姓名");
  688. }
  689. String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
  690. if (!sex.equals("性别")) {
  691. return CommonResult.fail("导入数据第四列为性别");
  692. }
  693. String nation = dataFormatter.formatCellValue(row.getCell(5));//民族
  694. if (!nation.equals("民族")) {
  695. return CommonResult.fail("导入数据第五列为民族");
  696. }
  697. String cardId = dataFormatter.formatCellValue(row.getCell(6));//身份证
  698. if (!cardId.equals("身份证")) {
  699. return CommonResult.fail("导入数据第六列为身份证");
  700. }
  701. String headImage = dataFormatter.formatCellValue(row.getCell(7));//照片
  702. if (!headImage.equals("照片")) {
  703. return CommonResult.fail("导入数据第七列为照片");
  704. }
  705. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));//常规时间组
  706. if (!timeGroup.equals("常规时间组")) {
  707. return CommonResult.fail("导入数据第八列为常规时间组");
  708. }
  709. String address = dataFormatter.formatCellValue(row.getCell(9));//住址
  710. if (!address.equals("住址")) {
  711. return CommonResult.fail("导入数据第九列为住址");
  712. }
  713. String phone = dataFormatter.formatCellValue(row.getCell(10));//联系电话
  714. if (!phone.equals("联系电话")) {
  715. return CommonResult.fail("导入数据第十列为联系电话");
  716. }
  717. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  718. if (!family.equals("家属")) {
  719. return CommonResult.fail("导入数据第十一列为家属");
  720. }
  721. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  722. if (!familyShip.equals("家属与本人关系")) {
  723. return CommonResult.fail("导入数据第十二列为家属与本人关系");
  724. }
  725. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  726. if (!phoneTwo.equals("联系电话2")) {
  727. return CommonResult.fail("导入数据第十三列为联系电话2");
  728. }
  729. String familyTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  730. if (!familyTwo.equals("家属2")) {
  731. return CommonResult.fail("导入数据第十四列为家属2");
  732. }
  733. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  734. if (!familyShipTwo.equals("家属与本人关系2")) {
  735. return CommonResult.fail("导入数据第十五列为家属与本人关系2");
  736. }
  737. } else {
  738. SmartUser user = new SmartUser();
  739. String name = dataFormatter.formatCellValue(row.getCell(3));
  740. if (ObjectUtils.isEmpty(name)) {
  741. return CommonResult.fail("第" + (rowNum + 2) + "条数据的名称不能为空");
  742. }
  743. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  744. if (ObjectUtils.isEmpty(schoolGrade)) {
  745. return CommonResult.fail(name + "的年级不能为空");
  746. }
  747. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  748. if (ObjectUtils.isEmpty(schoolClass)) {
  749. return CommonResult.fail(name + "的班级不能为空");
  750. }
  751. //不判断重复性 因为会出现双胞胎
  752. String phone = dataFormatter.formatCellValue(row.getCell(10));
  753. // if (!ObjectUtils.isEmpty(phone)) {
  754. // phones.add(phone);
  755. // }
  756. // if (phones.stream().distinct().count() != phones.size()) {
  757. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  758. // }
  759. //性别是否为空判断
  760. String sex = dataFormatter.formatCellValue(row.getCell(4));
  761. if (ObjectUtils.isEmpty(sex)) {
  762. return CommonResult.fail(name + "的性别不能为空");
  763. }
  764. //家庭住址是否为空判断
  765. String address = dataFormatter.formatCellValue(row.getCell(9));
  766. //民族是否为空判断
  767. String nation = dataFormatter.formatCellValue(row.getCell(5));
  768. if (ObjectUtils.isEmpty(nation)) {
  769. return CommonResult.fail(name + "的民族不能为空");
  770. }
  771. //部门是否为空判断
  772. String department = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "学生";
  773. if (ObjectUtils.isEmpty(department)) {
  774. return CommonResult.fail(name + "的部门不能为空");
  775. }
  776. Integer departmentId = null;
  777. Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst();
  778. if (departModel != null && departModel.isPresent()) {
  779. departmentId = departModel.get().getId();
  780. } else {
  781. departmentId = 1;
  782. }
  783. //学号重复判断
  784. String cardNo = dataFormatter.formatCellValue(row.getCell(2));
  785. if (!ObjectUtils.isEmpty(cardNo)) {
  786. cardNos.add(cardNo);
  787. }
  788. if (cardNos.stream().distinct().count() != cardNos.size()) {
  789. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  790. }
  791. //身份证重复判断
  792. String idCard = dataFormatter.formatCellValue(row.getCell(6));
  793. if (!ObjectUtils.isEmpty(idCard)) {
  794. idCards.add(idCard);
  795. }
  796. if (idCards.stream().distinct().count() != idCards.size()) {
  797. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  798. }
  799. user.setCardNo(cardNo == null ? "" : cardNo);
  800. user.setName(name == null ? "" : name);
  801. user.setIdentityId(eIdentityStatu.Student.getValue());
  802. user.setIdCard(idCard == null ? "" : idCard);
  803. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  804. user.setDepartmentId(departmentId);
  805. String cellImage = dataFormatter.formatCellValue(row.getCell(7));
  806. user.setHeadImage(cellImage);
  807. user.setDormitoryNumber("");
  808. String grade = schoolGrade == null ? "" : schoolGrade;
  809. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  810. if (oGrade != null && oGrade.isPresent()) {
  811. Integer gradeId = oGrade.get().getId();
  812. user.setGrade(String.valueOf(gradeId));
  813. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  814. if (oClass != null && oClass.isPresent()) {
  815. user.setSchoolClass(oClass.get().getId());
  816. } else {
  817. return CommonResult.fail(name + "的班级数据无效,导入失败");
  818. }
  819. } else {
  820. return CommonResult.fail(name + "的年级数据无效,导入失败");
  821. }
  822. user.setCollege("");
  823. user.setSpeciality("");
  824. user.setCampus("");
  825. user.setPhone("");
  826. user.setAffiliate("");
  827. user.setTitle("");
  828. user.setAddress(address == null ? "" : address);
  829. user.setNation(nation == null ? "" : nation);
  830. user.setOfStudent("");
  831. user.setGraduate("");
  832. user.setDuties(null);
  833. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));
  834. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  835. if (groupData != null && groupData.isPresent()) {
  836. user.setTimeGroupId(groupData.get().getId());
  837. } else {
  838. user.setTimeGroupId(0);
  839. }
  840. user.setIsCancel(eLogOff.Unlogout.getValue());
  841. result.add(user);
  842. //部门是否为空判断
  843. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  844. Integer familyDepartmentId = null;
  845. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  846. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  847. familyDepartmentId = familyDepartModel.get().getId();
  848. } else {
  849. familyDepartmentId = 16;
  850. }
  851. //region 家属
  852. if (!ObjectUtils.isEmpty(phone)) {
  853. if (phone.length() != 11) {
  854. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  855. }
  856. SmartUser familyOne = new SmartUser();
  857. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  858. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  859. familyOne.setDepartmentId(familyDepartmentId);
  860. familyOne.setPhone(phone);
  861. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  862. familyOne.setSexId(eSexStatu.Man.getValue());
  863. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  864. familyOne.setAffiliate(user.getCardNo());
  865. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  866. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  867. result.add(familyOne);
  868. }
  869. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  870. if (!ObjectUtils.isEmpty(phoneTwo)) {
  871. if (phoneTwo.length() != 11) {
  872. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  873. }
  874. SmartUser familyTwo = new SmartUser();
  875. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  876. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  877. familyTwo.setDepartmentId(familyDepartmentId);
  878. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  879. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  880. familyTwo.setSexId(eSexStatu.Man.getValue());
  881. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  882. familyTwo.setAffiliate(user.getCardNo());
  883. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  884. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  885. result.add(familyTwo);
  886. }
  887. //endregion
  888. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  889. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(13)))) {
  890. if (phone.equals(dataFormatter.formatCellValue(row.getCell(13)))) {
  891. return CommonResult.fail(name + "的学生家长手机号不可重复");
  892. }
  893. }
  894. //endregion
  895. }
  896. }
  897. }
  898. } catch (Exception e) {
  899. return CommonResult.fail("请按模板格式导入数据");
  900. }
  901. return CommonResult.ok(result);
  902. }
  903. /**
  904. * Xls文件读取方法
  905. *
  906. * @param inputStream 文件流
  907. * @return
  908. * @throws IOException
  909. */
  910. private CommonResult<List<SmartUser>> readXls(InputStream inputStream) throws IOException {
  911. List<String> phones = new ArrayList<>();
  912. List<String> idCards = new ArrayList<>();
  913. List<String> cardNos = new ArrayList<>();
  914. List<SmartUser> result = new ArrayList<>();
  915. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  916. List<SmartDepartment> departments = smartDepartmentService.list(null);
  917. List<SmartGrade> grades = smartGradeService.list(null); //年级
  918. List<SmartClass> classs = smartClassService.list(null);//班级
  919. List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
  920. //读取第一张sheet
  921. HSSFSheet sheetAt = sheets.getSheetAt(0);
  922. DataFormatter dataFormatter = new DataFormatter();
  923. try {
  924. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  925. HSSFRow row = sheetAt.getRow(rowNum);
  926. if (row != null) {
  927. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  928. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  929. //然后poi会根据字符串读取它
  930. //标题 校验
  931. if (rowNum == 0) {
  932. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  933. if (!schoolGrade.equals("年级")) {
  934. return CommonResult.fail("导入数据第一列为年级");
  935. }
  936. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  937. if (!schoolClass.equals("班级")) {
  938. return CommonResult.fail("导入数据第一列为班级");
  939. }
  940. String cardNo = dataFormatter.formatCellValue(row.getCell(2));//学号
  941. if (!cardNo.equals("学号")) {
  942. return CommonResult.fail("导入数据第二列为学号");
  943. }
  944. String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
  945. if (!name.equals("姓名")) {
  946. return CommonResult.fail("导入数据第三列为姓名");
  947. }
  948. String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
  949. if (!sex.equals("性别")) {
  950. return CommonResult.fail("导入数据第四列为性别");
  951. }
  952. String nation = dataFormatter.formatCellValue(row.getCell(5));//民族
  953. if (!nation.equals("民族")) {
  954. return CommonResult.fail("导入数据第五列为民族");
  955. }
  956. String cardId = dataFormatter.formatCellValue(row.getCell(6));//身份证
  957. if (!cardId.equals("身份证")) {
  958. return CommonResult.fail("导入数据第六列为身份证");
  959. }
  960. String headImage = dataFormatter.formatCellValue(row.getCell(7));//照片
  961. if (!headImage.equals("照片")) {
  962. return CommonResult.fail("导入数据第七列为照片");
  963. }
  964. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));//常规时间组
  965. if (!timeGroup.equals("常规时间组")) {
  966. return CommonResult.fail("导入数据第八列为常规时间组");
  967. }
  968. String address = dataFormatter.formatCellValue(row.getCell(9));//住址
  969. if (!address.equals("住址")) {
  970. return CommonResult.fail("导入数据第九列为住址");
  971. }
  972. String phone = dataFormatter.formatCellValue(row.getCell(10));//联系电话
  973. if (!phone.equals("联系电话")) {
  974. return CommonResult.fail("导入数据第十列为联系电话");
  975. }
  976. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  977. if (!family.equals("家属")) {
  978. return CommonResult.fail("导入数据第十一列为家属");
  979. }
  980. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  981. if (!familyShip.equals("家属与本人关系")) {
  982. return CommonResult.fail("导入数据第十二列为家属与本人关系");
  983. }
  984. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  985. if (!phoneTwo.equals("联系电话2")) {
  986. return CommonResult.fail("导入数据第十三列为联系电话2");
  987. }
  988. String familyTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  989. if (!familyTwo.equals("家属2")) {
  990. return CommonResult.fail("导入数据第十四列为家属2");
  991. }
  992. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  993. if (!familyShipTwo.equals("家属与本人关系2")) {
  994. return CommonResult.fail("导入数据第十五列为家属与本人关系2");
  995. }
  996. } else {
  997. SmartUser user = new SmartUser();
  998. String name = dataFormatter.formatCellValue(row.getCell(3));
  999. if (ObjectUtils.isEmpty(name)) {
  1000. return CommonResult.fail("第" + (rowNum + 2) + "条数据的名称不能为空");
  1001. }
  1002. String schoolGrade = dataFormatter.formatCellValue(row.getCell(0));//年级
  1003. if (ObjectUtils.isEmpty(schoolGrade)) {
  1004. return CommonResult.fail(name + "的年级不能为空");
  1005. }
  1006. String schoolClass = dataFormatter.formatCellValue(row.getCell(1));//班级
  1007. if (ObjectUtils.isEmpty(schoolClass)) {
  1008. return CommonResult.fail(name + "的班级不能为空");
  1009. }
  1010. //不判断重复性 因为会出现双胞胎
  1011. String phone = dataFormatter.formatCellValue(row.getCell(10));
  1012. // if (!ObjectUtils.isEmpty(phone)) {
  1013. // phones.add(phone);
  1014. // }
  1015. // if (phones.stream().distinct().count() != phones.size()) {
  1016. // return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据");
  1017. // }
  1018. //性别是否为空判断
  1019. String sex = dataFormatter.formatCellValue(row.getCell(4));
  1020. if (ObjectUtils.isEmpty(sex)) {
  1021. return CommonResult.fail(name + "的性别不能为空");
  1022. }
  1023. //家庭住址是否为空判断
  1024. String address = dataFormatter.formatCellValue(row.getCell(9));
  1025. //民族是否为空判断
  1026. String nation = dataFormatter.formatCellValue(row.getCell(5));
  1027. if (ObjectUtils.isEmpty(nation)) {
  1028. return CommonResult.fail(name + "的民族不能为空");
  1029. }
  1030. //部门是否为空判断
  1031. String department = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "学生";
  1032. if (ObjectUtils.isEmpty(department)) {
  1033. return CommonResult.fail(name + "的部门不能为空");
  1034. }
  1035. Integer departmentId = null;
  1036. Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst();
  1037. if (departModel != null && departModel.isPresent()) {
  1038. departmentId = departModel.get().getId();
  1039. } else {
  1040. departmentId = 1;
  1041. }
  1042. //学号重复判断
  1043. String cardNo = dataFormatter.formatCellValue(row.getCell(2));
  1044. if (!ObjectUtils.isEmpty(cardNo)) {
  1045. cardNos.add(cardNo);
  1046. }
  1047. if (cardNos.stream().distinct().count() != cardNos.size()) {
  1048. return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据");
  1049. }
  1050. //身份证重复判断
  1051. String idCard = dataFormatter.formatCellValue(row.getCell(6));
  1052. if (!ObjectUtils.isEmpty(idCard)) {
  1053. idCards.add(idCard);
  1054. }
  1055. if (idCards.stream().distinct().count() != idCards.size()) {
  1056. return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
  1057. }
  1058. user.setCardNo(cardNo == null ? "" : cardNo);
  1059. user.setName(name == null ? "" : name);
  1060. user.setIdentityId(eIdentityStatu.Student.getValue());
  1061. user.setIdCard(idCard == null ? "" : idCard);
  1062. user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
  1063. user.setDepartmentId(departmentId);
  1064. String cellImage = dataFormatter.formatCellValue(row.getCell(7));
  1065. user.setHeadImage(cellImage);
  1066. user.setDormitoryNumber("");
  1067. String grade = schoolGrade == null ? "" : schoolGrade;
  1068. Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
  1069. if (oGrade != null && oGrade.isPresent()) {
  1070. Integer gradeId = oGrade.get().getId();
  1071. user.setGrade(String.valueOf(gradeId));
  1072. Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && e.getGradeId().equals(gradeId)).findFirst();
  1073. if (oClass != null && oClass.isPresent()) {
  1074. user.setSchoolClass(oClass.get().getId());
  1075. } else {
  1076. return CommonResult.fail(name + "的班级数据无效,导入失败");
  1077. }
  1078. } else {
  1079. return CommonResult.fail(name + "的年级数据无效,导入失败");
  1080. }
  1081. user.setCollege("");
  1082. user.setSpeciality("");
  1083. user.setCampus("");
  1084. user.setPhone("");
  1085. user.setAffiliate("");
  1086. user.setTitle("");
  1087. user.setAddress(address == null ? "" : address);
  1088. user.setNation(nation == null ? "" : nation);
  1089. user.setOfStudent("");
  1090. user.setGraduate("");
  1091. user.setDuties(null);
  1092. String timeGroup = dataFormatter.formatCellValue(row.getCell(8));
  1093. Optional<SmartTimeGroup> groupData = timeGroups.stream().filter(e -> e.getName().equals(timeGroup)).findFirst();
  1094. if (groupData != null && groupData.isPresent()) {
  1095. user.setTimeGroupId(groupData.get().getId());
  1096. } else {
  1097. user.setTimeGroupId(0);
  1098. }
  1099. user.setIsCancel(eLogOff.Unlogout.getValue());
  1100. result.add(user);
  1101. //部门是否为空判断
  1102. String familyDepartment = dataFormatter.formatCellValue(row.getCell(1)).replace("年级", "") + "家长";
  1103. Integer familyDepartmentId = null;
  1104. Optional<SmartDepartment> familyDepartModel = departments.stream().filter(e -> e.getName().equals(familyDepartment)).findFirst();
  1105. if (familyDepartModel != null && familyDepartModel.isPresent()) {
  1106. familyDepartmentId = familyDepartModel.get().getId();
  1107. } else {
  1108. familyDepartmentId = 16;
  1109. }
  1110. //region 家属
  1111. if (!ObjectUtils.isEmpty(phone)) {
  1112. if (phone.length() != 11) {
  1113. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1114. }
  1115. SmartUser familyOne = new SmartUser();
  1116. String family = dataFormatter.formatCellValue(row.getCell(11));//家属
  1117. familyOne.setName(!ObjectUtils.isEmpty(family) ? family : "家长");
  1118. familyOne.setDepartmentId(familyDepartmentId);
  1119. familyOne.setPhone(phone);
  1120. familyOne.setIdentityId(eIdentityStatu.Parent.getValue());
  1121. familyOne.setSexId(eSexStatu.Man.getValue());
  1122. familyOne.setIsCancel(eLogOff.Unlogout.getValue());
  1123. familyOne.setAffiliate(user.getCardNo());
  1124. String familyShip = dataFormatter.formatCellValue(row.getCell(12));//家属与本人关系
  1125. familyOne.setShip(familyShip == null ? "其他" : familyShip);
  1126. result.add(familyOne);
  1127. }
  1128. String phoneTwo = dataFormatter.formatCellValue(row.getCell(13));//联系电话2
  1129. if (!ObjectUtils.isEmpty(phoneTwo)) {
  1130. if (phoneTwo.length() != 11) {
  1131. return CommonResult.fail(name + "的学生家长手机号长度不符合标准");
  1132. }
  1133. SmartUser familyTwo = new SmartUser();
  1134. String familyNameTwo = dataFormatter.formatCellValue(row.getCell(14));//家属2
  1135. familyTwo.setName(!ObjectUtils.isEmpty(familyNameTwo) ? familyNameTwo : "家长");
  1136. familyTwo.setDepartmentId(familyDepartmentId);
  1137. familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo);
  1138. familyTwo.setIdentityId(eIdentityStatu.Parent.getValue());
  1139. familyTwo.setSexId(eSexStatu.Man.getValue());
  1140. familyTwo.setIsCancel(eLogOff.Unlogout.getValue());
  1141. familyTwo.setAffiliate(user.getCardNo());
  1142. String familyShipTwo = dataFormatter.formatCellValue(row.getCell(15));//家属与本人关系2
  1143. familyTwo.setShip(familyShipTwo == null ? "其他" : familyShipTwo);
  1144. result.add(familyTwo);
  1145. }
  1146. //endregion
  1147. //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
  1148. if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(13)))) {
  1149. if (phone.equals(dataFormatter.formatCellValue(row.getCell(13)))) {
  1150. return CommonResult.fail(name + "的学生家长手机号不可重复");
  1151. }
  1152. }
  1153. //endregion
  1154. }
  1155. }
  1156. }
  1157. } catch (Exception e) {
  1158. return CommonResult.fail("请按模板格式导入数据");
  1159. }
  1160. return CommonResult.ok(result);
  1161. }
  1162. @Override
  1163. @DESRespondSecret(validated = true)
  1164. public CommonResult timeGroups() throws Exception {
  1165. List<TimeGroupVo> result = new ArrayList<>();
  1166. //region 获取百胜的时间组
  1167. String appId = controlConfig.getAppId();
  1168. String schoolno = controlConfig.getSchoolCode();
  1169. String timestamp = TimeExchange.DateNowTimeStamo();
  1170. String appSecret = controlConfig.getAppSecret();
  1171. String url = controlConfig.getUrl() + "timegroup/searchtimegroup";
  1172. JSONObject jsonobject = new JSONObject();
  1173. jsonobject.put("appid", appId);
  1174. String str = "{\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}";
  1175. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  1176. jsonobject.put("data", aesStr);
  1177. jsonobject.put("schoolno", schoolno);
  1178. jsonobject.put("timestamp", timestamp);
  1179. String md5Str = "appid=" + appId + "&data={\"pageindex\":\"" + 1 + "\",\"pagesize\":\"" + 20 + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  1180. String sign = CommonUtil.MD5(md5Str);
  1181. //sign签名
  1182. jsonobject.put("sign", sign);
  1183. //返回的结果中 code为1表示成功
  1184. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  1185. ObjectMapper objectMapper = new ObjectMapper();
  1186. BsTimeGroupVo bsDataResult = objectMapper.readValue(bsResult, BsTimeGroupVo.class);
  1187. if (!bsResult.contains("查询成功")) {
  1188. return CommonResult.fail(bsDataResult.getMsg());
  1189. }
  1190. // URL解码
  1191. String decodedUrl = URLDecoder.decode(bsDataResult.getData(), "UTF-8");
  1192. BsTimeGroupNoVo timeGroupNos = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsTimeGroupNoVo.class);
  1193. //endregion
  1194. List<SmartTimeGroup> groups = smartTimeGroupService.queryTimeGroups();
  1195. List<SmartTimeGroup> newGroups = new ArrayList<>();
  1196. List<SmartTimeGroup> oldGroups = new ArrayList<>();
  1197. if (timeGroupNos.getData() != null) {
  1198. for (BsTimeGroupNoListVo timeGroup : timeGroupNos.getData()) {
  1199. Optional<SmartTimeGroup> oGroup = groups == null ? null : groups.stream().filter(e -> e.getBsno().equals(timeGroup.getTg_no())).findFirst();
  1200. if (oGroup != null && oGroup.isPresent()) {
  1201. SmartTimeGroup oldData = new SmartTimeGroup();
  1202. oldData.setId(oGroup.get().getId());
  1203. oldData.setBsno(timeGroup.getTg_no());
  1204. oldData.setName(timeGroup.getTg_name());
  1205. oldData.setRemark(timeGroup.getTg_remark());
  1206. oldGroups.add(oldData);
  1207. } else {
  1208. SmartTimeGroup newData = new SmartTimeGroup();
  1209. newData.setBsno(timeGroup.getTg_no());
  1210. newData.setName(timeGroup.getTg_name());
  1211. newData.setRemark(timeGroup.getTg_remark());
  1212. newGroups.add(newData);
  1213. }
  1214. }
  1215. }
  1216. if (oldGroups != null && oldGroups.size() > 0) {
  1217. boolean updateGroup = smartTimeGroupService.updateSmartTimeGroups(oldGroups);
  1218. if (!updateGroup) {
  1219. return CommonResult.fail("获取时间组失败");
  1220. }
  1221. }
  1222. if (newGroups != null && newGroups.size() > 0) {
  1223. boolean insertGroup = smartTimeGroupService.insertSmartTimeGroups(newGroups);
  1224. if (!insertGroup) {
  1225. return CommonResult.fail("获取时间组失败");
  1226. }
  1227. }
  1228. //oldData集合不在newDatas集合中的内容
  1229. List<Integer> newDatas = oldGroups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
  1230. List<Integer> oldDatas = groups.stream().map(SmartTimeGroup::getId).collect(Collectors.toList());
  1231. List<Integer> deleteIds = oldDatas.stream().filter(item -> !newDatas.contains(item)).collect(Collectors.toList());//需要删除的id
  1232. if (deleteIds.size() > 0) {
  1233. int deleted = smartTimeGroupService.deletedTimeGroupByIds(deleteIds);
  1234. if (deleted <= 0) {
  1235. throw new Exception("获取时间组失败!");
  1236. }
  1237. }
  1238. List<SmartTimeGroup> groupDatas = smartTimeGroupService.queryTimeGroups();
  1239. for (SmartTimeGroup groupData : groupDatas) {
  1240. TimeGroupVo data = new TimeGroupVo();
  1241. data.setId(groupData.getId());
  1242. data.setName(groupData.getName());
  1243. result.add(data);
  1244. }
  1245. return CommonResult.ok(result);
  1246. }
  1247. /**
  1248. * 新增用户
  1249. *
  1250. * @param isur 用户数据
  1251. * @param bindingResult
  1252. * @return
  1253. */
  1254. @Override
  1255. @DESRespondSecret(validated = true)
  1256. public CommonResult insertSmartUser(insertSmartUserRequest isur, BindingResult bindingResult) throws Exception {
  1257. if (bindingResult.hasErrors()) {
  1258. String st = paramUtils.getParamError(bindingResult);
  1259. return CommonResult.fail(st);
  1260. }
  1261. int useBs = 1;
  1262. int useXw = 1;
  1263. //重复性判断
  1264. int existCount = smartUserService.querySmartUserByCardNo(isur.getCardNo());
  1265. if (existCount > 0) {
  1266. return CommonResult.fail("当前学号已存在,请勿重复添加");
  1267. }
  1268. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1269. SmartUser su = new SmartUser();
  1270. su.setTimeGroupId(isur.getTimeGroupId());
  1271. su.setCardNo(isur.getCardNo());
  1272. su.setName(isur.getName());
  1273. su.setIdentityId(isur.getIdentityId());
  1274. su.setIdCard(isur.getIdCard());
  1275. su.setSexId(isur.getSexId());
  1276. su.setDepartmentId(isur.getDepartmentId());
  1277. su.setHeadImage(isur.getHeadImage());
  1278. su.setGrade(isur.getGrade());
  1279. su.setCollege(isur.getCollege());
  1280. su.setSpeciality(isur.getSpeciality());
  1281. su.setSchoolClass(isur.getSchoolClass());
  1282. su.setCampus(isur.getCampus());
  1283. su.setDormitoryNumber(isur.getDormitoryNumber());
  1284. su.setPhone(isur.getPhone());
  1285. su.setAffiliate(StringUtils.join(isur.getAffiliate(), ","));
  1286. su.setTitle(isur.getTitle());
  1287. su.setAddress(isur.getAddress());
  1288. su.setNation(isur.getNation());
  1289. su.setOfStudent(isur.getOfStudent());
  1290. su.setGraduate(isur.getGraduate());
  1291. su.setDuties(isur.getDuties());
  1292. su.setIsCancel(eLogOff.Unlogout.getValue());
  1293. //region 人员信息加入到第三方api
  1294. //要将用户数据加入到希沃和百胜中
  1295. //希沃和百胜的老师、学生数据添加是不一样的,所以按身份添加
  1296. if (isur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  1297. //region 家长参数必填判断:手机号
  1298. if (isur.getPhone() == null) {
  1299. return CommonResult.fail("家长手机号不能为空");
  1300. }
  1301. //endregion
  1302. //拿到被关联学生的信息去获取对应的卡号
  1303. //有多个学生就循环学生
  1304. if (isur.getAffiliate() == null) {
  1305. return CommonResult.fail("被关联人不能为空");
  1306. }
  1307. if (isur.getAffiliate().size() <= 0) {
  1308. return CommonResult.fail("被关联人不能为空");
  1309. }
  1310. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(isur.getAffiliate());
  1311. //region 希沃新增编辑学生家长信息
  1312. if (useXw == 1) {
  1313. CommonResult insertOrUpdateStudent = insertOrUpdateStudentParent(seewoClient, studentDatas, isur.getName(), isur.getPhone());
  1314. if (!insertOrUpdateStudent.isSuccess()) {
  1315. return CommonResult.fail(insertOrUpdateStudent.getMessage());
  1316. }
  1317. }
  1318. //endregion
  1319. } else if (isur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  1320. //region 学生参数必填判断:年级、班级
  1321. if (isur.getGrade() == null) {
  1322. return CommonResult.fail("学生年级不能为空");
  1323. }
  1324. if (isur.getSchoolClass() == null) {
  1325. return CommonResult.fail("学生班级不能为空");
  1326. }
  1327. //endregion
  1328. //获取班级Uid
  1329. SmartClass classData = smartClassService.getSmartClassById(isur.getSchoolClass());
  1330. if (classData == null) {
  1331. return CommonResult.fail("班级数据无效,新增失败");
  1332. }
  1333. SmartGrade gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(isur.getGrade()));
  1334. if (gradeData == null) {
  1335. return CommonResult.fail("年级数据无效,新增失败");
  1336. }
  1337. //region 希沃新增学生信息
  1338. if (useXw == 1) {
  1339. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getPhone(), classData.getClassUid());
  1340. if (!insertStudent.isSuccess()) {
  1341. return CommonResult.fail(insertStudent.getMessage());
  1342. }
  1343. su.setXwStudentUid(insertStudent.getData());
  1344. //上传图片
  1345. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  1346. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  1347. photo.setPhotoUrl(su.getHeadImage());
  1348. photo.setUserCode(su.getCardNo());
  1349. photoList.add(photo);
  1350. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  1351. if (!result.isSuccess()) {
  1352. return result;
  1353. }
  1354. }
  1355. //endregion
  1356. //region 百胜新增学生信息
  1357. if (useBs == 1) {
  1358. /**
  1359. * 学生数据的有效期是到毕业年份的8月31日
  1360. */
  1361. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1362. String endTime = queryGraduationYear(gradeData.getGradeNo());
  1363. CommonResult<String> insertBsStudent = bsInsertStudent(isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getHeadImage(), isur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime);
  1364. if (!insertBsStudent.isSuccess()) {
  1365. return CommonResult.fail(insertBsStudent.getMessage());
  1366. }
  1367. su.setBsStudentNo(insertBsStudent.getData());
  1368. }
  1369. //endregion
  1370. } else if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//老师
  1371. //region 老师参数必填判断:职称、手机号
  1372. if (isur.getTitle() == null) {
  1373. return CommonResult.fail("老师职称不能为空");
  1374. }
  1375. if (isur.getPhone() == null) {
  1376. return CommonResult.fail("老师手机号不能为空");
  1377. }
  1378. //endregion
  1379. //region 希沃添加教师数据
  1380. if (useXw == 1) {
  1381. CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, isur.getPhone(), isur.getName(), isur.getHeadImage());
  1382. if (!insertTeacher.isSuccess()) {
  1383. return CommonResult.fail(insertTeacher.getMessage());
  1384. }
  1385. su.setXwTeacherCode(insertTeacher.getData());
  1386. //上传图片
  1387. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  1388. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  1389. photo.setPhotoUrl(su.getHeadImage());
  1390. photo.setUserCode(su.getPhone());
  1391. photoList.add(photo);
  1392. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  1393. if (!result.isSuccess()) {
  1394. return result;
  1395. }
  1396. }
  1397. //endregion
  1398. if (isur.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  1399. //获取班级Uid
  1400. SmartClass classData = smartClassService.getSmartClassById(isur.getSchoolClass());
  1401. if (classData == null) {
  1402. return CommonResult.fail("班级数据无效,新增失败");
  1403. }
  1404. //region 将班主任推送到希沃
  1405. if (useXw == 1) {
  1406. CommonResult pushMaster = SeewoPushMaster(seewoClient, isur.getPhone(), classData.getClassUid());
  1407. if (!pushMaster.isSuccess()) {
  1408. return CommonResult.fail(pushMaster.getMessage());
  1409. }
  1410. }
  1411. //endregion
  1412. }
  1413. SmartDepartment departmentData = smartDepartmentService.getSmartById(isur.getDepartmentId());
  1414. if (departmentData == null) {
  1415. return CommonResult.fail("部门数据无效,新增教师失败");
  1416. }
  1417. String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
  1418. if (departmentNo == null) {
  1419. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  1420. }
  1421. //region 百胜添加教师数据
  1422. if (useBs == 1) {
  1423. /**
  1424. * 教师数据的有效期是20年
  1425. */
  1426. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1427. String endTime = TimeExchange.addYear(20);
  1428. CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
  1429. if (!insertBsTeacher.isSuccess()) {
  1430. return CommonResult.fail(insertBsTeacher.getMessage());
  1431. }
  1432. su.setBsStaffCode(insertBsTeacher.getData());
  1433. }
  1434. //endregion
  1435. }
  1436. //endregion
  1437. //最后都要把数据加入到数据库中
  1438. int result = smartUserService.insertSmartUser(su);
  1439. //新增用户得将用户信息通过接口推送到希沃、百胜
  1440. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  1441. }
  1442. /**
  1443. * 更新用户
  1444. *
  1445. * @param usur 更新用户数据
  1446. * @param bindingResult
  1447. * @return
  1448. */
  1449. @Override
  1450. @DESRespondSecret(validated = true)
  1451. public CommonResult updateSmartUserById(updateSmartUserRequest usur, BindingResult bindingResult) throws Exception {
  1452. if (bindingResult.hasErrors()) {
  1453. String st = paramUtils.getParamError(bindingResult);
  1454. return CommonResult.fail(st);
  1455. }
  1456. //region 参数判断
  1457. if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  1458. if (usur.getTimeGroupId() == null) {
  1459. return CommonResult.fail("学生时间组不能为空");
  1460. }
  1461. if (usur.getCardNo() == null) {
  1462. return CommonResult.fail("学生编号不能为空");
  1463. }
  1464. if (usur.getHeadImage() == null) {
  1465. return CommonResult.fail("学生人脸照片不能为空");
  1466. }
  1467. }
  1468. //endregion
  1469. int useXw = 1;
  1470. int useBs = 1;
  1471. //更新的同时将百胜用户信息同步过去或者同步过来?
  1472. SmartUser su = smartUserService.getSmartById(usur.getId());
  1473. if (su == null) {
  1474. return CommonResult.fail("用户数据已失效,修改失败!");
  1475. }
  1476. //是否转换身份
  1477. boolean changeIdentity = false;
  1478. Integer oldIdentity = null;
  1479. String oldAffiliate = su.getAffiliate();
  1480. Integer oldSchoolClass = su.getSchoolClass();
  1481. String oldStaffNo = su.getBsStaffCode();
  1482. String oldCardNo = su.getCardNo();
  1483. if (usur.getIdentityId().intValue() != su.getIdentityId().intValue()) {
  1484. changeIdentity = true;
  1485. oldIdentity = su.getIdentityId().intValue();
  1486. }
  1487. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1488. su.setTimeGroupId(usur.getTimeGroupId());
  1489. su.setCardNo(usur.getCardNo());
  1490. su.setName(usur.getName());
  1491. su.setIdentityId(usur.getIdentityId());
  1492. su.setIdCard(usur.getIdCard());
  1493. su.setSexId(usur.getSexId());
  1494. su.setDepartmentId(usur.getDepartmentId());
  1495. su.setHeadImage(usur.getHeadImage());
  1496. su.setGrade(usur.getGrade());
  1497. su.setCollege(usur.getCollege());
  1498. su.setSpeciality(usur.getSpeciality());
  1499. su.setSchoolClass(usur.getSchoolClass());
  1500. su.setCampus(usur.getCampus());
  1501. su.setDormitoryNumber(usur.getDormitoryNumber());
  1502. su.setPhone(usur.getPhone());
  1503. su.setAffiliate(StringUtils.join(usur.getAffiliate(), ","));
  1504. su.setTitle(usur.getTitle());
  1505. su.setAddress(usur.getAddress());
  1506. su.setNation(usur.getNation());
  1507. su.setOfStudent(usur.getOfStudent());
  1508. su.setGraduate(usur.getGraduate());
  1509. su.setDuties(usur.getDuties());
  1510. su.setIsCancel(eLogOff.Unlogout.getValue());
  1511. if (usur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  1512. //拿到被关联学生的信息去获取对应的卡号
  1513. //有多个学生就循环学生
  1514. if (usur.getAffiliate() == null) {
  1515. return CommonResult.fail("被关联人不能为空");
  1516. }
  1517. if (usur.getAffiliate().size() <= 0) {
  1518. return CommonResult.fail("被关联人不能为空");
  1519. }
  1520. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(usur.getAffiliate());
  1521. if (!changeIdentity) {
  1522. //region 希沃新增编辑学生家长信息
  1523. if (useXw == 1) {
  1524. //学生与家长列表,最大100条
  1525. CommonResult insertOrUpdateResult = insertOrUpdateStudentParent(seewoClient, studentDatas, usur.getName(), usur.getPhone());
  1526. if (!insertOrUpdateResult.isSuccess()) {
  1527. return CommonResult.fail(insertOrUpdateResult.getMessage());
  1528. }
  1529. }
  1530. //endregion
  1531. } else {
  1532. if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  1533. //region 希沃删除学生
  1534. //获取班级Uid
  1535. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  1536. if (classData == null) {
  1537. return CommonResult.fail("班级数据无效,更新失败");
  1538. }
  1539. if (useXw == 1) {
  1540. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  1541. if (!deleteStudent.isSuccess()) {
  1542. return CommonResult.fail(deleteStudent.getMessage());
  1543. }
  1544. }
  1545. //endregion
  1546. //region 百胜删除学生
  1547. if (useBs == 1) {
  1548. CommonResult deleteBsStudent = bsDeleteStudent(su);
  1549. if (!deleteBsStudent.isSuccess()) {
  1550. return CommonResult.fail(deleteBsStudent.getMessage());
  1551. }
  1552. }
  1553. //endregion
  1554. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  1555. //获取班级Uid
  1556. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  1557. if (classData == null) {
  1558. return CommonResult.fail("班级数据无效,更新失败");
  1559. }
  1560. //region 希沃删除教师
  1561. if (useXw == 1) {
  1562. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  1563. if (!deleteTeacher.isSuccess()) {
  1564. return CommonResult.fail(deleteTeacher.getMessage());
  1565. }
  1566. }
  1567. //endregion
  1568. //region 希沃删除班主任
  1569. if (useXw == 1) {
  1570. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
  1571. if (deleteTeacherMaster.isSuccess()) {
  1572. return CommonResult.fail(deleteTeacherMaster.getMessage());
  1573. }
  1574. }
  1575. //endregion
  1576. //region 百胜删除教师
  1577. if (useBs == 1) {
  1578. CommonResult bsDeleteTeacher = bsDeleteTeacher(oldStaffNo);
  1579. if (!bsDeleteTeacher.isSuccess()) {
  1580. return CommonResult.fail(bsDeleteTeacher.getMessage());
  1581. }
  1582. }
  1583. //endregion
  1584. }
  1585. //region 希沃新增编辑学生家长信息
  1586. if (useXw == 1) {
  1587. CommonResult insertOrUpdate = insertOrUpdateStudentParent(seewoClient, studentDatas, su.getName(), su.getPhone());
  1588. if (!insertOrUpdate.isSuccess()) {
  1589. return CommonResult.fail(insertOrUpdate.getMessage());
  1590. }
  1591. }
  1592. //endregion
  1593. }
  1594. } else if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  1595. //region 年级和班级不能为空
  1596. if (usur.getGrade() == null) {
  1597. return CommonResult.fail("学生年级不能为空");
  1598. }
  1599. if (usur.getSchoolClass() == null) {
  1600. return CommonResult.fail("学生班级不能为空");
  1601. }
  1602. //endregion
  1603. //获取班级Uid
  1604. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  1605. if (classData == null) {
  1606. return CommonResult.fail("班级数据无效,更新失败");
  1607. }
  1608. //获取年级Uid
  1609. SmartGrade gradeData = smartGradeService.querySmartGradeById(Integer.valueOf(su.getGrade()));
  1610. if (gradeData == null) {
  1611. return CommonResult.fail("年级数据无效,新增失败");
  1612. }
  1613. if (!changeIdentity) {
  1614. //region 更新希沃学生信息
  1615. if (useXw == 1) {
  1616. CommonResult updateStudent = SeewoUpdateStudent(seewoClient, su);
  1617. if (!updateStudent.isSuccess()) {
  1618. if (updateStudent.getMessage().equals("学生不存在")) {
  1619. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
  1620. if (!insertStudent.isSuccess()) {
  1621. return CommonResult.fail(insertStudent.getMessage());
  1622. }
  1623. }
  1624. return CommonResult.fail(updateStudent.getMessage());
  1625. }
  1626. //上传图片
  1627. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  1628. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  1629. photo.setPhotoUrl(su.getHeadImage());
  1630. photo.setUserCode(su.getCardNo());
  1631. photoList.add(photo);
  1632. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  1633. if (!result.isSuccess()) {
  1634. return result;
  1635. }
  1636. }
  1637. //endregion
  1638. //region 更新百胜学生信息
  1639. if (useBs == 1) {
  1640. /**
  1641. * 学生数据的有效期是到毕业年份的8月31日
  1642. */
  1643. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1644. String endTime = queryGraduationYear(gradeData.getGradeNo());
  1645. CommonResult updateBsStudent = bsUpdateStudent(su, startTime, endTime);
  1646. if (!updateBsStudent.isSuccess()) {
  1647. if (updateBsStudent.getMessage().equals("人员不存在或已删除")) {
  1648. //region 百胜新增学生信息
  1649. CommonResult<String> insertBsStudent = bsInsertStudent(usur.getName(), usur.getCardNo(), usur.getSexId(), usur.getHeadImage(), usur.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime);
  1650. if (!insertBsStudent.isSuccess()) {
  1651. return CommonResult.fail(insertBsStudent.getMessage());
  1652. }
  1653. su.setBsStudentNo(insertBsStudent.getData());
  1654. //endregion
  1655. } else {
  1656. return CommonResult.fail(updateBsStudent.getMessage());
  1657. }
  1658. }
  1659. }
  1660. //endregion
  1661. } else {
  1662. //region 希沃新增学生信息
  1663. if (useXw == 1) {
  1664. CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
  1665. if (!insertStudent.isSuccess()) {
  1666. return CommonResult.fail(insertStudent.getMessage());
  1667. } else {
  1668. su.setXwStudentUid(insertStudent.getData());
  1669. }
  1670. //上传图片
  1671. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  1672. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  1673. photo.setPhotoUrl(su.getHeadImage());
  1674. photo.setUserCode(su.getCardNo());
  1675. photoList.add(photo);
  1676. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
  1677. if (!result.isSuccess()) {
  1678. return result;
  1679. }
  1680. }
  1681. //endregion
  1682. //region 百胜新增学生信息
  1683. if (useBs == 1) {
  1684. /**
  1685. * 学生数据的有效期是到毕业年份的8月31日
  1686. */
  1687. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1688. String endTime = queryGraduationYear(gradeData.getGradeNo());
  1689. CommonResult<String> insertBsStudent = bsInsertStudent(su.getName(), su.getCardNo(), su.getSexId(), su.getHeadImage(), su.getTimeGroupId(), classData.getBsClassNo(), startTime, endTime);
  1690. if (insertBsStudent.isSuccess()) {
  1691. su.setBsStudentNo(insertBsStudent.getData());
  1692. } else {
  1693. //region 希沃删除学生
  1694. //百胜数据插入失败后需要把已插入到希沃的数据删除
  1695. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  1696. if (!deleteStudent.isSuccess()) {
  1697. return CommonResult.fail(deleteStudent.getMessage());
  1698. }
  1699. //endregion
  1700. return CommonResult.fail("切换身份后," + insertBsStudent.getMessage() + ",百胜无法插入学生数据");
  1701. }
  1702. }
  1703. //endregion
  1704. if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
  1705. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
  1706. //region 希沃删除原有的家长关系
  1707. if (useXw == 1) {
  1708. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
  1709. if (!deleteResult.isSuccess()) {
  1710. return CommonResult.fail(deleteResult.getMessage());
  1711. }
  1712. }
  1713. //endregion
  1714. } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
  1715. //获取班级Uid
  1716. SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
  1717. if (oldClassData == null) {
  1718. return CommonResult.fail("班级数据无效,更新失败");
  1719. }
  1720. //region 希沃删除教师
  1721. if (useXw == 1) {
  1722. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
  1723. if (!deleteTeacher.isSuccess()) {
  1724. return CommonResult.fail(deleteTeacher.getMessage());
  1725. }
  1726. }
  1727. //endregion
  1728. //region 希沃删除班主任
  1729. if (useXw == 1) {
  1730. CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
  1731. if (!deleteMaster.isSuccess()) {
  1732. return CommonResult.fail(deleteMaster.getMessage());
  1733. }
  1734. }
  1735. //endregion
  1736. //region 百胜删除教师
  1737. if (useBs == 1) {
  1738. CommonResult deleteBsTeacher = bsDeleteTeacher(oldStaffNo);
  1739. if (!deleteBsTeacher.isSuccess()) {
  1740. return CommonResult.fail(deleteBsTeacher.getMessage());
  1741. }
  1742. }
  1743. //endregion
  1744. }
  1745. }
  1746. } else if (usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//教师
  1747. if (!changeIdentity) {
  1748. //region 希沃更新教师数据
  1749. if (useXw == 1) {
  1750. CommonResult<String> updateTeacher = SeewoUpdateTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
  1751. if (!updateTeacher.isSuccess()) {
  1752. return CommonResult.fail(updateTeacher.getMessage());
  1753. }
  1754. su.setXwTeacherCode(updateTeacher.getData());
  1755. //上传图片
  1756. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  1757. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  1758. photo.setPhotoUrl(su.getHeadImage());
  1759. photo.setUserCode(su.getPhone());
  1760. photoList.add(photo);
  1761. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  1762. if (!result.isSuccess()) {
  1763. return result;
  1764. }
  1765. }
  1766. //endregion
  1767. SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
  1768. if (departmentData == null) {
  1769. return CommonResult.fail("部门数据无效,更新教师失败");
  1770. }
  1771. String departmentNo = departmentData.getBsDepartmentNo();
  1772. if (departmentNo == null) {
  1773. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  1774. }
  1775. //region 百胜更新教师数据
  1776. if (useBs == 1) {
  1777. /**
  1778. * 教师数据的有效期是20年
  1779. */
  1780. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1781. String endTime = TimeExchange.addYear(20);
  1782. CommonResult<String> bsUpdateTeacher = updateBsTeacher(su, departmentNo, startTime, endTime);
  1783. if (!bsUpdateTeacher.isSuccess()) {
  1784. return CommonResult.fail(bsUpdateTeacher.getMessage());
  1785. }
  1786. su.setBsStaffCode(bsUpdateTeacher.getData());
  1787. }
  1788. //endregion
  1789. } else {
  1790. if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) {
  1791. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(",")));
  1792. //region 希沃删除原有的家长关系
  1793. if (useXw == 1) {
  1794. CommonResult deleteOldShip = deleteOldParentShip(seewoClient, studentDatas, su.getPhone());
  1795. if (!deleteOldShip.isSuccess()) {
  1796. return CommonResult.fail(deleteOldShip.getMessage());
  1797. }
  1798. }
  1799. //endregion
  1800. } else if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) {
  1801. //获取班级Uid
  1802. SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
  1803. if (classData == null) {
  1804. return CommonResult.fail("班级数据无效,更新失败");
  1805. }
  1806. //region 希沃删除学生
  1807. if (useXw == 1) {
  1808. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo);
  1809. if (!deleteStudent.isSuccess()) {
  1810. return CommonResult.fail(deleteStudent.getMessage());
  1811. }
  1812. }
  1813. //endregion
  1814. //region 百胜删除学生
  1815. if (useBs == 1) {
  1816. CommonResult deleteBsStudent = bsDeleteStudent(su);
  1817. if (!deleteBsStudent.isSuccess()) {
  1818. return CommonResult.fail(deleteBsStudent.getMessage());
  1819. }
  1820. }
  1821. //endregion
  1822. }
  1823. //region 希沃添加教师数据
  1824. if (useXw == 1) {
  1825. CommonResult<String> insertTeacher = SeewoInsertTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage());
  1826. if (!insertTeacher.isSuccess()) {
  1827. return CommonResult.fail(insertTeacher.getMessage());
  1828. }
  1829. su.setXwTeacherCode(insertTeacher.getData());
  1830. //上传图片
  1831. List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
  1832. PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
  1833. photo.setPhotoUrl(su.getHeadImage());
  1834. photo.setUserCode(su.getPhone());
  1835. photoList.add(photo);
  1836. CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Teacher.getValue());
  1837. if (!result.isSuccess()) {
  1838. return result;
  1839. }
  1840. }
  1841. //endregion
  1842. if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  1843. //获取班级Uid
  1844. SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass());
  1845. if (classData == null) {
  1846. return CommonResult.fail("班级数据无效,新增失败");
  1847. }
  1848. //region 将班主任推送到希沃
  1849. if (useXw == 1) {
  1850. CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid());
  1851. if (!pushMaster.isSuccess()) {
  1852. return CommonResult.fail(pushMaster.getMessage());
  1853. }
  1854. }
  1855. //endregion
  1856. }
  1857. SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
  1858. if (departmentData == null) {
  1859. return CommonResult.fail("部门数据无效,新增教师失败");
  1860. }
  1861. String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
  1862. if (departmentNo == null) {
  1863. return CommonResult.fail("百胜部门编号为空,新增教师失败");
  1864. }
  1865. //region 百胜添加教师数据
  1866. if (useBs == 1) {
  1867. /**
  1868. * 教师数据的有效期是20年
  1869. */
  1870. String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
  1871. String endTime = TimeExchange.addYear(20);
  1872. CommonResult<String> insertBsTeacher = bsInsertTeacher(su, departmentNo, startTime, endTime);
  1873. if (!insertBsTeacher.isSuccess()) {
  1874. return CommonResult.fail(insertBsTeacher.getMessage());
  1875. }
  1876. su.setBsStaffCode(insertBsTeacher.getData());
  1877. }
  1878. //endregion
  1879. }
  1880. }
  1881. int result = smartUserService.updateSmartUser(su);
  1882. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  1883. }
  1884. //region 希沃增删改查方法
  1885. //希沃批量上传头像 如果当前用户已存在图片 会进行覆盖
  1886. public CommonResult SeewoInsertBatchPhoto(SeewoClient seewoClient, List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList, Integer userType) throws JsonProcessingException {
  1887. //region 希沃上传第三方图片信息
  1888. //初始化客户端
  1889. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1890. PhotoServiceSavePhotosParam param = new PhotoServiceSavePhotosParam();
  1891. //请求体,MimeType为 application/json
  1892. PhotoServiceSavePhotosParam.JSONRequestBody requestBody = PhotoServiceSavePhotosParam.JSONRequestBody.builder()
  1893. .build();
  1894. param.setRequestBody(requestBody);
  1895. //
  1896. PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery query = PhotoServiceSavePhotosParam.ThirdSavePhotoBatchQuery.builder()
  1897. .appId(seewoConfig.getAppId())
  1898. .unitUid(seewoConfig.getSchoolId())
  1899. .userType(userType)
  1900. .build();
  1901. requestBody.setQuery(query);
  1902. // 图片保存列表
  1903. query.setPhotoList(photoList);
  1904. PhotoServiceSavePhotosRequest request = new PhotoServiceSavePhotosRequest(param);
  1905. // 该接口需要数据权限,请将授权资源id替换至下方,请妥善保管好授权资源id,避免泄露
  1906. // permissionId位置: 控制台 -> 应用详情 -> 我申请的 -> 已通过的接口 -> 调用范围 -> 审批信息 中查看授权资源的「学校id」或「区域id」
  1907. //request.setPermissionId(seewoConfig.getSchoolId());
  1908. System.out.println("入参:" + request);
  1909. System.out.println("入参:" + JSON.toJSON(request));
  1910. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  1911. PhotoServiceSavePhotosResult result = seewoClient.invoke(request);
  1912. System.out.println("出参:" + result);
  1913. ObjectMapper objectMapper = new ObjectMapper();
  1914. XwBodyVo xwResult = objectMapper.readValue(result.getBody(), XwBodyVo.class);
  1915. if (!xwResult.getCode().equals("000000")) {
  1916. return CommonResult.fail(result.getMessage());
  1917. }
  1918. //endregion
  1919. return CommonResult.ok("200", "图片添加成功");
  1920. }
  1921. //region 希沃批量新增学生信息
  1922. public CommonResult<List<StudentServiceBatchSaveClassStudentsResult.StudentInfoDto>> SeewoInsertBatchStudent
  1923. (SeewoClient seewoClient, List<StudentServiceBatchSaveClassStudentsParam.StudentInfo> students, String
  1924. classUid) {
  1925. //region 希沃新增学生信息
  1926. //初始化客户端
  1927. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1928. StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
  1929. //请求体,MimeType为 application/json
  1930. StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
  1931. .build();
  1932. param.setRequestBody(requestBody);
  1933. //查询条件
  1934. StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
  1935. .appId(seewoConfig.getAppId())
  1936. .schoolUid(seewoConfig.getSchoolId())
  1937. .classUid(classUid)
  1938. .build();
  1939. requestBody.setQuery(query);
  1940. // 学生列表
  1941. query.setStudents(students);
  1942. query.setInPlaceOld(false);// 是否删除旧学生再保存
  1943. param.setRequestBody(requestBody);
  1944. StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
  1945. System.out.println("入参:" + request);
  1946. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  1947. //request.setServerUrl("https://openapi.test.seewo.com")
  1948. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  1949. StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
  1950. System.out.println("出参:" + result);
  1951. if (result == null) {
  1952. return CommonResult.fail("希沃学生数据新增失败!");
  1953. }
  1954. if (!result.getResponseBody().getCode().equals("000000")) {
  1955. return CommonResult.fail(result.getResponseBody().getMessage());
  1956. }
  1957. return CommonResult.ok("200", "添加成功", result.getResponseBody().getData());
  1958. //endregion
  1959. }
  1960. //endregion
  1961. //region 希沃新增学生信息
  1962. public CommonResult<String> SeewoInsertStudent(SeewoClient seewoClient, String name, String cardNo, Integer sexId, String Phone, String classUid) {
  1963. //region 希沃新增学生信息
  1964. //初始化客户端
  1965. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  1966. StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam();
  1967. //请求体,MimeType为 application/json
  1968. StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder()
  1969. .build();
  1970. param.setRequestBody(requestBody);
  1971. //查询条件
  1972. StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder()
  1973. .appId(seewoConfig.getAppId())
  1974. .schoolUid(seewoConfig.getSchoolId())
  1975. .classUid(classUid)
  1976. .build();
  1977. requestBody.setQuery(query);
  1978. // 学生列表
  1979. StudentServiceBatchSaveClassStudentsParam.StudentInfo students = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder()
  1980. .studentName(name)
  1981. .studentCode(cardNo)
  1982. .gender(sexId)
  1983. .phone(Phone == null ? "" : Phone)
  1984. .build();
  1985. query.setStudents(java.util.Collections.singletonList(students));
  1986. query.setInPlaceOld(false);// 是否删除旧学生再保存
  1987. param.setRequestBody(requestBody);
  1988. StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param);
  1989. System.out.println("入参:" + request);
  1990. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  1991. //request.setServerUrl("https://openapi.test.seewo.com")
  1992. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  1993. StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request);
  1994. System.out.println("出参:" + result);
  1995. if (result == null) {
  1996. return CommonResult.fail("希沃学生数据新增失败!");
  1997. }
  1998. if (!result.getResponseBody().getCode().equals("000000")) {
  1999. return CommonResult.fail(result.getResponseBody().getMessage());
  2000. }
  2001. return CommonResult.ok("200", "添加成功", result.getResponseBody().getData().get(0).getUserUid());
  2002. //endregion
  2003. }
  2004. //endregion
  2005. //region 希沃更新学生信息
  2006. public CommonResult SeewoUpdateStudent(SeewoClient seewoClient, SmartUser su) {
  2007. //region 更新希沃学生信息
  2008. //初始化客户端
  2009. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2010. StudentServiceUpdateStudentInfoParam param = new StudentServiceUpdateStudentInfoParam();
  2011. //响应体,MimeType为 application/json
  2012. StudentServiceUpdateStudentInfoParam.RequestBody requestBody = StudentServiceUpdateStudentInfoParam.RequestBody.builder()
  2013. .build();
  2014. param.setRequestBody(requestBody);
  2015. //query
  2016. StudentServiceUpdateStudentInfoParam.Query query = StudentServiceUpdateStudentInfoParam.Query.builder()
  2017. .appId(seewoConfig.getAppId())
  2018. .schoolUid(seewoConfig.getSchoolId())
  2019. .studentUid(su.getXwStudentUid())
  2020. .studentCode(su.getCardNo())
  2021. .studentName(su.getName())
  2022. .build();
  2023. requestBody.setQuery(query);
  2024. param.setRequestBody(requestBody);
  2025. StudentServiceUpdateStudentInfoRequest request = new StudentServiceUpdateStudentInfoRequest(param);
  2026. System.out.println("入参:" + request);
  2027. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2028. //request.setServerUrl("https://openapi.test.seewo.com")
  2029. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2030. StudentServiceUpdateStudentInfoResult result = seewoClient.invoke(request);
  2031. System.out.println("出参:" + result);
  2032. if (result == null) {
  2033. return CommonResult.fail("希沃学生数据更新失败!");
  2034. }
  2035. if (!result.getResponseBody().getCode().equals("000000")) {
  2036. return CommonResult.fail(result.getResponseBody().getMessage());
  2037. }
  2038. return CommonResult.ok("更新成功");
  2039. //endregion
  2040. }
  2041. //endregion
  2042. //region 希沃删除学生
  2043. public CommonResult SeewoDeleteStudent(SeewoClient seewoClient, String ClassUid, String CardNo) {
  2044. //初始化客户端
  2045. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2046. StudentServiceRemoveClassStudentsParam deleteParam = new StudentServiceRemoveClassStudentsParam();
  2047. //请求体,MimeType为 application/json
  2048. StudentServiceRemoveClassStudentsParam.JSONRequestBody deleteRequestBody = StudentServiceRemoveClassStudentsParam.JSONRequestBody.builder()
  2049. .build();
  2050. deleteParam.setRequestBody(deleteRequestBody);
  2051. //查询条件
  2052. StudentServiceRemoveClassStudentsParam.UnbindStudentQuery deleteQuery = StudentServiceRemoveClassStudentsParam.UnbindStudentQuery.builder()
  2053. .appId(seewoConfig.getAppId())
  2054. .schoolUid(seewoConfig.getSchoolId())
  2055. .classUid(ClassUid)
  2056. .studentCodes(java.util.Collections.singletonList(CardNo))
  2057. .build();
  2058. deleteRequestBody.setQuery(deleteQuery);
  2059. deleteParam.setRequestBody(deleteRequestBody);
  2060. StudentServiceRemoveClassStudentsRequest deleteRequest = new StudentServiceRemoveClassStudentsRequest(deleteParam);
  2061. System.out.println("入参:" + deleteRequest);
  2062. //如果想要调用沙箱环境,请通过设置 deleteRequest 对象的 serverUrl 属性,如:
  2063. //deleteRequest.setServerUrl("https://openapi.test.seewo.com")
  2064. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2065. StudentServiceRemoveClassStudentsResult deleteResult = seewoClient.invoke(deleteRequest);
  2066. System.out.println("出参:" + deleteResult);
  2067. if (deleteResult == null) {
  2068. return CommonResult.fail("希沃删除学生数据失败!");
  2069. }
  2070. if (!deleteResult.getResponseBody().getCode().equals("000000")) {
  2071. return CommonResult.fail(deleteResult.getResponseBody().getMessage());
  2072. }
  2073. return CommonResult.ok("删除成功");
  2074. }
  2075. //endregion
  2076. //region 希沃添加老师数据
  2077. //老师数据会根据手机号判断新增不新增
  2078. //手机号相同的情况下更新不新增
  2079. public CommonResult<String> SeewoInsertTeacher(SeewoClient seewoClient, String phone, String name, String
  2080. headImage) {
  2081. //region 希沃添加教师数据
  2082. //初始化客户端
  2083. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2084. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  2085. //请求体,MimeType为 application/json
  2086. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  2087. .build();
  2088. param.setRequestBody(requestBody);
  2089. //老师信息
  2090. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  2091. .appId(seewoConfig.getAppId())
  2092. .schoolUid(seewoConfig.getSchoolId())
  2093. .build();
  2094. requestBody.setQuery(query);
  2095. // 老师列表
  2096. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  2097. .account(phone)//用户账号
  2098. .name(name)//用户名字
  2099. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  2100. .teacherCode(phone)//教师工号
  2101. .photoUrl(headImage)//图片链接
  2102. .build();
  2103. query.setTeachers(java.util.Collections.singletonList(teachers));
  2104. param.setRequestBody(requestBody);
  2105. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  2106. System.out.println("入参:" + request);
  2107. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2108. //request.setServerUrl("https://openapi.test.seewo.com")
  2109. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2110. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  2111. System.out.println("出参:" + result);
  2112. if (result == null) {
  2113. return CommonResult.fail("希沃教师数据新增失败!");
  2114. }
  2115. if (!result.getResponseBody().getCode().equals("000000")) {
  2116. return CommonResult.fail(result.getResponseBody().getMessage());
  2117. }
  2118. String teacherCode = phone;
  2119. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  2120. teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
  2121. }
  2122. return CommonResult.ok("200", "操作成功", teacherCode);
  2123. //endregion
  2124. }
  2125. //endregion
  2126. //region 希沃更新教师
  2127. public CommonResult<String> SeewoUpdateTeacher(SeewoClient seewoClient, String phone, String name, String
  2128. headImage) {
  2129. //region 希沃更新教师数据
  2130. //初始化客户端
  2131. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2132. TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam();
  2133. //请求体,MimeType为 application/json
  2134. TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder()
  2135. .build();
  2136. param.setRequestBody(requestBody);
  2137. //老师信息
  2138. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder()
  2139. .appId(seewoConfig.getAppId())
  2140. .schoolUid(seewoConfig.getSchoolId())
  2141. .build();
  2142. requestBody.setQuery(query);
  2143. // 老师列表
  2144. TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder()
  2145. .account(phone)//用户账号
  2146. .name(name)//用户名字
  2147. .accountType("phone")//账号类型 phone:手机号 email:邮箱
  2148. .teacherCode(phone)//教师工号
  2149. .photoUrl(headImage)//图片链接
  2150. .build();
  2151. query.setTeachers(java.util.Collections.singletonList(teachers));
  2152. param.setRequestBody(requestBody);
  2153. TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param);
  2154. System.out.println("入参:" + request);
  2155. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2156. //request.setServerUrl("https://openapi.test.seewo.com")
  2157. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2158. TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request);
  2159. System.out.println("出参:" + result);
  2160. if (result == null) {
  2161. return CommonResult.fail("希沃教师数据更新失败!");
  2162. }
  2163. if (!result.getResponseBody().getCode().equals("000000")) {
  2164. return CommonResult.fail(result.getResponseBody().getMessage());
  2165. }
  2166. String teacherCode = phone;
  2167. if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) {
  2168. teacherCode = result.getResponseBody().getData().get(0).getTeacherCode();
  2169. }
  2170. return CommonResult.ok("200", "操作成功", teacherCode);
  2171. //endregion
  2172. }
  2173. //endregion
  2174. //region 希沃删除教师
  2175. public CommonResult SeewoDeleteTeacher(SeewoClient seewoClient, String phone) {
  2176. //region 希沃删除教师
  2177. //初始化客户端
  2178. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2179. TeacherServiceBatchRemoveTeachersParam param = new TeacherServiceBatchRemoveTeachersParam();
  2180. //响应体,MimeType为 application/json
  2181. TeacherServiceBatchRemoveTeachersParam.RequestBody requestBody = TeacherServiceBatchRemoveTeachersParam.RequestBody.builder()
  2182. .build();
  2183. param.setRequestBody(requestBody);
  2184. //query
  2185. TeacherServiceBatchRemoveTeachersParam.Query query = TeacherServiceBatchRemoveTeachersParam.Query.builder()
  2186. .appId(seewoConfig.getAppId())
  2187. .schoolUid(seewoConfig.getSchoolId())
  2188. .phones(java.util.Collections.singletonList(phone))
  2189. .build();
  2190. requestBody.setQuery(query);
  2191. param.setRequestBody(requestBody);
  2192. TeacherServiceBatchRemoveTeachersRequest request = new TeacherServiceBatchRemoveTeachersRequest(param);
  2193. System.out.println("入参:" + request);
  2194. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2195. //request.setServerUrl("https://openapi.test.seewo.com")
  2196. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2197. TeacherServiceBatchRemoveTeachersResult result = seewoClient.invoke(request);
  2198. System.out.println("出参:" + result);
  2199. if (result == null) {
  2200. return CommonResult.fail("希沃教师数据删除失败!");
  2201. }
  2202. if (!result.getResponseBody().getCode().equals("000000")) {
  2203. return CommonResult.fail(result.getResponseBody().getMessage());
  2204. }
  2205. return CommonResult.ok("删除成功");
  2206. //endregion
  2207. }
  2208. //endregion
  2209. //region 希沃删除班主任
  2210. public CommonResult SeewoDeleteTeacherMaster(SeewoClient seewoClient, String classUid, String phone) {
  2211. //region 希沃删除班主任
  2212. //初始化客户端
  2213. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2214. TeacherServiceBatchRemoveClassMastersParam mastersParam = new TeacherServiceBatchRemoveClassMastersParam();
  2215. //响应体,MimeType为 application/json
  2216. TeacherServiceBatchRemoveClassMastersParam.RequestBody mastersRequestBody = TeacherServiceBatchRemoveClassMastersParam.RequestBody.builder()
  2217. .build();
  2218. mastersParam.setRequestBody(mastersRequestBody);
  2219. //query
  2220. TeacherServiceBatchRemoveClassMastersParam.Query mastersQuery = TeacherServiceBatchRemoveClassMastersParam.Query.builder()
  2221. .appId(seewoConfig.getAppId())
  2222. .schoolUid(seewoConfig.getSchoolId())
  2223. .classUid(classUid)
  2224. .userPhones(java.util.Collections.singletonList(phone))
  2225. .build();
  2226. mastersRequestBody.setQuery(mastersQuery);
  2227. mastersParam.setRequestBody(mastersRequestBody);
  2228. TeacherServiceBatchRemoveClassMastersRequest mastersRequest = new TeacherServiceBatchRemoveClassMastersRequest(mastersParam);
  2229. System.out.println("入参:" + mastersRequest);
  2230. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2231. //request.setServerUrl("https://openapi.test.seewo.com")
  2232. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2233. TeacherServiceBatchRemoveClassMastersResult masterResult = seewoClient.invoke(mastersRequest);
  2234. System.out.println("出参:" + masterResult);
  2235. if (masterResult == null) {
  2236. return CommonResult.fail("希沃教师数据删除失败!");
  2237. }
  2238. if (!masterResult.getResponseBody().getCode().equals("000000")) {
  2239. return CommonResult.fail(masterResult.getResponseBody().getMessage());
  2240. }
  2241. return CommonResult.ok("删除成功");
  2242. //endregion
  2243. }
  2244. //endregion
  2245. //region 希沃推送班主任
  2246. public CommonResult SeewoPushMaster(SeewoClient seewoClient, String phone, String classUid) {
  2247. //region 将班主任推送到希沃
  2248. //初始化客户端
  2249. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2250. TeacherServiceBatchSetClassMastersParam teacherClassParam = new TeacherServiceBatchSetClassMastersParam();
  2251. //响应体,MimeType为 application/json
  2252. TeacherServiceBatchSetClassMastersParam.RequestBody teacherClassRequestBody = TeacherServiceBatchSetClassMastersParam.RequestBody.builder()
  2253. .build();
  2254. teacherClassParam.setRequestBody(teacherClassRequestBody);
  2255. //query
  2256. List<String> teacherPhones = new ArrayList<>();
  2257. teacherPhones.add(phone);
  2258. TeacherServiceBatchSetClassMastersParam.Query teacherClassQuery = TeacherServiceBatchSetClassMastersParam.Query.builder()
  2259. .appId(seewoConfig.getAppId())
  2260. .schoolUid(seewoConfig.getSchoolId())
  2261. .classUid(classUid)
  2262. .userPhones(teacherPhones)
  2263. .build();
  2264. teacherClassRequestBody.setQuery(teacherClassQuery);
  2265. teacherClassParam.setRequestBody(teacherClassRequestBody);
  2266. TeacherServiceBatchSetClassMastersRequest teacherClassRequest = new TeacherServiceBatchSetClassMastersRequest(teacherClassParam);
  2267. System.out.println("入参:" + teacherClassRequest);
  2268. //如果想要调用沙箱环境,请通过设置 teacherClassRequest 对象的 serverUrl 属性,如:
  2269. //request.setServerUrl("https://openapi.test.seewo.com")
  2270. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2271. TeacherServiceBatchSetClassMastersResult teacherClassResult = seewoClient.invoke(teacherClassRequest);
  2272. System.out.println("出参:" + teacherClassResult);
  2273. if (teacherClassResult == null) {
  2274. return CommonResult.fail("希沃教师数据新增失败!");
  2275. }
  2276. if (!teacherClassResult.getResponseBody().getCode().equals("000000")) {
  2277. return CommonResult.fail(teacherClassResult.getResponseBody().getMessage());
  2278. }
  2279. return CommonResult.ok("添加成功");
  2280. //endregion
  2281. }
  2282. //endregion
  2283. //region 希沃新增编辑学生家长信息
  2284. public CommonResult insertOrUpdateStudentParent(SeewoClient
  2285. seewoClient, List<SmartUser> studentDatas, String name, String phone) {
  2286. //region 希沃新增编辑学生家长信息
  2287. //学生与家长列表,最大100条
  2288. List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> studentParents = new ArrayList<>();
  2289. for (SmartUser student : studentDatas) {
  2290. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  2291. .studentCode(student.getCardNo())
  2292. .build();
  2293. studentParents.add(students);
  2294. //家长列表,最多4个
  2295. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  2296. .name(name)
  2297. .phone(phone)
  2298. .index(0)
  2299. .build();
  2300. students.setParents(java.util.Collections.singletonList(parents));
  2301. }
  2302. //初始化客户端
  2303. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2304. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  2305. //响应体,MimeType为 application/json
  2306. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  2307. .build();
  2308. param.setRequestBody(requestBody);
  2309. //query
  2310. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  2311. .appId(seewoConfig.getAppId())
  2312. .schoolUid(seewoConfig.getSchoolId())
  2313. .build();
  2314. requestBody.setQuery(query);
  2315. query.setStudentParents(studentParents);
  2316. param.setRequestBody(requestBody);
  2317. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  2318. System.out.println("入参:" + request);
  2319. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  2320. //request.setServerUrl("https://openapi.test.seewo.com")
  2321. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2322. ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
  2323. System.out.println("出参:" + result);
  2324. if (result == null) {
  2325. return CommonResult.fail("希沃学生家长数据更新失败!");
  2326. }
  2327. if (!result.getResponseBody().getCode().equals("000000")) {
  2328. return CommonResult.fail(result.getResponseBody().getMessage());
  2329. }
  2330. return CommonResult.ok("新增成功");
  2331. //endregion
  2332. }
  2333. //endregion
  2334. //region 希沃删除学生原有的家长关系
  2335. public CommonResult deleteOldStudentParentShip(SeewoClient seewoClient, String cardNo, List<String> phones) throws
  2336. JsonProcessingException {
  2337. //region 删除原有的家长关系
  2338. //初始化客户端
  2339. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2340. ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
  2341. //请求体,MimeType为 application/json
  2342. ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
  2343. .build();
  2344. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  2345. //
  2346. ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
  2347. .appId(seewoConfig.getAppId())
  2348. .schoolUid(seewoConfig.getSchoolId())
  2349. .studentCodes(java.util.Collections.singletonList(cardNo))
  2350. .parentPhones(phones)
  2351. .build();
  2352. deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
  2353. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  2354. ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
  2355. System.out.println("入参:" + deleteOldFamilyRequest);
  2356. //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
  2357. //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
  2358. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2359. ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
  2360. System.out.println("出参:" + deleteOldFamilyResult);
  2361. if (deleteOldFamilyResult == null) {
  2362. return CommonResult.fail("希沃家长数据删除失败!");
  2363. }
  2364. if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
  2365. ObjectMapper objectMapper = new ObjectMapper();
  2366. XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
  2367. if (!result.getCode().equals("000000")) {
  2368. return CommonResult.fail(result.getMessage());
  2369. }
  2370. } else {
  2371. if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
  2372. return CommonResult.fail(deleteOldFamilyResult.getResponseBody().getResult().getMessage());
  2373. }
  2374. }
  2375. return CommonResult.ok("删除成功");
  2376. //endregion
  2377. }
  2378. //endregion
  2379. //region 希沃删除原有的家长关系
  2380. public CommonResult deleteOldParentShip(SeewoClient seewoClient, List<SmartUser> studentDatas, String phone) throws
  2381. JsonProcessingException {
  2382. //region 删除原有的家长关系
  2383. //初始化客户端
  2384. //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2385. ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam();
  2386. //请求体,MimeType为 application/json
  2387. ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder()
  2388. .build();
  2389. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  2390. //
  2391. ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder()
  2392. .appId(seewoConfig.getAppId())
  2393. .schoolUid(seewoConfig.getSchoolId())
  2394. .studentCodes(studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList()))
  2395. .parentPhones(java.util.Collections.singletonList(phone))
  2396. .build();
  2397. deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery);
  2398. deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody);
  2399. ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam);
  2400. System.out.println("入参:" + deleteOldFamilyRequest);
  2401. //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如:
  2402. //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com")
  2403. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  2404. ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest);
  2405. System.out.println("出参:" + deleteOldFamilyResult);
  2406. if (deleteOldFamilyResult == null) {
  2407. return CommonResult.fail("希沃家长数据删除失败!");
  2408. }
  2409. if (deleteOldFamilyResult.getResponseBody().getResult() == null) {
  2410. ObjectMapper objectMapper = new ObjectMapper();
  2411. XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class);
  2412. if (!result.getCode().equals("000000")) {
  2413. return CommonResult.fail(result.getMessage());
  2414. }
  2415. } else {
  2416. if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) {
  2417. return CommonResult.fail(deleteOldFamilyResult.getResponseBody().getResult().getMessage());
  2418. }
  2419. }
  2420. return CommonResult.ok("删除成功");
  2421. //endregion
  2422. }
  2423. //endregion
  2424. //endregion
  2425. //region 百胜增删改查方法
  2426. //region 百胜更新学生信息
  2427. public CommonResult bsUpdateStudent(SmartUser su, String startDate, String endDate) throws Exception {
  2428. //region 更新百胜学生信息
  2429. String appId = controlConfig.getAppId();
  2430. String schoolno = controlConfig.getSchoolCode();
  2431. String timestamp = TimeExchange.DateNowTimeStamo();
  2432. String appSecret = controlConfig.getAppSecret();
  2433. String url = controlConfig.getUrl() + "student/update";
  2434. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  2435. JSONObject jsonobject = new JSONObject();
  2436. jsonobject.put("appid", appId);
  2437. 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 + "\"}";
  2438. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2439. jsonobject.put("data", aesStr);
  2440. jsonobject.put("schoolno", schoolno);
  2441. jsonobject.put("timestamp", timestamp);
  2442. 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;
  2443. String sign = CommonUtil.MD5(md5Str);
  2444. //sign签名
  2445. jsonobject.put("sign", sign);
  2446. //返回的结果中 code为1表示成功
  2447. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2448. ObjectMapper objectMapper = new ObjectMapper();
  2449. BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class);
  2450. if (!bsResult.contains("更新成功")) {
  2451. return CommonResult.fail(result.getMsg());
  2452. }
  2453. return CommonResult.ok("更新成功");
  2454. //endregion
  2455. }
  2456. //endregion
  2457. //region 百胜新增学生
  2458. public CommonResult<String> bsInsertStudent(String name, String cardNo, Integer sexId, String
  2459. headImage, Integer timeGroupId, String bsClassNo, String startDate, String endDate) throws Exception {
  2460. //region 百胜新增学生信息
  2461. String appId = controlConfig.getAppId();
  2462. String schoolno = controlConfig.getSchoolCode();
  2463. String timestamp = TimeExchange.DateNowTimeStamo();
  2464. String appSecret = controlConfig.getAppSecret();
  2465. String url = controlConfig.getUrl() + "student/create";
  2466. String bsGroupNo = eGroupTime(timeGroupId);
  2467. JSONObject jsonobject = new JSONObject();
  2468. jsonobject.put("appid", appId);
  2469. 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 + "\"}";
  2470. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2471. jsonobject.put("data", aesStr);
  2472. jsonobject.put("schoolno", schoolno);
  2473. jsonobject.put("timestamp", timestamp);
  2474. 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;
  2475. String sign = CommonUtil.MD5(md5Str);
  2476. //sign签名
  2477. jsonobject.put("sign", sign);
  2478. //返回的结果中 code为1表示成功
  2479. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2480. ObjectMapper objectMapper = new ObjectMapper();
  2481. BsStudentVo grade = objectMapper.readValue(bsResult, BsStudentVo.class);
  2482. if (!bsResult.contains("添加成功")) {
  2483. return CommonResult.fail(grade.getMsg());
  2484. }
  2485. // URL解码
  2486. String decodedUrl = URLDecoder.decode(grade.getData(), "UTF-8");
  2487. BsStudentNoVo studentNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStudentNoVo.class);
  2488. return CommonResult.ok("200", "新增成功", studentNo.getStudent_no());
  2489. //endregion
  2490. }
  2491. //endregion
  2492. //region 百胜删除学生
  2493. public CommonResult bsDeleteStudent(SmartUser su) throws Exception {
  2494. //region 百胜删除学生
  2495. String appId = controlConfig.getAppId();
  2496. String schoolno = controlConfig.getSchoolCode();
  2497. String timestamp = TimeExchange.DateNowTimeStamo();
  2498. String appSecret = controlConfig.getAppSecret();
  2499. String url = controlConfig.getUrl() + "student/delete";
  2500. JSONObject jsonobject = new JSONObject();
  2501. jsonobject.put("appid", appId);
  2502. String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\"}";
  2503. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2504. jsonobject.put("data", aesStr);
  2505. jsonobject.put("schoolno", schoolno);
  2506. jsonobject.put("timestamp", timestamp);
  2507. String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  2508. String sign = CommonUtil.MD5(md5Str);
  2509. //sign签名
  2510. jsonobject.put("sign", sign);
  2511. //返回的结果中 code为1表示成功
  2512. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2513. ObjectMapper objectMapper = new ObjectMapper();
  2514. BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class);
  2515. if (!bsResult.contains("删除学生成功")) {
  2516. return CommonResult.fail(result.getMsg());
  2517. }
  2518. return CommonResult.ok("操作成功");
  2519. //endregion
  2520. }
  2521. //endregion
  2522. //region 百胜添加教师
  2523. public CommonResult<String> bsInsertTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
  2524. Exception {
  2525. //region 百胜添加教师数据
  2526. String appId = controlConfig.getAppId();
  2527. String schoolno = controlConfig.getSchoolCode();
  2528. String timestamp = TimeExchange.DateNowTimeStamo();
  2529. String appSecret = controlConfig.getAppSecret();
  2530. String url = controlConfig.getUrl() + "staff/create";
  2531. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  2532. JSONObject jsonobject = new JSONObject();
  2533. jsonobject.put("appid", appId);
  2534. 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 + "\"}";
  2535. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2536. jsonobject.put("data", aesStr);
  2537. jsonobject.put("schoolno", schoolno);
  2538. jsonobject.put("timestamp", timestamp);
  2539. 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;
  2540. String sign = CommonUtil.MD5(md5Str);
  2541. //sign签名
  2542. jsonobject.put("sign", sign);
  2543. //返回的结果中 code为1表示成功
  2544. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2545. ObjectMapper objectMapper = new ObjectMapper();
  2546. BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
  2547. if (!bsResult.contains("添加成功")) {
  2548. return CommonResult.fail(staff.getMsg());
  2549. }
  2550. // URL解码
  2551. String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
  2552. BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
  2553. su.setBsStaffCode(staffNo.getStaff_no());
  2554. return CommonResult.ok("200", "新增成功", staffNo.getStaff_no());
  2555. //endregion
  2556. }
  2557. //endregion
  2558. //region 百胜更新教师
  2559. public CommonResult<String> updateBsTeacher(SmartUser su, String departmentNo, String startDate, String endDate) throws
  2560. Exception {
  2561. //region 百胜更新教师数据
  2562. String appId = controlConfig.getAppId();
  2563. String schoolno = controlConfig.getSchoolCode();
  2564. String timestamp = TimeExchange.DateNowTimeStamo();
  2565. String appSecret = controlConfig.getAppSecret();
  2566. String url = controlConfig.getUrl() + "staff/update";
  2567. String bsGroupNo = eGroupTime(su.getTimeGroupId());
  2568. JSONObject jsonobject = new JSONObject();
  2569. jsonobject.put("appid", appId);
  2570. 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 + "\"}";
  2571. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2572. jsonobject.put("data", aesStr);
  2573. jsonobject.put("schoolno", schoolno);
  2574. jsonobject.put("timestamp", timestamp);
  2575. 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;
  2576. String sign = CommonUtil.MD5(md5Str);
  2577. //sign签名
  2578. jsonobject.put("sign", sign);
  2579. //返回的结果中 code为1表示成功
  2580. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2581. ObjectMapper objectMapper = new ObjectMapper();
  2582. BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
  2583. if (!bsResult.contains("添加成功")) {
  2584. return CommonResult.fail(staff.getMsg());
  2585. }
  2586. // URL解码
  2587. String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
  2588. BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class);
  2589. return CommonResult.ok("200", "操作成功", staffNo.getStaff_no());
  2590. //endregion
  2591. }
  2592. //endregion
  2593. //region百胜删除教师
  2594. public CommonResult bsDeleteTeacher(String staffNo) throws Exception {
  2595. //region 百胜删除教师
  2596. String appId = controlConfig.getAppId();
  2597. String schoolno = controlConfig.getSchoolCode();
  2598. String timestamp = TimeExchange.DateNowTimeStamo();
  2599. String appSecret = controlConfig.getAppSecret();
  2600. String url = controlConfig.getUrl() + "staff/delete";
  2601. JSONObject jsonobject = new JSONObject();
  2602. jsonobject.put("appid", appId);
  2603. String str = "{\"staff_no\":\"" + staffNo + "\"}";
  2604. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  2605. jsonobject.put("data", aesStr);
  2606. jsonobject.put("schoolno", schoolno);
  2607. jsonobject.put("timestamp", timestamp);
  2608. String md5Str = "appid=" + appId + "&data={\"staff_no\":\"" + staffNo + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  2609. String sign = CommonUtil.MD5(md5Str);
  2610. //sign签名
  2611. jsonobject.put("sign", sign);
  2612. //返回的结果中 code为1表示成功
  2613. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  2614. ObjectMapper objectMapper = new ObjectMapper();
  2615. BsControlVo result = objectMapper.readValue(bsResult, BsControlVo.class);
  2616. if (!bsResult.contains("删除成功")) {
  2617. return CommonResult.fail(result.getMsg());
  2618. }
  2619. return CommonResult.ok("删除成功");
  2620. //endregion
  2621. }
  2622. //endregion
  2623. //endregion
  2624. /**
  2625. * 用户分页数据查询
  2626. *
  2627. * @param currentPage 当前页数
  2628. * @param pageCount 一页数据条数
  2629. * @param departmentId 部门ID
  2630. * @return
  2631. */
  2632. @Override
  2633. @DESRespondSecret(validated = true)
  2634. public CommonResult queryPageSmartUser(int currentPage, int pageCount, Integer departmentId, String name, String userhead) {
  2635. //region 角色判断
  2636. String userID = AesUtils.decrypt(userhead);
  2637. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  2638. if (operateData == null) {
  2639. return CommonResult.fail("用户信息不合法,无法查看");
  2640. }
  2641. QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
  2642. queryWrapper.eq("user_id", operateData.getId());
  2643. List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
  2644. if (authorities == null) {
  2645. return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
  2646. }
  2647. if (authorities.size() <= 0) {
  2648. return CommonResult.fail("当前用户权限不足,无法查看对应部门数据");
  2649. }
  2650. List<String> viewAuthors = new ArrayList<>();//部门查看权限
  2651. List<String> manageAuthors = new ArrayList<>();//部门管理权限
  2652. for (SmartAuthority author : authorities) {
  2653. List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
  2654. if (views != null && views.size() > 0) {
  2655. viewAuthors.addAll(views);
  2656. }
  2657. List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
  2658. if (manages != null && manages.size() > 0) {
  2659. manageAuthors.addAll(manages);
  2660. }
  2661. }
  2662. List<String> AllAuths = new ArrayList<>();
  2663. AllAuths.addAll(viewAuthors);
  2664. AllAuths.addAll(manageAuthors);
  2665. AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
  2666. //endregion
  2667. //获取该部门下的所有子级部门ID
  2668. List<Integer> childDepartmentIds = new ArrayList<>();
  2669. List<SmartDepartment> departments = smartDepartmentService.list(null);
  2670. childDepartmentIds.add(departmentId);
  2671. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  2672. if (departmentId == null) {
  2673. childDepartmentIds = null;
  2674. }
  2675. List<Integer> authDepartments = new ArrayList<>();
  2676. for (Integer child : childDepartmentIds) {
  2677. if (AllAuths.contains(String.valueOf(child))) {
  2678. authDepartments.add(child);
  2679. }
  2680. }
  2681. PageUtils<UserVo> result = smartUserService.querySmartUserPages(currentPage, pageCount, authDepartments, name);
  2682. if (result != null && result.getList() != null) {
  2683. List<Integer> studentIds = new ArrayList<>();
  2684. List<String> studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(","));
  2685. for (String studentStr : studentStrs) {
  2686. if (!ObjectUtils.isEmpty(studentStr)) {
  2687. studentIds.add(Integer.valueOf(studentStr));
  2688. }
  2689. }
  2690. List<SmartUser> students = studentIds != null && studentIds.size() > 0 ? smartUserService.getSmartUserByIds(studentIds) : new ArrayList<>();
  2691. List<SmartClass> classs = smartClassService.list(null);
  2692. List<SmartIdentity> idnetitys = smartIdentityService.list(null);
  2693. for (UserVo data : result.getList()) {
  2694. data.setTimeGroupName(eGroupTime(data.getTimeGroupId()));
  2695. Optional<SmartIdentity> identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst();
  2696. if (identityData != null && identityData.isPresent()) {
  2697. data.setIdentity(identityData.get().getName());
  2698. }
  2699. data.setSex(eSexStatu.stringOf(data.getSexId()));
  2700. Optional<SmartDepartment> departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  2701. if (departmentData != null && departmentData.isPresent()) {
  2702. data.setDepartment(departmentData.get().getName());
  2703. }
  2704. Optional<SmartClass> nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst();
  2705. if (nowClass != null && nowClass.isPresent()) {
  2706. data.setClassStr(nowClass.get().getName());
  2707. }
  2708. List<AffiliateUserVo> datas = new ArrayList<>();
  2709. if (data.getAffiliate() != null) {
  2710. List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
  2711. for (String a : affiliates) {
  2712. if (!ObjectUtils.isEmpty(a)) {
  2713. Optional<SmartUser> student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst();
  2714. if (student != null && student.isPresent()) {
  2715. AffiliateUserVo affiliate = new AffiliateUserVo();
  2716. affiliate.setId(student.get().getId());
  2717. affiliate.setName(student.get().getName());
  2718. affiliate.setCardNo(student.get().getCardNo());
  2719. affiliate.setDepartmentId(student.get().getDepartmentId());
  2720. datas.add(affiliate);
  2721. }
  2722. }
  2723. }
  2724. }
  2725. data.setAffiliates(datas);
  2726. }
  2727. }
  2728. return CommonResult.ok(result);
  2729. }
  2730. @Override
  2731. @DESRespondSecret(validated = false)
  2732. public void smartUserExport(HttpServletResponse response, Integer departmentId, String name,String userhead) {
  2733. //region 角色判断
  2734. String userID = AesUtils.decrypt(userhead);
  2735. SmartUser operateData = smartUserService.getSmartById(Integer.valueOf(userID));
  2736. if (operateData != null) {
  2737. QueryWrapper<SmartAuthority> queryWrapper = new QueryWrapper<>();
  2738. queryWrapper.eq("user_id", operateData.getId());
  2739. List<SmartAuthority> authorities = smartAuthorityService.getAuthorByKey(queryWrapper);
  2740. if (authorities != null && authorities.size() > 0) {
  2741. List<String> viewAuthors = new ArrayList<>();//部门查看权限
  2742. List<String> manageAuthors = new ArrayList<>();//部门管理权限
  2743. for (SmartAuthority author : authorities) {
  2744. List<String> views = org.springframework.util.StringUtils.hasText(author.getDepartmentView().trim()) ? Arrays.asList(author.getDepartmentView().trim().split(",")) : new ArrayList<>();
  2745. if (views != null && views.size() > 0) {
  2746. viewAuthors.addAll(views);
  2747. }
  2748. List<String> manages = org.springframework.util.StringUtils.hasText(author.getDepartmentManage().trim()) ? Arrays.asList(author.getDepartmentManage().trim().split(",")) : new ArrayList<>();
  2749. if (manages != null && manages.size() > 0) {
  2750. manageAuthors.addAll(manages);
  2751. }
  2752. }
  2753. List<String> AllAuths = new ArrayList<>();
  2754. AllAuths.addAll(viewAuthors);
  2755. AllAuths.addAll(manageAuthors);
  2756. AllAuths = AllAuths.stream().distinct().collect(Collectors.toList());
  2757. //endregion
  2758. //获取该部门下的所有子级部门ID
  2759. List<Integer> childDepartmentIds = new ArrayList<>();
  2760. List<SmartDepartment> departments = smartDepartmentService.list(null);
  2761. childDepartmentIds.add(departmentId);
  2762. QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
  2763. if (departmentId == null) {
  2764. childDepartmentIds = null;
  2765. }
  2766. List<Integer> authDepartments = new ArrayList<>();
  2767. for (Integer child : childDepartmentIds) {
  2768. if (AllAuths.contains(String.valueOf(child))) {
  2769. authDepartments.add(child);
  2770. }
  2771. }
  2772. List<SmartUser> users = smartUserService.querySmartUsers(authDepartments, name);
  2773. List<String> affiliates = new ArrayList<>();
  2774. List<String> affiliateStr = users.stream().map(SmartUser::getAffiliate).collect(Collectors.toList());
  2775. for (String datas : affiliateStr) {
  2776. String[] dataArray = datas.split(",");
  2777. for (int i = 0; i < dataArray.length; i++) {
  2778. affiliates.add(dataArray[i]);
  2779. }
  2780. }
  2781. List<SmartUser> affiliateDatas = smartUserService.getSmartUserIds(affiliates);
  2782. List<Integer> dutieIds = users != null && users.size() > 0 ? users.stream().map(SmartUser::getDuties).collect(Collectors.toList()) : null;
  2783. //职务数据
  2784. List<SmartDuties> duties = dutieIds != null && dutieIds.size() > 0 ? smartDutiesService.queryDutiesByIds(dutieIds) : null;
  2785. //年级
  2786. List<SmartGrade> grades = smartGradeService.list(null);
  2787. //班级
  2788. List<SmartClass> classes = smartClassService.list(null);
  2789. //导出
  2790. Workbook workbook = new XSSFWorkbook();
  2791. Sheet sheet = workbook.createSheet("用户信息管理");
  2792. Row headerRow = sheet.createRow(0);
  2793. headerRow.createCell(0).setCellValue("序号");
  2794. headerRow.createCell(1).setCellValue("学号");
  2795. headerRow.createCell(2).setCellValue("姓名");
  2796. headerRow.createCell(3).setCellValue("身份");
  2797. headerRow.createCell(4).setCellValue("身份证号");
  2798. headerRow.createCell(5).setCellValue("性别");
  2799. headerRow.createCell(6).setCellValue("部门");
  2800. headerRow.createCell(7).setCellValue("人脸");
  2801. headerRow.createCell(8).setCellValue("年级");
  2802. headerRow.createCell(9).setCellValue("学院");
  2803. headerRow.createCell(10).setCellValue("专业");
  2804. headerRow.createCell(11).setCellValue("班级");
  2805. headerRow.createCell(12).setCellValue("校区");
  2806. headerRow.createCell(13).setCellValue("宿舍号");
  2807. headerRow.createCell(14).setCellValue("手机号");
  2808. headerRow.createCell(15).setCellValue("关联人");
  2809. headerRow.createCell(16).setCellValue("职称");
  2810. headerRow.createCell(17).setCellValue("家庭住址");
  2811. headerRow.createCell(18).setCellValue("民族");
  2812. headerRow.createCell(19).setCellValue("生源地");
  2813. headerRow.createCell(20).setCellValue("毕业学校");
  2814. headerRow.createCell(21).setCellValue("职务");
  2815. for (int i = 0; i < users.size(); i++) {
  2816. SmartUser user = users.get(i);
  2817. Row dataRow = sheet.createRow(i + 1);
  2818. dataRow.createCell(0).setCellValue(i + 1);//序号
  2819. dataRow.createCell(1).setCellValue(user.getCardNo());//学号
  2820. dataRow.createCell(2).setCellValue(user.getName());//姓名
  2821. dataRow.createCell(3).setCellValue(eIdentityStatu.stringOf(user.getIdentityId()));//身份
  2822. dataRow.createCell(4).setCellValue(user.getIdCard());//身份证号
  2823. dataRow.createCell(5).setCellValue(eSexStatu.stringOf(user.getSexId()));//性别
  2824. //获取父级部门ID
  2825. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(user.getDepartmentId())).findFirst();
  2826. if (department != null && department.isPresent()) {
  2827. dataRow.createCell(6).setCellValue(QueryParentDepartments(department.get().getParentId(), departments, null));//部门
  2828. }
  2829. dataRow.createCell(7).setCellValue(user.getHeadImage() == null ? "" : user.getHeadImage());//人脸
  2830. String grade = "";
  2831. Optional<SmartGrade> gradeData = grades == null ? null : grades.stream().filter(e -> e.getId().toString().equals(user.getGrade())).findFirst();
  2832. if (gradeData != null && gradeData.isPresent()) {
  2833. grade = gradeData.get().getName();
  2834. }
  2835. dataRow.createCell(8).setCellValue(grade);//年级
  2836. dataRow.createCell(9).setCellValue(user.getCollege() == null ? "" : user.getCollege());//学院
  2837. dataRow.createCell(10).setCellValue(user.getSpeciality() == null ? "" : user.getSpeciality());//专业
  2838. String classStr = "";
  2839. Optional<SmartClass> classData = classes == null ? null : classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst();
  2840. if (classData != null && classData.isPresent()) {
  2841. classStr = classData.get().getName();
  2842. }
  2843. dataRow.createCell(11).setCellValue(classStr);//班级
  2844. dataRow.createCell(12).setCellValue(user.getCampus() == null ? "" : user.getCampus());//校区
  2845. dataRow.createCell(13).setCellValue(user.getDormitoryNumber() == null ? "" : user.getDormitoryNumber());//宿舍号
  2846. dataRow.createCell(14).setCellValue(user.getPhone() == null ? "" : user.getPhone());//手机号
  2847. List<String> affiliateCellStrs = new ArrayList<>();
  2848. if (user.getAffiliate() != null && affiliateDatas != null) {
  2849. String[] affArrayStr = user.getAffiliate().split(",");
  2850. for (int j = 0; j < affArrayStr.length; j++) {
  2851. String affArrayIndex = affArrayStr[j];
  2852. Optional<SmartUser> affUser = affiliateDatas.stream().filter(e -> e.getId().toString().equals(affArrayIndex)).findFirst();
  2853. if (affUser != null && affUser.isPresent()) {
  2854. affiliateCellStrs.add(affUser.get().getName());
  2855. }
  2856. }
  2857. }
  2858. dataRow.createCell(15).setCellValue(StringUtils.join(affiliateCellStrs, ","));//关联人
  2859. dataRow.createCell(16).setCellValue(user.getTitle() == null ? "" : user.getTitle());//职称
  2860. dataRow.createCell(17).setCellValue(user.getAddress() == null ? "" : user.getAddress());//家庭住址
  2861. dataRow.createCell(18).setCellValue(user.getNation() == null ? "" : user.getNation());//民族
  2862. dataRow.createCell(19).setCellValue(user.getOfStudent() == null ? "" : user.getOfStudent());//生源地
  2863. dataRow.createCell(20).setCellValue(user.getGraduate() == null ? "" : user.getGraduate());//毕业学校
  2864. String dutieStr = "";
  2865. if (duties != null && duties.size() > 0 && user.getDuties() != null) {
  2866. Optional<SmartDuties> oduty = duties.stream().filter(e -> e.getId().equals(user.getDuties())).findFirst();
  2867. if (oduty != null && oduty.isPresent()) {
  2868. dutieStr = oduty.get().getName();
  2869. }
  2870. }
  2871. dataRow.createCell(21).setCellValue(dutieStr);//职务
  2872. }
  2873. // 将工作簿写入文件
  2874. ExcelUtils.excelDownload(workbook, "用户信息.xlsx", response);
  2875. }
  2876. }
  2877. }
  2878. /**
  2879. * 根据父级ID获取树形数据
  2880. *
  2881. * @param parentID 父级ID
  2882. * @param lists 数据集合
  2883. * @return
  2884. */
  2885. private List<DepartmentTreeVo> QueryDepartmentTreeRecords(Integer parentID, List<SmartDepartment> lists, List<Integer> departmentIds) {
  2886. List<DepartmentTreeVo> newTrees = new ArrayList<>();
  2887. List<SmartDepartment> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
  2888. for (SmartDepartment data : datas) {
  2889. departmentIds.add(data.getId());
  2890. QueryDepartmentTreeRecords(data.getId(), lists, departmentIds);
  2891. }
  2892. return newTrees;
  2893. }
  2894. /**
  2895. * 根据父级ID获取父级数据
  2896. *
  2897. * @param parentID 子级ID
  2898. * @param lists 数据集合
  2899. * @return
  2900. */
  2901. private String QueryParentDepartments(Integer parentID, List<SmartDepartment> lists, String departmentStr) {
  2902. Optional<SmartDepartment> data = lists.stream().filter(e -> e.getId().equals(parentID)).findFirst();
  2903. if (data != null && data.isPresent()) {
  2904. departmentStr = departmentStr == null ? data.get().getName() : data.get().getName() + "/" + departmentStr;
  2905. departmentStr = QueryParentDepartments(data.get().getParentId(), lists, departmentStr);
  2906. }
  2907. return departmentStr;
  2908. }
  2909. @Override
  2910. @DESRespondSecret(validated = true)
  2911. public CommonResult deleteSmartUserByIdOld(useridsRequest ur, BindingResult bindingResult) throws Exception {
  2912. if (bindingResult.hasErrors()) {
  2913. String st = paramUtils.getParamError(bindingResult);
  2914. return CommonResult.fail(st);
  2915. }
  2916. List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
  2917. if (users.size() != ur.getUserIds().size()) {
  2918. return CommonResult.fail("存在无效用户数据,删除失败!");
  2919. }
  2920. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  2921. for (SmartUser user : users) {
  2922. if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
  2923. List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
  2924. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
  2925. //region 删除原有的家长关系
  2926. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
  2927. if (!deleteResult.isSuccess()) {
  2928. return CommonResult.fail(deleteResult.getMessage());
  2929. }
  2930. //endregion
  2931. } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  2932. //查找家长
  2933. List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
  2934. //获取班级Uid
  2935. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  2936. if (classData == null) {
  2937. return CommonResult.fail("班级数据无效,更新失败");
  2938. }
  2939. //region 百胜删除学生
  2940. CommonResult deleteBsStudent = bsDeleteStudent(user);
  2941. if (!deleteBsStudent.isSuccess()) {
  2942. return CommonResult.fail(deleteBsStudent.getMessage());
  2943. }
  2944. //endregion
  2945. //region 希沃删除学生
  2946. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
  2947. if (!deleteStudent.isSuccess()) {
  2948. return CommonResult.fail(deleteStudent.getMessage());
  2949. }
  2950. //endregion
  2951. if (parents != null) {
  2952. //region 删除原有的家长关系
  2953. CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
  2954. if (!deleteResult.isSuccess()) {
  2955. return CommonResult.fail(deleteResult.getMessage());
  2956. }
  2957. //endregion
  2958. }
  2959. } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  2960. //获取班级Uid
  2961. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  2962. if (classData == null) {
  2963. return CommonResult.fail("班级数据无效,更新失败");
  2964. }
  2965. //region 希沃删除教师
  2966. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
  2967. if (!deleteTeacher.isSuccess()) {
  2968. return CommonResult.fail(deleteTeacher.getMessage());
  2969. }
  2970. //endregion
  2971. //region 希沃删除班主任
  2972. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
  2973. if (deleteTeacherMaster.isSuccess()) {
  2974. return CommonResult.fail(deleteTeacherMaster.getMessage());
  2975. }
  2976. //endregion
  2977. //region 百胜删除教师
  2978. CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
  2979. if (!bsDeleteTeacher.isSuccess()) {
  2980. return CommonResult.fail(bsDeleteTeacher.getMessage());
  2981. }
  2982. //endregion
  2983. }
  2984. }
  2985. int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
  2986. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  2987. }
  2988. @Override
  2989. public CommonResult deleteSmartUserById(useridsRequest ur, BindingResult bindingResult) throws Exception {
  2990. if (bindingResult.hasErrors()) {
  2991. String st = paramUtils.getParamError(bindingResult);
  2992. return CommonResult.fail(st);
  2993. }
  2994. List<SmartUser> users = smartUserService.getSmartUserByIds(ur.getUserIds());
  2995. if (users.size() != ur.getUserIds().size()) {
  2996. return CommonResult.fail("存在无效用户数据,删除失败!");
  2997. }
  2998. //先删除咱自己数据库里的用户数据
  2999. int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
  3000. if (result <= 0) {
  3001. return CommonResult.fail("删除失败");
  3002. }
  3003. List<deleteUserVo> deleteUsers = new ArrayList<>();
  3004. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3005. for (SmartUser user : users) {
  3006. deleteUserVo deleteUser = new deleteUserVo();
  3007. deleteUser.setId(user.getId());
  3008. if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {
  3009. List<String> studentIds = Arrays.asList(user.getAffiliate().split(","));
  3010. List<SmartUser> studentDatas = smartUserService.getSmartUserIds(studentIds);
  3011. //region 删除原有的家长关系
  3012. CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone());
  3013. if (!deleteResult.isSuccess()) {
  3014. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败:" + deleteResult.getMessage() + ";";
  3015. deleteUser.setReason(reason);
  3016. //return CommonResult.fail(deleteResult.getMessage());
  3017. }
  3018. //endregion
  3019. } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {
  3020. //查找家长
  3021. List<SmartUser> parents = smartUserService.getAffiliateList(user.getId());
  3022. //获取班级Uid
  3023. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  3024. if (classData == null) {
  3025. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;";
  3026. deleteUser.setReason(reason);
  3027. //return CommonResult.fail("班级数据无效,更新失败");
  3028. }
  3029. //region 百胜删除学生
  3030. CommonResult deleteBsStudent = bsDeleteStudent(user);
  3031. if (!deleteBsStudent.isSuccess()) {
  3032. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除学生失败;" + deleteBsStudent.getMessage() + ";";
  3033. deleteUser.setReason(reason);
  3034. //return CommonResult.fail(deleteBsStudent.getMessage());
  3035. }
  3036. //endregion
  3037. //region 希沃删除学生
  3038. CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo());
  3039. if (!deleteStudent.isSuccess()) {
  3040. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除学生失败;" + deleteStudent.getMessage() + ";";
  3041. ;
  3042. deleteUser.setReason(reason);
  3043. //return CommonResult.fail(deleteStudent.getMessage());
  3044. }
  3045. //endregion
  3046. if (parents != null) {
  3047. //region 删除原有的家长关系
  3048. CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList()));
  3049. if (!deleteResult.isSuccess()) {
  3050. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败;" + deleteResult.getMessage() + ";";
  3051. ;
  3052. deleteUser.setReason(reason);
  3053. //return CommonResult.fail(deleteResult.getMessage());
  3054. }
  3055. //endregion
  3056. }
  3057. } else if (user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {
  3058. //获取班级Uid
  3059. SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass());
  3060. if (classData == null) {
  3061. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;";
  3062. deleteUser.setReason(reason);
  3063. //return CommonResult.fail("班级数据无效,更新失败");
  3064. }
  3065. //region 希沃删除教师
  3066. CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone());
  3067. if (!deleteTeacher.isSuccess()) {
  3068. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + deleteTeacher.getMessage() + ";";
  3069. ;
  3070. deleteUser.setReason(reason);
  3071. //return CommonResult.fail(deleteTeacher.getMessage());
  3072. }
  3073. //endregion
  3074. //region 希沃删除班主任
  3075. CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone());
  3076. if (deleteTeacherMaster.isSuccess()) {
  3077. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除班主任失败;" + deleteTeacherMaster.getMessage() + ";";
  3078. ;
  3079. deleteUser.setReason(reason);
  3080. //return CommonResult.fail(deleteTeacherMaster.getMessage());
  3081. }
  3082. //endregion
  3083. //region 百胜删除教师
  3084. CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode());
  3085. if (!bsDeleteTeacher.isSuccess()) {
  3086. String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;" + bsDeleteTeacher.getMessage() + ";";
  3087. ;
  3088. deleteUser.setReason(reason);
  3089. //return CommonResult.fail(bsDeleteTeacher.getMessage());
  3090. }
  3091. //endregion
  3092. }
  3093. if (deleteUser.getReason() != null) {
  3094. deleteUsers.add(deleteUser);
  3095. }
  3096. }
  3097. if (deleteUsers != null && deleteUsers.size() > 0) {
  3098. int deleteUser = smartUserService.deleteUserBatch(deleteUsers);
  3099. return deleteUser > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  3100. }
  3101. return CommonResult.ok("删除成功");
  3102. }
  3103. @Override
  3104. @DESRespondSecret(validated = true)
  3105. public CommonResult queryAffiliateUserById(int id) {
  3106. List<AffiliateUserVo> result = smartUserService.queryAffiliateUserById(id);
  3107. if (result != null && result.size() > 0) {
  3108. List<SmartDepartment> departments = smartDepartmentService.list(null);
  3109. for (AffiliateUserVo data : result) {
  3110. //获取父级部门ID
  3111. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  3112. if (department != null && department.isPresent()) {
  3113. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  3114. data.setDepartmentName(departmentName);
  3115. }
  3116. }
  3117. }
  3118. return CommonResult.ok(result);
  3119. }
  3120. @Override
  3121. @DESRespondSecret(validated = true)
  3122. public CommonResult downloadUserExcel() {
  3123. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/人员信息表.xlsx");
  3124. }
  3125. @Override
  3126. @DESRespondSecret(validated = true)
  3127. public CommonResult downloadUpdateUserExcel() {
  3128. return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/更新信息表.xlsx");
  3129. }
  3130. @Override
  3131. @DESRespondSecret(validated = true)
  3132. public CommonResult queryStudents(int userId) {
  3133. List<SmartUser> students = new ArrayList<>();
  3134. SmartUser user = smartUserService.getSmartById(userId);
  3135. if (user == null) {
  3136. return CommonResult.fail("用户信息为空,获取学生列表数据失败");
  3137. }
  3138. if (user.getAffiliate() == null) {
  3139. return CommonResult.ok(students);
  3140. }
  3141. List<Integer> affiliateIds = new ArrayList<>();
  3142. List<String> affiliates = Arrays.asList(user.getAffiliate().split(","));
  3143. for (String affiliate : affiliates) {
  3144. affiliateIds.add(Integer.valueOf(affiliate));
  3145. }
  3146. students = smartUserService.getSmartUserByIds(affiliateIds);
  3147. List<ParentOfStudentsVo> result = new ArrayList<>();
  3148. for (SmartUser student : students) {
  3149. ParentOfStudentsVo data = new ParentOfStudentsVo();
  3150. data.setId(student.getId());
  3151. data.setName(student.getName());
  3152. data.setCardNo(student.getCardNo());
  3153. data.setDepartmentId(student.getDepartmentId());
  3154. result.add(data);
  3155. }
  3156. return CommonResult.ok(result);
  3157. }
  3158. @Override
  3159. @DESRespondSecret(validated = true)
  3160. public CommonResult queryInfoData(int id) {
  3161. SmartUser su = smartUserService.getSmartById(id);
  3162. if (su == null) {
  3163. return CommonResult.fail("用户信息失效,获取用户信息失败");
  3164. }
  3165. //部门数据集合
  3166. List<SmartDepartment> departments = smartDepartmentService.list(null);
  3167. WechatUserVo userData = new WechatUserVo();
  3168. userData.setId(su.getId());
  3169. userData.setCardNo(su.getCardNo());
  3170. userData.setTimeGroupId(su.getTimeGroupId());
  3171. userData.setName(su.getName());
  3172. userData.setIdentityId(su.getIdentityId());
  3173. userData.setIdCard(su.getIdCard());
  3174. userData.setSexId(su.getSexId());
  3175. userData.setDepartmentId(su.getDepartmentId());
  3176. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(su.getDepartmentId())).findFirst();
  3177. if (department != null && department.isPresent()) {
  3178. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  3179. userData.setDepartmentName(departmentName == null ? "" : departmentName + "/" + department.get().getName());
  3180. }
  3181. userData.setHeadImage(su.getHeadImage());
  3182. userData.setGrade(su.getGrade());
  3183. userData.setCollege(su.getCollege());
  3184. userData.setSpeciality(su.getSpeciality());
  3185. userData.setSchoolClass(su.getSchoolClass());
  3186. userData.setCampus(su.getCampus());
  3187. userData.setDormitoryNumber(su.getDormitoryNumber());
  3188. userData.setPhone(su.getPhone());
  3189. userData.setAffiliate(su.getAffiliate());
  3190. //查找关联人
  3191. if (su.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
  3192. List<AffiliateParentVo> parents = smartUserService.queryAffiliateParents(su.getId());
  3193. if (parents != null && parents.size() > 0) {
  3194. String affiliateStr = StringUtils.join(parents.stream().map(AffiliateParentVo::getName).collect(Collectors.toList()), ",");
  3195. userData.setAffiliateName(affiliateStr);
  3196. }
  3197. } else if (su.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长
  3198. if (su.getAffiliate() != null) {
  3199. List<String> affiliates = Arrays.asList(su.getAffiliate().split(","));
  3200. List<SmartUser> childs = smartUserService.getSmartUserIds(affiliates);
  3201. String affiliateStr = StringUtils.join(childs.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
  3202. userData.setAffiliateName(affiliateStr);
  3203. }
  3204. }
  3205. //关联人名称用逗号隔开
  3206. userData.setTitle(su.getTitle());
  3207. userData.setAddress(su.getAddress());
  3208. userData.setNation(su.getNation());
  3209. userData.setOfStudent(su.getOfStudent());
  3210. userData.setGraduate(su.getGraduate());
  3211. userData.setDuties(su.getDuties());
  3212. userData.setIsPush(su.getIsPush());
  3213. userData.setIsCancel(su.getIsCancel());
  3214. userData.setOpenId(su.getOpenId());
  3215. userData.setXOpenId(su.getXOpenId());
  3216. userData.setGzhOpenId(su.getGzhOpenId());
  3217. userData.setXwStudentUid(su.getXwStudentUid());
  3218. userData.setBsStudentNo(su.getBsStudentNo());
  3219. userData.setXwTeacherCode(su.getXwTeacherCode());
  3220. userData.setBsStaffCode(su.getBsStaffCode());
  3221. return CommonResult.ok(userData);
  3222. }
  3223. @Override
  3224. @DESRespondSecret(validated = true)
  3225. public CommonResult bindStudent(bindStudentRequest bsr, BindingResult bindingResult) {
  3226. if (bindingResult.hasErrors()) {
  3227. String st = paramUtils.getParamError(bindingResult);
  3228. return CommonResult.fail(st);
  3229. }
  3230. SmartUser parentUser = smartUserService.getSmartById(bsr.getUserId());
  3231. if (parentUser == null) {
  3232. return CommonResult.fail("当前用户信息无效,绑定失败!");
  3233. }
  3234. if (parentUser.getIdentityId().intValue() != eIdentityStatu.Parent.getValue()) {
  3235. return CommonResult.fail("当前用户身份无法进行绑定操作");
  3236. }
  3237. //查找是否存在学生数据
  3238. SmartUser studentUser = smartUserService.queryUserInfo(bsr.getName(), bsr.getCardNo(), bsr.getIdCard());
  3239. if (studentUser == null) {
  3240. return CommonResult.fail("当前学生不存在,绑定失败!");
  3241. }
  3242. //判断是否已绑定过
  3243. if (parentUser.getAffiliate() == null) {
  3244. parentUser.setAffiliate(String.valueOf(studentUser.getId()));
  3245. } else {
  3246. List<String> newAffiliates = new ArrayList<>();
  3247. List<String> affiliates = Arrays.asList(parentUser.getAffiliate().split(","));
  3248. long existCount = affiliates.stream().filter(e -> e.equals(String.valueOf(studentUser.getId()))).count();
  3249. if (existCount > 0) {
  3250. return CommonResult.fail("当前学生信息已绑定过,请勿重复操作!");
  3251. }
  3252. parentUser.setAffiliate(parentUser.getAffiliate() + "," + String.valueOf(studentUser.getId()));
  3253. }
  3254. //region 新增希沃学生家长信息
  3255. //初始化客户端
  3256. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  3257. ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam();
  3258. //响应体,MimeType为 application/json
  3259. ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder()
  3260. .build();
  3261. param.setRequestBody(requestBody);
  3262. //query
  3263. ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder()
  3264. .appId(seewoConfig.getAppId())
  3265. .schoolUid(seewoConfig.getSchoolId())
  3266. .build();
  3267. requestBody.setQuery(query);
  3268. //学生与家长列表,最大100条
  3269. ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem studentParents = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder()
  3270. .studentCode(studentUser.getCardNo())
  3271. .build();
  3272. query.setStudentParents(java.util.Collections.singletonList(studentParents));
  3273. //家长列表,最多4个
  3274. ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder()
  3275. .name(parentUser.getName())
  3276. .phone(parentUser.getPhone())
  3277. .index(0)
  3278. .build();
  3279. studentParents.setParents(java.util.Collections.singletonList(parents));
  3280. param.setRequestBody(requestBody);
  3281. ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param);
  3282. System.out.println("入参:" + request);
  3283. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  3284. //request.setServerUrl("https://openapi.test.seewo.com")
  3285. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  3286. ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request);
  3287. System.out.println("出参:" + result);
  3288. if (result == null) {
  3289. return CommonResult.fail("希沃学生家长数据添加失败!");
  3290. }
  3291. if (!result.getResponseBody().getCode().equals("000000")) {
  3292. return CommonResult.fail(result.getResponseBody().getMessage());
  3293. }
  3294. //endregion
  3295. int updateResult = smartUserService.updateSmartUser(parentUser);
  3296. return updateResult > 0 ? CommonResult.ok("绑定成功") : CommonResult.fail("绑定失败");
  3297. }
  3298. @Override
  3299. public CommonResult queryUserData(int id) {
  3300. SmartUserVo user = smartUserService.querySmartUserById(id);
  3301. return CommonResult.ok(user);
  3302. }
  3303. @Override
  3304. public CommonResult queryUserDeletePage(int currentPage, int pageCount) {
  3305. PageUtils<UserDeleteVo> result = smartUserService.queryUserDeletePage(currentPage, pageCount);
  3306. List<SmartDepartment> departments = smartDepartmentService.list(null);
  3307. for (UserDeleteVo data : result.getList()) {
  3308. data.setIdentityStr(eIdentityStatu.stringOf(data.getIdentityId()));//身份
  3309. //获取父级部门ID
  3310. Optional<SmartDepartment> department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst();
  3311. if (department != null && department.isPresent()) {
  3312. String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null);
  3313. data.setDepartmentStr(departmentName);
  3314. }
  3315. }
  3316. return CommonResult.ok(result);
  3317. }
  3318. public String eGroupTime(Integer id) {
  3319. SmartTimeGroup result = smartTimeGroupService.queryTimeGroupById(id);
  3320. return result == null ? "" : result.getBsno();
  3321. }
  3322. public Integer eGroupTime(String name) {
  3323. SmartTimeGroup result = smartTimeGroupService.queryTimeGroupByName(name);
  3324. return result == null ? 0 : result.getId();
  3325. }
  3326. /**
  3327. * 根据年级查询毕业年份
  3328. *
  3329. * @return
  3330. */
  3331. public String queryGraduationYear(int grade) {
  3332. String endTime = "";
  3333. int endYear = Year.now().getValue();
  3334. // 获取当前年份
  3335. LocalDate currentDate = LocalDate.now();
  3336. switch (grade) {
  3337. case 7:
  3338. if (currentDate.getMonthValue() < 9) {
  3339. endYear = endYear + 2;
  3340. } else {
  3341. endYear = endYear + 3;
  3342. }
  3343. break;
  3344. case 8:
  3345. if (currentDate.getMonthValue() < 9) {
  3346. endYear = endYear + 1;
  3347. } else {
  3348. endYear = endYear + 2;
  3349. }
  3350. break;
  3351. case 9:
  3352. break;
  3353. default:
  3354. break;
  3355. }
  3356. endTime = endYear + "-08-31 23:59:59";
  3357. return endTime;
  3358. }
  3359. }