|
|
@@ -6,10 +6,12 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
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.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.toolkit.MPJWrappers;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.model.result.RT;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
|
@@ -27,9 +29,12 @@ import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
|
|
|
import com.xjrsoft.module.personnel.service.ITeacherFaceProcessService;
|
|
|
import com.xjrsoft.module.personnel.vo.FaceManagementVo;
|
|
|
import com.xjrsoft.module.system.service.ICodeRuleService;
|
|
|
+import com.xjrsoft.module.system.service.IFileService;
|
|
|
+import com.xjrsoft.module.system.vo.ImageVo;
|
|
|
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;
|
|
|
@@ -42,7 +47,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/personnel" + "/facemanager")
|
|
|
@@ -53,6 +61,7 @@ public class FaceManagementController {
|
|
|
private ICodeRuleService codeRuleService;
|
|
|
private final ITeacherFaceProcessService teacherFaceProcessService;
|
|
|
private final IStundentFaceProcessService stundentFaceProcessService;
|
|
|
+ private final IFileService fileService;
|
|
|
|
|
|
@GetMapping(value = "/page")
|
|
|
@ApiOperation(value = "人脸列表(分页)")
|
|
|
@@ -147,16 +156,30 @@ public class FaceManagementController {
|
|
|
@PostMapping(value = "/add")
|
|
|
@ApiOperation(value = "新增人脸")
|
|
|
@SaCheckPermission("facemanager:add")
|
|
|
- public RT<Boolean> add(AddFaceManagementDto dto, @RequestParam("file") MultipartFile file) {
|
|
|
- FaceManagement faceManagement = BeanUtil.toBean(dto, FaceManagement.class);
|
|
|
- try {
|
|
|
- faceManagement.setRegisterBase64(ImageUtil.ImageHandler(file));
|
|
|
- } catch (Exception e) {
|
|
|
- return RT.error(e.getMessage());
|
|
|
+ public RT<Long> add(AddFaceManagementDto dto, @RequestParam("file") MultipartFile file) {
|
|
|
+
|
|
|
+ String filename = file.getOriginalFilename();
|
|
|
+ String suffix = StringUtils.substringAfterLast(filename, StringPool.DOT);
|
|
|
+ String[] imgSuffix = new String[]{"png", "jpg", "jpeg"};
|
|
|
+
|
|
|
+ if (!Arrays.asList(imgSuffix).contains(suffix)) {
|
|
|
+ throw new MyException("图片格式不正确!");
|
|
|
}
|
|
|
- boolean isSuccess = faceManagementService.add(faceManagement);
|
|
|
+ Map<String, String> map = new HashMap<String, String>() {
|
|
|
+ {
|
|
|
+ put("jpg", "data:image/jpg;base64,");
|
|
|
+ put("jpeg", "data:image/jpeg;base64,");
|
|
|
+ put("png", "data:image/png;base64,");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ ImageVo imageVo = fileService.addRubAndHand(file);
|
|
|
+ dto.setFileId(imageVo.getFolderId());
|
|
|
+ FaceManagement faceManagement = BeanUtil.toBean(dto, FaceManagement.class);
|
|
|
+ faceManagement.setRegisterBase64(map.get(suffix) + imageVo.getBase64());
|
|
|
+ faceManagementService.add(faceManagement);
|
|
|
codeRuleService.useEncode("FACECODE");
|
|
|
- return RT.ok(isSuccess);
|
|
|
+ return RT.ok(imageVo.getFolderId());
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -165,16 +188,28 @@ public class FaceManagementController {
|
|
|
@PostMapping(value = "/update")
|
|
|
@ApiOperation(value = "修改人脸")
|
|
|
@SaCheckPermission("facemanager:edit")
|
|
|
- public RT<Boolean> update(UpdateFaceManagementDto dto, @RequestParam(name = "file",required = false) MultipartFile file) {
|
|
|
- FaceManagement faceManagement = BeanUtil.toBean(dto, FaceManagement.class);
|
|
|
- if (file != null) {
|
|
|
- try {
|
|
|
- faceManagement.setRegisterBase64(ImageUtil.ImageHandler(file));
|
|
|
- } catch (Exception e) {
|
|
|
- return RT.error(e.getMessage());
|
|
|
- }
|
|
|
+ public RT<Long> update(UpdateFaceManagementDto dto, @RequestParam(name = "file",required = false) MultipartFile file) {
|
|
|
+ String filename = file.getOriginalFilename();
|
|
|
+ String suffix = StringUtils.substringAfterLast(filename, StringPool.DOT);
|
|
|
+ String[] imgSuffix = new String[]{"png", "jpg", "jpeg"};
|
|
|
+
|
|
|
+ if (!Arrays.asList(imgSuffix).contains(suffix)) {
|
|
|
+ throw new MyException("图片格式不正确!");
|
|
|
}
|
|
|
- return RT.ok(faceManagementService.update(faceManagement));
|
|
|
+ Map<String, String> map = new HashMap<String, String>() {
|
|
|
+ {
|
|
|
+ put("jpg", "data:image/jpg;base64,");
|
|
|
+ put("jpeg", "data:image/jpeg;base64,");
|
|
|
+ put("png", "data:image/png;base64,");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ ImageVo imageVo = fileService.addRubAndHand(file);
|
|
|
+ dto.setFileId(imageVo.getFolderId());
|
|
|
+ FaceManagement faceManagement = BeanUtil.toBean(dto, FaceManagement.class);
|
|
|
+ faceManagement.setRegisterBase64(map.get(suffix) + imageVo.getBase64());
|
|
|
+ faceManagementService.update(faceManagement);
|
|
|
+ return RT.ok(imageVo.getFolderId());
|
|
|
|
|
|
}
|
|
|
|