|
@@ -1,32 +1,48 @@
|
|
|
package com.xjrsoft.module.personnel.controller;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.github.yulichang.toolkit.MPJWrappers;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.model.result.RT;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
|
import com.xjrsoft.common.utils.FileZipUtil;
|
|
|
import com.xjrsoft.common.utils.UploadUtil;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.base.vo.StudentClassVo;
|
|
|
+import com.xjrsoft.module.hikvision.util.FaceImportUtil;
|
|
|
import com.xjrsoft.module.personnel.dto.AddStundentFaceProcessDto;
|
|
|
import com.xjrsoft.module.personnel.dto.StundentFaceProcessPageDto;
|
|
|
import com.xjrsoft.module.personnel.dto.UpdateStundentFaceProcessDto;
|
|
|
+import com.xjrsoft.module.personnel.entity.FaceManagement;
|
|
|
import com.xjrsoft.module.personnel.entity.StundentFaceProcess;
|
|
|
+import com.xjrsoft.module.personnel.service.IFaceManagementService;
|
|
|
import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
|
|
|
import com.xjrsoft.module.personnel.vo.StundentFaceProcessPageVo;
|
|
|
import com.xjrsoft.module.personnel.vo.StundentFaceProcessVo;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudentUser;
|
|
|
+import com.xjrsoft.module.student.service.IStudentManagerService;
|
|
|
import com.xjrsoft.module.system.entity.DictionaryDetail;
|
|
|
import com.xjrsoft.module.system.entity.File;
|
|
|
+import com.xjrsoft.module.system.service.IFileService;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -38,12 +54,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Base64;
|
|
|
+import java.util.Date;
|
|
|
import java.util.Enumeration;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.zip.ZipEntry;
|
|
|
import java.util.zip.ZipFile;
|
|
|
|
|
@@ -61,6 +80,10 @@ public class StundentFaceProcessController {
|
|
|
|
|
|
|
|
|
private final IStundentFaceProcessService stundentFaceProcessService;
|
|
|
+ private final IStudentManagerService studentManagerService;
|
|
|
+ private final IFileService fileService;
|
|
|
+ private final IFaceManagementService faceManagementService;
|
|
|
+ private final IBaseClassService classService;
|
|
|
|
|
|
@GetMapping(value = "/page")
|
|
|
@ApiOperation(value="学生人脸信息审核列表(分页)")
|
|
@@ -137,32 +160,107 @@ public class StundentFaceProcessController {
|
|
|
|
|
|
@PostMapping(value = "/batch-upload")
|
|
|
@ApiOperation(value = "批量新增学生人脸")
|
|
|
- @SaCheckPermission("facemanager:add")
|
|
|
- public RT<Boolean> add(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ @SaCheckPermission("stundentfaceprocess:batch-upload")
|
|
|
+ public RT<Boolean> batchUpload(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ List<BaseStudentUser> list = studentManagerService.list(
|
|
|
+ new MPJLambdaWrapper<BaseStudentUser>().distinct()
|
|
|
+ .select(BaseStudentUser::getId)
|
|
|
+ .select(BaseStudentUser.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentUser.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentUser::getId)
|
|
|
+ .eq(BaseStudent::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseStudentUser::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, BaseStudentUser> studentMap = new HashMap<>();
|
|
|
+ for (BaseStudentUser baseStudentUser : list) {
|
|
|
+ studentMap.put(baseStudentUser.getCredentialNumber(), baseStudentUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<StudentClassVo> studentClass = classService.getStudentClass();
|
|
|
+ Map<Long, StudentClassVo> studentClassMap = new HashMap<>();
|
|
|
+ for (StudentClassVo classVo : studentClass) {
|
|
|
+ studentClassMap.put(classVo.getUserId(), classVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long folderId = IdWorker.getId();
|
|
|
ZipFile zipFile = FileZipUtil.convertToZipFile(file);
|
|
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
|
|
while (entries.hasMoreElements()){
|
|
|
ZipEntry entry = entries.nextElement();
|
|
|
- String name = entry.getName();
|
|
|
- InputStream stream = zipFile.getInputStream(entry); //读取文件内容
|
|
|
-
|
|
|
-// try (OutputStream outputStream = new FileOutputStream(file)) {
|
|
|
-// byte[] buffer = new byte[4096];
|
|
|
-// int bytesRead;
|
|
|
-// while ((bytesRead = stream.read(buffer)) != -1) {
|
|
|
-// outputStream.write(buffer, 0, bytesRead);
|
|
|
-// }
|
|
|
-// } finally {
|
|
|
-// if (stream != null) {
|
|
|
-// stream.close();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //保存到云服务器
|
|
|
-// String filePath = UploadUtil.uploadFile(file);
|
|
|
+ String filename = entry.getName();
|
|
|
+ InputStream inputStream = zipFile.getInputStream(entry); //读取文件内容
|
|
|
+
|
|
|
+ String idNumber = filename.substring(0, 17);
|
|
|
+ BaseStudentUser studentUser = studentMap.get(idNumber);
|
|
|
+ //将照片转换成base64
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ byte[] imageBytes = outputStream.toByteArray();
|
|
|
+ String base64String = Base64.getEncoder().encodeToString(imageBytes);
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
|
|
|
+ //保存到云服务器
|
|
|
+ String filePath = UploadUtil.uploadFileByte(filename, imageBytes);
|
|
|
+
|
|
|
+ //存入数据库
|
|
|
+ long fileId = IdUtil.getSnowflakeNextId();
|
|
|
+ String suffix = StringUtils.substringAfterLast(filename, StringPool.DOT);
|
|
|
+
|
|
|
+ File fileEntity = new File();
|
|
|
+ fileEntity.setId(fileId);
|
|
|
+ fileEntity.setFolderId(folderId);
|
|
|
+ fileEntity.setFileName(filename);
|
|
|
+ fileEntity.setCreateDate(LocalDateTime.now());
|
|
|
+ fileEntity.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ fileEntity.setDeleteMark(0);
|
|
|
+ fileEntity.setFileUrl(filePath);
|
|
|
+ fileEntity.setFileSize(file.getSize());
|
|
|
+ fileEntity.setFileSuffiex(StringPool.DOT + suffix);
|
|
|
+ fileEntity.setFileType(suffix);
|
|
|
+ fileService.save(fileEntity);
|
|
|
+
|
|
|
+ long baseFaceId = IdUtil.getSnowflakeNextId();
|
|
|
+ FaceManagement baseFace = new FaceManagement();
|
|
|
+ baseFace.setId(baseFaceId);
|
|
|
+ baseFace.setRegisterBase64(base64String);
|
|
|
+ baseFace.setUserId(studentUser.getId());
|
|
|
+ baseFace.setSex(studentUser.getGender());
|
|
|
+ baseFace.setName(studentUser.getName());
|
|
|
+ baseFace.setIdno(studentUser.getCredentialNumber());
|
|
|
+ baseFace.setVerifyStatus(1);
|
|
|
+ baseFace.setCreateDate(LocalDateTime.now());
|
|
|
+ baseFace.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ baseFace.setDeleteMark(0);
|
|
|
+ baseFace.setStatus(1);
|
|
|
+ baseFace.setFileId(fileId);
|
|
|
+ baseFace.setUserType(2L);
|
|
|
+ faceManagementService.save(baseFace);
|
|
|
+
|
|
|
+ StudentClassVo classVo = studentClassMap.get(studentUser.getId());
|
|
|
+ StundentFaceProcess studentFace = new StundentFaceProcess();
|
|
|
+ studentFace.setStatus(1);
|
|
|
+ studentFace.setCreateDate(new Date());
|
|
|
+ studentFace.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ studentFace.setDeleteMark(0);
|
|
|
+ studentFace.setGender(studentUser.getGender());
|
|
|
+ studentFace.setFacePhoto(fileId);
|
|
|
+ studentFace.setName(studentUser.getName());
|
|
|
+ studentFace.setClassId(classVo.getId());
|
|
|
+ studentFace.setClassCn(classVo.getName());
|
|
|
+ studentFace.setTeacherId(classVo.getTeacherId());
|
|
|
+ studentFace.setIdentityCard(studentUser.getCredentialNumber());
|
|
|
+ studentFace.setStatus(1);
|
|
|
+ studentFace.setExamStatus(1);
|
|
|
+ stundentFaceProcessService.save(studentFace);
|
|
|
+
|
|
|
+ //将人脸上传海康
|
|
|
+ FaceImportUtil.ImportStudentFace(studentFace.getId());
|
|
|
}
|
|
|
return RT.ok(true);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|