diff --git a/src/main/java/com/biutag/supervision/controller/mobileSupervision/PhotoController.java b/src/main/java/com/biutag/supervision/controller/mobileSupervision/PhotoController.java index 043603b..43fb814 100644 --- a/src/main/java/com/biutag/supervision/controller/mobileSupervision/PhotoController.java +++ b/src/main/java/com/biutag/supervision/controller/mobileSupervision/PhotoController.java @@ -3,6 +3,7 @@ package com.biutag.supervision.controller.mobileSupervision; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.biutag.supervision.common.UserContextHolder; import com.biutag.supervision.pojo.Result; import com.biutag.supervision.pojo.dto.FileBase64Dto; @@ -14,6 +15,7 @@ import com.biutag.supervision.service.SupPhotoService; import com.biutag.supervision.util.ImgUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; import org.springframework.web.bind.annotation.*; import java.io.ByteArrayInputStream; @@ -72,12 +74,18 @@ public class PhotoController { photo.setDate(LocalDate.now().toString()); UserAuth user = UserContextHolder.getCurrentUser(); photo.setCreateUsername(user.getUserName()); - // 创建缩略图 - photo.setThumbnailBase64(ImgUtils.createSquareThumbnailBase64(fileService.download(filePath), 100)); photoService.save(photo); + updateThumbnailBase64(photo.getId(), filePath); return Result.success(photo); } + @Async + public void updateThumbnailBase64(Integer id, String filePath) { + // 更新缩略图 + String thumbnailBase64 = ImgUtils.createSquareThumbnailBase64(fileService.download(filePath), 100); + photoService.update(new LambdaUpdateWrapper().eq(SupPhoto::getId, id).set(SupPhoto::getThumbnailBase64, thumbnailBase64)); + } + @DeleteMapping("{id}") public Result del(@PathVariable Integer id) { photoService.removeById(id);