Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
673873a2
Commit
673873a2
authored
Jan 11, 2022
by
284718418@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.云盘-显示大小:10KB,5M,2G 优化
parent
81486567
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
3 deletions
+71
-3
src/main/java/cn/timer/api/controller/disk/DiskCatalogueController.java
+1
-2
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
+2
-1
src/main/java/cn/timer/api/utils/FileUtils.java
+68
-0
No files found.
src/main/java/cn/timer/api/controller/disk/DiskCatalogueController.java
View file @
673873a2
...
...
@@ -287,8 +287,7 @@ public class DiskCatalogueController {
// 删除之前的成员 全部重新添加
DiskCloudDiskUser
.
builder
().
deleteFlag
(
1
).
build
().
update
(
new
QueryWrapper
<
DiskCloudDiskUser
>()
.
lambda
().
eq
(
DiskCloudDiskUser:
:
getOrgId
,
userBean
.
getOrgCode
())
.
eq
(
DiskCloudDiskUser:
:
getCatalogueId
,
catalogue
.
getId
())
.
eq
(
DiskCloudDiskUser:
:
getUserId
,
userBean
.
getEmpNum
()));
.
eq
(
DiskCloudDiskUser:
:
getCatalogueId
,
catalogue
.
getId
()));
}
diskCatalogue
.
setId
(
catalogue
.
getId
());
...
...
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
View file @
673873a2
...
...
@@ -14,6 +14,7 @@ import cn.timer.api.dto.disk.DiskFilesDto;
import
cn.timer.api.dto.disk.DiskFilesParam
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.utils.FileUtils
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
...
...
@@ -91,7 +92,7 @@ public class DiskFilesController {
diskFiles
.
setTitle
(
dto
.
getResourceFileName
());
diskFiles
.
setFileSize
(
dto
.
getFileSize
());
// 显示大小:10KB,5M,2G 后续优化
diskFiles
.
setShowSize
(
dto
.
getFileSize
()
+
"B"
);
diskFiles
.
setShowSize
(
FileUtils
.
getSize
(
dto
.
getFileSize
())
);
diskFiles
.
setUserName
(
userBean
.
getUserInfo
().
getName
());
diskFiles
.
insert
();
...
...
src/main/java/cn/timer/api/utils/FileUtils.java
0 → 100644
View file @
673873a2
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
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment