Commit 673873a2 by 284718418@qq.com

1.云盘-显示大小:10KB,5M,2G 优化

parent 81486567
...@@ -287,8 +287,7 @@ public class DiskCatalogueController { ...@@ -287,8 +287,7 @@ public class DiskCatalogueController {
// 删除之前的成员 全部重新添加 // 删除之前的成员 全部重新添加
DiskCloudDiskUser.builder().deleteFlag(1).build().update(new QueryWrapper<DiskCloudDiskUser>() DiskCloudDiskUser.builder().deleteFlag(1).build().update(new QueryWrapper<DiskCloudDiskUser>()
.lambda().eq(DiskCloudDiskUser::getOrgId, userBean.getOrgCode()) .lambda().eq(DiskCloudDiskUser::getOrgId, userBean.getOrgCode())
.eq(DiskCloudDiskUser::getCatalogueId, catalogue.getId()) .eq(DiskCloudDiskUser::getCatalogueId, catalogue.getId()));
.eq(DiskCloudDiskUser::getUserId, userBean.getEmpNum()));
} }
diskCatalogue.setId(catalogue.getId()); diskCatalogue.setId(catalogue.getId());
......
...@@ -14,6 +14,7 @@ import cn.timer.api.dto.disk.DiskFilesDto; ...@@ -14,6 +14,7 @@ import cn.timer.api.dto.disk.DiskFilesDto;
import cn.timer.api.dto.disk.DiskFilesParam; import cn.timer.api.dto.disk.DiskFilesParam;
import cn.timer.api.dto.disk.FileInfoDto; import cn.timer.api.dto.disk.FileInfoDto;
import cn.timer.api.service.FtpService; import cn.timer.api.service.FtpService;
import cn.timer.api.utils.FileUtils;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
...@@ -91,7 +92,7 @@ public class DiskFilesController { ...@@ -91,7 +92,7 @@ public class DiskFilesController {
diskFiles.setTitle(dto.getResourceFileName()); diskFiles.setTitle(dto.getResourceFileName());
diskFiles.setFileSize(dto.getFileSize()); diskFiles.setFileSize(dto.getFileSize());
// 显示大小:10KB,5M,2G 后续优化 // 显示大小:10KB,5M,2G 后续优化
diskFiles.setShowSize(dto.getFileSize() + "B"); diskFiles.setShowSize(FileUtils.getSize(dto.getFileSize()));
diskFiles.setUserName(userBean.getUserInfo().getName()); diskFiles.setUserName(userBean.getUserInfo().getName());
diskFiles.insert(); diskFiles.insert();
......
package cn.timer.api.utils;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/1/11
*/
public class FileUtils {
/**
* 获取文件的大小(返回到达的最高单位)
* 比如:1024Byte就不再用Byte
* 直接返回1KB
* 返回值精确到小数点后3位
* @param size 文件大小
* @return 文件的大小 若文件不存在或者不是文件就返回 “”
*/
public static String getSize(long size) {
double s = (double) size;
String unit;
if (size != -1L) {
int l;
if (size < 1024L) {
l = 0;
} else if (size < 1024L * 1024L) {
l = 1;
s = (double) size / 1024L;
} else {
for (l = 2; size >= 1024L * 1024L; l++) {
size = size / 1024L;
if ((size / 1024L) < 1024L) {
s = (double) size / 1024L;
break;
}
}
}
switch (l) {
case 0:
unit = "Byte";
break;
case 1:
unit = "KB";
break;
case 2:
unit = "MB";
break;
case 3:
unit = "GB";
break;
case 4:
unit = "TB";
break;
default:
unit = "ER";
}
String format = String.format("%.3f", s);
return format + unit;
}
return "";
}
public static void main(String[] args) {
System.out.println(getSize(42721));
System.out.println(getSize(18560));
System.out.println(getSize(37516712));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment