|
@@ -1,45 +1,74 @@
|
|
|
package com.xjrsoft.module.personnel.controller;
|
|
|
|
|
|
+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.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.toolkit.MPJWrappers;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
+import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
|
import com.xjrsoft.common.model.result.RT;
|
|
|
+import com.xjrsoft.common.utils.FileZipUtil;
|
|
|
+import com.xjrsoft.common.utils.ImageUtil;
|
|
|
+import com.xjrsoft.common.utils.UploadUtil;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.module.base.vo.StudentClassVo;
|
|
|
+import com.xjrsoft.module.hikvision.util.ApiUtil;
|
|
|
+import com.xjrsoft.module.organization.entity.Department;
|
|
|
import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
|
+import com.xjrsoft.module.organization.service.IDepartmentService;
|
|
|
+import com.xjrsoft.module.organization.vo.DepartmentVo;
|
|
|
import com.xjrsoft.module.personnel.dto.AddTeacherFaceProcessDto;
|
|
|
import com.xjrsoft.module.personnel.dto.UpdateTeacherFaceProcessDto;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
|
|
|
import com.xjrsoft.module.personnel.dto.TeacherFaceProcessPageDto;
|
|
|
import com.xjrsoft.module.personnel.entity.CarMessageApply;
|
|
|
+import com.xjrsoft.module.personnel.entity.FaceManagement;
|
|
|
import com.xjrsoft.module.personnel.entity.StundentFaceProcess;
|
|
|
import com.xjrsoft.module.personnel.entity.TeacherFaceProcess;
|
|
|
+import com.xjrsoft.module.personnel.service.IFaceManagementService;
|
|
|
import com.xjrsoft.module.personnel.service.ITeacherFaceProcessService;
|
|
|
import com.xjrsoft.module.personnel.vo.TeacherFaceProcessPageVo;
|
|
|
|
|
|
import com.xjrsoft.module.personnel.vo.TeacherFaceProcessVo;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudentUser;
|
|
|
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.BaseTeacher;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
+import com.xjrsoft.module.teacher.service.ITeacherbaseManagerService;
|
|
|
import com.xjrsoft.module.teacher.vo.XjrUserPageVo;
|
|
|
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.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
-import java.util.List;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipFile;
|
|
|
|
|
|
/**
|
|
|
* @title: 人脸信息审核
|
|
@@ -56,6 +85,14 @@ public class TeacherFaceProcessController {
|
|
|
|
|
|
private final ITeacherFaceProcessService teacherFaceProcessService;
|
|
|
|
|
|
+ private final ITeacherbaseManagerService teacherbaseManagerService;
|
|
|
+
|
|
|
+ private final IFaceManagementService faceManagementService;
|
|
|
+
|
|
|
+ private final IFileService fileService;
|
|
|
+
|
|
|
+ private final IDepartmentService departmentService;
|
|
|
+
|
|
|
@GetMapping(value = "/page")
|
|
|
@ApiOperation(value="人脸信息审核列表(分页)")
|
|
|
@SaCheckPermission("teacherfaceprocess:detail")
|
|
@@ -130,4 +167,211 @@ public class TeacherFaceProcessController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @PostMapping(value = "/batch-import")
|
|
|
+ @ApiOperation(value = "批量新增教师人脸")
|
|
|
+ @SaCheckPermission("stundentfaceprocess:batch-upload")
|
|
|
+ public RT<Boolean> batchUpload(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ List<XjrUserPageVo> list = teacherbaseManagerService.selectJoinList(XjrUserPageVo.class,
|
|
|
+ new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .distinct()
|
|
|
+ .select(XjrUser::getId)
|
|
|
+ .selectAs(Department::getId, XjrUserPageVo::getDeptId)
|
|
|
+ .selectAs(Department::getName, XjrUserPageVo::getDeptIdCn)
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUserPageVo.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(UserDeptRelation.class, UserDeptRelation::getUserId, XjrUser::getId)
|
|
|
+ .leftJoin(Department.class, Department::getId, UserDeptRelation::getDeptId)
|
|
|
+ .eq(XjrUser::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(Department::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, XjrUserPageVo> teacherMap = new HashMap<>();
|
|
|
+ for (XjrUserPageVo teacher : list) {
|
|
|
+ teacherMap.put(teacher.getCredentialNumber(), teacher);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TeacherFaceProcess> faceList = teacherFaceProcessService.list(
|
|
|
+ new QueryWrapper<TeacherFaceProcess>().lambda()
|
|
|
+ .eq(TeacherFaceProcess::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<Long, TeacherFaceProcess> faceMap = new HashMap<>();
|
|
|
+ for (TeacherFaceProcess faceProcess : faceList) {
|
|
|
+ faceMap.put(faceProcess.getUserId(), faceProcess);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FaceManagement> faceManagementList = faceManagementService.list(
|
|
|
+ new QueryWrapper<FaceManagement>().lambda()
|
|
|
+ .select(FaceManagement.class, face -> !face.getColumn().equals("registerBase64"))
|
|
|
+ .select(FaceManagement.class, face -> !face.getColumn().equals("register_base64"))
|
|
|
+ .eq(FaceManagement::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(FaceManagement::getUserType, 1)
|
|
|
+ );
|
|
|
+ Map<Long, FaceManagement> faceManagementMap = new HashMap<>();
|
|
|
+ for (FaceManagement management : faceManagementList) {
|
|
|
+ faceManagementMap.put(management.getUserId(), management);
|
|
|
+ }
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
+
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ ZipFile zipFile = FileZipUtil.convertToZipFile(file);
|
|
|
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
|
|
+ while (entries.hasMoreElements()){
|
|
|
+ ZipEntry entry = entries.nextElement();
|
|
|
+ String filename = entry.getName();
|
|
|
+ InputStream inputStream = zipFile.getInputStream(entry); //读取文件内容
|
|
|
+ String[] split = filename.split("\\.");
|
|
|
+ String idNumber = split[0].substring(split[0].length() - 18);
|
|
|
+ XjrUserPageVo teacherUser = teacherMap.get(idNumber);
|
|
|
+ if(teacherUser == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //将照片转换成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();
|
|
|
+ //压缩到200k
|
|
|
+ imageBytes = ImageUtil.compressUnderSize(imageBytes, 204800);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ Long folderId = IdWorker.getId();
|
|
|
+ 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);
|
|
|
+
|
|
|
+ TeacherFaceProcess process = faceMap.get(Long.parseLong(teacherUser.getId()));
|
|
|
+ if(process == null){
|
|
|
+ long baseFaceId = IdUtil.getSnowflakeNextId();
|
|
|
+ FaceManagement baseFace = new FaceManagement();
|
|
|
+ baseFace.setId(baseFaceId);
|
|
|
+ baseFace.setRegisterBase64(base64String);
|
|
|
+ baseFace.setUserId(Long.parseLong(teacherUser.getId()));
|
|
|
+ baseFace.setSex(teacherUser.getGender());
|
|
|
+ baseFace.setName(teacherUser.getName());
|
|
|
+ baseFace.setIdno(teacherUser.getCredentialNumber());
|
|
|
+ baseFace.setVerifyStatus(1);
|
|
|
+ baseFace.setCreateDate(LocalDateTime.now());
|
|
|
+ baseFace.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ baseFace.setDeleteMark(0);
|
|
|
+ baseFace.setStatus(1);
|
|
|
+ baseFace.setFileId(folderId);
|
|
|
+ baseFace.setUserType(2L);
|
|
|
+ faceManagementService.save(baseFace);
|
|
|
+
|
|
|
+ TeacherFaceProcess teacherFace = new TeacherFaceProcess();
|
|
|
+ teacherFace.setStatus(1);
|
|
|
+ teacherFace.setCreateDate(new Date());
|
|
|
+ teacherFace.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ teacherFace.setDeleteMark(0);
|
|
|
+ teacherFace.setGender(teacherUser.getGender());
|
|
|
+ teacherFace.setFacePhoto(folderId);
|
|
|
+ teacherFace.setName(teacherUser.getName());
|
|
|
+ teacherFace.setDepId(Long.parseLong(teacherUser.getDeptId()));
|
|
|
+ teacherFace.setDepCn(teacherUser.getDeptIdCn());
|
|
|
+ teacherFace.setIdentityCard(teacherUser.getCredentialNumber());
|
|
|
+ teacherFace.setStatus(1);
|
|
|
+ teacherFace.setUserId(Long.parseLong(teacherUser.getId()));
|
|
|
+ teacherFace.setExamStatus(1);
|
|
|
+
|
|
|
+ //将人脸上传海康
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("personId", teacherUser.getId());
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
+
|
|
|
+ Map<String, String> querys = new HashMap<>();
|
|
|
+ querys.put("tagId", "frs");
|
|
|
+
|
|
|
+ String apiPath = "/api/resource/v1/face/single/add";
|
|
|
+ String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
|
|
|
+ teacherFace.setHikvisionResult(response);
|
|
|
+ teacherFaceProcessService.save(teacherFace);
|
|
|
+ } else {
|
|
|
+ process.setStatus(1);
|
|
|
+ process.setExamStatus(1);
|
|
|
+ process.setModifyDate(new Date());
|
|
|
+ process.setModifyUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ process.setDeleteMark(0);
|
|
|
+ process.setFacePhoto(folderId);
|
|
|
+
|
|
|
+ String faceId = null;
|
|
|
+ if(process.getHikvisionResult() != null && process.getHikvisionResult().startsWith("{") && process.getHikvisionResult().endsWith("}")){
|
|
|
+ JsonObject object = parser.parse(process.getHikvisionResult()).getAsJsonObject();
|
|
|
+ if("0".equals(object.get("code").getAsString()) && "success".equals(object.get("msg").getAsString())){
|
|
|
+ faceId = object.get("data").getAsJsonObject().get("faceId").getAsString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(faceId == null){
|
|
|
+ String apiUrl = "/api/resource/v1/person/condition/personInfo";
|
|
|
+ JsonObject paramsJson = new JsonObject();
|
|
|
+ paramsJson.addProperty("paramName", "personId");
|
|
|
+ JsonArray array = new JsonArray();
|
|
|
+ array.add(teacherUser.getId());
|
|
|
+ paramsJson.add("paramValue", array);
|
|
|
+ String personInfoRes = apiUtil.doPost(apiUrl, paramsJson.toString(), null);
|
|
|
+
|
|
|
+ JsonObject personInfoData = parser.parse(personInfoRes).getAsJsonObject();
|
|
|
+ if("0".equals(personInfoData.get("code").getAsString()) && "success".equals(personInfoData.get("msg").getAsString())){
|
|
|
+ JsonObject dataJson = personInfoData.get("data").getAsJsonObject();
|
|
|
+ if(dataJson.get("total").getAsInt() > 0){
|
|
|
+ JsonArray personPhoto = dataJson.get("list").getAsJsonArray().get(0)
|
|
|
+ .getAsJsonObject().get("personPhoto").getAsJsonArray();
|
|
|
+ if(personPhoto.size() > 0){
|
|
|
+ faceId = personPhoto.get(0).getAsJsonObject().get("personPhotoIndexCode").getAsString();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新海康数据
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ String apiPath;
|
|
|
+ if(faceId != null){
|
|
|
+ apiPath = "/api/resource/v1/face/single/update";
|
|
|
+ paramJson.addProperty("faceId", faceId);
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ apiPath = "/api/resource/v1/face/single/add";
|
|
|
+ paramJson.addProperty("personId", teacherUser.getId());
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
+ }
|
|
|
+ String result = apiUtil.doPost(apiPath, paramJson.toString(), null);
|
|
|
+ if(result.startsWith("{") && result.endsWith("}")){
|
|
|
+ JsonObject object = parser.parse(result).getAsJsonObject();
|
|
|
+ if("0".equals(object.get("code").getAsString()) && "success".equals(object.get("msg").getAsString())){
|
|
|
+ process.setHikvisionResult(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ teacherFaceProcessService.updateById(process);
|
|
|
+
|
|
|
+ FaceManagement faceManagement = faceManagementMap.get(Long.parseLong(teacherUser.getId()));
|
|
|
+ faceManagement.setVerifyStatus(2);
|
|
|
+ faceManagement.setRegisterBase64(base64String);
|
|
|
+ faceManagementService.update(faceManagement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return RT.ok(true);
|
|
|
+ }
|
|
|
+
|
|
|
}
|