SmartUserController.java 152 KB

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