mirror of
https://github.com/BgaSol/sol-cloud
synced 2026-05-05 23:58:33 +00:00
refactor(file): Adjust the file creation logic to set the default value and creation time uniformly
This commit is contained in:
parent
50de33cffc
commit
64b008538e
2 changed files with 8 additions and 7 deletions
|
|
@ -43,11 +43,6 @@ public class FileCreateDto extends BaseCreateDto<FileEntity> {
|
|||
@JsonIgnore
|
||||
@Schema(hidden = true)
|
||||
public FileEntity toEntity() {
|
||||
FileEntity entity = super.toEntity(FILE_MAPSTRUCT_IMPL.toEntity(this));
|
||||
if (ObjectUtils.isEmpty(entity.getSource())) {
|
||||
this.source = "default";
|
||||
}
|
||||
entity.setCreateTime(new Date());
|
||||
return entity;
|
||||
return super.toEntity(FILE_MAPSTRUCT_IMPL.toEntity(this));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
|
|
@ -46,6 +47,12 @@ public class FileService extends BaseService<FileEntity, FilePageDto> {
|
|||
* 通过文件流保存文件
|
||||
*/
|
||||
public FileEntity save(MultipartFile multipartFile, FileEntity fileEntity) {
|
||||
fileEntity.setCreateTime(new Date());
|
||||
fileEntity.setBucket(minioConfig.getBucket());
|
||||
if (ObjectUtils.isEmpty(fileEntity.getSource())) {
|
||||
fileEntity.setSource("default");
|
||||
}
|
||||
|
||||
if (ObjectUtils.isEmpty(multipartFile)) {
|
||||
return this.save(fileEntity);
|
||||
}
|
||||
|
|
@ -101,7 +108,6 @@ public class FileService extends BaseService<FileEntity, FilePageDto> {
|
|||
} catch (IOException e) {
|
||||
throw new BaseException("获取文件HASH失败");
|
||||
}
|
||||
fileEntity.setBucket(minioConfig.getBucket());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue