|
@@ -7,12 +7,15 @@ 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.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.model.result.R;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
|
+import com.xjrsoft.common.utils.ImageUtil;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.module.organization.entity.User;
|
|
|
import com.xjrsoft.module.personnel.dto.*;
|
|
@@ -23,12 +26,19 @@ import com.xjrsoft.module.system.service.ICodeRuleService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
|
|
|
|
@@ -79,11 +89,16 @@ public class FaceManagementController {
|
|
|
return R.ok(BeanUtil.toBean(faceManagement, FaceManagementVo.class));
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(method = POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
|
|
|
- @ApiOperation(value = "新增人脸", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ @PostMapping
|
|
|
+ @ApiOperation(value = "新增人脸")
|
|
|
@SaCheckPermission("facemanager:add")
|
|
|
- public R add(@Valid @RequestBody AddFaceManagementDto dto, @RequestPart MultipartFile file) {
|
|
|
+ public R add(AddFaceManagementDto dto, @RequestParam("file") MultipartFile file) {
|
|
|
FaceManagement faceManagement = BeanUtil.toBean(dto, FaceManagement.class);
|
|
|
+ try {
|
|
|
+ faceManagement.setRegisterBase64(ImageHandler(file));
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.error(e.getMessage());
|
|
|
+ }
|
|
|
boolean isSuccess = faceManagementService.add(faceManagement);
|
|
|
codeRuleService.useEncode("FACECODE");
|
|
|
return R.ok(isSuccess);
|
|
@@ -93,9 +108,13 @@ public class FaceManagementController {
|
|
|
@PutMapping
|
|
|
@ApiOperation(value = "修改人脸")
|
|
|
@SaCheckPermission("facemanager:edit")
|
|
|
- public R update(@Valid @RequestBody UpdateFaceManagementDto dto) {
|
|
|
-
|
|
|
+ public R update(UpdateFaceManagementDto dto, @RequestParam("file") MultipartFile file) {
|
|
|
FaceManagement faceManagement = BeanUtil.toBean(dto, FaceManagement.class);
|
|
|
+ try {
|
|
|
+ faceManagement.setRegisterBase64(ImageHandler(file));
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.error(e.getMessage());
|
|
|
+ }
|
|
|
return R.ok(faceManagementService.update(faceManagement));
|
|
|
|
|
|
}
|
|
@@ -114,4 +133,27 @@ public class FaceManagementController {
|
|
|
public R delete(@Valid @RequestBody List<Long> ids) {
|
|
|
return R.ok(faceManagementService.delete(ids));
|
|
|
}
|
|
|
+
|
|
|
+ // 图片处理
|
|
|
+ public String ImageHandler(@NotNull MultipartFile file) throws IOException {
|
|
|
+ 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("图片格式不正确!");
|
|
|
+ }
|
|
|
+ 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,");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ Long maxSize = 2097152L; // 最大文件2M
|
|
|
+ byte[] resultImg = ImageUtil.compressUnderSize(file.getBytes(), maxSize);
|
|
|
+
|
|
|
+ return map.get(imgSuffix) + ImageUtil.bytesEncode2Base64(resultImg);
|
|
|
+ }
|
|
|
}
|