| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632 |
- package com.template.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- 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.api.SmartUserControllerAPI;
- import com.template.common.utils.*;
- import com.template.config.ControlConfig;
- import com.template.config.SeewoConfig;
- import com.template.model.enumModel.eFileType;
- import com.template.model.enumModel.eIdentityStatu;
- import com.template.model.enumModel.eLogOff;
- import com.template.model.enumModel.eSexStatu;
- import com.template.model.pojo.SmartClass;
- import com.template.model.pojo.SmartDepartment;
- import com.template.model.pojo.SmartGrade;
- import com.template.model.pojo.SmartUser;
- import com.template.model.request.changeDepartmentRequest;
- import com.template.model.request.insertSmartUserRequest;
- import com.template.model.request.updateSmartUserRequest;
- import com.template.model.request.useridsRequest;
- 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.lang.reflect.Array;
- 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;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author ceshi
- * @since 2023-12-04
- */
- @RestController
- 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 SmartDepartmentService smartDepartmentService;
- @Override
- 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
- public CommonResult changeDepartment(changeDepartmentRequest cdr, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- List<SmartUser> 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
- public CommonResult importExcelUsers(MultipartFile excelFile, String headImage) throws IOException {
- List<SmartUser> 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<List<SmartUser>> resultData = readXls(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
- CommonResult<List<SmartUser>> resultData = readXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else {
- return CommonResult.fail("用户导入只支持Xls、Xlsx");
- }
- List<String> uploadImages = Arrays.asList(headImage.split(","));
- for (SmartUser user : result) {
- Optional<String> image = uploadImages == null ? null : uploadImages.stream().filter(e -> e.equals("https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/headImage/" + user.getHeadImage())).findFirst();
- if (image != null && image.isPresent()) {
- user.setHeadImage(image.get());
- }
- }
- //批量存储用户信息
- boolean resultBool = smartUserService.saveBatch(result);
- return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
- }
- /**
- * 批量导入用户信息
- * 以身份证号作为判断依据 如果存在重复数据就提示存在重复数据
- * 开发流程:建议先去拿到excel中的所有数据的身份证号去数据库中找一遍是否存在重复数据
- * 如果不存在重复数据就把附件文件夹中的附件文件上传到cos服务器上
- * 然后手动拼接一个人脸照片文件地址存入对应的数据中
- *
- * @param zipFile zip压缩包
- * @return
- */
- @Override
- public CommonResult importZipUsers(MultipartFile zipFile) throws IOException {
- List<SmartUser> result = new ArrayList<>();
- MultipartFile excelFile = null;
- List<MultipartFile> 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<List<SmartUser>> resultData = readXls(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else if (excelStr.equals("xlsx")) {
- CommonResult<List<SmartUser>> 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<String> uploadImages = Arrays.asList(uploadResult.split(","));
- for (SmartUser user : result) {
- Optional<String> 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文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readXlsx(InputStream inputStream) throws IOException {
- List<String> phones = new ArrayList<>();
- List<String> idCards = new ArrayList<>();
- List<String> cardNos = new ArrayList<>();
- List<SmartUser> result = new ArrayList<>();
- XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- List<SmartGrade> grades = smartGradeService.list(null); //年级
- List<SmartClass> 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 cardNo = dataFormatter.formatCellValue(row.getCell(0));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第一列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(1));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第二列为姓名");
- }
- String identity = dataFormatter.formatCellValue(row.getCell(2));//身份
- if (!identity.equals("身份")) {
- return CommonResult.fail("导入数据第三列为身份");
- }
- String idCard = dataFormatter.formatCellValue(row.getCell(3));//身份证
- if (!idCard.equals("身份证")) {
- return CommonResult.fail("导入数据第四列为身份证");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
- if (!sex.equals("性别")) {
- return CommonResult.fail("导入数据第五列为性别");
- }
- String department = dataFormatter.formatCellValue(row.getCell(5));//部门
- if (!department.equals("部门")) {
- return CommonResult.fail("导入数据第六列为部门");
- }
- String headImage = dataFormatter.formatCellValue(row.getCell(6));//人脸照片
- if (!headImage.equals("人脸照片")) {
- return CommonResult.fail("导入数据第七列为人脸照片");
- }
- String dormitoryNumber = dataFormatter.formatCellValue(row.getCell(7));//宿舍号
- if (!dormitoryNumber.equals("宿舍号")) {
- return CommonResult.fail("导入数据第八列为宿舍号");
- }
- String grade = dataFormatter.formatCellValue(row.getCell(8));//年级
- if (!grade.equals("年级")) {
- return CommonResult.fail("导入数据第九列为年级");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(9));//班级
- if (!schoolClass.equals("班级")) {
- return CommonResult.fail("导入数据第十列为班级");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(10));//手机号
- if (!phone.equals("手机号")) {
- return CommonResult.fail("导入数据第十一列为手机号");
- }
- String affiliate = dataFormatter.formatCellValue(row.getCell(11));//关联人
- if (!affiliate.equals("关联人")) {
- return CommonResult.fail("导入数据第十二列为关联人");
- }
- String title = dataFormatter.formatCellValue(row.getCell(12));//职称
- if (!title.equals("职称")) {
- return CommonResult.fail("导入数据第十三列为职称");
- }
- String address = dataFormatter.formatCellValue(row.getCell(13));//家庭住址
- if (!address.equals("家庭住址")) {
- return CommonResult.fail("导入数据第十四列为家庭住址");
- }
- String nation = dataFormatter.formatCellValue(row.getCell(14));//民族
- if (!nation.equals("民族")) {
- return CommonResult.fail("导入数据第十五列为民族");
- }
- String ofStudent = dataFormatter.formatCellValue(row.getCell(15));//生源地
- if (!ofStudent.equals("生源地")) {
- return CommonResult.fail("导入数据第十六列为生源地");
- }
- String graduate = dataFormatter.formatCellValue(row.getCell(16));//毕业学校
- if (!graduate.equals("毕业学校")) {
- return CommonResult.fail("导入数据第十七列为毕业学校");
- }
- String duties = dataFormatter.formatCellValue(row.getCell(17));//职务
- if (!duties.equals("职务")) {
- return CommonResult.fail("导入数据第十八列为职务");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(1));
- if (ObjectUtils.isEmpty(name)) {
- return CommonResult.fail("第" + (rowNum + 2) + "条数据的名称不能为空");
- }
- //身份是否为空判断
- String identity = dataFormatter.formatCellValue(row.getCell(2));
- if (ObjectUtils.isEmpty(identity)) {
- return CommonResult.fail(name + "的身份不能为空");
- }
- String dormitoryNumber = dataFormatter.formatCellValue(row.getCell(7));//宿舍号
- String grade = dataFormatter.formatCellValue(row.getCell(8));//年级
- String schoolClass = dataFormatter.formatCellValue(row.getCell(9));//班级
- //身份为学生的情况下 宿舍号、年级、班级不能为空
- if (eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Student.getValue()) {
- if (ObjectUtils.isEmpty(dormitoryNumber)) {
- return CommonResult.fail(name + "的宿舍号不能为空");
- }
- if (ObjectUtils.isEmpty(grade)) {
- return CommonResult.fail(name + "的年级不能为空");
- }
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的班级不能为空");
- }
- }
- //手机号重复判断
- String phone = dataFormatter.formatCellValue(row.getCell(10));
- if (eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Parent.getValue() || eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Teacher.getValue()) {
- 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 affiliate = dataFormatter.formatCellValue(row.getCell(11));//关联人
- if (eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Parent.getValue()) {
- if (ObjectUtils.isEmpty(affiliate)) {
- return CommonResult.fail(name + "的关联人不能为空");
- }
- }
- //性别是否为空判断
- String sex = dataFormatter.formatCellValue(row.getCell(4));
- if (ObjectUtils.isEmpty(sex)) {
- return CommonResult.fail(name + "的性别不能为空");
- }
- //家庭住址是否为空判断
- String address = dataFormatter.formatCellValue(row.getCell(13));
- if (ObjectUtils.isEmpty(address)) {
- return CommonResult.fail(name + "的家庭住址不能为空");
- }
- //民族是否为空判断
- String nation = dataFormatter.formatCellValue(row.getCell(14));
- if (ObjectUtils.isEmpty(nation)) {
- return CommonResult.fail(name + "的民族不能为空");
- }
- //部门是否为空判断
- String department = dataFormatter.formatCellValue(row.getCell(5));
- if (ObjectUtils.isEmpty(department)) {
- return CommonResult.fail(name + "的部门不能为空");
- }
- int lastIndex = department.lastIndexOf("/");
- Integer departmentId = null;
- if (lastIndex >= 0) {
- Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department.substring(lastIndex))).findFirst();
- if (departModel != null && departModel.isPresent()) {
- departmentId = departModel.get().getId();
- }
- }
- //学号重复判断
- String cardNo = dataFormatter.formatCellValue(row.getCell(0));
- if (!ObjectUtils.isEmpty(cardNo)) {
- cardNos.add(cardNo);
- }
- if (cardNos.stream().distinct().count() != cardNos.size()) {
- return CommonResult.fail("导入的Excel中,卡号:" + cardNo + "存在重复数据");
- }
- //身份证重复判断
- String idCard = dataFormatter.formatCellValue(row.getCell(3));
- if (!ObjectUtils.isEmpty(idCard)) {
- idCards.add(idCard);
- }
- //List<String> noEmptyIdCards = idCards.stream().filter(e -> !e.equals("") || e != null).collect(Collectors.toList());
- if (idCards.stream().distinct().count() != idCards.size()) {
- return CommonResult.fail("导入的Excel中,身份证号:" + idCard + "存在重复数据");
- }
- user.setCardNo(cardNo == null ? "" : cardNo);
- user.setName(name == null ? "" : name);
- user.setIdentityId(identity == null ? eIdentityStatu.Student.getValue() : eIdentityStatu.integerOf(identity));
- 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(dormitoryNumber == null ? "" : dormitoryNumber);
- user.setGrade(grade == null ? "" : grade);
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- Integer gradeId = oGrade.get().getId();
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && 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(phone == null ? "" : phone);
- user.setAffiliate(affiliate == null ? "" : affiliate);
- String title = dataFormatter.formatCellValue(row.getCell(12));//职称
- user.setTitle(title == null ? "" : title);
- user.setAddress(address == null ? "" : address);
- user.setNation(nation == null ? "" : nation);
- String ofStudent = dataFormatter.formatCellValue(row.getCell(15));//生源地
- user.setOfStudent(ofStudent == null ? "" : ofStudent);
- String graduate = dataFormatter.formatCellValue(row.getCell(16));//毕业学校
- user.setGraduate(graduate == null ? "" : graduate);
- String duties = dataFormatter.formatCellValue(row.getCell(17));//职务
- user.setDuties(duties == null ? "" : duties);
- user.setIsCancel(eLogOff.Unlogout.getValue());
- result.add(user);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- /**
- * Xls文件读取方法
- *
- * @param inputStream 文件流
- * @return
- * @throws IOException
- */
- private CommonResult<List<SmartUser>> readXls(InputStream inputStream) throws IOException {
- List<String> phones = new ArrayList<>();
- List<String> idCards = new ArrayList<>();
- List<String> cardNos = new ArrayList<>();
- List<SmartUser> result = new ArrayList<>();
- HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- List<SmartGrade> grades = smartGradeService.list(null); //年级
- List<SmartClass> 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 cardNo = dataFormatter.formatCellValue(row.getCell(0));//学号
- if (!cardNo.equals("学号")) {
- return CommonResult.fail("导入数据第一列为学号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(1));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第二列为姓名");
- }
- String identity = dataFormatter.formatCellValue(row.getCell(2));//身份
- if (!identity.equals("身份")) {
- return CommonResult.fail("导入数据第三列为身份");
- }
- String idCard = dataFormatter.formatCellValue(row.getCell(3));//身份证
- if (!idCard.equals("身份证")) {
- return CommonResult.fail("导入数据第四列为身份证");
- }
- String sex = dataFormatter.formatCellValue(row.getCell(4));//性别
- if (!sex.equals("性别")) {
- return CommonResult.fail("导入数据第五列为性别");
- }
- String department = dataFormatter.formatCellValue(row.getCell(5));//部门
- if (!department.equals("部门")) {
- return CommonResult.fail("导入数据第六列为部门");
- }
- String headImage = dataFormatter.formatCellValue(row.getCell(6));//人脸照片
- if (!headImage.equals("人脸照片")) {
- return CommonResult.fail("导入数据第七列为人脸照片");
- }
- String dormitoryNumber = dataFormatter.formatCellValue(row.getCell(7));//宿舍号
- if (!dormitoryNumber.equals("宿舍号")) {
- return CommonResult.fail("导入数据第八列为宿舍号");
- }
- String grade = dataFormatter.formatCellValue(row.getCell(8));//年级
- if (!grade.equals("年级")) {
- return CommonResult.fail("导入数据第九列为年级");
- }
- String schoolClass = dataFormatter.formatCellValue(row.getCell(9));//班级
- if (!schoolClass.equals("班级")) {
- return CommonResult.fail("导入数据第十列为班级");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(10));//手机号
- if (!phone.equals("手机号")) {
- return CommonResult.fail("导入数据第十一列为手机号");
- }
- String affiliate = dataFormatter.formatCellValue(row.getCell(11));//关联人
- if (!affiliate.equals("关联人")) {
- return CommonResult.fail("导入数据第十二列为关联人");
- }
- String title = dataFormatter.formatCellValue(row.getCell(12));//职称
- if (!title.equals("职称")) {
- return CommonResult.fail("导入数据第十三列为职称");
- }
- String address = dataFormatter.formatCellValue(row.getCell(13));//家庭住址
- if (!address.equals("家庭住址")) {
- return CommonResult.fail("导入数据第十四列为家庭住址");
- }
- String nation = dataFormatter.formatCellValue(row.getCell(14));//民族
- if (!nation.equals("民族")) {
- return CommonResult.fail("导入数据第十五列为民族");
- }
- String ofStudent = dataFormatter.formatCellValue(row.getCell(15));//生源地
- if (!ofStudent.equals("生源地")) {
- return CommonResult.fail("导入数据第十六列为生源地");
- }
- String graduate = dataFormatter.formatCellValue(row.getCell(16));//毕业学校
- if (!graduate.equals("毕业学校")) {
- return CommonResult.fail("导入数据第十七列为毕业学校");
- }
- String duties = dataFormatter.formatCellValue(row.getCell(17));//职务
- if (!duties.equals("职务")) {
- return CommonResult.fail("导入数据第十八列为职务");
- }
- } else {
- SmartUser user = new SmartUser();
- String name = dataFormatter.formatCellValue(row.getCell(1));
- if (ObjectUtils.isEmpty(name)) {
- return CommonResult.fail("第" + (rowNum + 2) + "条数据的名称不能为空");
- }
- //身份是否为空判断
- String identity = dataFormatter.formatCellValue(row.getCell(2));
- if (ObjectUtils.isEmpty(identity)) {
- return CommonResult.fail(name + "的身份不能为空");
- }
- String dormitoryNumber = dataFormatter.formatCellValue(row.getCell(7));//宿舍号
- String grade = dataFormatter.formatCellValue(row.getCell(8));//年级
- String schoolClass = dataFormatter.formatCellValue(row.getCell(9));//班级
- //身份为学生的情况下 宿舍号、年级、班级不能为空
- if (eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Student.getValue()) {
- if (ObjectUtils.isEmpty(dormitoryNumber)) {
- return CommonResult.fail(name + "的宿舍号不能为空");
- }
- if (ObjectUtils.isEmpty(grade)) {
- return CommonResult.fail(name + "的年级不能为空");
- }
- if (ObjectUtils.isEmpty(schoolClass)) {
- return CommonResult.fail(name + "的班级不能为空");
- }
- }
- //手机号重复判断
- String phone = dataFormatter.formatCellValue(row.getCell(10));
- if (eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Parent.getValue() || eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Teacher.getValue()) {
- 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 affiliate = dataFormatter.formatCellValue(row.getCell(11));//关联人
- if (eIdentityStatu.integerOf(identity).intValue() == eIdentityStatu.Parent.getValue()) {
- if (ObjectUtils.isEmpty(affiliate)) {
- return CommonResult.fail(name + "的关联人不能为空");
- }
- }
- //性别是否为空判断
- String sex = dataFormatter.formatCellValue(row.getCell(4));
- if (ObjectUtils.isEmpty(sex)) {
- return CommonResult.fail(name + "的性别不能为空");
- }
- //家庭住址是否为空判断
- String address = dataFormatter.formatCellValue(row.getCell(13));
- if (ObjectUtils.isEmpty(address)) {
- return CommonResult.fail(name + "的家庭住址不能为空");
- }
- //民族是否为空判断
- String nation = dataFormatter.formatCellValue(row.getCell(14));
- if (ObjectUtils.isEmpty(nation)) {
- return CommonResult.fail(name + "的民族不能为空");
- }
- //部门是否为空判断
- String department = dataFormatter.formatCellValue(row.getCell(5));
- if (ObjectUtils.isEmpty(department)) {
- return CommonResult.fail(name + "的部门不能为空");
- }
- int lastIndex = department.lastIndexOf("/");
- Integer departmentId = null;
- if (lastIndex >= 0) {
- Optional<SmartDepartment> departModel = departments.stream().filter(e -> e.getName().equals(department.substring(lastIndex))).findFirst();
- if (departModel != null && departModel.isPresent()) {
- departmentId = departModel.get().getId();
- }
- }
- //学号重复判断
- String cardNo = dataFormatter.formatCellValue(row.getCell(0));
- if (!ObjectUtils.isEmpty(cardNo)) {
- cardNos.add(cardNo);
- }
- if (cardNos.stream().distinct().count() != cardNos.size()) {
- return CommonResult.fail("导入的Excel中,卡号:" + cardNo + "存在重复数据");
- }
- //身份证重复判断
- String idCard = dataFormatter.formatCellValue(row.getCell(3));
- if (!ObjectUtils.isEmpty(idCard)) {
- idCards.add(idCard);
- }
- //List<String> noEmptyIdCards = idCards.stream().filter(e -> !e.equals("") || e != null).collect(Collectors.toList());
- if (idCards.stream().distinct().count() != idCards.size()) {
- return CommonResult.fail("导入的Excel中,身份证号:" + idCard + "存在重复数据");
- }
- user.setCardNo(cardNo == null ? "" : cardNo);
- user.setName(name == null ? "" : name);
- user.setIdentityId(identity == null ? eIdentityStatu.Student.getValue() : eIdentityStatu.integerOf(identity));
- 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(dormitoryNumber == null ? "" : dormitoryNumber);
- user.setGrade(grade == null ? "" : grade);
- Optional<SmartGrade> oGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
- if (oGrade != null && oGrade.isPresent()) {
- Integer gradeId = oGrade.get().getId();
- Optional<SmartClass> oClass = classs.stream().filter(e -> e.getName().equals(schoolClass) && 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(phone == null ? "" : phone);
- user.setAffiliate(affiliate == null ? "" : affiliate);
- String title = dataFormatter.formatCellValue(row.getCell(12));//职称
- user.setTitle(title == null ? "" : title);
- user.setAddress(address == null ? "" : address);
- user.setNation(nation == null ? "" : nation);
- String ofStudent = dataFormatter.formatCellValue(row.getCell(15));//生源地
- user.setOfStudent(ofStudent == null ? "" : ofStudent);
- String graduate = dataFormatter.formatCellValue(row.getCell(16));//毕业学校
- user.setGraduate(graduate == null ? "" : graduate);
- String duties = dataFormatter.formatCellValue(row.getCell(17));//职务
- user.setDuties(duties == null ? "" : duties);
- user.setIsCancel(eLogOff.Unlogout.getValue());
- result.add(user);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- /**
- * 新增用户
- *
- * @param isur 用户数据
- * @param bindingResult
- * @return
- */
- @Override
- 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("当前学号已存在,请勿重复添加");
- }
- SmartUser su = new SmartUser();
- 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()) {//家长
- //拿到被关联学生的信息去获取对应的卡号
- //有多个学生就循环学生
- if (isur.getAffiliate() == null) {
- return CommonResult.fail("被关联人不能为空");
- }
- if (isur.getAffiliate().size() <= 0) {
- return CommonResult.fail("被关联人不能为空");
- }
- List<SmartUser> studentDatas = smartUserService.getSmartUserIds(isur.getAffiliate());
- //region 希沃新增编辑学生家长信息
- //学生与家长列表,最大100条
- List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> 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(isur.getName())
- .phone(isur.getPhone())
- .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);
- //endregion
- if (result == null) {
- return CommonResult.fail("希沃学生家长数据添加失败!");
- }
- if (!result.getResponseBody().getCode().equals("000000")) {
- return CommonResult.fail(result.getResponseBody().getMessage());
- }
- } else if (isur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
- //获取班级Uid
- SmartClass classData = smartClassService.getSmartClassById(isur.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(isur.getName())
- .studentCode(isur.getCardNo())
- .gender(isur.getSexId())
- .phone(isur.getPhone() == null ? "" : isur.getPhone())
- .build();
- query.setStudents(java.util.Collections.singletonList(students));
- query.setInPlaceOld(true);// 是否删除旧学生再保存
- 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());
- }
- su.setXwStudentUid(result.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 = "http://schoolopenapi.szymzh.com/openapi/student/create";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_name\":\"" + isur.getName() + "\",\"classtab_no\":\"" + classData.getBsClassNo() + "\",\"student_number\":\"" + isur.getCardNo() + "\",\"student_sex\":\"" + isur.getSexId() + "\",\"student_photo\":\"" + imageUtils.getBase64Url(isur.getHeadImage()) + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_name\":\"" + isur.getName() + "\",\"classtab_no\":\"" + classData.getBsClassNo() + "\",\"student_number\":\"" + isur.getCardNo() + "\",\"student_sex\":\"" + isur.getSexId() + "\",\"student_photo\":\"" + imageUtils.getBase64Url(isur.getHeadImage()) + "\"}" + "&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), BsStudentNoVo.class);
- su.setBsStudentNo(studentNo.getStudent_no());
- }
- //endregion
- } else if (isur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//老师
- //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(isur.getPhone())//用户账号
- .name(isur.getName())//用户名字
- .accountType("phone")//账号类型 phone:手机号 email:邮箱
- .teacherCode("")//教师工号
- .photoUrl(isur.getHeadImage())//图片链接
- .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());
- }
- su.setXwTeacherCode(result.getResponseBody().getData().get(0).getTeacherCode());
- //endregion
- //region 百胜添加教师数据
- SmartDepartment departmentData = smartDepartmentService.getSmartById(isur.getDepartmentId());
- if (departmentData == null) {
- return CommonResult.fail("部门数据无效,新增教师失败");
- }
- String departmentNo = departmentData.getBsDepartmentNo();//"DT1701845086538710";
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = "http://schoolopenapi.szymzh.com/openapi/staff/create";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"staff_name\":\"" + isur.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"stafft_number\":\"" + isur.getCardNo() + "\",\"staff_phone\":\"" + isur.getPhone() + "\",\"staff_sex\":\"" + isur.getSexId() + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(isur.getHeadImage()) + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"staff_name\":\"" + isur.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"stafft_number\":\"" + isur.getCardNo() + "\",\"staff_phone\":\"" + isur.getPhone() + "\",\"staff_sex\":\"" + isur.getSexId() + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(isur.getHeadImage()) + "\"}" + "&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();
- BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
- // URL解码
- String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
- BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl), BsStaffNoVo.class);
- su.setBsStaffCode(staffNo.getStaff_no());
- }
- //endregion
- }
- //endregion
- //最后都要把数据加入到数据库中
- int result = smartUserService.insertSmartUser(su);
- //新增用户得将用户信息通过接口推送到希沃、百胜
- return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
- }
- /**
- * 更新用户
- *
- * @param usur 更新用户数据
- * @param bindingResult
- * @return
- */
- @Override
- 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("用户数据已失效,修改失败!");
- }
- 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<SmartUser> studentDatas = smartUserService.getSmartUserIds(usur.getAffiliate());
- //region 希沃新增编辑学生家长信息
- //学生与家长列表,最大100条
- List<ParentServiceBatchSaveOrUpdateParentsParam.StudentParentsItem> 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(usur.getName())
- .phone(usur.getPhone())
- .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());
- }
- //endregion
- } else if (usur.getIdentityId().intValue() == eIdentityStatu.Student.getValue()) {//学生
- //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());
- }
- //endregion
- //region 更新百胜学生信息
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = "http://schoolopenapi.szymzh.com/openapi/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()) + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str), "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()) + "\"}" + "&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("更新成功")) {
- return CommonResult.fail("百胜学生信息更新失败");
- }
- //endregion
- } else if (usur.getIdentityId().intValue() == eIdentityStatu.Teacher.getValue()) {//教师
- //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(su.getPhone())//用户账号
- .name(su.getName())//用户名字
- .accountType("phone")//账号类型 phone:手机号 email:邮箱
- .teacherCode("")//教师工号
- .photoUrl(su.getHeadImage())//图片链接
- .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());
- }
- su.setXwTeacherCode(result.getResponseBody().getData().get(0).getTeacherCode());
- //endregion
- //region 百胜更新教师数据
- SmartDepartment departmentData = smartDepartmentService.getSmartById(su.getDepartmentId());
- if (departmentData == null) {
- return CommonResult.fail("部门数据无效,更新教师失败");
- }
- String departmentNo = departmentData.getBsDepartmentNo();
- String appId = controlConfig.getAppId();
- String schoolno = controlConfig.getSchoolCode();
- String timestamp = TimeExchange.DateNowTimeStamo();
- String appSecret = controlConfig.getAppSecret();
- String url = "http://schoolopenapi.szymzh.com/openapi/staff/update";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"staff_no\":\"" + su.getBsStaffCode() + "\"staff_name\":\"" + su.getName() + "\",\"department_no\":\"" + departmentNo + "\",\"stafft_number\":\"" + su.getCardNo() + "\",\"staff_phone\":\"" + su.getPhone() + "\",\"staff_sex\":\"" + su.getSexId() + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str), "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 + "\",\"stafft_number\":\"" + su.getCardNo() + "\",\"staff_phone\":\"" + su.getPhone() + "\",\"staff_sex\":\"" + su.getSexId() + "\",\"staff_photo\":\"" + imageUtils.getBase64Url(su.getHeadImage()) + "\"}" + "&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();
- BsStaffVo staff = objectMapper.readValue(bsResult, BsStaffVo.class);
- // URL解码
- String decodedUrl = URLDecoder.decode(staff.getData(), "UTF-8");
- BsStaffNoVo staffNo = objectMapper.readValue(decrypt(decodedUrl), BsStaffNoVo.class);
- su.setBsStaffCode(staffNo.getStaff_no());
- }
- //endregion
- }
- int result = smartUserService.updateSmartUser(su);
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- /**
- * 用户分页数据查询
- *
- * @param currentPage 当前页数
- * @param pageCount 一页数据条数
- * @param departmentId 部门ID
- * @return
- */
- @Override
- public CommonResult queryPageSmartUser(int currentPage, int pageCount, Integer departmentId, String name) {
- //获取该部门下的所有子级部门ID
- List<Integer> childDepartmentIds = new ArrayList<>();
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- childDepartmentIds.add(departmentId);
- QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
- if (departmentId == null) {
- childDepartmentIds = null;
- }
- PageUtils<UserVo> result = smartUserService.querySmartUserPages(currentPage, pageCount, childDepartmentIds, name);
- if (result != null && result.getList() != null) {
- List<Integer> studentIds = new ArrayList<>();
- List<String> 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<SmartUser> students = smartUserService.getSmartUserByIds(studentIds);
- List<SmartClass> classs = smartClassService.list(null);
- for (UserVo data : result.getList()) {
- data.setIdentity(eIdentityStatu.stringOf(data.getIdentityId()));
- data.setSex(eSexStatu.stringOf(data.getSexId()));
- Optional<SmartDepartment> 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<SmartClass> 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<AffiliateUserVo> datas = new ArrayList<>();
- List<String> affiliates = Arrays.asList(data.getAffiliate().split(","));
- for (String a : affiliates) {
- if(!ObjectUtils.isEmpty(a)){
- Optional<SmartUser> 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
- public void smartUserExport(HttpServletResponse response, Integer departmentId, String name) {
- //获取该部门下的所有子级部门ID
- List<Integer> childDepartmentIds = new ArrayList<>();
- List<SmartDepartment> departments = smartDepartmentService.list(null);
- childDepartmentIds.add(departmentId);
- QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
- List<SmartUser> users = smartUserService.querySmartUsers(childDepartmentIds, name);
- //导出
- 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<SmartDepartment> 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());
- dataRow.createCell(8).setCellValue(user.getGrade());
- dataRow.createCell(9).setCellValue(user.getCollege());
- dataRow.createCell(10).setCellValue(user.getSpeciality());
- dataRow.createCell(11).setCellValue(user.getSchoolClass());
- dataRow.createCell(12).setCellValue(user.getCampus());
- dataRow.createCell(13).setCellValue(user.getDormitoryNumber());
- dataRow.createCell(14).setCellValue(user.getPhone());
- dataRow.createCell(15).setCellValue(user.getAffiliate());
- dataRow.createCell(16).setCellValue(user.getTitle());
- dataRow.createCell(17).setCellValue(user.getAddress());
- dataRow.createCell(18).setCellValue(user.getNation());
- dataRow.createCell(19).setCellValue(user.getOfStudent());
- dataRow.createCell(20).setCellValue(user.getGraduate());
- dataRow.createCell(21).setCellValue(user.getDuties());
- }
- // 将工作簿写入文件
- ExcelUtils.excelDownload(workbook, "用户信息.xlsx", response);
- }
- /**
- * 根据父级ID获取树形数据
- *
- * @param parentID 父级ID
- * @param lists 数据集合
- * @return
- */
- private List<DepartmentTreeVo> QueryDepartmentTreeRecords(Integer parentID, List<SmartDepartment> lists, List<Integer> departmentIds) {
- List<DepartmentTreeVo> newTrees = new ArrayList<>();
- List<SmartDepartment> 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<SmartDepartment> lists, String departmentStr) {
- Optional<SmartDepartment> 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;
- QueryParentDepartments(data.get().getParentId(), lists, departmentStr);
- }
- return departmentStr;
- }
- @Override
- public CommonResult deleteSmartUserById(useridsRequest ur, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- int data = smartUserService.getSmartUserCountByIds(ur.getUserIds());
- if (data != ur.getUserIds().size()) {
- return CommonResult.fail("存在无效用户数据,删除失败!");
- }
- int result = smartUserService.deleteSmartUserByIds(ur.getUserIds());
- return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
- }
- @Override
- public CommonResult queryAffiliateUserById(int id) {
- List<AffiliateUserVo> result = smartUserService.queryAffiliateUserById(id);
- return CommonResult.ok(result);
- }
- @Override
- public CommonResult downloadUserExcel() {
- return CommonResult.ok("200", "操作成功", "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/人员信息表.xlsx");
- }
- @Override
- public CommonResult queryStudents(int userId) {
- List<SmartUser> students = new ArrayList<>();
- SmartUser user = smartUserService.getSmartById(userId);
- if (user == null) {
- return CommonResult.fail("用户信息为空,获取学生列表数据失败");
- }
- if (user.getAffiliate() == null) {
- return CommonResult.ok(students);
- }
- List<Integer> affiliateIds = new ArrayList<>();
- List<String> affiliates = Arrays.asList(user.getAffiliate().split(","));
- for (String affiliate : affiliates) {
- affiliateIds.add(Integer.valueOf(affiliate));
- }
- students = smartUserService.getSmartUserByIds(affiliateIds);
- List<ParentOfStudentsVo> 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);
- }
- public static void main(String[] args) throws Exception {
- //region 百胜新增学生信息
- String image = "https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/out_www.yalijuda.com_%E5%8D%8E%E5%BF%97%E6%9D%B0%E3%80%9018279462576%E3%80%91_1h5oBWtHvG.jpg";
- String appId = "sc5efc60f2bd373df9";
- String schoolno = "SL1701743624375793";
- String timestamp = "20240110090422121";//TimeExchange.DateNowTimeStamo();
- String appSecret = "fe0d767a2a394d1b81ccda6fc0ce5ecc";
- String url = "http://schoolopenapi.szymzh.com/openapi/student/create";
- JSONObject jsonobject = new JSONObject();
- jsonobject.put("appid", appId);
- String str = "{\"student_name\":\"" + "李四" + "\",\"classtab_no\":\"" + "CS1704704260801286" + "\",\"student_number\":\"" + "A123457" + "\",\"student_sex\":\"" + 1 + "\",\"student_photo\":\"" + imageUtils.getBase64Url(image) + "\"}";
- String aesStr = URLEncoder.encode(AesTestOne.encrypt(str), "UTF-8");
- jsonobject.put("data", aesStr);
- jsonobject.put("schoolno", schoolno);
- jsonobject.put("timestamp", timestamp);
- String md5Str = "appid=" + appId + "&data={\"student_name\":\"" + "李四" + "\",\"classtab_no\":\"" + "CS1704704260801286" + "\",\"student_number\":\"" + "A123457" + "\",\"student_sex\":\"" + 1 + "\",\"student_photo\":\"" + imageUtils.getBase64Url(image) + "\"}" + "&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());
- System.out.println(bsResult);
- 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), BsStudentNoVo.class);
- String sdsd = "";
- }
- //endregion
- }
- }
|