package com.template.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.qcloud.cos.utils.IOUtils; import com.seewo.open.sdk.DefaultSeewoClient; import com.seewo.open.sdk.SeewoClient; import com.seewo.open.sdk.auth.Account; import com.template.annotation.DESRespondSecret; import com.template.api.SmartUserControllerAPI; import com.template.common.utils.*; import com.template.config.ControlConfig; import com.template.config.SeewoConfig; import com.template.model.enumModel.*; import com.template.model.pojo.*; import com.template.model.request.*; import com.template.model.result.CommonResult; import com.template.model.result.PageUtils; import com.template.model.seewo.*; import com.template.model.vo.*; import com.template.services.*; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.Charset; import java.util.*; import java.util.stream.Collectors; import java.util.zip.ZipInputStream; import static com.template.common.utils.AesTestOne.decrypt; /** *

* 前端控制器 *

* * @author ceshi * @since 2023-12-04 */ @RestController //返回参数加密注解 @DESRespondSecret public class SmartUserController implements SmartUserControllerAPI { @Resource private SeewoConfig seewoConfig; @Resource private ControlConfig controlConfig; @Autowired private SmartUserService smartUserService; @Autowired private SmartGradeService smartGradeService; @Autowired private SmartClassService smartClassService; @Autowired private SmartUploadService smartUploadService; @Autowired private SmartDutiesService smartDutiesService; @Autowired private SmartDepartmentService smartDepartmentService; @Autowired private SmartIdentityService smartIdentityService; @Override @DESRespondSecret(validated = true) public CommonResult logoffAccount(useridsRequest ur, BindingResult bindingResult) { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } int user = smartUserService.getSmartUserCountByIds(ur.getUserIds()); if (user != ur.getUserIds().size()) { return CommonResult.fail("用户信息已失效"); } // for (:) { // // } // user.setIsCancel(eLogOff.Logout.getValue()); // // int updateResult = smartUserService.updateSmartUser(user); return 0 > 0 ? CommonResult.ok("注销成功") : CommonResult.fail("注销失败"); } @Override @DESRespondSecret(validated = true) public CommonResult changeDepartment(changeDepartmentRequest cdr, BindingResult bindingResult) { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } List users = smartUserService.getSmartUserByIds(cdr.getUserIds()); if (users == null) { return CommonResult.fail("用户信息无效,移动失败!"); } if (users.size() != cdr.getUserIds().size()) { return CommonResult.fail("存在无效用户数据,移动失败!"); } for (SmartUser user : users) { user.setDepartmentId(cdr.getDepartmentId()); } boolean result = smartUserService.updateUserBatchById(users); return result ? CommonResult.ok("移动成功") : CommonResult.fail("移动失败"); } @Override @DESRespondSecret(validated = true) public CommonResult importExcelUsers(MultipartFile excelFile, String headImage) throws Exception { List result = new ArrayList<>(); //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像 if (excelFile.isEmpty() || excelFile.getSize() == 0) { return CommonResult.fail("压缩包中的excel文件不能为空"); } String ContentType = excelFile.getContentType(); InputStream inputStream = excelFile.getInputStream(); //xls格式文件 if (ContentType.equals(eFileType.Xls.getValue())) { CommonResult> resultData = readXls(inputStream); if (!resultData.isSuccess()) { return resultData; } result = resultData.getData(); } else if (ContentType.equals(eFileType.Xlsx.getValue())) { CommonResult> resultData = readXlsx(inputStream); if (!resultData.isSuccess()) { return resultData; } result = resultData.getData(); } else { return CommonResult.fail("用户导入只支持Xls、Xlsx"); } List uploadImages = Arrays.asList(headImage.split(",")); for (SmartUser user : result) { Optional image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/" + user.getHeadImage())).findFirst(); if (image != null && image.isPresent()) { user.setHeadImage(image.get()); } else { if (user.getIdentityId().equals(eIdentityStatu.Student.getValue())) { return CommonResult.fail(user.getName() + "头像不存在,导入失败"); } } } //region 将数据加入第三方 List studentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList()); //判断是否存在重复数据 List cardNos = studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList()); List existUsers = smartUserService.querySmartUserByCardNos(cardNos); if (existUsers != null && existUsers.size() > 0) { String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ","); return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入"); } for (SmartUser student : studentDatas) { //region 学生参数必填判断:年级、班级 if (student.getGrade() == null) { return CommonResult.fail("学生年级不能为空"); } if (student.getSchoolClass() == null) { return CommonResult.fail("学生班级不能为空"); } //endregion //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(student.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,新增失败"); } //region 希沃新增学生信息 //初始化客户端 SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam(); //请求体,MimeType为 application/json StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder() .build(); param.setRequestBody(requestBody); //查询条件 StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .classUid(classData.getClassUid()) .build(); requestBody.setQuery(query); // 学生列表 StudentServiceBatchSaveClassStudentsParam.StudentInfo students = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder() .studentName(student.getName()) .studentCode(student.getCardNo()) .gender(student.getSexId()) .phone(student.getPhone() == null ? "" : student.getPhone()) .build(); query.setStudents(java.util.Collections.singletonList(students)); query.setInPlaceOld(false);// 是否删除旧学生再保存 param.setRequestBody(requestBody); StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param); String jsonString = JSON.toJSONString(request); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 StudentServiceBatchSaveClassStudentsResult studentResult = seewoClient.invoke(request); System.out.println("出参:" + studentResult); if (studentResult == null) { return CommonResult.fail("希沃学生数据新增失败!"); } if (!studentResult.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(studentResult.getResponseBody().getMessage()); } student.setXwStudentUid(studentResult.getResponseBody().getData().get(0).getUserUid()); //endregion //region 百胜新增学生信息 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "student/create"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); 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()) + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); 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 + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); if (bsResult.contains("添加成功")) { ObjectMapper objectMapper = new ObjectMapper(); BsStudentVo grade = objectMapper.readValue(bsResult, BsStudentVo.class); // URL解码 String decodedUrl = URLDecoder.decode(grade.getData(), "UTF-8"); BsStudentNoVo studentNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStudentNoVo.class); student.setBsStudentNo(studentNo.getStudent_no()); } //endregion } if (studentDatas != null && studentDatas.size() > 0) { //批量存储学生信息 boolean resultBool = smartUserService.saveBatch(studentDatas); if (!resultBool) { return CommonResult.fail("导入失败"); } //region 希沃新增编辑学生家长信息 //学生与家长列表,最大100条 List studentParents = new ArrayList<>(); for (SmartUser student : studentDatas) { ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder() .studentCode(student.getCardNo()) .build(); studentParents.add(students); List parentDatas = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue() && e.getAffiliate().equals(student.getCardNo())).collect(Collectors.toList()); List parents = new ArrayList<>(); int i = 0; for (SmartUser parent : parentDatas) { ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem data = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder() .name(parent.getName()) .phone(parent.getPhone()) .index(i) .build(); parents.add(data); ++i; } //家长列表,最多4个 students.setParents(parents); } //初始化客户端 SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam(); //响应体,MimeType为 application/json ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder() .build(); param.setRequestBody(requestBody); //query ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .build(); requestBody.setQuery(query); query.setStudentParents(studentParents); param.setRequestBody(requestBody); ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param); String jsonString = JSON.toJSONString(request); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 ParentServiceBatchSaveOrUpdateParentsResult parentResult = seewoClient.invoke(request); System.out.println("出参:" + parentResult); //endregion if (parentResult == null) { return CommonResult.fail("希沃学生家长数据添加失败!"); } if (!parentResult.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(parentResult.getResponseBody().getMessage()); } } //endregion List parents = result.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList()); if (cardNos != null && cardNos.size() > 0) { List students = smartUserService.querySmartUserByCardNos(cardNos); for (SmartUser parent : parents) { Optional student = students.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst(); if (student != null && student.isPresent()) { parent.setAffiliate(String.valueOf(student.get().getId())); } } if (parents != null && parents.size() > 0) { //批量存储家长信息 boolean resultBool = smartUserService.saveBatch(parents); if (!resultBool) { return CommonResult.fail("导入失败!"); } } } return CommonResult.ok("导入成功"); } /** * 批量导入用户信息 * 以身份证号作为判断依据 如果存在重复数据就提示存在重复数据 * 开发流程:建议先去拿到excel中的所有数据的身份证号去数据库中找一遍是否存在重复数据 * 如果不存在重复数据就把附件文件夹中的附件文件上传到cos服务器上 * 然后手动拼接一个人脸照片文件地址存入对应的数据中 * * @param zipFile zip压缩包 * @return */ @Override @DESRespondSecret(validated = true) public CommonResult importZipUsers(MultipartFile zipFile) throws IOException { List result = new ArrayList<>(); MultipartFile excelFile = null; List multipartFileHashMap = new ArrayList<>(); String excelStr = null; if (zipFile != null) { //解压压缩文件并上传文件 ByteArrayOutputStream byteOut = null; ZipInputStream zipIn = null; try { java.util.zip.ZipEntry zipEntry = null; zipIn = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK")); while ((zipEntry = zipIn.getNextEntry()) != null) { String fileName = zipEntry.getName(); if (fileName.contains("人脸照片") && (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg"))) { byteOut = new ByteArrayOutputStream(); IOUtils.copy(zipIn, byteOut); InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray()); MultipartFile multipartFile = FileUtils.getMultipartFile(inputStream, fileName); multipartFileHashMap.add(multipartFile); } else if (fileName.contains("人员信息采集表") && (fileName.endsWith(".xlsx") || fileName.endsWith(".xls"))) { excelStr = fileName.endsWith(".xlsx") ? "xlsx" : "xls"; byteOut = new ByteArrayOutputStream(); IOUtils.copy(zipIn, byteOut); InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray()); excelFile = FileUtils.getMultipartFile(inputStream, fileName); } } } catch (Exception e) { e.printStackTrace(); } finally { if (byteOut != null) { byteOut.close(); } if (zipIn != null) { zipIn.close(); } } } //先解析excel如果excel不满足格式就提示错误信息 避免提前占用带宽上传头像 if (excelFile.isEmpty() || excelFile.getSize() == 0) { return CommonResult.fail("压缩包中的excel文件不能为空"); } String ContentType = excelFile.getContentType(); InputStream inputStream = excelFile.getInputStream(); //xls格式文件 if (excelStr.equals("xls")) { CommonResult> resultData = readXls(inputStream); if (!resultData.isSuccess()) { return resultData; } result = resultData.getData(); } else if (excelStr.equals("xlsx")) { CommonResult> resultData = readXlsx(inputStream); if (!resultData.isSuccess()) { return resultData; } result = resultData.getData(); } else { return CommonResult.fail("用户导入只支持Xls、Xlsx"); } //cos上传 返回图片地址 String uploadResult = smartUploadService.upload(multipartFileHashMap.toArray(new MultipartFile[0])); List uploadImages = Arrays.asList(uploadResult.split(",")); for (SmartUser user : result) { Optional headImage = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/headImage/" + user.getHeadImage())).findFirst(); if (headImage != null && headImage.isPresent()) { user.setHeadImage(headImage.get()); } } //批量存储用户信息 boolean resultBool = smartUserService.saveBatch(result); return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败"); } /** * Xlsx文件读取方法ss * * @param inputStream 文件流 * @return * @throws IOException */ private CommonResult> readXlsx(InputStream inputStream) throws IOException { List phones = new ArrayList<>(); List idCards = new ArrayList<>(); List cardNos = new ArrayList<>(); List result = new ArrayList<>(); XSSFWorkbook sheets = new XSSFWorkbook(inputStream); List departments = smartDepartmentService.list(null); List grades = smartGradeService.list(null); //年级 List classs = smartClassService.list(null);//班级 //读取第一张sheet XSSFSheet sheetAt = sheets.getSheetAt(0); DataFormatter dataFormatter = new DataFormatter(); try { for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) { XSSFRow row = sheetAt.getRow(rowNum); if (row != null) { //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。 //所以先使用setCellType()方法先将该单元格的类型设置为STRING //然后poi会根据字符串读取它 //标题 校验 if (rowNum == 0) { String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//班级 if (!schoolClass.equals("班级")) { return CommonResult.fail("导入数据第一列为班级"); } String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号 if (!cardNo.equals("学号")) { return CommonResult.fail("导入数据第二列为学号"); } String name = dataFormatter.formatCellValue(row.getCell(2));//姓名 if (!name.equals("姓名")) { return CommonResult.fail("导入数据第三列为姓名"); } String sex = dataFormatter.formatCellValue(row.getCell(3));//性别 if (!sex.equals("性别")) { return CommonResult.fail("导入数据第四列为性别"); } String nation = dataFormatter.formatCellValue(row.getCell(4));//民族 if (!nation.equals("民族")) { return CommonResult.fail("导入数据第五列为民族"); } String cardId = dataFormatter.formatCellValue(row.getCell(5));//身份证 if (!cardId.equals("身份证")) { return CommonResult.fail("导入数据第六列为身份证"); } String headImage = dataFormatter.formatCellValue(row.getCell(6));//照片 if (!headImage.equals("照片")) { return CommonResult.fail("导入数据第七列为照片"); } String timeGroup = dataFormatter.formatCellValue(row.getCell(7));//常规时间组 if (!timeGroup.equals("常规时间组")) { return CommonResult.fail("导入数据第八列为常规时间组"); } String address = dataFormatter.formatCellValue(row.getCell(8));//住址 if (!address.equals("住址")) { return CommonResult.fail("导入数据第九列为住址"); } String phone = dataFormatter.formatCellValue(row.getCell(9));//联系电话 if (!phone.equals("联系电话")) { return CommonResult.fail("导入数据第十列为联系电话"); } String family = dataFormatter.formatCellValue(row.getCell(10));//家属 if (!family.equals("家属")) { return CommonResult.fail("导入数据第十一列为家属"); } String familyShip = dataFormatter.formatCellValue(row.getCell(11));//家属与本人关系 if (!familyShip.equals("家属与本人关系")) { return CommonResult.fail("导入数据第十二列为家属与本人关系"); } String phoneTwo = dataFormatter.formatCellValue(row.getCell(12));//联系电话2 if (!phoneTwo.equals("联系电话2")) { return CommonResult.fail("导入数据第十三列为联系电话2"); } String familyTwo = dataFormatter.formatCellValue(row.getCell(13));//家属2 if (!familyTwo.equals("家属2")) { return CommonResult.fail("导入数据第十四列为家属2"); } String familyShipTwo = dataFormatter.formatCellValue(row.getCell(14));//家属与本人关系2 if (!familyShipTwo.equals("家属与本人关系2")) { return CommonResult.fail("导入数据第十五列为家属与本人关系2"); } } else { SmartUser user = new SmartUser(); String name = dataFormatter.formatCellValue(row.getCell(2)); if (ObjectUtils.isEmpty(name)) { return CommonResult.fail("第" + (rowNum + 2) + "条数据的名称不能为空"); } String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//班级 if (ObjectUtils.isEmpty(schoolClass)) { return CommonResult.fail(name + "的班级不能为空"); } //手机号重复判断 String phone = dataFormatter.formatCellValue(row.getCell(9)); if (ObjectUtils.isEmpty(phone)) { return CommonResult.fail(name + "家属的手机号不能为空"); } if (!ObjectUtils.isEmpty(phone)) { phones.add(phone); } if (phones.stream().distinct().count() != phones.size()) { return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据"); } String family = dataFormatter.formatCellValue(row.getCell(10));//家属 if (ObjectUtils.isEmpty(family)) { return CommonResult.fail(name + "的家属不能为空"); } //性别是否为空判断 String sex = dataFormatter.formatCellValue(row.getCell(3)); if (ObjectUtils.isEmpty(sex)) { return CommonResult.fail(name + "的性别不能为空"); } //家庭住址是否为空判断 String address = dataFormatter.formatCellValue(row.getCell(8)); if (ObjectUtils.isEmpty(address)) { return CommonResult.fail(name + "的家庭住址不能为空"); } //民族是否为空判断 String nation = dataFormatter.formatCellValue(row.getCell(4)); if (ObjectUtils.isEmpty(nation)) { return CommonResult.fail(name + "的民族不能为空"); } //部门是否为空判断 String department = dataFormatter.formatCellValue(row.getCell(0)).replace("年级", "") + "学生"; if (ObjectUtils.isEmpty(department)) { return CommonResult.fail(name + "的部门不能为空"); } Integer departmentId = null; Optional departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst(); if (departModel != null && departModel.isPresent()) { departmentId = departModel.get().getId(); } else { departmentId = 1; } //学号重复判断 String cardNo = dataFormatter.formatCellValue(row.getCell(1)); if (!ObjectUtils.isEmpty(cardNo)) { cardNos.add(cardNo); } if (cardNos.stream().distinct().count() != cardNos.size()) { return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据"); } //身份证重复判断 String idCard = dataFormatter.formatCellValue(row.getCell(5)); if (!ObjectUtils.isEmpty(idCard)) { idCards.add(idCard); } if (idCards.stream().distinct().count() != idCards.size()) { return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据"); } user.setCardNo(cardNo == null ? "" : cardNo); user.setName(name == null ? "" : name); user.setIdentityId(eIdentityStatu.Student.getValue()); user.setIdCard(idCard == null ? "" : idCard); user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex)); user.setDepartmentId(departmentId); String cellImage = dataFormatter.formatCellValue(row.getCell(6)); user.setHeadImage(cellImage); user.setDormitoryNumber(""); String grade = schoolClass == null ? "" : schoolClass.substring(0, 3); Optional oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst(); if (oGrade != null && oGrade.isPresent()) { Integer gradeId = oGrade.get().getId(); user.setGrade(String.valueOf(gradeId)); String schoolClassStr = schoolClass.replace("grade", ""); Optional oClass = classs.stream().filter(e -> (grade + e.getName()).equals(schoolClassStr) && e.getGradeId().equals(gradeId)).findFirst(); if (oClass != null && oClass.isPresent()) { user.setSchoolClass(oClass.get().getId()); } else { return CommonResult.fail(name + "的班级数据无效,导入失败"); } } else { return CommonResult.fail(name + "的年级数据无效,导入失败"); } user.setCollege(""); user.setSpeciality(""); user.setCampus(""); user.setPhone(""); user.setAffiliate(""); user.setTitle(""); user.setAddress(address == null ? "" : address); user.setNation(nation == null ? "" : nation); user.setOfStudent(""); user.setGraduate(""); user.setDuties(null); String timeGroup = dataFormatter.formatCellValue(row.getCell(7)); user.setTimeGroupId(eTimeGroup.integerOfTimeName(timeGroup)); user.setIsCancel(eLogOff.Unlogout.getValue()); result.add(user); //region 家属 SmartUser familyOne = new SmartUser(); familyOne.setName(family); familyOne.setDepartmentId(1); familyOne.setPhone(phone); familyOne.setIdentityId(eIdentityStatu.Parent.getValue()); familyOne.setSexId(eSexStatu.Man.getValue()); familyOne.setIsCancel(eLogOff.Unlogout.getValue()); familyOne.setAffiliate(user.getCardNo()); String familyShip = dataFormatter.formatCellValue(row.getCell(11));//家属与本人关系 familyOne.setShip(familyShip == null ? "" : familyShip); result.add(familyOne); SmartUser familyTwo = new SmartUser(); String familyNameTwo = dataFormatter.formatCellValue(row.getCell(13));//家属2 if (!ObjectUtils.isEmpty(familyNameTwo)) { familyTwo.setName(familyNameTwo); familyTwo.setDepartmentId(1); String phoneTwo = dataFormatter.formatCellValue(row.getCell(12));//联系电话2 familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo); familyTwo.setIdentityId(eIdentityStatu.Parent.getValue()); familyTwo.setSexId(eSexStatu.Man.getValue()); familyTwo.setIsCancel(eLogOff.Unlogout.getValue()); familyTwo.setAffiliate(user.getCardNo()); String familyShipTwo = dataFormatter.formatCellValue(row.getCell(14));//家属与本人关系2 familyTwo.setShip(familyShipTwo == null ? "" : familyShipTwo); result.add(familyTwo); } //endregion } } } } catch (Exception e) { return CommonResult.fail("请按模板格式导入数据"); } return CommonResult.ok(result); } /** * Xls文件读取方法 * * @param inputStream 文件流 * @return * @throws IOException */ private CommonResult> readXls(InputStream inputStream) throws IOException { List phones = new ArrayList<>(); List idCards = new ArrayList<>(); List cardNos = new ArrayList<>(); List result = new ArrayList<>(); HSSFWorkbook sheets = new HSSFWorkbook(inputStream); List departments = smartDepartmentService.list(null); List grades = smartGradeService.list(null); //年级 List classs = smartClassService.list(null);//班级 //读取第一张sheet HSSFSheet sheetAt = sheets.getSheetAt(0); DataFormatter dataFormatter = new DataFormatter(); try { for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) { HSSFRow row = sheetAt.getRow(rowNum); if (row != null) { //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。 //所以先使用setCellType()方法先将该单元格的类型设置为STRING //然后poi会根据字符串读取它 //标题 校验 if (rowNum == 0) { String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//班级 if (!schoolClass.equals("班级")) { return CommonResult.fail("导入数据第一列为班级"); } String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号 if (!cardNo.equals("学号")) { return CommonResult.fail("导入数据第二列为学号"); } String name = dataFormatter.formatCellValue(row.getCell(2));//姓名 if (!name.equals("姓名")) { return CommonResult.fail("导入数据第三列为姓名"); } String sex = dataFormatter.formatCellValue(row.getCell(3));//性别 if (!sex.equals("性别")) { return CommonResult.fail("导入数据第四列为性别"); } String nation = dataFormatter.formatCellValue(row.getCell(4));//民族 if (!nation.equals("民族")) { return CommonResult.fail("导入数据第五列为民族"); } String cardId = dataFormatter.formatCellValue(row.getCell(5));//身份证 if (!cardId.equals("身份证")) { return CommonResult.fail("导入数据第六列为身份证"); } String headImage = dataFormatter.formatCellValue(row.getCell(6));//照片 if (!headImage.equals("照片")) { return CommonResult.fail("导入数据第七列为照片"); } String timeGroup = dataFormatter.formatCellValue(row.getCell(7));//常规时间组 if (!timeGroup.equals("常规时间组")) { return CommonResult.fail("导入数据第八列为常规时间组"); } String address = dataFormatter.formatCellValue(row.getCell(8));//住址 if (!address.equals("住址")) { return CommonResult.fail("导入数据第九列为住址"); } String phone = dataFormatter.formatCellValue(row.getCell(9));//联系电话 if (!phone.equals("联系电话")) { return CommonResult.fail("导入数据第十列为联系电话"); } String family = dataFormatter.formatCellValue(row.getCell(10));//家属 if (!family.equals("家属")) { return CommonResult.fail("导入数据第十一列为家属"); } String familyShip = dataFormatter.formatCellValue(row.getCell(11));//家属与本人关系 if (!familyShip.equals("家属与本人关系")) { return CommonResult.fail("导入数据第十二列为家属与本人关系"); } String phoneTwo = dataFormatter.formatCellValue(row.getCell(12));//联系电话2 if (!phoneTwo.equals("联系电话2")) { return CommonResult.fail("导入数据第十三列为联系电话2"); } String familyTwo = dataFormatter.formatCellValue(row.getCell(13));//家属2 if (!familyTwo.equals("家属2")) { return CommonResult.fail("导入数据第十四列为家属2"); } String familyShipTwo = dataFormatter.formatCellValue(row.getCell(14));//家属与本人关系2 if (!familyShipTwo.equals("家属与本人关系2")) { return CommonResult.fail("导入数据第十五列为家属与本人关系2"); } } else { SmartUser user = new SmartUser(); String name = dataFormatter.formatCellValue(row.getCell(2)); if (ObjectUtils.isEmpty(name)) { return CommonResult.fail("第" + (rowNum + 2) + "条数据的名称不能为空"); } String schoolClass = dataFormatter.formatCellValue(row.getCell(0));//班级 if (ObjectUtils.isEmpty(schoolClass)) { return CommonResult.fail(name + "的班级不能为空"); } //手机号重复判断 String phone = dataFormatter.formatCellValue(row.getCell(9)); if (ObjectUtils.isEmpty(phone)) { return CommonResult.fail(name + "家属的手机号不能为空"); } if (!ObjectUtils.isEmpty(phone)) { phones.add(phone); } if (phones.stream().distinct().count() != phones.size()) { return CommonResult.fail("导入的Excel中,联系电话:" + phone + "存在重复数据"); } String family = dataFormatter.formatCellValue(row.getCell(10));//家属 if (ObjectUtils.isEmpty(family)) { return CommonResult.fail(name + "的家属不能为空"); } //性别是否为空判断 String sex = dataFormatter.formatCellValue(row.getCell(3)); if (ObjectUtils.isEmpty(sex)) { return CommonResult.fail(name + "的性别不能为空"); } //家庭住址是否为空判断 String address = dataFormatter.formatCellValue(row.getCell(8)); if (ObjectUtils.isEmpty(address)) { return CommonResult.fail(name + "的家庭住址不能为空"); } //民族是否为空判断 String nation = dataFormatter.formatCellValue(row.getCell(4)); if (ObjectUtils.isEmpty(nation)) { return CommonResult.fail(name + "的民族不能为空"); } //部门是否为空判断 String department = dataFormatter.formatCellValue(row.getCell(0)).replace("年级", "") + "学生"; if (ObjectUtils.isEmpty(department)) { return CommonResult.fail(name + "的部门不能为空"); } Integer departmentId = null; Optional departModel = departments.stream().filter(e -> e.getName().equals(department)).findFirst(); if (departModel != null && departModel.isPresent()) { departmentId = departModel.get().getId(); } else { departmentId = 1; } //学号重复判断 String cardNo = dataFormatter.formatCellValue(row.getCell(1)); if (!ObjectUtils.isEmpty(cardNo)) { cardNos.add(cardNo); } if (cardNos.stream().distinct().count() != cardNos.size()) { return CommonResult.fail("导入的Excel中," + name + "的学号:" + cardNo + "存在重复数据"); } //身份证重复判断 String idCard = dataFormatter.formatCellValue(row.getCell(5)); if (!ObjectUtils.isEmpty(idCard)) { idCards.add(idCard); } if (idCards.stream().distinct().count() != idCards.size()) { return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据"); } user.setCardNo(cardNo == null ? "" : cardNo); user.setName(name == null ? "" : name); user.setIdentityId(eIdentityStatu.Student.getValue()); user.setIdCard(idCard == null ? "" : idCard); user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex)); user.setDepartmentId(departmentId); String cellImage = dataFormatter.formatCellValue(row.getCell(6)); user.setHeadImage(cellImage); user.setDormitoryNumber(""); String grade = schoolClass == null ? "" : schoolClass.substring(0, 3); Optional oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst(); if (oGrade != null && oGrade.isPresent()) { Integer gradeId = oGrade.get().getId(); user.setGrade(String.valueOf(gradeId)); String schoolClassStr = schoolClass.replace("grade", ""); Optional oClass = classs.stream().filter(e -> (grade + e.getName()).equals(schoolClassStr) && e.getGradeId().equals(gradeId)).findFirst(); if (oClass != null && oClass.isPresent()) { user.setSchoolClass(oClass.get().getId()); } else { return CommonResult.fail(name + "的班级数据无效,导入失败"); } } else { return CommonResult.fail(name + "的年级数据无效,导入失败"); } user.setCollege(""); user.setSpeciality(""); user.setCampus(""); user.setPhone(""); user.setAffiliate(""); user.setTitle(""); user.setAddress(address == null ? "" : address); user.setNation(nation == null ? "" : nation); user.setOfStudent(""); user.setGraduate(""); user.setDuties(null); String timeGroup = dataFormatter.formatCellValue(row.getCell(7)); user.setTimeGroupId(eTimeGroup.integerOfTimeName(timeGroup)); user.setIsCancel(eLogOff.Unlogout.getValue()); result.add(user); //region 家属 SmartUser familyOne = new SmartUser(); familyOne.setName(family); familyOne.setDepartmentId(1); familyOne.setPhone(phone); familyOne.setIdentityId(eIdentityStatu.Parent.getValue()); familyOne.setAffiliate(user.getCardNo()); familyOne.setSexId(eSexStatu.Man.getValue()); familyOne.setIsCancel(eLogOff.Unlogout.getValue()); String familyShip = dataFormatter.formatCellValue(row.getCell(11));//家属与本人关系 familyOne.setShip(familyShip == null ? "" : familyShip); result.add(familyOne); SmartUser familyTwo = new SmartUser(); String familyNameTwo = dataFormatter.formatCellValue(row.getCell(13));//家属2 if (!ObjectUtils.isEmpty(familyNameTwo)) { familyTwo.setName(familyNameTwo); familyTwo.setDepartmentId(1); String phoneTwo = dataFormatter.formatCellValue(row.getCell(12));//联系电话2 familyTwo.setPhone(phoneTwo == null ? "" : phoneTwo); familyTwo.setIdentityId(eIdentityStatu.Parent.getValue()); familyTwo.setSexId(eSexStatu.Man.getValue()); familyTwo.setIsCancel(eLogOff.Unlogout.getValue()); familyTwo.setAffiliate(user.getCardNo()); String familyShipTwo = dataFormatter.formatCellValue(row.getCell(14));//家属与本人关系2 familyTwo.setShip(familyShipTwo == null ? "" : familyShipTwo); result.add(familyTwo); } //endregion } } } } catch (Exception e) { return CommonResult.fail("请按模板格式导入数据"); } return CommonResult.ok(result); } @Override @DESRespondSecret(validated = true) public CommonResult timeGroups() { List result = new ArrayList<>(); for (int i = 1; i <= 3; i++) { TimeGroupVo data = new TimeGroupVo(); data.setId(i); data.setName(eTimeGroup.stringOfName(i)); result.add(data); } return CommonResult.ok(result); } /** * 新增用户 * * @param isur 用户数据 * @param bindingResult * @return */ @Override @DESRespondSecret(validated = true) public CommonResult insertSmartUser(insertSmartUserRequest isur, BindingResult bindingResult) throws Exception { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } //重复性判断 int existCount = smartUserService.querySmartUserByCardNo(isur.getCardNo()); if (existCount > 0) { return CommonResult.fail("当前学号已存在,请勿重复添加"); } SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); SmartUser su = new SmartUser(); su.setTimeGroupId(isur.getTimeGroupId()); su.setCardNo(isur.getCardNo()); su.setName(isur.getName()); su.setIdentityId(isur.getIdentityId()); su.setIdCard(isur.getIdCard()); su.setSexId(isur.getSexId()); su.setDepartmentId(isur.getDepartmentId()); su.setHeadImage(isur.getHeadImage()); su.setGrade(isur.getGrade()); su.setCollege(isur.getCollege()); su.setSpeciality(isur.getSpeciality()); su.setSchoolClass(isur.getSchoolClass()); su.setCampus(isur.getCampus()); su.setDormitoryNumber(isur.getDormitoryNumber()); su.setPhone(isur.getPhone()); su.setAffiliate(StringUtils.join(isur.getAffiliate(), ",")); su.setTitle(isur.getTitle()); su.setAddress(isur.getAddress()); su.setNation(isur.getNation()); su.setOfStudent(isur.getOfStudent()); su.setGraduate(isur.getGraduate()); su.setDuties(isur.getDuties()); su.setIsCancel(eLogOff.Unlogout.getValue()); //region 人员信息加入到第三方api //要将用户数据加入到希沃和百胜中 //希沃和百胜的老师、学生数据添加是不一样的,所以按身份添加 if (isur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长 //region 家长参数必填判断:手机号 if (isur.getPhone() == null) { return CommonResult.fail("家长手机号不能为空"); } //endregion //拿到被关联学生的信息去获取对应的卡号 //有多个学生就循环学生 if (isur.getAffiliate() == null) { return CommonResult.fail("被关联人不能为空"); } if (isur.getAffiliate().size() <= 0) { return CommonResult.fail("被关联人不能为空"); } List studentDatas = smartUserService.getSmartUserIds(isur.getAffiliate()); //region 希沃新增编辑学生家长信息 CommonResult insertOrUpdateStudent = insertOrUpdateStudentParent(seewoClient, studentDatas, isur.getName(), isur.getPhone()); if (!insertOrUpdateStudent.isSuccess()) { return CommonResult.fail(insertOrUpdateStudent.getMessage()); } //endregion } else if (isur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生 //region 学生参数必填判断:年级、班级 if (isur.getGrade() == null) { return CommonResult.fail("学生年级不能为空"); } if (isur.getSchoolClass() == null) { return CommonResult.fail("学生班级不能为空"); } //endregion //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(isur.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,新增失败"); } //region 希沃新增学生信息 CommonResult insertStudent = SeewoInsertStudent(seewoClient, isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getPhone(), classData.getClassUid()); if (!insertStudent.isSuccess()) { return CommonResult.fail(insertStudent.getMessage()); } su.setXwStudentUid(insertStudent.getData()); //endregion //region 百胜新增学生信息 CommonResult insertBsStudent = bsInsertStudent(isur.getName(), isur.getCardNo(), isur.getSexId(), isur.getHeadImage(), isur.getTimeGroupId(), classData.getBsClassNo()); if (!insertBsStudent.isSuccess()) { return CommonResult.fail(insertBsStudent.getMessage()); } su.setBsStudentNo(insertBsStudent.getData()); //endregion } else if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//老师 //region 老师参数必填判断:职称、手机号 if (isur.getTitle() == null) { return CommonResult.fail("老师职称不能为空"); } if (isur.getPhone() == null) { return CommonResult.fail("老师手机号不能为空"); } //endregion //region 希沃添加教师数据 CommonResult insertTeacher = SeewoInsertTeacher(seewoClient, isur.getPhone(), isur.getName(), isur.getHeadImage()); if (!insertTeacher.isSuccess()) { return CommonResult.fail(insertTeacher.getMessage()); } su.setXwTeacherCode(insertTeacher.getData()); //endregion if (isur.getDuties().intValue() == eDuties.ClassTeacher.getValue()) { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(isur.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,新增失败"); } //region 将班主任推送到希沃 CommonResult pushMaster = SeewoPushMaster(seewoClient, isur.getPhone(), classData.getClassUid()); if (!pushMaster.isSuccess()) { return CommonResult.fail(pushMaster.getMessage()); } //endregion } SmartDepartment departmentData = smartDepartmentService.getSmartById(isur.getDepartmentId()); if (departmentData == null) { return CommonResult.fail("部门数据无效,新增教师失败"); } String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710"; if (departmentNo == null) { return CommonResult.fail("百胜部门编号为空,新增教师失败"); } //region 百胜添加教师数据 CommonResult insertBsTeacher = bsInsertTeacher(su, departmentNo); if (!insertBsTeacher.isSuccess()) { return CommonResult.fail(insertBsTeacher.getMessage()); } su.setBsStaffCode(insertBsTeacher.getData()); //endregion } //endregion //最后都要把数据加入到数据库中 int result = smartUserService.insertSmartUser(su); //新增用户得将用户信息通过接口推送到希沃、百胜 return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败"); } /** * 更新用户 * * @param usur 更新用户数据 * @param bindingResult * @return */ @Override @DESRespondSecret(validated = true) public CommonResult updateSmartUserById(updateSmartUserRequest usur, BindingResult bindingResult) throws Exception { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } //更新的同时将百胜用户信息同步过去或者同步过来? SmartUser su = smartUserService.getSmartById(usur.getId()); if (su == null) { CommonResult.fail("用户数据已失效,修改失败!"); } //是否转换身份 boolean changeIdentity = false; Integer oldIdentity = null; String oldAffiliate = su.getAffiliate(); Integer oldSchoolClass = su.getSchoolClass(); String oldStaffNo = su.getBsStaffCode(); String oldCardNo = su.getCardNo(); if (usur.getIdentityId().intValue() != su.getIdentityId().intValue()) { changeIdentity = true; oldIdentity = su.getIdentityId().intValue(); } SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); su.setTimeGroupId(usur.getTimeGroupId()); su.setCardNo(usur.getCardNo()); su.setName(usur.getName()); su.setIdentityId(usur.getIdentityId()); su.setIdCard(usur.getIdCard()); su.setSexId(usur.getSexId()); su.setDepartmentId(usur.getDepartmentId()); su.setHeadImage(usur.getHeadImage()); su.setGrade(usur.getGrade()); su.setCollege(usur.getCollege()); su.setSpeciality(usur.getSpeciality()); su.setSchoolClass(usur.getSchoolClass()); su.setCampus(usur.getCampus()); su.setDormitoryNumber(usur.getDormitoryNumber()); su.setPhone(usur.getPhone()); su.setAffiliate(StringUtils.join(usur.getAffiliate(), ",")); su.setTitle(usur.getTitle()); su.setAddress(usur.getAddress()); su.setNation(usur.getNation()); su.setOfStudent(usur.getOfStudent()); su.setGraduate(usur.getGraduate()); su.setDuties(usur.getDuties()); su.setIsCancel(eLogOff.Unlogout.getValue()); if (usur.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长 //拿到被关联学生的信息去获取对应的卡号 //有多个学生就循环学生 if (usur.getAffiliate() == null) { return CommonResult.fail("被关联人不能为空"); } if (usur.getAffiliate().size() <= 0) { return CommonResult.fail("被关联人不能为空"); } List studentDatas = smartUserService.getSmartUserIds(usur.getAffiliate()); if (!changeIdentity) { //region 希沃新增编辑学生家长信息 //学生与家长列表,最大100条 CommonResult insertOrUpdateResult = insertOrUpdateStudentParent(seewoClient, studentDatas, usur.getName(), usur.getPhone()); if (!insertOrUpdateResult.isSuccess()) { return CommonResult.fail(insertOrUpdateResult.getMessage()); } //endregion } else { if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) { //region 希沃删除学生 //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo); if (!deleteStudent.isSuccess()) { return CommonResult.fail(deleteStudent.getMessage()); } //endregion //region 百胜删除学生 CommonResult deleteBsStudent = bsDeleteStudent(su); if (!deleteBsStudent.isSuccess()) { return CommonResult.fail(deleteBsStudent.getMessage()); } //endregion } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } //region 希沃删除教师 CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone()); if (!deleteTeacher.isSuccess()) { return CommonResult.fail(deleteTeacher.getMessage()); } //endregion //region 希沃删除班主任 CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone()); if (deleteTeacherMaster.isSuccess()) { return CommonResult.fail(deleteTeacherMaster.getMessage()); } //endregion //region 百胜删除教师 CommonResult bsDeleteTeacher = bsDeleteTeacher(oldStaffNo); if (!bsDeleteTeacher.isSuccess()) { return CommonResult.fail(bsDeleteTeacher.getMessage()); } //endregion } //region 希沃新增编辑学生家长信息 CommonResult insertOrUpdate = insertOrUpdateStudentParent(seewoClient, studentDatas, su.getName(), su.getPhone()); if (!insertOrUpdate.isSuccess()) { return CommonResult.fail(insertOrUpdate.getMessage()); } //endregion } } else if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生 //region 年级和班级不能为空 if (usur.getGrade() == null) { return CommonResult.fail("学生年级不能为空"); } if (usur.getSchoolClass() == null) { return CommonResult.fail("学生班级不能为空"); } //endregion if (!changeIdentity) { //region 更新希沃学生信息 CommonResult updateStudent = SeewoUpdateStudent(seewoClient, su); if (!updateStudent.isSuccess()) { if (updateStudent.getMessage().equals("学生不存在")) { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } CommonResult insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid()); if (!insertStudent.isSuccess()) { return CommonResult.fail(insertStudent.getMessage()); } } return CommonResult.fail(updateStudent.getMessage()); } //endregion //region 更新百胜学生信息 CommonResult updateBsStudent = bsUpdateStudent(su); if (!updateBsStudent.isSuccess()) { if (updateBsStudent.getMessage().equals("人员不存在或已删除")) { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(usur.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } //region 百胜新增学生信息 CommonResult insertBsStudent = bsInsertStudent(usur.getName(), usur.getCardNo(), usur.getSexId(), usur.getHeadImage(), usur.getTimeGroupId(), classData.getBsClassNo()); if (!insertBsStudent.isSuccess()) { return CommonResult.fail(insertBsStudent.getMessage()); } su.setBsStudentNo(insertBsStudent.getData()); //endregion } else { return CommonResult.fail(updateBsStudent.getMessage()); } } //endregion } else { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,新增失败"); } //region 希沃新增学生信息 CommonResult insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid()); if (!insertStudent.isSuccess()) { return CommonResult.fail(insertStudent.getMessage()); } else { su.setXwStudentUid(insertStudent.getData()); } //endregion //region 百胜新增学生信息 CommonResult insertBsStudent = bsInsertStudent(su.getName(), su.getCardNo(), su.getSexId(), su.getHeadImage(), su.getTimeGroupId(), classData.getBsClassNo()); if (insertBsStudent.isSuccess()) { su.setBsStudentNo(insertBsStudent.getData()); } else { //region 希沃删除学生 //百胜数据插入失败后需要把已插入到希沃的数据删除 CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo); if (!deleteStudent.isSuccess()) { return CommonResult.fail(deleteStudent.getMessage()); } //endregion return CommonResult.fail("切换身份后," + insertBsStudent.getMessage() + ",百胜无法插入学生数据"); } //endregion if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) { List studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(","))); //region 删除原有的家长关系 CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, su.getPhone()); if (!deleteResult.isSuccess()) { return CommonResult.fail(deleteResult.getMessage()); } //endregion } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) { //获取班级Uid SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass); if (oldClassData == null) { return CommonResult.fail("班级数据无效,更新失败"); } //region 希沃删除教师 CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone()); if (!deleteTeacher.isSuccess()) { return CommonResult.fail(deleteTeacher.getMessage()); } //endregion //region 希沃删除班主任 CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone()); if (!deleteMaster.isSuccess()) { return CommonResult.fail(deleteMaster.getMessage()); } //endregion //region 百胜删除教师 CommonResult deleteBsTeacher = bsDeleteTeacher(oldStaffNo); if (!deleteBsTeacher.isSuccess()) { return CommonResult.fail(deleteBsTeacher.getMessage()); } //endregion } } } else if (usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//教师 if (!changeIdentity) { //region 希沃更新教师数据 CommonResult updateTeacher = SeewoUpdateTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage()); if (!updateTeacher.isSuccess()) { return CommonResult.fail(updateTeacher.getMessage()); } su.setXwTeacherCode(updateTeacher.getData()); //endregion SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId()); if (departmentData == null) { return CommonResult.fail("部门数据无效,更新教师失败"); } String departmentNo = departmentData.getBsDepartmentNo(); if (departmentNo == null) { return CommonResult.fail("百胜部门编号为空,新增教师失败"); } //region 百胜更新教师数据 CommonResult bsUpdateTeacher = updateBsTeacher(su, departmentNo); if (!bsUpdateTeacher.isSuccess()) { return CommonResult.fail(bsUpdateTeacher.getMessage()); } su.setBsStaffCode(bsUpdateTeacher.getData()); //endregion } else { if (oldIdentity.intValue() == eIdentityStatu.Parent.getValue()) { List studentDatas = smartUserService.getSmartUserIds(Arrays.asList(oldAffiliate.split(","))); //region 删除原有的家长关系 CommonResult deleteOldShip = deleteOldParentShip(seewoClient, studentDatas, su.getPhone()); if (!deleteOldShip.isSuccess()) { return CommonResult.fail(deleteOldShip.getMessage()); } //endregion } else if (oldIdentity.intValue() == eIdentityStatu.Student.getValue()) { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } //region 希沃删除学生 CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), oldCardNo); if (!deleteStudent.isSuccess()) { return CommonResult.fail(deleteStudent.getMessage()); } //endregion //region 百胜删除学生 CommonResult deleteBsStudent = bsDeleteStudent(su); if (!deleteBsStudent.isSuccess()) { return CommonResult.fail(deleteBsStudent.getMessage()); } //endregion } //region 希沃添加教师数据 CommonResult insertTeacher = SeewoInsertTeacher(seewoClient, su.getPhone(), su.getName(), su.getHeadImage()); if (!insertTeacher.isSuccess()) { return CommonResult.fail(insertTeacher.getMessage()); } su.setXwTeacherCode(insertTeacher.getData()); //endregion if (su.getDuties().intValue() == eDuties.ClassTeacher.getValue()) { //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(su.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,新增失败"); } //region 将班主任推送到希沃 CommonResult pushMaster = SeewoPushMaster(seewoClient, su.getPhone(), classData.getClassUid()); if (!pushMaster.isSuccess()) { return CommonResult.fail(pushMaster.getMessage()); } //endregion } SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId()); if (departmentData == null) { return CommonResult.fail("部门数据无效,新增教师失败"); } String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710"; if (departmentNo == null) { return CommonResult.fail("百胜部门编号为空,新增教师失败"); } //region 百胜添加教师数据 CommonResult insertBsTeacher = bsInsertTeacher(su, departmentNo); if (!insertBsTeacher.isSuccess()) { return CommonResult.fail(insertBsTeacher.getMessage()); } su.setBsStaffCode(insertBsTeacher.getData()); //endregion } } int result = smartUserService.updateSmartUser(su); return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败"); } //region 希沃增删改查方法 //region 希沃新增学生信息 public CommonResult SeewoInsertStudent(SeewoClient seewoClient, String name, String cardNo, Integer sexId, String Phone, String classUid) { //region 希沃新增学生信息 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); StudentServiceBatchSaveClassStudentsParam param = new StudentServiceBatchSaveClassStudentsParam(); //请求体,MimeType为 application/json StudentServiceBatchSaveClassStudentsParam.JSONRequestBody requestBody = StudentServiceBatchSaveClassStudentsParam.JSONRequestBody.builder() .build(); param.setRequestBody(requestBody); //查询条件 StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery query = StudentServiceBatchSaveClassStudentsParam.StudentSaveQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .classUid(classUid) .build(); requestBody.setQuery(query); // 学生列表 StudentServiceBatchSaveClassStudentsParam.StudentInfo students = StudentServiceBatchSaveClassStudentsParam.StudentInfo.builder() .studentName(name) .studentCode(cardNo) .gender(sexId) .phone(Phone == null ? "" : Phone) .build(); query.setStudents(java.util.Collections.singletonList(students)); query.setInPlaceOld(false);// 是否删除旧学生再保存 param.setRequestBody(requestBody); StudentServiceBatchSaveClassStudentsRequest request = new StudentServiceBatchSaveClassStudentsRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 StudentServiceBatchSaveClassStudentsResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃学生数据新增失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } return CommonResult.ok("200", "添加成功", result.getResponseBody().getData().get(0).getUserUid()); //endregion } //endregion //region 希沃更新学生信息 public CommonResult SeewoUpdateStudent(SeewoClient seewoClient, SmartUser su) { //region 更新希沃学生信息 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); StudentServiceUpdateStudentInfoParam param = new StudentServiceUpdateStudentInfoParam(); //响应体,MimeType为 application/json StudentServiceUpdateStudentInfoParam.RequestBody requestBody = StudentServiceUpdateStudentInfoParam.RequestBody.builder() .build(); param.setRequestBody(requestBody); //query StudentServiceUpdateStudentInfoParam.Query query = StudentServiceUpdateStudentInfoParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .studentUid(su.getXwStudentUid()) .studentCode(su.getCardNo()) .studentName(su.getName()) .build(); requestBody.setQuery(query); param.setRequestBody(requestBody); StudentServiceUpdateStudentInfoRequest request = new StudentServiceUpdateStudentInfoRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 StudentServiceUpdateStudentInfoResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃学生数据更新失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } return CommonResult.ok("更新成功"); //endregion } //endregion //region 希沃删除学生 public CommonResult SeewoDeleteStudent(SeewoClient seewoClient, String ClassUid, String CardNo) { //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); StudentServiceRemoveClassStudentsParam deleteParam = new StudentServiceRemoveClassStudentsParam(); //请求体,MimeType为 application/json StudentServiceRemoveClassStudentsParam.JSONRequestBody deleteRequestBody = StudentServiceRemoveClassStudentsParam.JSONRequestBody.builder() .build(); deleteParam.setRequestBody(deleteRequestBody); //查询条件 StudentServiceRemoveClassStudentsParam.UnbindStudentQuery deleteQuery = StudentServiceRemoveClassStudentsParam.UnbindStudentQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .classUid(ClassUid) .studentCodes(java.util.Collections.singletonList(CardNo)) .build(); deleteRequestBody.setQuery(deleteQuery); deleteParam.setRequestBody(deleteRequestBody); StudentServiceRemoveClassStudentsRequest deleteRequest = new StudentServiceRemoveClassStudentsRequest(deleteParam); System.out.println("入参:" + deleteRequest); //如果想要调用沙箱环境,请通过设置 deleteRequest 对象的 serverUrl 属性,如: //deleteRequest.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 StudentServiceRemoveClassStudentsResult deleteResult = seewoClient.invoke(deleteRequest); System.out.println("出参:" + deleteResult); if (deleteResult == null) { return CommonResult.fail("希沃删除学生数据失败!"); } if (!deleteResult.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(deleteResult.getResponseBody().getMessage()); } return CommonResult.ok("删除成功"); } //endregion //region 希沃添加老师数据 public CommonResult SeewoInsertTeacher(SeewoClient seewoClient, String phone, String name, String headImage) { //region 希沃添加教师数据 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam(); //请求体,MimeType为 application/json TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder() .build(); param.setRequestBody(requestBody); //老师信息 TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .build(); requestBody.setQuery(query); // 老师列表 TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder() .account(phone)//用户账号 .name(name)//用户名字 .accountType("phone")//账号类型 phone:手机号 email:邮箱 .teacherCode(phone)//教师工号 .photoUrl(headImage)//图片链接 .build(); query.setTeachers(java.util.Collections.singletonList(teachers)); param.setRequestBody(requestBody); TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃教师数据新增失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } String teacherCode = phone; if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) { teacherCode = result.getResponseBody().getData().get(0).getTeacherCode(); } return CommonResult.ok("200", "操作成功", teacherCode); //endregion } //endregion //region 希沃更新教师 public CommonResult SeewoUpdateTeacher(SeewoClient seewoClient, String phone, String name, String headImage) { //region 希沃更新教师数据 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); TeacherServiceBatchSaveOrUpdateTeacherParam param = new TeacherServiceBatchSaveOrUpdateTeacherParam(); //请求体,MimeType为 application/json TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody requestBody = TeacherServiceBatchSaveOrUpdateTeacherParam.JSONRequestBody.builder() .build(); param.setRequestBody(requestBody); //老师信息 TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery query = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherBatchQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .build(); requestBody.setQuery(query); // 老师列表 TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery teachers = TeacherServiceBatchSaveOrUpdateTeacherParam.SaveOrUpdateTeacherQuery.builder() .account(phone)//用户账号 .name(name)//用户名字 .accountType("phone")//账号类型 phone:手机号 email:邮箱 .teacherCode(phone)//教师工号 .photoUrl(headImage)//图片链接 .build(); query.setTeachers(java.util.Collections.singletonList(teachers)); param.setRequestBody(requestBody); TeacherServiceBatchSaveOrUpdateTeacherRequest request = new TeacherServiceBatchSaveOrUpdateTeacherRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 TeacherServiceBatchSaveOrUpdateTeacherResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃教师数据更新失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } String teacherCode = phone; if (result.getResponseBody().getData() != null && result.getResponseBody().getData().size() > 0) { teacherCode = result.getResponseBody().getData().get(0).getTeacherCode(); } return CommonResult.ok("200", "操作成功", teacherCode); //endregion } //endregion //region 希沃删除教师 public CommonResult SeewoDeleteTeacher(SeewoClient seewoClient, String phone) { //region 希沃删除教师 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); TeacherServiceBatchRemoveTeachersParam param = new TeacherServiceBatchRemoveTeachersParam(); //响应体,MimeType为 application/json TeacherServiceBatchRemoveTeachersParam.RequestBody requestBody = TeacherServiceBatchRemoveTeachersParam.RequestBody.builder() .build(); param.setRequestBody(requestBody); //query TeacherServiceBatchRemoveTeachersParam.Query query = TeacherServiceBatchRemoveTeachersParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .phones(java.util.Collections.singletonList(phone)) .build(); requestBody.setQuery(query); param.setRequestBody(requestBody); TeacherServiceBatchRemoveTeachersRequest request = new TeacherServiceBatchRemoveTeachersRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 TeacherServiceBatchRemoveTeachersResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃教师数据删除失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } return CommonResult.ok("删除成功"); //endregion } //endregion //region 希沃删除班主任 public CommonResult SeewoDeleteTeacherMaster(SeewoClient seewoClient, String classUid, String phone) { //region 希沃删除班主任 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); TeacherServiceBatchRemoveClassMastersParam mastersParam = new TeacherServiceBatchRemoveClassMastersParam(); //响应体,MimeType为 application/json TeacherServiceBatchRemoveClassMastersParam.RequestBody mastersRequestBody = TeacherServiceBatchRemoveClassMastersParam.RequestBody.builder() .build(); mastersParam.setRequestBody(mastersRequestBody); //query TeacherServiceBatchRemoveClassMastersParam.Query mastersQuery = TeacherServiceBatchRemoveClassMastersParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .classUid(classUid) .userPhones(java.util.Collections.singletonList(phone)) .build(); mastersRequestBody.setQuery(mastersQuery); mastersParam.setRequestBody(mastersRequestBody); TeacherServiceBatchRemoveClassMastersRequest mastersRequest = new TeacherServiceBatchRemoveClassMastersRequest(mastersParam); System.out.println("入参:" + mastersRequest); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 TeacherServiceBatchRemoveClassMastersResult masterResult = seewoClient.invoke(mastersRequest); System.out.println("出参:" + masterResult); if (masterResult == null) { return CommonResult.fail("希沃教师数据删除失败!"); } if (!masterResult.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(masterResult.getResponseBody().getMessage()); } return CommonResult.ok("删除成功"); //endregion } //endregion //region 希沃推送班主任 public CommonResult SeewoPushMaster(SeewoClient seewoClient, String phone, String classUid) { //region 将班主任推送到希沃 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); TeacherServiceBatchSetClassMastersParam teacherClassParam = new TeacherServiceBatchSetClassMastersParam(); //响应体,MimeType为 application/json TeacherServiceBatchSetClassMastersParam.RequestBody teacherClassRequestBody = TeacherServiceBatchSetClassMastersParam.RequestBody.builder() .build(); teacherClassParam.setRequestBody(teacherClassRequestBody); //query List teacherPhones = new ArrayList<>(); teacherPhones.add(phone); TeacherServiceBatchSetClassMastersParam.Query teacherClassQuery = TeacherServiceBatchSetClassMastersParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .classUid(classUid) .userPhones(teacherPhones) .build(); teacherClassRequestBody.setQuery(teacherClassQuery); teacherClassParam.setRequestBody(teacherClassRequestBody); TeacherServiceBatchSetClassMastersRequest teacherClassRequest = new TeacherServiceBatchSetClassMastersRequest(teacherClassParam); System.out.println("入参:" + teacherClassRequest); //如果想要调用沙箱环境,请通过设置 teacherClassRequest 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 TeacherServiceBatchSetClassMastersResult teacherClassResult = seewoClient.invoke(teacherClassRequest); System.out.println("出参:" + teacherClassResult); if (teacherClassResult == null) { return CommonResult.fail("希沃教师数据新增失败!"); } if (!teacherClassResult.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(teacherClassResult.getResponseBody().getMessage()); } return CommonResult.ok("添加成功"); //endregion } //endregion //region 希沃新增编辑学生家长信息 public CommonResult insertOrUpdateStudentParent(SeewoClient seewoClient, List studentDatas, String name, String phone) { //region 希沃新增编辑学生家长信息 //学生与家长列表,最大100条 List studentParents = new ArrayList<>(); for (SmartUser student : studentDatas) { ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem students = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder() .studentCode(student.getCardNo()) .build(); studentParents.add(students); //家长列表,最多4个 ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder() .name(name) .phone(phone) .index(0) .build(); students.setParents(java.util.Collections.singletonList(parents)); } //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam(); //响应体,MimeType为 application/json ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder() .build(); param.setRequestBody(requestBody); //query ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .build(); requestBody.setQuery(query); query.setStudentParents(studentParents); param.setRequestBody(requestBody); ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃学生家长数据更新失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } return CommonResult.ok("新增成功"); //endregion } //endregion //region 希沃删除学生原有的家长关系 public CommonResult deleteOldStudentParentShip(SeewoClient seewoClient, String cardNo, List phones) throws JsonProcessingException { //region 删除原有的家长关系 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam(); //请求体,MimeType为 application/json ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder() .build(); deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody); // ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .studentCodes(java.util.Collections.singletonList(cardNo)) .parentPhones(phones) .build(); deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery); deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody); ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam); System.out.println("入参:" + deleteOldFamilyRequest); //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如: //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest); System.out.println("出参:" + deleteOldFamilyResult); if (deleteOldFamilyResult == null) { return CommonResult.fail("希沃家长数据删除失败!"); } if(deleteOldFamilyResult.getResponseBody().getResult() == null){ ObjectMapper objectMapper = new ObjectMapper(); XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class); if(!result.getCode().equals("000000")){ return CommonResult.fail(result.getMessage()); } }else{ if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) { return CommonResult.fail(deleteOldFamilyResult.getResponseBody().getResult().getMessage()); } } return CommonResult.ok("删除成功"); //endregion } //endregion //region 希沃删除原有的家长关系 public CommonResult deleteOldParentShip(SeewoClient seewoClient, List studentDatas, String phone) throws JsonProcessingException { //region 删除原有的家长关系 //初始化客户端 //SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); ParentServiceRemoveStudentParentConditionParam deleteOldFamilyParam = new ParentServiceRemoveStudentParentConditionParam(); //请求体,MimeType为 application/json ParentServiceRemoveStudentParentConditionParam.JSONRequestBody deleteOldFamilyRequestBody = ParentServiceRemoveStudentParentConditionParam.JSONRequestBody.builder() .build(); deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody); // ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery deleteOldFamilyquery = ParentServiceRemoveStudentParentConditionParam.ThirdRemoveStudentParentQuery.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .studentCodes(studentDatas.stream().map(SmartUser::getCardNo).collect(Collectors.toList())) .parentPhones(java.util.Collections.singletonList(phone)) .build(); deleteOldFamilyRequestBody.setQuery(deleteOldFamilyquery); deleteOldFamilyParam.setRequestBody(deleteOldFamilyRequestBody); ParentServiceRemoveStudentParentConditionRequest deleteOldFamilyRequest = new ParentServiceRemoveStudentParentConditionRequest(deleteOldFamilyParam); System.out.println("入参:" + deleteOldFamilyRequest); //如果想要调用沙箱环境,请通过设置 deleteOldFamilyRequest 对象的 serverUrl 属性,如: //deleteOldFamilyRequest.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 ParentServiceRemoveStudentParentConditionResult deleteOldFamilyResult = seewoClient.invoke(deleteOldFamilyRequest); System.out.println("出参:" + deleteOldFamilyResult); if (deleteOldFamilyResult == null) { return CommonResult.fail("希沃家长数据删除失败!"); } if(deleteOldFamilyResult.getResponseBody().getResult() == null){ ObjectMapper objectMapper = new ObjectMapper(); XwBodyVo result = objectMapper.readValue(deleteOldFamilyResult.getBody(), XwBodyVo.class); if(!result.getCode().equals("000000")){ return CommonResult.fail(result.getMessage()); } }else{ if (!deleteOldFamilyResult.getResponseBody().getResult().getCode().equals("000000")) { return CommonResult.fail(deleteOldFamilyResult.getResponseBody().getResult().getMessage()); } } return CommonResult.ok("删除成功"); //endregion } //endregion //endregion //region 百胜增删改查方法 //region 百胜更新学生信息 public CommonResult bsUpdateStudent(SmartUser su) throws Exception { //region 更新百胜学生信息 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "student/update"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); 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()) + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); 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 + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); ObjectMapper objectMapper = new ObjectMapper(); BsClassVo result = objectMapper.readValue(bsResult, BsClassVo.class); if (!bsResult.contains("更新成功")) { return CommonResult.fail(result.getMsg()); } return CommonResult.ok("更新成功"); //endregion } //endregion //region 百胜新增学生 public CommonResult bsInsertStudent(String name, String cardNo, Integer sexId, String headImage, Integer timeGroupId, String bsClassNo) throws Exception { //region 百胜新增学生信息 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "student/create"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); String str = "{\"student_name\":\"" + name + "\",\"classtab_no\":\"" + bsClassNo + "\",\"student_number\":\"" + cardNo + "\",\"student_sex\":\"" + sexId + "\",\"student_photo\":\"" + imageUtils.getBase64Url(headImage) + "\",\"student_tgno\":\"" + eTimeGroup.stringOf(timeGroupId) + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); 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 + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); ObjectMapper objectMapper = new ObjectMapper(); BsStudentVo grade = objectMapper.readValue(bsResult, BsStudentVo.class); if (!bsResult.contains("添加成功")) { return CommonResult.fail(grade.getMsg()); } // URL解码 String decodedUrl = URLDecoder.decode(grade.getData(), "UTF-8"); BsStudentNoVo studentNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStudentNoVo.class); return CommonResult.ok("200", "新增成功", studentNo.getStudent_no()); //endregion } //endregion //region 百胜删除学生 public CommonResult bsDeleteStudent(SmartUser su) throws Exception { //region 百胜删除学生 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "student/delete"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); String str = "{\"student_no\":\"" + su.getBsStudentNo() + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); String md5Str = "appid=" + appId + "&data={\"student_no\":\"" + su.getBsStudentNo() + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); ObjectMapper objectMapper = new ObjectMapper(); BsDeleteStudentVo result = objectMapper.readValue(bsResult, BsDeleteStudentVo.class); if (!bsResult.contains("删除学生成功")) { return CommonResult.fail(result.getMsg()); } return CommonResult.ok("操作成功"); //endregion } //endregion //region 百胜添加教师 public CommonResult bsInsertTeacher(SmartUser su, String departmentNo) throws Exception { //region 百胜添加教师数据 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "staff/create"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); 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()) + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); 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 + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); ObjectMapper objectMapper = new ObjectMapper(); BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class); if (!bsResult.contains("添加成功")) { return CommonResult.fail(staff.getMsg()); } // URL解码 String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8"); BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class); su.setBsStaffCode(staffNo.getStaff_no()); return CommonResult.ok("200", "新增成功", staffNo.getStaff_no()); //endregion } //endregion //region 百胜更新教师 public CommonResult updateBsTeacher(SmartUser su, String departmentNo) throws Exception { //region 百胜更新教师数据 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "staff/update"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); 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()) + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); 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 + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); ObjectMapper objectMapper = new ObjectMapper(); BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class); if (!bsResult.contains("添加成功")) { return CommonResult.fail(staff.getMsg()); } // URL解码 String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8"); BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsStaffNoVo.class); return CommonResult.ok("200", "操作成功", staffNo.getStaff_no()); //endregion } //endregion //region百胜删除教师 public CommonResult bsDeleteTeacher(String staffNo) throws Exception { //region 百胜删除教师 String appId = controlConfig.getAppId(); String schoolno = controlConfig.getSchoolCode(); String timestamp = TimeExchange.DateNowTimeStamo(); String appSecret = controlConfig.getAppSecret(); String url = controlConfig.getUrl() + "staff/delete"; JSONObject jsonobject = new JSONObject(); jsonobject.put("appid", appId); String str = "{\"staff_no\":\"" + staffNo + "\"}"; String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8"); jsonobject.put("data", aesStr); jsonobject.put("schoolno", schoolno); jsonobject.put("timestamp", timestamp); String md5Str = "appid=" + appId + "&data={\"staff_no\":\"" + staffNo + "\"}" + "&schoolno=" + schoolno + "×tamp=" + timestamp + "&key=" + appSecret; String sign = CommonUtil.MD5(md5Str); //sign签名 jsonobject.put("sign", sign); //返回的结果中 code为1表示成功 String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString()); ObjectMapper objectMapper = new ObjectMapper(); BsControlVo result = objectMapper.readValue(bsResult, BsControlVo.class); if (!bsResult.contains("删除成功")) { return CommonResult.fail(result.getMsg()); } return CommonResult.ok("删除成功"); //endregion } //endregion //endregion /** * 用户分页数据查询 * * @param currentPage 当前页数 * @param pageCount 一页数据条数 * @param departmentId 部门ID * @return */ @Override @DESRespondSecret(validated = true) public CommonResult queryPageSmartUser(int currentPage, int pageCount, Integer departmentId, String name) { //获取该部门下的所有子级部门ID List childDepartmentIds = new ArrayList<>(); List departments = smartDepartmentService.list(null); childDepartmentIds.add(departmentId); QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds); if (departmentId == null) { childDepartmentIds = null; } PageUtils result = smartUserService.querySmartUserPages(currentPage, pageCount, childDepartmentIds, name); if (result != null && result.getList() != null) { List studentIds = new ArrayList<>(); List studentStrs = Arrays.asList(StringUtils.join(result.getList().stream().map(UserVo::getAffiliate).collect(Collectors.toList()), ",").split(",")); for (String studentStr : studentStrs) { if (!ObjectUtils.isEmpty(studentStr)) { studentIds.add(Integer.valueOf(studentStr)); } } List students = smartUserService.getSmartUserByIds(studentIds); List classs = smartClassService.list(null); List idnetitys = smartIdentityService.list(null); for (UserVo data : result.getList()) { Optional identityData = idnetitys.stream().filter(e -> e.getId().equals(data.getIdentityId())).findFirst(); if (identityData != null && identityData.isPresent()) { data.setIdentity(identityData.get().getName()); } data.setSex(eSexStatu.stringOf(data.getSexId())); Optional departmentData = departments == null ? null : departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst(); if (departmentData != null && departmentData.isPresent()) { data.setDepartment(departmentData.get().getName()); } Optional nowClass = classs == null ? null : classs.stream().filter(e -> e.getId().equals(data.getSchoolClass())).findFirst(); if (nowClass != null && nowClass.isPresent()) { data.setClassStr(nowClass.get().getName()); } List datas = new ArrayList<>(); if (data.getAffiliate() != null) { List affiliates = Arrays.asList(data.getAffiliate().split(",")); for (String a : affiliates) { if (!ObjectUtils.isEmpty(a)) { Optional student = students.stream().filter(e -> e.getId().equals(Integer.valueOf(a))).findFirst(); if (student != null && student.isPresent()) { AffiliateUserVo affiliate = new AffiliateUserVo(); affiliate.setId(student.get().getId()); affiliate.setName(student.get().getName()); affiliate.setCardNo(student.get().getCardNo()); affiliate.setDepartmentId(student.get().getDepartmentId()); datas.add(affiliate); } } } } data.setAffiliates(datas); } } return CommonResult.ok(result); } @Override @DESRespondSecret(validated = false) public void smartUserExport(HttpServletResponse response, Integer departmentId, String name) { //获取该部门下的所有子级部门ID List childDepartmentIds = new ArrayList<>(); List departments = smartDepartmentService.list(null); childDepartmentIds.add(departmentId); QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds); List users = smartUserService.querySmartUsers(childDepartmentIds, name); List affiliates = new ArrayList<>(); List affiliateStr = users.stream().map(SmartUser::getAffiliate).collect(Collectors.toList()); for (String datas : affiliateStr) { String[] dataArray = datas.split(","); for (int i = 0; i < dataArray.length; i++) { affiliates.add(dataArray[i]); } } List affiliateDatas = smartUserService.getSmartUserIds(affiliates); List dutieIds = users != null && users.size() > 0 ? users.stream().map(SmartUser::getDuties).collect(Collectors.toList()) : null; //职务数据 List duties = dutieIds != null && dutieIds.size() > 0 ? smartDutiesService.queryDutiesByIds(dutieIds) : null; //年级 List grades = smartGradeService.list(null); //班级 List classes = smartClassService.list(null); //导出 Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("用户信息管理"); Row headerRow = sheet.createRow(0); headerRow.createCell(0).setCellValue("序号"); headerRow.createCell(1).setCellValue("学号"); headerRow.createCell(2).setCellValue("姓名"); headerRow.createCell(3).setCellValue("身份"); headerRow.createCell(4).setCellValue("身份证号"); headerRow.createCell(5).setCellValue("性别"); headerRow.createCell(6).setCellValue("部门"); headerRow.createCell(7).setCellValue("人脸"); headerRow.createCell(8).setCellValue("年级"); headerRow.createCell(9).setCellValue("学院"); headerRow.createCell(10).setCellValue("专业"); headerRow.createCell(11).setCellValue("班级"); headerRow.createCell(12).setCellValue("校区"); headerRow.createCell(13).setCellValue("宿舍号"); headerRow.createCell(14).setCellValue("手机号"); headerRow.createCell(15).setCellValue("关联人"); headerRow.createCell(16).setCellValue("职称"); headerRow.createCell(17).setCellValue("家庭住址"); headerRow.createCell(18).setCellValue("民族"); headerRow.createCell(19).setCellValue("生源地"); headerRow.createCell(20).setCellValue("毕业学校"); headerRow.createCell(21).setCellValue("职务"); for (int i = 0; i < users.size(); i++) { SmartUser user = users.get(i); Row dataRow = sheet.createRow(i + 1); dataRow.createCell(0).setCellValue(i + 1);//序号 dataRow.createCell(1).setCellValue(user.getCardNo());//学号 dataRow.createCell(2).setCellValue(user.getName());//姓名 dataRow.createCell(3).setCellValue(eIdentityStatu.stringOf(user.getIdentityId()));//身份 dataRow.createCell(4).setCellValue(user.getIdCard());//身份证号 dataRow.createCell(5).setCellValue(eSexStatu.stringOf(user.getSexId()));//性别 //获取父级部门ID Optional department = departments.stream().filter(e -> e.getId().equals(user.getDepartmentId())).findFirst(); if (department != null && department.isPresent()) { dataRow.createCell(6).setCellValue(QueryParentDepartments(department.get().getParentId(), departments, null));//部门 } dataRow.createCell(7).setCellValue(user.getHeadImage() == null ? "" : user.getHeadImage());//人脸 String grade = ""; Optional gradeData = grades == null ? null : grades.stream().filter(e -> e.getId().toString().equals(user.getGrade())).findFirst(); if (gradeData != null && gradeData.isPresent()) { grade = gradeData.get().getName(); } dataRow.createCell(8).setCellValue(grade);//年级 dataRow.createCell(9).setCellValue(user.getCollege() == null ? "" : user.getCollege());//学院 dataRow.createCell(10).setCellValue(user.getSpeciality() == null ? "" : user.getSpeciality());//专业 String classStr = ""; Optional classData = classes == null ? null : classes.stream().filter(e -> e.getId().equals(user.getSchoolClass())).findFirst(); if (classData != null && classData.isPresent()) { classStr = classData.get().getName(); } dataRow.createCell(11).setCellValue(classStr);//班级 dataRow.createCell(12).setCellValue(user.getCampus() == null ? "" : user.getCampus());//校区 dataRow.createCell(13).setCellValue(user.getDormitoryNumber() == null ? "" : user.getDormitoryNumber());//宿舍号 dataRow.createCell(14).setCellValue(user.getPhone() == null ? "" : user.getPhone());//手机号 List affiliateCellStrs = new ArrayList<>(); if (user.getAffiliate() != null && affiliateDatas != null) { String[] affArrayStr = user.getAffiliate().split(","); for (int j = 0; j < affArrayStr.length; j++) { String affArrayIndex = affArrayStr[j]; Optional affUser = affiliateDatas.stream().filter(e -> e.getId().toString().equals(affArrayIndex)).findFirst(); if (affUser != null && affUser.isPresent()) { affiliateCellStrs.add(affUser.get().getName()); } } } dataRow.createCell(15).setCellValue(StringUtils.join(affiliateCellStrs, ","));//关联人 dataRow.createCell(16).setCellValue(user.getTitle() == null ? "" : user.getTitle());//职称 dataRow.createCell(17).setCellValue(user.getAddress() == null ? "" : user.getAddress());//家庭住址 dataRow.createCell(18).setCellValue(user.getNation() == null ? "" : user.getNation());//民族 dataRow.createCell(19).setCellValue(user.getOfStudent() == null ? "" : user.getOfStudent());//生源地 dataRow.createCell(20).setCellValue(user.getGraduate() == null ? "" : user.getGraduate());//毕业学校 String dutieStr = ""; if (duties != null && duties.size() > 0 && user.getDuties() != null) { Optional oduty = duties.stream().filter(e -> e.getId().equals(user.getDuties())).findFirst(); if (oduty != null && oduty.isPresent()) { dutieStr = oduty.get().getName(); } } dataRow.createCell(21).setCellValue(dutieStr);//职务 } // 将工作簿写入文件 ExcelUtils.excelDownload(workbook, "用户信息.xlsx", response); } /** * 根据父级ID获取树形数据 * * @param parentID 父级ID * @param lists 数据集合 * @return */ private List QueryDepartmentTreeRecords(Integer parentID, List lists, List departmentIds) { List newTrees = new ArrayList<>(); List datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList()); for (SmartDepartment data : datas) { departmentIds.add(data.getId()); QueryDepartmentTreeRecords(data.getId(), lists, departmentIds); } return newTrees; } /** * 根据父级ID获取父级数据 * * @param parentID 子级ID * @param lists 数据集合 * @return */ private String QueryParentDepartments(Integer parentID, List lists, String departmentStr) { Optional data = lists.stream().filter(e -> e.getId().equals(parentID)).findFirst(); if (data != null && data.isPresent()) { departmentStr = departmentStr == null ? data.get().getName() : data.get().getName() + "/" + departmentStr; departmentStr = QueryParentDepartments(data.get().getParentId(), lists, departmentStr); } return departmentStr; } @Override @DESRespondSecret(validated = true) public CommonResult deleteSmartUserByIdOld(useridsRequest ur, BindingResult bindingResult) throws Exception { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } List users = smartUserService.getSmartUserByIds(ur.getUserIds()); if (users.size() != ur.getUserIds().size()) { return CommonResult.fail("存在无效用户数据,删除失败!"); } SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); for (SmartUser user : users) { if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) { List studentIds = Arrays.asList(user.getAffiliate().split(",")); List studentDatas = smartUserService.getSmartUserIds(studentIds); //region 删除原有的家长关系 CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone()); if (!deleteResult.isSuccess()) { return CommonResult.fail(deleteResult.getMessage()); } //endregion } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) { //查找家长 List parents = smartUserService.getAffiliateList(user.getId()); //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } //region 百胜删除学生 CommonResult deleteBsStudent = bsDeleteStudent(user); if (!deleteBsStudent.isSuccess()) { return CommonResult.fail(deleteBsStudent.getMessage()); } //endregion //region 希沃删除学生 CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo()); if (!deleteStudent.isSuccess()) { return CommonResult.fail(deleteStudent.getMessage()); } //endregion if(parents != null){ //region 删除原有的家长关系 CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList())); if (!deleteResult.isSuccess()) { return CommonResult.fail(deleteResult.getMessage()); } //endregion } } else if(user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()){ //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass()); if (classData == null) { return CommonResult.fail("班级数据无效,更新失败"); } //region 希沃删除教师 CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone()); if (!deleteTeacher.isSuccess()) { return CommonResult.fail(deleteTeacher.getMessage()); } //endregion //region 希沃删除班主任 CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone()); if (deleteTeacherMaster.isSuccess()) { return CommonResult.fail(deleteTeacherMaster.getMessage()); } //endregion //region 百胜删除教师 CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode()); if (!bsDeleteTeacher.isSuccess()) { return CommonResult.fail(bsDeleteTeacher.getMessage()); } //endregion } } int result = smartUserService.deleteSmartUserByIds(ur.getUserIds()); return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败"); } @Override public CommonResult deleteSmartUserById(useridsRequest ur, BindingResult bindingResult) throws Exception { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } List users = smartUserService.getSmartUserByIds(ur.getUserIds()); if (users.size() != ur.getUserIds().size()) { return CommonResult.fail("存在无效用户数据,删除失败!"); } //先删除咱自己数据库里的用户数据 int result = smartUserService.deleteSmartUserByIds(ur.getUserIds()); if(result <= 0){ return CommonResult.fail("删除失败"); } List deleteUsers = new ArrayList<>(); SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); for (SmartUser user : users) { deleteUserVo deleteUser = new deleteUserVo(); deleteUser.setId(user.getId()); if (user.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) { List studentIds = Arrays.asList(user.getAffiliate().split(",")); List studentDatas = smartUserService.getSmartUserIds(studentIds); //region 删除原有的家长关系 CommonResult deleteResult = deleteOldParentShip(seewoClient, studentDatas, user.getPhone()); if (!deleteResult.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败:"+deleteResult.getMessage()+";"; deleteUser.setReason(reason); //return CommonResult.fail(deleteResult.getMessage()); } //endregion } else if (user.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) { //查找家长 List parents = smartUserService.getAffiliateList(user.getId()); //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass()); if (classData == null) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;"; deleteUser.setReason(reason); //return CommonResult.fail("班级数据无效,更新失败"); } //region 百胜删除学生 CommonResult deleteBsStudent = bsDeleteStudent(user); if (!deleteBsStudent.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除学生失败;"+deleteBsStudent.getMessage()+";";; deleteUser.setReason(reason); //return CommonResult.fail(deleteBsStudent.getMessage()); } //endregion //region 希沃删除学生 CommonResult deleteStudent = SeewoDeleteStudent(seewoClient, classData.getClassUid(), user.getCardNo()); if (!deleteStudent.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除学生失败;"+deleteStudent.getMessage()+";";; deleteUser.setReason(reason); //return CommonResult.fail(deleteStudent.getMessage()); } //endregion if(parents != null){ //region 删除原有的家长关系 CommonResult deleteResult = deleteOldStudentParentShip(seewoClient, user.getCardNo(), parents.stream().map(SmartUser::getPhone).collect(Collectors.toList())); if (!deleteResult.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除家长关系失败;"+deleteResult.getMessage()+";";; deleteUser.setReason(reason); //return CommonResult.fail(deleteResult.getMessage()); } //endregion } } else if(user.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()){ //获取班级Uid SmartClass classData = smartClassService.getSmartClassById(user.getSchoolClass()); if (classData == null) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "班级数据无效,百胜删除学生失败;"; deleteUser.setReason(reason); //return CommonResult.fail("班级数据无效,更新失败"); } //region 希沃删除教师 CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, user.getPhone()); if (!deleteTeacher.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;"+deleteTeacher.getMessage()+";";; deleteUser.setReason(reason); //return CommonResult.fail(deleteTeacher.getMessage()); } //endregion //region 希沃删除班主任 CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), user.getPhone()); if (deleteTeacherMaster.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "希沃删除班主任失败;"+deleteTeacherMaster.getMessage()+";";; deleteUser.setReason(reason); //return CommonResult.fail(deleteTeacherMaster.getMessage()); } //endregion //region 百胜删除教师 CommonResult bsDeleteTeacher = bsDeleteTeacher(user.getBsStaffCode()); if (!bsDeleteTeacher.isSuccess()) { String reason = (deleteUser.getReason() == null ? "" : deleteUser.getReason()) + "百胜删除老师失败;"+bsDeleteTeacher.getMessage()+";";; deleteUser.setReason(reason); //return CommonResult.fail(bsDeleteTeacher.getMessage()); } //endregion } if(deleteUser.getReason() != null){ deleteUsers.add(deleteUser); } } if(deleteUsers != null && deleteUsers.size() > 0){ int deleteUser = smartUserService.deleteUserBatch(deleteUsers); return deleteUser > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败"); } return CommonResult.ok("删除成功"); } @Override @DESRespondSecret(validated = true) public CommonResult queryAffiliateUserById(int id) { List result = smartUserService.queryAffiliateUserById(id); if (result != null && result.size() > 0) { List departments = smartDepartmentService.list(null); for (AffiliateUserVo data : result) { //获取父级部门ID Optional department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst(); if (department != null && department.isPresent()) { String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null); data.setDepartmentName(departmentName); } } } return CommonResult.ok(result); } @Override @DESRespondSecret(validated = true) public CommonResult downloadUserExcel() { return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/人员信息表.xlsx"); } @Override @DESRespondSecret(validated = true) public CommonResult queryStudents(int userId) { List students = new ArrayList<>(); SmartUser user = smartUserService.getSmartById(userId); if (user == null) { return CommonResult.fail("用户信息为空,获取学生列表数据失败"); } if (user.getAffiliate() == null) { return CommonResult.ok(students); } List affiliateIds = new ArrayList<>(); List affiliates = Arrays.asList(user.getAffiliate().split(",")); for (String affiliate : affiliates) { affiliateIds.add(Integer.valueOf(affiliate)); } students = smartUserService.getSmartUserByIds(affiliateIds); List result = new ArrayList<>(); for (SmartUser student : students) { ParentOfStudentsVo data = new ParentOfStudentsVo(); data.setId(student.getId()); data.setName(student.getName()); data.setCardNo(student.getCardNo()); data.setDepartmentId(student.getDepartmentId()); result.add(data); } return CommonResult.ok(result); } @Override @DESRespondSecret(validated = true) public CommonResult queryInfoData(int id) { SmartUser su = smartUserService.getSmartById(id); if (su == null) { return CommonResult.fail("用户信息失效,获取用户信息失败"); } //部门数据集合 List departments = smartDepartmentService.list(null); WechatUserVo userData = new WechatUserVo(); userData.setId(su.getId()); userData.setCardNo(su.getCardNo()); userData.setTimeGroupId(su.getTimeGroupId()); userData.setName(su.getName()); userData.setIdentityId(su.getIdentityId()); userData.setIdCard(su.getIdCard()); userData.setSexId(su.getSexId()); userData.setDepartmentId(su.getDepartmentId()); Optional department = departments.stream().filter(e -> e.getId().equals(su.getDepartmentId())).findFirst(); if (department != null && department.isPresent()) { String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null); userData.setDepartmentName(departmentName == null ? "" : departmentName + "/" + department.get().getName()); } userData.setHeadImage(su.getHeadImage()); userData.setGrade(su.getGrade()); userData.setCollege(su.getCollege()); userData.setSpeciality(su.getSpeciality()); userData.setSchoolClass(su.getSchoolClass()); userData.setCampus(su.getCampus()); userData.setDormitoryNumber(su.getDormitoryNumber()); userData.setPhone(su.getPhone()); userData.setAffiliate(su.getAffiliate()); //查找关联人 if (su.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生 List parents = smartUserService.queryAffiliateParents(su.getId()); if (parents != null && parents.size() > 0) { String affiliateStr = StringUtils.join(parents.stream().map(AffiliateParentVo::getName).collect(Collectors.toList()), ","); userData.setAffiliateName(affiliateStr); } } else if (su.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()) {//家长 if (su.getAffiliate() != null) { List affiliates = Arrays.asList(su.getAffiliate().split(",")); List childs = smartUserService.getSmartUserIds(affiliates); String affiliateStr = StringUtils.join(childs.stream().map(SmartUser::getName).collect(Collectors.toList()), ","); userData.setAffiliateName(affiliateStr); } } //关联人名称用逗号隔开 userData.setTitle(su.getTitle()); userData.setAddress(su.getAddress()); userData.setNation(su.getNation()); userData.setOfStudent(su.getOfStudent()); userData.setGraduate(su.getGraduate()); userData.setDuties(su.getDuties()); userData.setIsPush(su.getIsPush()); userData.setIsCancel(su.getIsCancel()); userData.setOpenId(su.getOpenId()); userData.setXOpenId(su.getXOpenId()); userData.setGzhOpenId(su.getGzhOpenId()); userData.setXwStudentUid(su.getXwStudentUid()); userData.setBsStudentNo(su.getBsStudentNo()); userData.setXwTeacherCode(su.getXwTeacherCode()); userData.setBsStaffCode(su.getBsStaffCode()); return CommonResult.ok(userData); } @Override @DESRespondSecret(validated = true) public CommonResult bindStudent(bindStudentRequest bsr, BindingResult bindingResult) { if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } SmartUser parentUser = smartUserService.getSmartById(bsr.getUserId()); if (parentUser == null) { return CommonResult.fail("当前用户信息无效,绑定失败!"); } if (parentUser.getIdentityId().intValue() != eIdentityStatu.Parent.getValue()) { return CommonResult.fail("当前用户身份无法进行绑定操作"); } //查找是否存在学生数据 SmartUser studentUser = smartUserService.queryUserInfo(bsr.getName(), bsr.getCardNo(), bsr.getIdCard()); if (studentUser == null) { return CommonResult.fail("当前学生不存在,绑定失败!"); } //判断是否已绑定过 if (parentUser.getAffiliate() == null) { parentUser.setAffiliate(String.valueOf(studentUser.getId())); } else { List newAffiliates = new ArrayList<>(); List affiliates = Arrays.asList(parentUser.getAffiliate().split(",")); long existCount = affiliates.stream().filter(e -> e.equals(String.valueOf(studentUser.getId()))).count(); if (existCount > 0) { return CommonResult.fail("当前学生信息已绑定过,请勿重复操作!"); } parentUser.setAffiliate(parentUser.getAffiliate() + "," + String.valueOf(studentUser.getId())); } //region 新增希沃学生家长信息 //初始化客户端 SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret())); ParentServiceBatchSaveOrUpdateParentsParam param = new ParentServiceBatchSaveOrUpdateParentsParam(); //响应体,MimeType为 application/json ParentServiceBatchSaveOrUpdateParentsParam.RequestBody requestBody = ParentServiceBatchSaveOrUpdateParentsParam.RequestBody.builder() .build(); param.setRequestBody(requestBody); //query ParentServiceBatchSaveOrUpdateParentsParam.Query query = ParentServiceBatchSaveOrUpdateParentsParam.Query.builder() .appId(seewoConfig.getAppId()) .schoolUid(seewoConfig.getSchoolId()) .build(); requestBody.setQuery(query); //学生与家长列表,最大100条 ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem studentParents = ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem.builder() .studentCode(studentUser.getCardNo()) .build(); query.setStudentParents(java.util.Collections.singletonList(studentParents)); //家长列表,最多4个 ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem parents = ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem.builder() .name(parentUser.getName()) .phone(parentUser.getPhone()) .index(0) .build(); studentParents.setParents(java.util.Collections.singletonList(parents)); param.setRequestBody(requestBody); ParentServiceBatchSaveOrUpdateParentsRequest request = new ParentServiceBatchSaveOrUpdateParentsRequest(param); System.out.println("入参:" + request); //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如: //request.setServerUrl("https://openapi.test.seewo.com") //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法 ParentServiceBatchSaveOrUpdateParentsResult result = seewoClient.invoke(request); System.out.println("出参:" + result); if (result == null) { return CommonResult.fail("希沃学生家长数据添加失败!"); } if (!result.getResponseBody().getCode().equals("000000")) { return CommonResult.fail(result.getResponseBody().getMessage()); } //endregion int updateResult = smartUserService.updateSmartUser(parentUser); return updateResult > 0 ? CommonResult.ok("绑定成功") : CommonResult.fail("绑定失败"); } @Override public CommonResult queryUserData(int id) { SmartUserVo user = smartUserService.querySmartUserById(id); return CommonResult.ok(user); } @Override public CommonResult queryUserDeletePage(int currentPage, int pageCount) { PageUtils result = smartUserService.queryUserDeletePage(currentPage, pageCount); List departments = smartDepartmentService.list(null); for (UserDeleteVo data :result.getList()) { data.setIdentityStr(eIdentityStatu.stringOf(data.getIdentityId()));//身份 //获取父级部门ID Optional department = departments.stream().filter(e -> e.getId().equals(data.getDepartmentId())).findFirst(); if (department != null && department.isPresent()) { String departmentName = QueryParentDepartments(department.get().getParentId(), departments, null); data.setDepartmentStr(departmentName); } } return CommonResult.ok(result); } }