SmartUserController.java 182 KB

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