|
|
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.*;
|
|
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
|
|
+import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClient;
|
|
|
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.dal.dataobject.file.FileDO;
|
|
|
@@ -16,6 +17,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
|
|
|
|
|
@@ -54,6 +58,15 @@ public class FileServiceImpl implements FileService {
|
|
|
// 上传到文件存储器
|
|
|
FileClient client = fileConfigService.getMasterFileClient();
|
|
|
Assert.notNull(client, "客户端(master) 不能为空");
|
|
|
+
|
|
|
+ // 本地存储时,按日期进行分文件夹存储
|
|
|
+ if (client instanceof LocalFileClient) {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy/MM/dd/");
|
|
|
+ String directory = today.format(pattern);
|
|
|
+ path = directory + path;
|
|
|
+ }
|
|
|
+
|
|
|
String url = client.upload(content, path, type);
|
|
|
|
|
|
// 保存到数据库
|
|
|
@@ -91,6 +104,15 @@ public class FileServiceImpl implements FileService {
|
|
|
// 上传到文件存储器
|
|
|
FileClient client = fileConfigService.getMasterFileClient();
|
|
|
Assert.notNull(client, "客户端(master) 不能为空");
|
|
|
+
|
|
|
+ // 本地存储时,按日期进行分文件夹存储
|
|
|
+ if (client instanceof LocalFileClient) {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy/MM/dd/");
|
|
|
+ String directory = today.format(pattern);
|
|
|
+ path = directory + path;
|
|
|
+ }
|
|
|
+
|
|
|
String url = client.upload(content, path, type);
|
|
|
|
|
|
// 保存到数据库
|