|
@@ -17,9 +17,11 @@ import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
|
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
|
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils;
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
@@ -32,6 +34,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EX
|
|
|
*
|
|
*
|
|
|
* @author 芋道源码
|
|
* @author 芋道源码
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class FileServiceImpl implements FileService {
|
|
public class FileServiceImpl implements FileService {
|
|
|
|
|
|
|
@@ -159,6 +162,31 @@ public class FileServiceImpl implements FileService {
|
|
|
fileMapper.deleteById(id);
|
|
fileMapper.deleteById(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void deleteByUrl(String url) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ FileDO fileDO = fileMapper.selectOne(Wrappers.<FileDO>lambdaQuery()
|
|
|
|
|
+ .eq(FileDO::getUrl, url));
|
|
|
|
|
+ if (fileDO == null) {
|
|
|
|
|
+ throw exception(FILE_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 校验存在
|
|
|
|
|
+ FileDO file = validateFileExists(fileDO.getId());
|
|
|
|
|
+
|
|
|
|
|
+ // 从文件存储器中删除
|
|
|
|
|
+ FileClient client = fileConfigService.getFileClient(file.getConfigId());
|
|
|
|
|
+ Assert.notNull(client, "客户端({}) 不能为空", file.getConfigId());
|
|
|
|
|
+ client.delete(file.getPath());
|
|
|
|
|
+
|
|
|
|
|
+ // 删除记录
|
|
|
|
|
+ fileMapper.deleteById(fileDO.getId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("文件删除失败{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private FileDO validateFileExists(Long id) {
|
|
private FileDO validateFileExists(Long id) {
|
|
|
FileDO fileDO = fileMapper.selectById(id);
|
|
FileDO fileDO = fileMapper.selectById(id);
|
|
|
if (fileDO == null) {
|
|
if (fileDO == null) {
|