|
@@ -40,6 +40,13 @@ public class FileServiceImpl implements FileService {
|
|
|
return fileMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public PageResult<FileDO> getFilePageWithAnotherOne(FilePageReqVO pageReqVO) {
|
|
|
+ // 可以直接调用 mapper 的 selectPage 方法,添加 another 字段的条件
|
|
|
+ return fileMapper.selectPageWithAnotherOne(pageReqVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@SneakyThrows
|
|
|
public String createFile(String name, String path, byte[] content) {
|
|
@@ -70,6 +77,39 @@ public class FileServiceImpl implements FileService {
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
+ //自加的
|
|
|
+ @Override
|
|
|
+ @SneakyThrows
|
|
|
+ public String createFile(String name, String path, byte[] content, Boolean another) {
|
|
|
+ // 计算默认的 path 名
|
|
|
+ String type = FileTypeUtils.getMineType(content, name);
|
|
|
+ if (StrUtil.isEmpty(path)) {
|
|
|
+ path = FileUtils.generatePath(content, name);
|
|
|
+ }
|
|
|
+ // 如果 name 为空,则使用 path 填充
|
|
|
+ if (StrUtil.isEmpty(name)) {
|
|
|
+ name = path;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传到文件存储器
|
|
|
+ FileClient client = fileConfigService.getMasterFileClient();
|
|
|
+ Assert.notNull(client, "客户端(master) 不能为空");
|
|
|
+ String url = client.upload(content, path, type);
|
|
|
+
|
|
|
+ // 保存到数据库
|
|
|
+ FileDO file = new FileDO();
|
|
|
+ file.setConfigId(client.getId());
|
|
|
+ file.setName(name);
|
|
|
+ file.setPath(path);
|
|
|
+ file.setUrl(url);
|
|
|
+ file.setType(type);
|
|
|
+ file.setSize(content.length);
|
|
|
+ file.setAnother(another); // 新增字段的设置
|
|
|
+ fileMapper.insert(file);
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Long createFile(FileCreateReqVO createReqVO) {
|
|
|
FileDO file = BeanUtils.toBean(createReqVO, FileDO.class);
|