|
|
@@ -1,24 +1,56 @@
|
|
|
package com.template.controller;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.qcloud.cos.utils.IOUtils;
|
|
|
import com.template.api.SmartUserControllerAPI;
|
|
|
+import com.template.common.utils.ExcelUtils;
|
|
|
+import com.template.common.utils.FileUtils;
|
|
|
import com.template.common.utils.paramUtils;
|
|
|
+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.SmartDepartment;
|
|
|
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.result.CommonResult;
|
|
|
import com.template.model.result.PageUtils;
|
|
|
import com.template.model.vo.AffiliateUserVo;
|
|
|
+import com.template.model.vo.DepartmentTreeVo;
|
|
|
+import com.template.model.vo.UserVo;
|
|
|
+import com.template.services.SmartDepartmentService;
|
|
|
+import com.template.services.SmartUploadService;
|
|
|
import com.template.services.SmartUserService;
|
|
|
+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.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.zip.ZipInputStream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 前端控制器
|
|
|
+ * 前端控制器
|
|
|
* </p>
|
|
|
*
|
|
|
* @author ceshi
|
|
|
@@ -30,20 +62,709 @@ public class SmartUserController implements SmartUserControllerAPI {
|
|
|
@Autowired
|
|
|
private SmartUserService smartUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SmartUploadService smartUploadService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SmartDepartmentService smartDepartmentService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult logoffAccount(int id) {
|
|
|
+ SmartUser user = smartUserService.getSmartById(id);
|
|
|
+ if (user == null) {
|
|
|
+ return CommonResult.fail("用户信息已失效");
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setIsCancel(eLogOff.Logout.getValue());
|
|
|
+
|
|
|
+ int updateResult = smartUserService.updateSmartUser(user);
|
|
|
+
|
|
|
+ return updateResult > 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);
|
|
|
+
|
|
|
+ //读取第一张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);
|
|
|
+ user.setSchoolClass(schoolClass == null ? "" : schoolClass);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ //读取第一张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);
|
|
|
+ user.setSchoolClass(schoolClass == null ? "" : schoolClass);
|
|
|
+ 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 smartApply 用户数据
|
|
|
+ *
|
|
|
+ * @param isur 用户数据
|
|
|
* @param bindingResult
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResult insertSmartUser(SmartUser smartApply, BindingResult bindingResult) {
|
|
|
+ public CommonResult insertSmartUser(insertSmartUserRequest isur, BindingResult bindingResult) {
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
String st = paramUtils.getParamError(bindingResult);
|
|
|
return CommonResult.fail(st);
|
|
|
}
|
|
|
|
|
|
- int result = smartUserService.insertSmartUser(smartApply);
|
|
|
+ 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());
|
|
|
+
|
|
|
+ int result = smartUserService.insertSmartUser(su);
|
|
|
|
|
|
//新增用户得将用户信息通过接口推送到希沃、百胜
|
|
|
|
|
|
@@ -52,44 +773,193 @@ public class SmartUserController implements SmartUserControllerAPI {
|
|
|
|
|
|
/**
|
|
|
* 更新用户
|
|
|
- * @param sa 用户数据
|
|
|
+ *
|
|
|
+ * @param usur 更新用户数据
|
|
|
* @param bindingResult
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResult updateSmartUserById(SmartUser sa, BindingResult bindingResult) {
|
|
|
+ public CommonResult updateSmartUserById(updateSmartUserRequest usur, BindingResult bindingResult) {
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
String st = paramUtils.getParamError(bindingResult);
|
|
|
return CommonResult.fail(st);
|
|
|
}
|
|
|
|
|
|
//更新的同时将百胜用户信息同步过去或者同步过来?
|
|
|
+ SmartUser su = smartUserService.getSmartById(usur.getId());
|
|
|
+
|
|
|
+ if (su == null) {
|
|
|
+ CommonResult.fail("用户数据已失效,修改失败!");
|
|
|
+ }
|
|
|
|
|
|
- int result = smartUserService.updateSmartUser(sa);
|
|
|
+ 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());
|
|
|
+
|
|
|
+ int result = smartUserService.updateSmartUser(su);
|
|
|
return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户分页数据查询
|
|
|
- * @param currentPage 当前页数
|
|
|
- * @param pageCount 一页数据条数
|
|
|
- * @param name 查询名称
|
|
|
+ *
|
|
|
+ * @param currentPage 当前页数
|
|
|
+ * @param pageCount 一页数据条数
|
|
|
+ * @param departmentId 部门ID
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResult queryPageSmartUser(int currentPage, int pageCount, String name) {
|
|
|
- PageUtils<SmartUser> result = smartUserService.queryPageSmartUsers(currentPage, pageCount, name);
|
|
|
+ public CommonResult queryPageSmartUser(int currentPage, int pageCount, int departmentId, String name) {
|
|
|
+ //获取该部门下的所有子级部门ID
|
|
|
+ List<Integer> childDepartmentIds = new ArrayList<>();
|
|
|
+ List<SmartDepartment> departments = smartDepartmentService.list(null);
|
|
|
+ childDepartmentIds.add(departmentId);
|
|
|
+ QueryDepartmentTreeRecords(departmentId, departments, childDepartmentIds);
|
|
|
+
|
|
|
+ PageUtils<UserVo> result = smartUserService.querySmartUserPages(currentPage, pageCount, childDepartmentIds, name);
|
|
|
|
|
|
return CommonResult.ok(result);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void smartUserExport(HttpServletResponse response, int 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(int id) {
|
|
|
|
|
|
SmartUser data = smartUserService.getSmartById(id);
|
|
|
|
|
|
- if(data == null){
|
|
|
+ if (data == null) {
|
|
|
return CommonResult.fail("当前数据不存在,删除失败!");
|
|
|
}
|
|
|
|