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
59005c05
Commit
59005c05
authored
Jan 12, 2022
by
284718418@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.BUG修改
parent
e6a4991b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
181 additions
and
25 deletions
+181
-25
src/main/java/cn/timer/api/controller/disk/DiskCatalogueController.java
+1
-1
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
+94
-13
src/main/java/cn/timer/api/controller/disk/sevice/DiskFilesService.java
+8
-0
src/main/java/cn/timer/api/controller/disk/sevice/DiskFilesServiceImpl.java
+16
-9
src/main/java/cn/timer/api/dao/disk/DiskFilesMapper.java
+8
-0
src/main/java/cn/timer/api/dto/disk/DiskFileCatalogueDto.java
+47
-0
src/main/java/cn/timer/api/utils/FileUtils.java
+2
-2
src/main/resources/mapping/disk/DiskFilesMapper.xml
+5
-0
No files found.
src/main/java/cn/timer/api/controller/disk/DiskCatalogueController.java
View file @
59005c05
...
...
@@ -90,7 +90,7 @@ public class DiskCatalogueController {
}
diskCatalogue
.
setCreateUserId
(
userBean
.
getEmpNum
());
diskCatalogue
.
setOrgId
(
userBean
.
getOrgCode
());
diskCatalogue
.
setUserName
(
userBean
.
get
UserInfo
().
getN
ame
());
diskCatalogue
.
setUserName
(
userBean
.
get
QyzxEmpLogin
().
getUsern
ame
());
diskCatalogue
.
setUpdateUserId
(
userBean
.
getEmpNum
());
Boolean
count
=
diskCatalogue
.
insertOrUpdate
();
// 云盘修改
...
...
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
View file @
59005c05
...
...
@@ -9,14 +9,14 @@ import cn.timer.api.config.annotation.UserBean;
import
cn.timer.api.config.enuminterface.JxglEnumInterface
;
import
cn.timer.api.config.exception.CustomException
;
import
cn.timer.api.config.sftp.SftpConfiguration
;
import
cn.timer.api.dto.disk.DiskCatalogueDto
;
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.controller.disk.sevice.DiskFilesService
;
import
cn.timer.api.dto.disk.*
;
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
cn.timer.api.utils.UserIp
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -24,15 +24,20 @@ import io.swagger.annotations.ApiParam;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.transaction.Transactional
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -50,6 +55,8 @@ public class DiskFilesController {
@Autowired
private
FtpService
ftpService
;
@Autowired
private
DiskFilesService
diskFilesService
;
@Value
(
"${sftp.client.root}"
)
private
String
root
;
...
...
@@ -68,7 +75,7 @@ public class DiskFilesController {
@PostMapping
(
"/upload"
)
@ApiOperation
(
value
=
"上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
upload
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
true
)
MultipartFile
[]
file
,
@ApiParam
(
"文件文件夹或共享空间ID"
)
@RequestParam
(
required
=
true
)
Integer
catalogueId
)
{
@ApiParam
(
"文件文件夹或共享空间ID"
)
@RequestParam
(
required
=
true
)
Integer
catalogueId
,
HttpServletRequest
request
)
{
if
(
catalogueId
<=
0
){
return
ResultUtil
.
error
(
"上传失败,请选择文件夹"
);
}
...
...
@@ -91,9 +98,10 @@ public class DiskFilesController {
diskFiles
.
setUrlPath
(
dto
.
getUrlPath
());
diskFiles
.
setTitle
(
dto
.
getResourceFileName
());
diskFiles
.
setFileSize
(
dto
.
getFileSize
());
// 显示大小:10KB,5M,2G
后续优化
// 显示大小:10KB,5M,2G
diskFiles
.
setShowSize
(
FileUtils
.
getSize
(
dto
.
getFileSize
()));
diskFiles
.
setUserName
(
userBean
.
getUserInfo
().
getName
());
diskFiles
.
setUserName
(
userBean
.
getQyzxEmpLogin
().
getUsername
());
diskFiles
.
setUploadIp
(
UserIp
.
getIpAddr
(
request
));
diskFiles
.
insert
();
//新增中间关系
...
...
@@ -108,7 +116,7 @@ public class DiskFilesController {
diskFilesLog
.
setTitle
(
dto
.
getResourceFileName
());
diskFilesLog
.
setType
(
JxglEnumInterface
.
DiskFilesLogType
.
CREATE_LOG
.
getType
());
diskFilesLog
.
setUserId
(
userBean
.
getEmpNum
());
diskFilesLog
.
setUserName
(
userBean
.
get
UserInfo
().
getN
ame
());
diskFilesLog
.
setUserName
(
userBean
.
get
QyzxEmpLogin
().
getUsern
ame
());
diskFilesLog
.
insert
();
}
...
...
@@ -118,7 +126,7 @@ public class DiskFilesController {
}
return
ResultUtil
.
error
(
"上传文件失败"
);
}
@ResponseBody
/*
@ResponseBody
@GetMapping("/download")
@ApiOperation(value = "下载普通文件", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> download(@CurrentUser UserBean userBean,
...
...
@@ -142,7 +150,7 @@ public class DiskFilesController {
diskFilesLog.setTitle(diskFiles.getTitle());
diskFilesLog.setType(JxglEnumInterface.DiskFilesLogType.DOWN_LOAD_LOG.getType());
diskFilesLog.setUserId(userBean.getEmpNum());
diskFilesLog
.
setUserName
(
userBean
.
get
UserInfo
().
getN
ame
());
diskFilesLog.setUserName(userBean.get
QyzxEmpLogin().getUsern
ame());
diskFilesLog.insert();
return ResultUtil.success();
}
...
...
@@ -151,7 +159,7 @@ public class DiskFilesController {
throw new CustomException("下载文件异常,请联系管理员");
}
return ResultUtil.error("下载文件失败");
}
}
*/
/**
* 云盘-文件重命名
*
...
...
@@ -166,7 +174,7 @@ public class DiskFilesController {
DiskFiles
entity
=
new
DiskFiles
();
DiskFiles
diskFiles
=
DiskFiles
.
builder
().
id
(
diskFilesParam
.
getId
()).
build
().
selectById
();
if
(
StringUtils
.
isEmpty
(
diskFiles
)
||
!
diskFiles
.
getCreateUserId
().
equals
(
userBean
.
getEmpNum
()))
{
return
ResultUtil
.
error
(
"操作失败!"
);
return
ResultUtil
.
error
(
"
无权限,
操作失败!"
);
}
entity
.
setId
(
diskFiles
.
getId
());
entity
.
setTitle
(
diskFilesParam
.
getName
());
...
...
@@ -185,7 +193,7 @@ public class DiskFilesController {
diskFilesLog
.
setFileSize
(
diskFiles
.
getFileSize
()
+
"B"
);
diskFilesLog
.
setTitle
(
diskFiles
.
getTitle
());
diskFilesLog
.
setUserId
(
userBean
.
getEmpNum
());
diskFilesLog
.
setUserName
(
userBean
.
get
UserInfo
().
getN
ame
());
diskFilesLog
.
setUserName
(
userBean
.
get
QyzxEmpLogin
().
getUsern
ame
());
diskFilesLog
.
insert
();
return
ResultUtil
.
data
(
StringUtils
.
isEmpty
(
diskFilesParam
.
getDeleteFlag
())?
"文件重命名成功"
:
"删除文件成功"
);
}
else
{
...
...
@@ -197,4 +205,77 @@ public class DiskFilesController {
}
}
/**
* 云盘-我的文件空间大小
*
* @param userBean
* @return
*/
@GetMapping
(
value
=
"/mycatalogue"
)
@ApiOperation
(
value
=
"我的文件空间大小"
,
httpMethod
=
"GET"
,
notes
=
"我的文件空间大小"
)
public
Result
<
Object
>
myCatalogue
(
@CurrentUser
UserBean
userBean
)
{
try
{
DiskFileCatalogueDto
diskFileCatalogueDto
=
diskFilesService
.
getFileCount
(
userBean
.
getEmpNum
());
return
ResultUtil
.
data
(
diskFileCatalogueDto
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
throw
new
CustomException
(
"获取我的文件空间大小异常"
);
}
}
@GetMapping
(
value
=
"/exportContract"
)
public
void
exportContract
(
@CurrentUser
UserBean
userBean
,
@ApiParam
(
"文件ID"
)
@RequestParam
(
required
=
true
)
Integer
fileId
,
HttpServletResponse
resp
)
{
if
(
fileId
==
null
||
fileId
<=
0
)
{
throw
new
CustomException
(
"下载失败,请选择文件下载"
);
}
DiskFiles
diskFiles
=
DiskFiles
.
builder
().
id
(
fileId
).
build
().
selectById
();
if
(
StringUtils
.
isEmpty
(
diskFiles
)){
throw
new
CustomException
(
"下载失败,文件不存在"
);
}
FileInputStream
fis
=
null
;
BufferedInputStream
bis
=
null
;
OutputStream
os
;
File
filePath
=
null
;
try
{
String
name
=
diskFiles
.
getTitle
()+
diskFiles
.
getFileType
();
resp
.
setContentType
(
"application/octet-stream"
);
resp
.
setHeader
(
"content-disposition"
,
"attachment; filename="
+
new
String
(
name
.
getBytes
(
"UTF8"
),
"ISO-8859-1"
));
resp
.
setCharacterEncoding
(
"UTF-8"
);
filePath
=
new
File
(
diskFiles
.
getDiskPath
());
byte
[]
buffer
=
new
byte
[
1024
];
fis
=
new
FileInputStream
(
filePath
);
bis
=
new
BufferedInputStream
(
fis
);
os
=
resp
.
getOutputStream
();
int
i
=
bis
.
read
(
buffer
);
while
(
i
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
i
);
i
=
bis
.
read
(
buffer
);
}
os
.
flush
();
DiskFilesLog
diskFilesLog
=
DiskFilesLog
.
builder
().
build
();
//新增 文件浏览记录
diskFilesLog
.
setFilePath
(
diskFiles
.
getUrlPath
());
diskFilesLog
.
setFilesId
(
diskFiles
.
getId
());
diskFilesLog
.
setFileSize
(
diskFiles
.
getFileSize
()
+
"B"
);
diskFilesLog
.
setTitle
(
diskFiles
.
getTitle
());
diskFilesLog
.
setType
(
JxglEnumInterface
.
DiskFilesLogType
.
DOWN_LOAD_LOG
.
getType
());
diskFilesLog
.
setUserId
(
userBean
.
getEmpNum
());
diskFilesLog
.
setUserName
(
userBean
.
getQyzxEmpLogin
().
getUsername
());
diskFilesLog
.
insert
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/main/java/cn/timer/api/controller/disk/sevice/DiskFilesService.java
View file @
59005c05
...
...
@@ -3,6 +3,7 @@ package cn.timer.api.controller.disk.sevice;
import
cn.timer.api.bean.disk.DiskCatalogue
;
import
cn.timer.api.bean.disk.DiskFiles
;
import
cn.timer.api.dto.disk.DiskCatalogueParam
;
import
cn.timer.api.dto.disk.DiskFileCatalogueDto
;
import
java.util.List
;
...
...
@@ -20,4 +21,11 @@ public interface DiskFilesService {
* @return
*/
List
<
DiskFiles
>
getDiskFiles
(
DiskCatalogueParam
diskCatalogueParam
);
/**
* 获取用户文件空间大小
* @param userId
* @return
*/
DiskFileCatalogueDto
getFileCount
(
Integer
userId
);
}
src/main/java/cn/timer/api/controller/disk/sevice/DiskFilesServiceImpl.java
View file @
59005c05
package
cn
.
timer
.
api
.
controller
.
disk
.
sevice
;
import
cn.timer.api.bean.disk.DiskCatalogue
;
import
cn.timer.api.bean.disk.DiskCatalogueFiles
;
import
cn.timer.api.bean.disk.DiskFiles
;
import
cn.timer.api.dao.disk.DiskCatalogueMapper
;
import
cn.timer.api.dao.disk.DiskFilesMapper
;
import
cn.timer.api.dto.disk.DiskCatalogueParam
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
cn.timer.api.dto.disk.DiskFileCatalogueDto
;
import
cn.timer.api.utils.FileUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.
Collection
Utils
;
import
org.springframework.util.
String
Utils
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author wuqingjun
...
...
@@ -33,4 +27,17 @@ public class DiskFilesServiceImpl implements DiskFilesService {
public
List
<
DiskFiles
>
getDiskFiles
(
DiskCatalogueParam
diskCatalogueParam
)
{
return
diskFilesMapper
.
selectListByParam
(
diskCatalogueParam
);
}
@Override
public
DiskFileCatalogueDto
getFileCount
(
Integer
userId
)
{
DiskFileCatalogueDto
dto
=
diskFilesMapper
.
selectFileCount
(
userId
);
if
(
StringUtils
.
isEmpty
(
dto
)){
dto
=
new
DiskFileCatalogueDto
();
}
dto
.
setShowCountSize
(
FileUtils
.
getSize
(
dto
.
getCountSize
()));
dto
.
setSize
(
1
*
1024
*
1024
*
1024L
);
//dto.setShowSize(FileUtils.getSize(dto.getSize()));
dto
.
setShowSize
(
"1G"
);
return
dto
;
}
}
src/main/java/cn/timer/api/dao/disk/DiskFilesMapper.java
View file @
59005c05
...
...
@@ -3,6 +3,7 @@ package cn.timer.api.dao.disk;
import
cn.timer.api.bean.disk.DiskFiles
;
import
cn.timer.api.dto.disk.DiskCatalogueParam
;
import
cn.timer.api.dto.disk.DiskFileCatalogueDto
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
...
...
@@ -26,5 +27,12 @@ public interface DiskFilesMapper extends BaseMapper<DiskFiles> {
* @return
*/
List
<
DiskFiles
>
selectListByParam
(
@Param
(
"param"
)
DiskCatalogueParam
diskCatalogueParam
);
/**
* 获取用户文件空间大小
* @param userId
* @return
*/
DiskFileCatalogueDto
selectFileCount
(
@Param
(
"userId"
)
Integer
userId
);
}
src/main/java/cn/timer/api/dto/disk/DiskFileCatalogueDto.java
0 → 100644
View file @
59005c05
package
cn
.
timer
.
api
.
dto
.
disk
;
import
cn.timer.api.config.exception.ValidationMsg
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2021-12-27 10:05:49
*/
@Data
public
class
DiskFileCatalogueDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1230022223946170921L
;
/**
* 所有文件总大小
*/
@ApiModelProperty
(
value
=
"文件总大小"
)
private
Long
countSize
;
/**
* 所有文件总大小 显示值MB,KB
*/
@ApiModelProperty
(
value
=
"文件总大小 显示值 带单位MB,KB"
)
private
String
showCountSize
;
/**
* 给定空间大小
*/
@ApiModelProperty
(
value
=
"给定空间大小 Byte"
)
private
Long
size
;
/**
* 给定空间大小 显示值MB,KB
*/
@ApiModelProperty
(
value
=
"给定空间大小 显示值 带单位MB,KB"
)
private
String
showSize
;
}
src/main/java/cn/timer/api/utils/FileUtils.java
View file @
59005c05
...
...
@@ -11,7 +11,7 @@ public class FileUtils {
* 获取文件的大小(返回到达的最高单位)
* 比如:1024Byte就不再用Byte
* 直接返回1KB
* 返回值精确到小数点后
3
位
* 返回值精确到小数点后
2
位
* @param size 文件大小
* @return 文件的大小 若文件不存在或者不是文件就返回 “”
*/
...
...
@@ -54,7 +54,7 @@ public class FileUtils {
default
:
unit
=
"ER"
;
}
String
format
=
String
.
format
(
"%.
3
f"
,
s
);
String
format
=
String
.
format
(
"%.
2
f"
,
s
);
return
format
+
unit
;
}
return
""
;
...
...
src/main/resources/mapping/disk/DiskFilesMapper.xml
View file @
59005c05
...
...
@@ -32,4 +32,8 @@
ORDER BY f.create_time DESC
</select>
<select
id=
"selectFileCount"
resultType=
"cn.timer.api.dto.disk.DiskFileCatalogueDto"
>
SELECT COALESCE(sum(file_size),0) as countSize FROM `disk_files` where create_user_id = #{userId} AND delete_flag=0
</select>
</mapper>
\ No newline at end of file
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