mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-25 18:57:11 +08:00
@@ -20,6 +20,7 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import cn.hutool.core.util.ClassUtil;
|
import cn.hutool.core.util.ClassUtil;
|
||||||
import cn.hutool.core.util.EscapeUtil;
|
import cn.hutool.core.util.EscapeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.x.file.storage.core.FileInfo;
|
import org.dromara.x.file.storage.core.FileInfo;
|
||||||
@@ -49,10 +50,14 @@ public class FileRecorderImpl implements FileRecorder {
|
|||||||
|
|
||||||
private final FileMapper fileMapper;
|
private final FileMapper fileMapper;
|
||||||
private final StorageMapper storageMapper;
|
private final StorageMapper storageMapper;
|
||||||
|
private final IdentifierGenerator identifierGenerator;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean save(FileInfo fileInfo) {
|
public boolean save(FileInfo fileInfo) {
|
||||||
FileDO file = new FileDO();
|
FileDO file = new FileDO();
|
||||||
|
Number id = identifierGenerator.nextId(fileInfo);
|
||||||
|
file.setId(id.longValue());
|
||||||
|
fileInfo.setId(id.longValue() + "");
|
||||||
String originalFilename = EscapeUtil.unescape(fileInfo.getOriginalFilename());
|
String originalFilename = EscapeUtil.unescape(fileInfo.getOriginalFilename());
|
||||||
file.setName(StrUtil.contains(originalFilename, StringConstants.DOT)
|
file.setName(StrUtil.contains(originalFilename, StringConstants.DOT)
|
||||||
? StrUtil.subBefore(originalFilename, StringConstants.DOT, true)
|
? StrUtil.subBefore(originalFilename, StringConstants.DOT, true)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传响应信息
|
* 文件上传响应信息
|
||||||
@@ -37,9 +38,27 @@ public class FileUploadResp implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件 id
|
||||||
|
*/
|
||||||
|
@Schema(description = "文件 id", example = "1897293810343682049")
|
||||||
|
private String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件 URL
|
* 文件 URL
|
||||||
*/
|
*/
|
||||||
@Schema(description = "文件 URL", example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg")
|
@Schema(description = "文件 URL", example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缩略图文件 URL
|
||||||
|
*/
|
||||||
|
@Schema(description = "缩略图文件 URL", example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg")
|
||||||
|
private String thUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 元数据
|
||||||
|
*/
|
||||||
|
@Schema(description = "元数据")
|
||||||
|
private Map<String, String> metadata;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
|||||||
FileInfo fileInfo = uploadPretreatment.upload();
|
FileInfo fileInfo = uploadPretreatment.upload();
|
||||||
String domain = StrUtil.appendIfMissing(storage.getDomain(), StringConstants.SLASH);
|
String domain = StrUtil.appendIfMissing(storage.getDomain(), StringConstants.SLASH);
|
||||||
fileInfo.setUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getFilename()));
|
fileInfo.setUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getFilename()));
|
||||||
|
fileInfo.setThUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getThFilename()));
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,12 @@ public class CommonController {
|
|||||||
public FileUploadResp upload(@NotNull(message = "文件不能为空") MultipartFile file) {
|
public FileUploadResp upload(@NotNull(message = "文件不能为空") MultipartFile file) {
|
||||||
ValidationUtils.throwIf(file::isEmpty, "文件不能为空");
|
ValidationUtils.throwIf(file::isEmpty, "文件不能为空");
|
||||||
FileInfo fileInfo = fileService.upload(file);
|
FileInfo fileInfo = fileService.upload(file);
|
||||||
return FileUploadResp.builder().url(fileInfo.getUrl()).build();
|
return FileUploadResp.builder()
|
||||||
|
.id(fileInfo.getId())
|
||||||
|
.url(fileInfo.getUrl())
|
||||||
|
.thUrl(fileInfo.getThUrl())
|
||||||
|
.metadata(fileInfo.getMetadata())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
|
@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
|
||||||
|
|||||||
Reference in New Issue
Block a user