Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
00df5b16a5
|
|
@ -85,6 +85,7 @@ public class CommonUploadService {
|
|||
String suffix = UploadSuffixEnum.getValueByKey(jsonObj.getString("suffix"));
|
||||
// 生成文件路径
|
||||
String uploadPath = FileUtil.generateDatePath(file, suffix).replace("\\", "/");
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
// 上传结果
|
||||
String uploadResult = null;
|
||||
if(Objects.equals(uploadSize,"small")){
|
||||
|
|
@ -95,7 +96,8 @@ public class CommonUploadService {
|
|||
if(StringUtils.isEmpty(uploadResult)){
|
||||
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());
|
||||
return AjaxResult.error(Constants.UPLOAD_ERROR);
|
||||
}
|
||||
map.put("uploadPath", uploadPath);
|
||||
map.put("fileRes", FileUtil.getFileInfo(file,uploadPath));
|
||||
map.put("ocrResult", ocrResponse);
|
||||
return AjaxResult.success(Constants.UPLOAD_SUCCESS,map);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
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.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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.删除
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ package com.bonus.file.util;
|
|||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -97,4 +101,39 @@ public class FileUtil {
|
|||
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