Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ac49f204
authored
Sep 28, 2023
by
李小龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:
parent
a8ef199e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
387 additions
and
1 deletions
saas-module/src/main/java/com/makeit/controller/sys/SaasFileController.java
saas-module/src/main/java/com/makeit/controller/sys/SaasUploadController.java
server-common/src/main/java/com/makeit/module/admin/dto/plat/PlatRoleDTOVO.java
server-service/src/main/java/com/makeit/entity/platform/auth/PlatRoleOrg.java
server-service/src/main/java/com/makeit/service/platform/auth/impl/PlatRoleServiceImpl.java
saas-module/src/main/java/com/makeit/controller/sys/SaasFileController.java
0 → 100644
View file @
ac49f204
package
com
.
makeit
.
controller
.
sys
;
import
com.makeit.common.dto.BaseIdDTO
;
import
com.makeit.common.response.ApiResponseEntity
;
import
com.makeit.common.response.ApiResponseUtils
;
import
com.makeit.module.system.dto.SysFileDTOVO
;
import
com.makeit.module.system.entity.SysFile
;
import
com.makeit.module.system.service.SysFileService
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.storage.AccessoryRepository
;
import
com.makeit.utils.storage.DataWithMeta
;
import
com.makeit.utils.sys.FileUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.util.UriUtils
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.util.Arrays
;
import
java.util.List
;
@Api
(
tags
=
"saas-文件"
)
@RestController
@RequestMapping
(
"/saas/sys/file"
)
public
class
SaasFileController
{
@Autowired
public
AccessoryRepository
accessoryRepository
;
@Autowired
private
SysFileService
sysFileService
;
@ApiOperation
(
"获取文件临时路径路径"
)
@PostMapping
(
"getFileTmp"
)
public
ApiResponseEntity
<
SysFileDTOVO
>
getFileTmp
(
@RequestBody
BaseIdDTO
baseIdDTO
)
{
SysFileDTOVO
sysFileDTOVO
=
BeanDtoVoUtils
.
convert
(
sysFileService
.
getById
(
baseIdDTO
.
getId
()),
SysFileDTOVO
.
class
);
sysFileDTOVO
.
setFullUrl
(
accessoryRepository
.
getTmpURL
(
sysFileDTOVO
.
getUrl
()));
return
ApiResponseUtils
.
success
(
sysFileDTOVO
);
}
@ApiOperation
(
"获取文件路径"
)
@PostMapping
(
"getFile"
)
public
ApiResponseEntity
<
List
<
SysFileDTOVO
>>
getFile
(
@RequestBody
BaseIdDTO
baseIdDTO
)
{
return
ApiResponseUtils
.
success
(
FileUtil
.
convertMultiply
(
Arrays
.
asList
(
baseIdDTO
.
getId
())).
get
(
0
));
}
@ApiOperation
(
"获取文件路径集合"
)
@PostMapping
(
"getFileList"
)
public
ApiResponseEntity
<
List
<
List
<
SysFileDTOVO
>>>
getFile
(
@RequestBody
List
<
String
>
list
)
{
return
ApiResponseUtils
.
success
(
FileUtil
.
convertMultiply
(
list
));
}
//这种方式可以 只是不能设置下载文件名
// @ApiOperation("下载文件")
// @PostMapping("downloadFile")
// public byte[] downloadFile(@RequestBody BaseIdDTO baseIdDTO) {
// return aliyunOSSRepository.getBytes(UriUtils.decode(StringUtils.substringAfter(sysFileService.getById(baseIdDTO.getId()).getUrl(), "oss/"), "UTF-8"));
// }
void
downloadFile
(
HttpServletResponse
response
,
String
id
)
throws
IOException
{
SysFile
sysFile
=
sysFileService
.
getById
(
id
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
// 设置文件头:最后一个参数是设置下载文件名
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
sysFile
.
getFileName
(),
"UTF-8"
));
OutputStream
outputStream
=
response
.
getOutputStream
();
outputStream
.
write
(
accessoryRepository
.
getBytes
(
UriUtils
.
decode
(
StringUtils
.
substringAfter
(
sysFile
.
getUrl
(),
"oss/"
),
"UTF-8"
)));
}
//这样是可以
// private void previewFile(HttpServletResponse response, String id) throws IOException {
//
// SysFile sysFile = sysFileService.getById(id);
//
// response.setCharacterEncoding("UTF-8");
// response.setContentType("application/octet-stream");
// // 设置文件头:最后一个参数是设置下载文件名
// response.setHeader("Content-disposition", "inline;filename=" + URLEncoder.encode(sysFile.getFileName(), "UTF-8"));
//
// String suffix = sysFile.getUrl().substring(sysFile.getUrl().lastIndexOf("."));
//
// Map<String, String> map = new HashMap<>(16);
// map.put(".pdf", "application/pdf");
// map.put(".png", "image/png");
// map.put(".jpg", "image/jpg");
// map.put(".jpeg", "image/jpeg");
//
// String contentType = map.get(suffix);
// if (StringUtils.isNotBlank(contentType)) {
// response.setContentType(contentType);
// }
//
// OutputStream outputStream = response.getOutputStream();
// outputStream.write(aliyunOSSRepository.getBytes(UriUtils.decode(StringUtils.substringAfter(sysFile.getUrl(), "oss/"), "UTF-8")));
// outputStream.close();
// }
private
void
previewFile
(
HttpServletResponse
response
,
String
id
)
throws
IOException
{
SysFile
sysFile
=
sysFileService
.
getById
(
id
);
response
.
setCharacterEncoding
(
"UTF-8"
);
// 设置文件头:最后一个参数是设置下载文件名
response
.
setHeader
(
"Content-disposition"
,
"inline;filename="
+
URLEncoder
.
encode
(
sysFile
.
getFileName
(),
"UTF-8"
));
DataWithMeta
dataWithMeta
=
accessoryRepository
.
getDataWithMeta
(
UriUtils
.
decode
(
StringUtils
.
substringAfter
(
sysFile
.
getUrl
(),
"oss/"
),
"UTF-8"
));
response
.
setContentType
(
dataWithMeta
.
getContentType
());
OutputStream
outputStream
=
response
.
getOutputStream
();
outputStream
.
write
(
dataWithMeta
.
getBytes
());
outputStream
.
close
();
}
@ApiOperation
(
"下载文件(json id)"
)
@RequestMapping
(
value
=
"downloadFile"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
void
downloadFile
(
HttpServletResponse
response
,
@RequestBody
BaseIdDTO
baseIdDTO
)
throws
IOException
{
downloadFile
(
response
,
baseIdDTO
.
getId
());
}
@ApiOperation
(
"预览文件(json id)"
)
@RequestMapping
(
value
=
"previewFile"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
void
previewFile
(
HttpServletResponse
response
,
@RequestBody
BaseIdDTO
baseIdDTO
)
throws
IOException
{
previewFile
(
response
,
baseIdDTO
.
getId
());
}
@ApiOperation
(
"下载文件"
)
@RequestMapping
(
value
=
"downloadFileParam"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
void
downloadFileParam
(
HttpServletResponse
response
,
String
id
)
throws
IOException
{
downloadFile
(
response
,
id
);
}
@ApiOperation
(
"预览文件"
)
@RequestMapping
(
value
=
"previewFileParam"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
void
previewFileParam
(
HttpServletResponse
response
,
String
id
)
throws
IOException
{
previewFile
(
response
,
id
);
}
@ApiOperation
(
"批量保存"
)
@PostMapping
(
"addList"
)
public
ApiResponseEntity
<?>
addList
(
@RequestBody
List
<
SysFileDTOVO
>
list
)
{
List
<
SysFile
>
fileList
=
BeanDtoVoUtils
.
listVo
(
list
,
SysFile
.
class
);
sysFileService
.
saveBatch
(
fileList
);
return
ApiResponseUtils
.
success
(
StreamUtil
.
map
(
fileList
,
SysFile:
:
getId
));
}
}
saas-module/src/main/java/com/makeit/controller/sys/SaasUploadController.java
0 → 100644
View file @
ac49f204
package
com
.
makeit
.
controller
.
sys
;
import
com.makeit.common.response.ApiResponseEntity
;
import
com.makeit.common.response.ApiResponseUtils
;
import
com.makeit.module.system.dto.SysFileDTOVO
;
import
com.makeit.module.system.dto.UploadKeyDTO
;
import
com.makeit.module.system.entity.SysFile
;
import
com.makeit.module.system.service.SysFileService
;
import
com.makeit.utils.contract.word.WordConverterUtil
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.storage.HwObsRepository
;
import
com.makeit.utils.storage.PostSignature
;
import
com.makeit.utils.sys.FileUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.StopWatch
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
/**
* @author liuhb
* @date 2021/12/14
*/
@Api
(
tags
=
"saas-文件"
)
@RestController
@RequestMapping
(
"/saas/storage"
)
public
class
SaasUploadController
extends
BaseController
{
@Autowired
private
SysFileService
sysFileService
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SaasUploadController
.
class
);
// @ApiOperation(value = "获取key")
// @PostMapping("getKey")
// public String getKey(@ApiParam(value = "originalFilename") String originalFilename) {
// String fullPath = getFullPath(null, originalFilename);
// return getUri(accessoryRepository.getKey(fullPath));
// }
@ApiOperation
(
value
=
"获取key"
)
@PostMapping
(
"getKey"
)
public
SysFileDTOVO
getKey
(
@RequestBody
UploadKeyDTO
dto
)
{
SysFileDTOVO
sysFile
=
new
SysFileDTOVO
();
sysFile
.
setFileName
(
dto
.
getOriginalFilename
());
String
fullPath
=
getFullPath
(
null
,
dto
.
getOriginalFilename
());
sysFile
.
setUrl
(
getUri
(
HwObsRepository
.
APIURI
+
accessoryRepository
.
getKey
(
fullPath
)));
sysFile
.
setKey
(
accessoryRepository
.
getKey
(
fullPath
));
return
sysFile
;
}
@ApiOperation
(
value
=
"获取签名"
)
@PostMapping
(
"getSignature"
)
public
PostSignature
getPostSignature
()
{
return
accessoryRepository
.
getPostSignature
();
}
private
String
replaceSuffix
(
String
name
)
{
int
index
=
name
.
lastIndexOf
(
"."
);
return
name
.
substring
(
0
,
index
)
+
".pdf"
;
}
private
List
<
SysFile
>
uploadInternal
(
List
<
MultipartFile
>
files
,
String
convertToPdf
)
{
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
();
List
<
SysFile
>
sysFileList
=
StreamUtil
.
map
(
files
,
e
->
{
try
{
SysFile
sysFile
=
new
SysFile
();
sysFile
.
setFileName
(
e
.
getOriginalFilename
());
String
fullPath
=
getFullPath
(
null
,
e
.
getOriginalFilename
());
sysFile
.
setUrl
(
getUri
(
storageRepository
(
"1"
).
save
(
e
.
getBytes
(),
fullPath
)));
if
(
"1"
.
equals
(
convertToPdf
))
{
fullPath
=
getFullPath
(
null
,
replaceSuffix
(
e
.
getOriginalFilename
()));
sysFile
.
setPdfUrl
(
getUri
(
storageRepository
(
"1"
).
save
(
WordConverterUtil
.
convert
(
e
.
getInputStream
()),
fullPath
)));
}
sysFile
.
setMime
(
e
.
getContentType
());
return
sysFile
;
}
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
});
sysFileService
.
saveBatch
(
sysFileList
);
stopWatch
.
stop
();
logger
.
info
(
"文件上传耗时:{} ms"
,
stopWatch
.
getLastTaskTimeMillis
());
return
sysFileList
;
}
private
List
<
SysFile
>
convertAndUploadInternal
(
List
<
MultipartFile
>
files
)
{
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
();
List
<
SysFile
>
sysFileList
=
StreamUtil
.
map
(
files
,
e
->
{
try
{
SysFile
sysFile
=
new
SysFile
();
sysFile
.
setFileName
(
replaceSuffix
(
e
.
getOriginalFilename
()));
String
fullPath
=
getFullPath
(
null
,
replaceSuffix
(
e
.
getOriginalFilename
()));
sysFile
.
setUrl
(
getUri
(
storageRepository
(
"1"
).
save
(
WordConverterUtil
.
convert
(
e
.
getInputStream
()),
fullPath
)));
sysFile
.
setMime
(
e
.
getContentType
());
return
sysFile
;
}
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
});
sysFileService
.
saveBatch
(
sysFileList
);
stopWatch
.
stop
();
logger
.
info
(
"文件上传耗时:{} ms"
,
stopWatch
.
getLastTaskTimeMillis
());
return
sysFileList
;
}
@ApiOperation
(
value
=
"统一文件上传"
)
@PostMapping
(
"uploadFile"
)
public
ApiResponseEntity
<
List
<
String
>>
uploadFile
(
@ApiParam
(
value
=
"convertToPdf"
)
@RequestParam
(
defaultValue
=
"0"
)
String
convertToPdf
,
@ApiParam
(
value
=
"files"
)
List
<
MultipartFile
>
files
)
{
List
<
SysFile
>
sysFileList
=
uploadInternal
(
files
,
convertToPdf
);
return
ApiResponseUtils
.
success
(
StreamUtil
.
map
(
sysFileList
,
SysFile:
:
getId
));
}
@ApiOperation
(
value
=
"统一文件上传返回路径"
)
@PostMapping
(
"uploadFileUrl"
)
public
ApiResponseEntity
<
List
<
SysFileDTOVO
>>
uploadFileUrl
(
@ApiParam
(
value
=
"convertToPdf"
)
@RequestParam
(
defaultValue
=
"0"
)
String
convertToPdf
,
@ApiParam
(
value
=
"files"
)
List
<
MultipartFile
>
files
)
{
List
<
SysFile
>
sysFileList
=
uploadInternal
(
files
,
convertToPdf
);
List
<
SysFileDTOVO
>
voList
=
BeanDtoVoUtils
.
listVo
(
sysFileList
,
SysFileDTOVO
.
class
);
FileUtil
.
fillFullUrl
(
voList
);
FileUtil
.
fillPdfFullUrl
(
voList
);
return
ApiResponseUtils
.
success
(
voList
);
}
@ApiOperation
(
value
=
"统一转换为pdf后上传"
)
@PostMapping
(
"convertAndUploadFile"
)
public
ApiResponseEntity
<
List
<
String
>>
convertAndUploadFile
(
@ApiParam
(
value
=
"files"
)
List
<
MultipartFile
>
files
)
{
List
<
SysFile
>
sysFileList
=
convertAndUploadInternal
(
files
);
return
ApiResponseUtils
.
success
(
StreamUtil
.
map
(
sysFileList
,
SysFile:
:
getId
));
}
@ApiOperation
(
value
=
"统一转换为pdf后上传返回路径"
)
@PostMapping
(
"convertAndUploadFileUrl"
)
public
ApiResponseEntity
<
List
<
SysFileDTOVO
>>
convertAndUploadFileUrl
(
@ApiParam
(
value
=
"files"
)
List
<
MultipartFile
>
files
)
{
List
<
SysFile
>
sysFileList
=
convertAndUploadInternal
(
files
);
List
<
SysFileDTOVO
>
voList
=
BeanDtoVoUtils
.
listVo
(
sysFileList
,
SysFileDTOVO
.
class
);
FileUtil
.
fillFullUrl
(
voList
);
//FileUtil.fillPdfFullUrl(voList);
return
ApiResponseUtils
.
success
(
voList
);
}
//下面两个的作用
//返回给前端的路径 要基于下面两个转发
@ApiOperation
(
"获取oss文件"
)
@RequestMapping
(
value
=
"oss/**"
,
method
=
RequestMethod
.
GET
)
public
void
getOssFile
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
Exception
{
// String filepath = req.getRequestURI();
// filepath = UriUtils.decode(StringUtils.substringAfter(filepath, "oss"), "UTF-8");
// //.toString().split("\\?")[0];
// resp.sendRedirect(accessoryRepository.getPermanentURL(filepath));
resp
.
sendRedirect
(
accessoryRepository
.
getPermanentURL
(
req
.
getRequestURI
()));
}
@ApiOperation
(
"获取oss文件(临时路径)"
)
@RequestMapping
(
value
=
"tmp/oss/**"
,
method
=
RequestMethod
.
GET
)
public
void
getOssFileTmpPath
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
Exception
{
// String filepath = req.getRequestURI();
// filepath = UriUtils.decode(StringUtils.substringAfter(filepath, "tmp/oss"), "UTF-8");
// //.toString().split("\\?")[0];
// resp.sendRedirect(accessoryRepository.getTmpURL(filepath));
resp
.
sendRedirect
(
accessoryRepository
.
getTmpURL
(
req
.
getRequestURI
()));
}
//private String name;
// private String nameOrigin;
// private String extName;
// private Long fileSize;
// private String storeType;//video audio img pdf等
// private String relativePath;
}
server-common/src/main/java/com/makeit/module/admin/dto/plat/PlatRoleDTOVO.java
View file @
ac49f204
...
@@ -28,6 +28,8 @@ public class PlatRoleDTOVO extends BaseOrgDTO implements Serializable {
...
@@ -28,6 +28,8 @@ public class PlatRoleDTOVO extends BaseOrgDTO implements Serializable {
@ApiModelProperty
(
value
=
"部门名称"
)
@ApiModelProperty
(
value
=
"部门名称"
)
private
String
deptName
;
private
String
deptName
;
private
String
orgPath
;
@TableField
(
exist
=
false
)
@TableField
(
exist
=
false
)
@ApiModelProperty
(
value
=
"角色名称集合"
)
@ApiModelProperty
(
value
=
"角色名称集合"
)
private
List
<
String
>
nameList
;
private
List
<
String
>
nameList
;
...
...
server-service/src/main/java/com/makeit/entity/platform/auth/PlatRoleOrg.java
View file @
ac49f204
...
@@ -6,10 +6,12 @@ import lombok.Data;
...
@@ -6,10 +6,12 @@ import lombok.Data;
/**
/**
* 租户端角色部门关联表
* 租户端角色部门关联表
* 角色和所属部门 一对一
* @TableName plat_role_org
* @TableName plat_role_org
*/
*/
@TableName
(
value
=
"plat_role_org"
)
@TableName
(
value
=
"plat_role_org"
)
@Data
@Data
@Deprecated
public
class
PlatRoleOrg
extends
BaseBusEntity
{
public
class
PlatRoleOrg
extends
BaseBusEntity
{
/**
/**
...
...
server-service/src/main/java/com/makeit/service/platform/auth/impl/PlatRoleServiceImpl.java
View file @
ac49f204
...
@@ -186,7 +186,10 @@ implements PlatRoleService {
...
@@ -186,7 +186,10 @@ implements PlatRoleService {
PlatRoleDTOVO
vo
=
BeanDtoVoUtils
.
convert
(
getById
(
id
),
PlatRoleDTOVO
.
class
);
PlatRoleDTOVO
vo
=
BeanDtoVoUtils
.
convert
(
getById
(
id
),
PlatRoleDTOVO
.
class
);
JoinUtil
.
join
(
Arrays
.
asList
(
vo
),
platOrgService
,
PlatRoleDTOVO:
:
getOrgId
,
PlatOrg:
:
getId
,
(
r
,
e
)
->
r
.
setDeptName
(
e
.
getName
()));
JoinUtil
.
join
(
Arrays
.
asList
(
vo
),
platOrgService
,
PlatRoleDTOVO:
:
getOrgId
,
PlatOrg:
:
getId
,
(
r
,
e
)
->{
r
.
setDeptName
(
e
.
getName
());
r
.
setOrgPath
(
e
.
getPath
()+
","
+
e
.
getId
());
}
);
List
<
PlatMenuDTOVO
>
assignMenuDTO
=
getAssignMenuDTO
(
id
);
List
<
PlatMenuDTOVO
>
assignMenuDTO
=
getAssignMenuDTO
(
id
);
List
<
PlatMenuDTOVO
>
tree
=
tree
(
assignMenuDTO
);
List
<
PlatMenuDTOVO
>
tree
=
tree
(
assignMenuDTO
);
...
...
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