feat(image): 添加图片清理功能- 新增 FileStorageService 用于文件上传、下载和删除操作- 实现 ImageCleanupService 清理冗余图片

- 添加 ImageCleanupController 提供手动清理图片的 API
- 创建 ImageCleanupScheduler定时清理冗余图片
- 更新相关 Mapper 接口,增加必要的查询和删除方法
This commit is contained in:
2025-08-06 17:29:11 +08:00
parent 8cdba1c0e6
commit b28446c4b6
8 changed files with 211 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
package com.test.bijihoudaun.controller;
import com.test.bijihoudaun.service.ImageCleanupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 图片清理控制器
* 提供手动触发清理冗余图片的API端点
*/
@RestController
@RequestMapping("/api/admin")
public class ImageCleanupController {
@Autowired
private ImageCleanupService imageCleanupService;
/**
* 手动触发清理冗余图片
* @return 清理结果
*/
@PostMapping("/cleanup-images")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<?> cleanupImages() {
int deletedCount = imageCleanupService.cleanupRedundantImages();
return ResponseEntity.ok().body("成功清理 " + deletedCount + " 个冗余图片");
}
}