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
c873e96f
authored
Nov 30, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat:引入oss
parent
9e3c041e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
297 additions
and
8 deletions
saas-module/src/main/java/com/makeit/controller/device/SaasDeviceController.java
server-common/src/main/java/com/makeit/oss/AccessoryRepository.java
server-common/src/main/java/com/makeit/oss/AliyunOSSRepository.java
server-common/src/main/java/com/makeit/utils/FileUtils.java
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
server-service/src/main/java/com/makeit/vo/platform/device/PlatDeviceListVO.java
server-web/src/main/resources/application-dev.yml
server-web/src/main/resources/application-test.yml
saas-module/src/main/java/com/makeit/controller/device/SaasDeviceController.java
View file @
c873e96f
...
@@ -116,7 +116,7 @@ public class SaasDeviceController {
...
@@ -116,7 +116,7 @@ public class SaasDeviceController {
@AuthIgnore
@AuthIgnore
public
ApiResponseEntity
devicePushLog
(
@RequestParam
(
value
=
"file"
,
required
=
false
)
MultipartFile
multipartFile
,
public
ApiResponseEntity
devicePushLog
(
@RequestParam
(
value
=
"file"
,
required
=
false
)
MultipartFile
multipartFile
,
@RequestParam
(
value
=
"deviceId"
)
String
deviceId
)
{
@RequestParam
(
value
=
"deviceId"
)
String
deviceId
)
{
platDeviceService
.
devicePushLog
(
multipartFile
);
platDeviceService
.
devicePushLog
(
multipartFile
,
deviceId
);
return
ApiResponseUtils
.
success
();
return
ApiResponseUtils
.
success
();
}
}
...
...
server-common/src/main/java/com/makeit/oss/AccessoryRepository.java
0 → 100644
View file @
c873e96f
package
com
.
makeit
.
oss
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.validation.constraints.NotNull
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.net.URL
;
public
interface
AccessoryRepository
{
/**
* 根据保存的相对路径获取存储的文件对象
*
* @return java.io.File
* @Author 滕鑫源
* @Date 2020/8/20 14:46
* @Param path
* @Param fileName
**/
File
get
(
String
path
,
String
fileName
)
throws
FileNotFoundException
;
URL
getURL
(
String
path
,
String
fileName
)
throws
FileNotFoundException
;
/**
* 根据保存的相对路径获取可下载文件的完整http路径
*
* @Author 滕鑫源
* @Date 2020/8/26 10:46
* @param path
* @param fileName
* @return
**/
// String getUrl(String path, String fileName);
/**
* 根据给定的多个相对路径获取多个存储的文件对象
*
* @Author 滕鑫源
* @Date 2020/8/26 10:46
* @param urls
* @return
**/
// List<File> findList(String... urls);
/**
* 保存文件对象
*
* @Author 滕鑫源
* @Date 2020/8/20 14:47
* @Param file
* @Param fileName
**/
File
save
(
File
file
,
String
path
,
String
fileName
);
/**
* 保存文件流文件为文件对象
*
* @Author 滕鑫源
* @Date 2020/8/20 14:49
* @Param file
* @Param fileName
**/
File
save
(
MultipartFile
file
,
String
path
,
String
fileName
);
/**
* 保存输入流为文件对象
*
* @Author 滕鑫源
* @Date 2020/8/20 14:47
* @Param file
* @Param fileName
**/
File
save
(
InputStream
is
,
String
path
,
@NotNull
String
fileName
);
}
server-common/src/main/java/com/makeit/oss/AliyunOSSRepository.java
0 → 100644
View file @
c873e96f
package
com
.
makeit
.
oss
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
com.aliyun.oss.OSSException
;
import
com.aliyun.oss.model.OSSObject
;
import
com.aliyun.oss.model.ObjectMetadata
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.makeit.utils.FileUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.validation.constraints.NotNull
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
/**
* aliyunOSS存储服务类
*
* @author 滕鑫源
* @date 2020/8/20 14:42
*/
@Component
public
class
AliyunOSSRepository
implements
AccessoryRepository
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Value
(
"${aliyun.oss.baseDir}"
)
private
String
accessoryBaseDir
;
@Value
(
"${aliyun.oss.endpoint}"
)
private
String
endpoint
;
@Value
(
"${aliyun.oss.accessKey}"
)
private
String
accessKeyId
;
@Value
(
"${aliyun.oss.secretKey}"
)
private
String
accessKeySecret
;
@Value
(
"${aliyun.oss.bucket}"
)
private
String
bucketName
;
@Override
public
File
get
(
String
path
,
String
fileName
)
throws
FileNotFoundException
{
logger
.
debug
(
"开始从aliyun-oss获取文件: {}{}{}"
,
path
,
"/"
,
fileName
);
long
begin
=
System
.
currentTimeMillis
();
InputStream
is
=
null
;
try
{
if
(
path
==
null
)
{
path
=
""
;
}
OSS
client
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
OSSObject
object
=
client
.
getObject
(
bucketName
,
accessoryBaseDir
+
"/"
+
path
+
"/"
+
fileName
);
is
=
object
.
getObjectContent
();
File
localTempDir
=
new
File
(
FileUtils
.
getTempDirectory
()
+
File
.
separator
+
accessoryBaseDir
+
File
.
separator
+
path
);
FileUtils
.
createDirectory
(
localTempDir
.
getPath
());
File
dest
=
new
File
(
localTempDir
,
fileName
);
FileUtils
.
copyInputStreamToFile
(
is
,
dest
);
client
.
shutdown
();
return
dest
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
OSSException
e
)
{
throw
new
FileNotFoundException
(
"指定的文件不存在"
);
}
finally
{
if
(
is
!=
null
){
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
logger
.
debug
(
"完成从aliyun-oss获取文件: {}"
,
System
.
currentTimeMillis
()
-
begin
);
}
return
null
;
}
@Override
public
URL
getURL
(
String
path
,
String
fileName
)
throws
FileNotFoundException
{
logger
.
debug
(
"开始从aliyun-oss获取文件: {}{}{}"
,
path
,
"/"
,
fileName
);
long
begin
=
System
.
currentTimeMillis
();
URL
downloadURL
=
null
;
try
{
if
(
path
==
null
)
{
path
=
""
;
}
OSS
client
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
Date
expireDate
=
DateUtils
.
addHours
(
new
Date
(),
1
);
downloadURL
=
client
.
generatePresignedUrl
(
bucketName
,
accessoryBaseDir
+
"/"
+
path
+
"/"
+
fileName
,
expireDate
);
return
downloadURL
;
}
catch
(
OSSException
e
)
{
throw
new
FileNotFoundException
(
"指定的文件不存在"
);
}
finally
{
logger
.
debug
(
"完成从aliyun-oss获取文件临时授权路径 {}, 耗时: {}"
,
downloadURL
,
System
.
currentTimeMillis
()
-
begin
);
}
}
/**
* 保存文件对象
*
* @param file
* @param path
* @param fileName
* @Author 滕鑫源
* @Date 2020/8/20 14:47
*/
@Override
public
File
save
(
File
file
,
String
path
,
String
fileName
)
{
logger
.
debug
(
"开始向aliyun-oss保存文件: {}"
,
fileName
);
long
begin
=
System
.
currentTimeMillis
();
OSS
client
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
ObjectMetadata
meta
=
new
ObjectMetadata
();
meta
.
setContentDisposition
(
"attachment;filename="
+
new
String
(
fileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
accessoryBaseDir
+
"/"
+
path
+
"/"
+
fileName
,
file
,
meta
);
client
.
putObject
(
putObjectRequest
);
client
.
shutdown
();
logger
.
debug
(
"完成向aliyun-oss保存文件: {}"
,
System
.
currentTimeMillis
()
-
begin
);
return
file
;
}
/**
* 保存文件流文件为文件对象
*
* @param file
* @param path
* @param fileName
* @Author 滕鑫源
* @Date 2020/8/20 14:49
*/
@Override
public
File
save
(
MultipartFile
file
,
String
path
,
String
fileName
)
{
logger
.
debug
(
"开始向aliyun-oss保存文件: {}"
,
fileName
);
long
begin
=
System
.
currentTimeMillis
();
try
{
OSS
client
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
ObjectMetadata
meta
=
new
ObjectMetadata
();
meta
.
setContentDisposition
(
"attachment;filename="
+
new
String
(
fileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
accessoryBaseDir
+
"/"
+
path
+
(
path
.
endsWith
(
"/"
)
?
""
:
"/"
)
+
fileName
,
file
.
getInputStream
(),
meta
);
client
.
putObject
(
putObjectRequest
);
client
.
shutdown
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
logger
.
debug
(
"完成向aliyun-oss保存文件: {}"
,
System
.
currentTimeMillis
()
-
begin
);
return
null
;
}
/**
* 保存输入流为文件对象
*
* @param is
* @param path
* @param fileName
* @Author 滕鑫源
* @Date 2020/8/20 14:47
*/
@Override
public
File
save
(
InputStream
is
,
String
path
,
@NotNull
String
fileName
)
{
logger
.
debug
(
"开始向aliyun-oss保存文件: {}"
,
fileName
);
long
begin
=
System
.
currentTimeMillis
();
try
{
OSS
client
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
ObjectMetadata
meta
=
new
ObjectMetadata
();
meta
.
setContentDisposition
(
"attachment;filename="
+
new
String
(
fileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
accessoryBaseDir
+
"/"
+
path
+
(
path
.
endsWith
(
"/"
)
?
""
:
"/"
)
+
fileName
,
is
,
meta
);
client
.
putObject
(
putObjectRequest
);
client
.
shutdown
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
logger
.
debug
(
"完成向aliyun-oss保存文件: {}"
,
System
.
currentTimeMillis
()
-
begin
);
return
null
;
}
}
server-common/src/main/java/com/makeit/utils/FileUtils.java
0 → 100644
View file @
c873e96f
This diff is collapsed.
Click to expand it.
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
View file @
c873e96f
...
@@ -90,5 +90,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
...
@@ -90,5 +90,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatAlarmCallDeviceVO
callingDevice
(
PlatCallingDeviceDTO
dto
);
PlatAlarmCallDeviceVO
callingDevice
(
PlatCallingDeviceDTO
dto
);
void
devicePushLog
(
MultipartFile
multipartFile
);
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
);
}
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
c873e96f
...
@@ -44,8 +44,8 @@ import com.makeit.module.iot.vo.DeviceProperties;
...
@@ -44,8 +44,8 @@ import com.makeit.module.iot.vo.DeviceProperties;
import
com.makeit.module.iot.vo.DeviceState
;
import
com.makeit.module.iot.vo.DeviceState
;
import
com.makeit.module.system.service.SysDictionaryCategoryService
;
import
com.makeit.module.system.service.SysDictionaryCategoryService
;
import
com.makeit.module.system.vo.DictionaryVo
;
import
com.makeit.module.system.vo.DictionaryVo
;
import
com.makeit.oss.AliyunOSSRepository
;
import
com.makeit.service.platform.auth.PlatOrgService
;
import
com.makeit.service.platform.auth.PlatOrgService
;
import
com.makeit.service.platform.auth.PlatRoleService
;
import
com.makeit.service.platform.device.PlatDeviceOtherService
;
import
com.makeit.service.platform.device.PlatDeviceOtherService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.elder.PlatElderService
;
import
com.makeit.service.platform.elder.PlatElderService
;
...
@@ -60,17 +60,14 @@ import com.makeit.shengwang.agora.service.ShengwangService;
...
@@ -60,17 +60,14 @@ import com.makeit.shengwang.agora.service.ShengwangService;
import
com.makeit.shengwang.agora.vo.PlatAlarmCallDeviceVO
;
import
com.makeit.shengwang.agora.vo.PlatAlarmCallDeviceVO
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
import
com.makeit.utils.data.convert.BeanDtoVoUtils
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.data.convert.PageUtil
;
import
com.makeit.utils.data.convert.PageUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.old.StringUtils
;
import
com.makeit.utils.old.StringUtils
;
import
com.makeit.utils.request.RequestUtil
;
import
com.makeit.utils.sql.join.JoinUtil
;
import
com.makeit.utils.sql.join.JoinUtil
;
import
com.makeit.vo.platform.device.PlatChildDeviceListVO
;
import
com.makeit.vo.platform.device.PlatChildDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceActiveVO
;
import
com.makeit.vo.platform.device.PlatDeviceActiveVO
;
import
com.makeit.vo.platform.device.PlatDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
...
@@ -130,6 +127,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
...
@@ -130,6 +127,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private
ShengwangService
shengwangService
;
private
ShengwangService
shengwangService
;
@Autowired
@Autowired
private
ShengwangProperties
shengwangProperties
;
private
ShengwangProperties
shengwangProperties
;
@Autowired
private
AliyunOSSRepository
aliyunOSSRepository
;
@Override
@Override
public
PageVO
<
PlatDeviceListVO
>
page
(
PageReqDTO
<
PlatDeviceQueryDTO
>
pageReqDTO
)
{
public
PageVO
<
PlatDeviceListVO
>
page
(
PageReqDTO
<
PlatDeviceQueryDTO
>
pageReqDTO
)
{
...
@@ -837,7 +836,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
...
@@ -837,7 +836,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
}
@Override
@Override
public
void
devicePushLog
(
MultipartFile
multipartFile
)
{
public
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
)
{
log
.
info
(
"接受到设备上传的文件,设备id:{}"
,
deviceId
);
aliyunOSSRepository
.
save
(
multipartFile
,
deviceId
,
multipartFile
.
getOriginalFilename
());
}
}
}
}
server-service/src/main/java/com/makeit/vo/platform/device/PlatDeviceListVO.java
View file @
c873e96f
...
@@ -93,6 +93,8 @@ public class PlatDeviceListVO extends BaseTenantDTO {
...
@@ -93,6 +93,8 @@ public class PlatDeviceListVO extends BaseTenantDTO {
private
String
roomName
;
private
String
roomName
;
private
String
bedName
;
private
String
bedName
;
@ApiModelProperty
(
value
=
"许可证"
)
private
String
deviceLicense
;
}
}
server-web/src/main/resources/application-dev.yml
View file @
c873e96f
...
@@ -62,6 +62,11 @@ mybatis-plus:
...
@@ -62,6 +62,11 @@ mybatis-plus:
configuration
:
configuration
:
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
logging
:
level
:
root
:
debug
file
:
file
:
filePath
:
file
filePath
:
file
file
:
D:/pro/${file.filePath}
file
:
D:/pro/${file.filePath}
...
@@ -163,6 +168,16 @@ shengwang:
...
@@ -163,6 +168,16 @@ shengwang:
pid
:
9851781E9E31453DA3C572A4A4AF9402
pid
:
9851781E9E31453DA3C572A4A4AF9402
aliyun
:
oss
:
accessKey
:
LTAI5tMjaFCiaYYLmtCLiuMj
secretKey
:
Oq1925mQ8663nxaf83MyoOGAbVM71H
endpoint
:
oss-cn-shenzhen.aliyuncs.com
bucket
:
kangyang-oss
baseDir
:
kangyang
server-web/src/main/resources/application-test.yml
View file @
c873e96f
...
@@ -157,3 +157,12 @@ shengwang:
...
@@ -157,3 +157,12 @@ shengwang:
customerSecret
:
bd81828a133140a58dfb04e9d80eba43
customerSecret
:
bd81828a133140a58dfb04e9d80eba43
pid
:
9851781E9E31453DA3C572A4A4AF9402
pid
:
9851781E9E31453DA3C572A4A4AF9402
aliyun
:
oss
:
accessKey
:
LTAI5tMjaFCiaYYLmtCLiuMj
secretKey
:
Oq1925mQ8663nxaf83MyoOGAbVM71H
endpoint
:
oss-cn-shenzhen.aliyuncs.com
bucket
:
kangyang-oss
baseDir
:
kangyang
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