文件上传修改
This commit is contained in:
parent
7231778bbb
commit
077819a261
|
|
@ -85,6 +85,7 @@ public class CommonUploadService {
|
||||||
String suffix = UploadSuffixEnum.getValueByKey(jsonObj.getString("suffix"));
|
String suffix = UploadSuffixEnum.getValueByKey(jsonObj.getString("suffix"));
|
||||||
// 生成文件路径
|
// 生成文件路径
|
||||||
String uploadPath = FileUtil.generateDatePath(file, suffix).replace("\\", "/");
|
String uploadPath = FileUtil.generateDatePath(file, suffix).replace("\\", "/");
|
||||||
|
Map<String, Object> map = new HashMap<>(16);
|
||||||
// 上传结果
|
// 上传结果
|
||||||
String uploadResult = null;
|
String uploadResult = null;
|
||||||
if(Objects.equals(uploadSize,"small")){
|
if(Objects.equals(uploadSize,"small")){
|
||||||
|
|
@ -95,7 +96,8 @@ public class CommonUploadService {
|
||||||
if(StringUtils.isEmpty(uploadResult)){
|
if(StringUtils.isEmpty(uploadResult)){
|
||||||
return AjaxResult.error(Constants.UPLOAD_ERROR);
|
return AjaxResult.error(Constants.UPLOAD_ERROR);
|
||||||
}
|
}
|
||||||
return AjaxResult.success(Constants.UPLOAD_SUCCESS,uploadPath);
|
map.put("fileRes", FileUtil.getFileInfo(file,uploadPath));
|
||||||
|
return AjaxResult.success(Constants.UPLOAD_SUCCESS,map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,7 +165,7 @@ public class CommonUploadService {
|
||||||
log.error(e.toString(),e.getMessage());
|
log.error(e.toString(),e.getMessage());
|
||||||
return AjaxResult.error(Constants.UPLOAD_ERROR);
|
return AjaxResult.error(Constants.UPLOAD_ERROR);
|
||||||
}
|
}
|
||||||
map.put("uploadPath", uploadPath);
|
map.put("fileRes", FileUtil.getFileInfo(file,uploadPath));
|
||||||
map.put("ocrResult", ocrResponse);
|
map.put("ocrResult", ocrResponse);
|
||||||
return AjaxResult.success(Constants.UPLOAD_SUCCESS,map);
|
return AjaxResult.success(Constants.UPLOAD_SUCCESS,map);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
package com.bonus.common.domain.file.po;
|
package com.bonus.common.domain.file.po;
|
||||||
|
|
||||||
|
import com.bonus.common.core.domain.model.LoginUser;
|
||||||
|
import com.bonus.common.utils.SecurityUtils;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统资源文件表
|
* 系统资源文件表
|
||||||
|
|
@ -68,17 +71,21 @@ public class ResourceFilePo {
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
private Date createTime;
|
private Date createTime = new Date();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人
|
* 创建人
|
||||||
*/
|
*/
|
||||||
private Long createUserId;
|
private Long createUserId = Optional.ofNullable(SecurityUtils.getLoginUser())
|
||||||
|
.map(LoginUser::getUserId)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人姓名
|
* 创建人姓名
|
||||||
*/
|
*/
|
||||||
private String createUserName;
|
private String createUserName = Optional.ofNullable(SecurityUtils.getLoginUser())
|
||||||
|
.map(LoginUser::getUsername)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除状态 0.未删除 1.删除
|
* 删除状态 0.未删除 1.删除
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@ package com.bonus.file.util;
|
||||||
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -97,4 +101,39 @@ public class FileUtil {
|
||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件信息
|
||||||
|
* @param file
|
||||||
|
* @param path
|
||||||
|
* @return String
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2025/10/22 15:37
|
||||||
|
*/
|
||||||
|
public static String getFileInfo(MultipartFile file,String path) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("filePath", path);
|
||||||
|
map.put("sourceFileName", file.getOriginalFilename());
|
||||||
|
map.put("fileName", file.getOriginalFilename());
|
||||||
|
map.put("suffixName", getFileExtension(file.getOriginalFilename()));
|
||||||
|
map.put("fileSize", getFileSizeInMB(file));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件的大小
|
||||||
|
* @param file
|
||||||
|
* @return double
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2025/10/22 15:42
|
||||||
|
*/
|
||||||
|
public static double getFileSizeInMB(MultipartFile file) {
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
long sizeInBytes = file.getSize();
|
||||||
|
BigDecimal sizeInMB = new BigDecimal(sizeInBytes)
|
||||||
|
.divide(new BigDecimal(1024 * 1024), 2, RoundingMode.HALF_UP);
|
||||||
|
return sizeInMB.doubleValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue