fix:文件上传优化
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.nl.dev.modular.file.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
@@ -30,8 +32,8 @@ import org.nl.common.pojo.CommonEntity;
|
||||
public class DevFile extends CommonEntity {
|
||||
|
||||
/** id */
|
||||
@Schema(description = "id")
|
||||
private String id;
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 存储引擎 */
|
||||
@Schema(description = "存储引擎")
|
||||
|
||||
@@ -22,4 +22,9 @@ import org.nl.dev.modular.file.entity.DevFile;
|
||||
* @date 2022/2/23 18:40
|
||||
**/
|
||||
public interface DevFileMapper extends BaseMapper<DevFile> {
|
||||
|
||||
|
||||
@Insert("INSERT INTO local_storage (engine,bucket,name, suffix,sizeKb,sizeInfo,objName, storagePath, downloadPath, thumbnail, extJson) VALUES (#{name}, #{suffix}, #{path}, #{type}, #{size}, #{orderCode}, #{createTime}, #{createName}, #{updateTime})")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
void insertUseGeneratedKeys(LocalStorage user);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.nl.dev.dto.DevFileApiDto;
|
||||
import org.nl.dev.modular.file.entity.DevFile;
|
||||
import org.nl.dev.modular.file.enums.DevFileEngineTypeEnum;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.nl.dev.api.DevFileApi;
|
||||
@@ -78,10 +80,11 @@ public class DevFileApiProvider implements DevFileApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getFileInfoById(String id) {
|
||||
return Optional.ofNullable(devFileService.getById(id))
|
||||
.map(JSONUtil::parseObj)
|
||||
.orElse(new JSONObject());
|
||||
public DevFileApiDto getFileInfoById(Long id) {
|
||||
DevFile byId = devFileService.getById(id);
|
||||
DevFileApiDto dto = new DevFileApiDto();
|
||||
BeanUtils.copyProperties(dto,byId);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -141,7 +141,7 @@ public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> impl
|
||||
}
|
||||
|
||||
// 生成id
|
||||
String fileId = IdWorker.getIdStr();
|
||||
Long fileId = IdWorker.getId();
|
||||
|
||||
// 存储桶名称
|
||||
String bucketName = null;
|
||||
@@ -210,7 +210,7 @@ public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> impl
|
||||
if(ObjectUtil.isEmpty(apiUrl)) {
|
||||
throw new CommonException("后端域名地址未正确配置:snowy.config.common.backend-url为空");
|
||||
}
|
||||
downloadUrl= apiUrl + "/dev/file/download?id=" + fileId;
|
||||
downloadUrl= apiUrl + "/api/localStorage/download?storageId=" + fileId;
|
||||
devFile.setDownloadPath(downloadUrl);
|
||||
} else {
|
||||
// 阿里云、腾讯云、MINIO可以直接使用存储地址(公网)作为下载地址
|
||||
@@ -233,7 +233,7 @@ public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> impl
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/22 15:58
|
||||
**/
|
||||
public String genFileKey(String fileId, MultipartFile file) {
|
||||
public String genFileKey(Long fileId, MultipartFile file) {
|
||||
|
||||
// 获取文件原始名称
|
||||
String originalFileName = file.getOriginalFilename();
|
||||
|
||||
Reference in New Issue
Block a user