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
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
786 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 {
@AuthIgnore
public
ApiResponseEntity
devicePushLog
(
@RequestParam
(
value
=
"file"
,
required
=
false
)
MultipartFile
multipartFile
,
@RequestParam
(
value
=
"deviceId"
)
String
deviceId
)
{
platDeviceService
.
devicePushLog
(
multipartFile
);
platDeviceService
.
devicePushLog
(
multipartFile
,
deviceId
);
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
/**
* Copyright © 2021-2026 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package
com
.
makeit
.
utils
;
import
cn.hutool.core.util.StrUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
/**
* 文件操作工具类
* 实现文件的创建、删除、复制、压缩、解压以及目录的创建、删除、复制、压缩解压等功能
* @author jeeplus
* @version 2021-06-21
*/
public
class
FileUtils
extends
org
.
apache
.
commons
.
io
.
FileUtils
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
FileUtils
.
class
);
/**
* 判断是否是文件
* @param source
*/
public
static
boolean
isFile
(
String
source
)
{
return
new
File
(
source
).
isFile
();
}
/**
* 判断是否是目录
* @param source
*/
public
static
boolean
isFolder
(
String
source
)
{
return
new
File
(
source
).
isDirectory
();
}
/**
* 复制单个文件,如果目标文件存在,则不覆盖
* @param srcFileName 待复制的文件名
* @param descFileName 目标文件名
* @return 如果复制成功,则返回true,否则返回false
*/
public
static
boolean
copyFile
(
String
srcFileName
,
String
descFileName
)
{
return
FileUtils
.
copyFileCover
(
srcFileName
,
descFileName
,
false
);
}
/**
* 复制单个文件
* @param srcFileName 待复制的文件名
* @param descFileName 目标文件名
* @param coverlay 如果目标文件已存在,是否覆盖
* @return 如果复制成功,则返回true,否则返回false
*/
public
static
boolean
copyFileCover
(
String
srcFileName
,
String
descFileName
,
boolean
coverlay
)
{
File
srcFile
=
new
File
(
srcFileName
);
// 判断源文件是否存在
if
(!
srcFile
.
exists
())
{
log
.
debug
(
"复制文件失败,源文件 "
+
srcFileName
+
" 不存在!"
);
return
false
;
}
// 判断源文件是否是合法的文件
else
if
(!
srcFile
.
isFile
())
{
log
.
debug
(
"复制文件失败,"
+
srcFileName
+
" 不是一个文件!"
);
return
false
;
}
File
descFile
=
new
File
(
descFileName
);
// 判断目标文件是否存在
if
(
descFile
.
exists
())
{
// 如果目标文件存在,并且允许覆盖
if
(
coverlay
)
{
log
.
debug
(
"目标文件已存在,准备删除!"
);
if
(!
FileUtils
.
delFile
(
descFileName
))
{
log
.
debug
(
"删除目标文件 "
+
descFileName
+
" 失败!"
);
return
false
;
}
}
else
{
log
.
debug
(
"复制文件失败,目标文件 "
+
descFileName
+
" 已存在!"
);
return
false
;
}
}
else
{
if
(!
descFile
.
getParentFile
().
exists
())
{
// 如果目标文件所在的目录不存在,则创建目录
log
.
debug
(
"目标文件所在的目录不存在,创建目录!"
);
// 创建目标文件所在的目录
if
(!
descFile
.
getParentFile
().
mkdirs
())
{
log
.
debug
(
"创建目标文件所在的目录失败!"
);
return
false
;
}
}
}
// 准备复制文件
// 读取的位数
int
readByte
=
0
;
InputStream
ins
=
null
;
OutputStream
outs
=
null
;
try
{
// 打开源文件
ins
=
new
FileInputStream
(
srcFile
);
// 打开目标文件的输出流
outs
=
new
FileOutputStream
(
descFile
);
byte
[]
buf
=
new
byte
[
1024
];
// 一次读取1024个字节,当readByte为-1时表示文件已经读取完毕
while
((
readByte
=
ins
.
read
(
buf
))
!=
-
1
)
{
// 将读取的字节流写入到输出流
outs
.
write
(
buf
,
0
,
readByte
);
}
log
.
debug
(
"复制单个文件 "
+
srcFileName
+
" 到"
+
descFileName
+
"成功!"
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
debug
(
"复制文件失败:"
+
e
.
getMessage
());
return
false
;
}
finally
{
// 关闭输入输出流,首先关闭输出流,然后再关闭输入流
if
(
outs
!=
null
)
{
try
{
outs
.
close
();
}
catch
(
IOException
oute
)
{
oute
.
printStackTrace
();
}
}
if
(
ins
!=
null
)
{
try
{
ins
.
close
();
}
catch
(
IOException
ine
)
{
ine
.
printStackTrace
();
}
}
}
}
/**
* 复制整个目录的内容,如果目标目录存在,则不覆盖
* @param srcDirName 源目录名
* @param descDirName 目标目录名
* @return 如果复制成功返回true,否则返回false
*/
public
static
boolean
copyDirectory
(
String
srcDirName
,
String
descDirName
)
{
return
FileUtils
.
copyDirectoryCover
(
srcDirName
,
descDirName
,
false
);
}
/**
* 复制整个目录的内容
* @param srcDirName 源目录名
* @param descDirName 目标目录名
* @param coverlay 如果目标目录存在,是否覆盖
* @return 如果复制成功返回true,否则返回false
*/
public
static
boolean
copyDirectoryCover
(
String
srcDirName
,
String
descDirName
,
boolean
coverlay
)
{
File
srcDir
=
new
File
(
srcDirName
);
// 判断源目录是否存在
if
(!
srcDir
.
exists
())
{
log
.
debug
(
"复制目录失败,源目录 "
+
srcDirName
+
" 不存在!"
);
return
false
;
}
// 判断源目录是否是目录
else
if
(!
srcDir
.
isDirectory
())
{
log
.
debug
(
"复制目录失败,"
+
srcDirName
+
" 不是一个目录!"
);
return
false
;
}
// 如果目标文件夹名不以文件分隔符结尾,自动添加文件分隔符
String
descDirNames
=
descDirName
;
if
(!
descDirNames
.
endsWith
(
File
.
separator
))
{
descDirNames
=
descDirNames
+
File
.
separator
;
}
File
descDir
=
new
File
(
descDirNames
);
// 如果目标文件夹存在
if
(
descDir
.
exists
())
{
if
(
coverlay
)
{
// 允许覆盖目标目录
log
.
debug
(
"目标目录已存在,准备删除!"
);
if
(!
FileUtils
.
delFile
(
descDirNames
))
{
log
.
debug
(
"删除目录 "
+
descDirNames
+
" 失败!"
);
return
false
;
}
}
else
{
log
.
debug
(
"目标目录复制失败,目标目录 "
+
descDirNames
+
" 已存在!"
);
return
false
;
}
}
else
{
// 创建目标目录
log
.
debug
(
"目标目录不存在,准备创建!"
);
if
(!
descDir
.
mkdirs
())
{
log
.
debug
(
"创建目标目录失败!"
);
return
false
;
}
}
boolean
flag
=
true
;
// 列出源目录下的所有文件名和子目录名
File
[]
files
=
srcDir
.
listFiles
();
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
// 如果是一个单个文件,则直接复制
if
(
files
[
i
].
isFile
())
{
flag
=
FileUtils
.
copyFile
(
files
[
i
].
getAbsolutePath
(),
descDirName
+
files
[
i
].
getName
());
// 如果拷贝文件失败,则退出循环
if
(!
flag
)
{
break
;
}
}
// 如果是子目录,则继续复制目录
if
(
files
[
i
].
isDirectory
())
{
flag
=
FileUtils
.
copyDirectory
(
files
[
i
]
.
getAbsolutePath
(),
descDirName
+
files
[
i
].
getName
());
// 如果拷贝目录失败,则退出循环
if
(!
flag
)
{
break
;
}
}
}
if
(!
flag
)
{
log
.
debug
(
"复制目录 "
+
srcDirName
+
" 到 "
+
descDirName
+
" 失败!"
);
return
false
;
}
log
.
debug
(
"复制目录 "
+
srcDirName
+
" 到 "
+
descDirName
+
" 成功!"
);
return
true
;
}
/**
*
* 删除文件,可以删除单个文件或文件夹
*
* @param fileName 被删除的文件名
* @return 如果删除成功,则返回true,否是返回false
*/
public
static
boolean
delFile
(
String
fileName
)
{
File
file
=
new
File
(
fileName
);
if
(!
file
.
exists
())
{
log
.
debug
(
fileName
+
" 文件不存在!"
);
return
true
;
}
else
{
if
(
file
.
isFile
())
{
return
FileUtils
.
deleteFile
(
fileName
);
}
else
{
return
FileUtils
.
deleteDirectory
(
fileName
);
}
}
}
/**
*
* 删除单个文件
*
* @param fileName 被删除的文件名
* @return 如果删除成功,则返回true,否则返回false
*/
public
static
boolean
deleteFile
(
String
fileName
)
{
File
file
=
new
File
(
fileName
);
if
(
file
.
exists
()
&&
file
.
isFile
())
{
if
(
file
.
delete
())
{
log
.
debug
(
"删除文件 "
+
fileName
+
" 成功!"
);
return
true
;
}
else
{
log
.
debug
(
"删除文件 "
+
fileName
+
" 失败!"
);
return
false
;
}
}
else
{
log
.
debug
(
fileName
+
" 文件不存在!"
);
return
true
;
}
}
/**
*
* 删除目录及目录下的文件
*
* @param dirName 被删除的目录所在的文件路径
* @return 如果目录删除成功,则返回true,否则返回false
*/
public
static
boolean
deleteDirectory
(
String
dirName
)
{
String
dirNames
=
dirName
;
if
(!
dirNames
.
endsWith
(
File
.
separator
))
{
dirNames
=
dirNames
+
File
.
separator
;
}
File
dirFile
=
new
File
(
dirNames
);
if
(!
dirFile
.
exists
()
||
!
dirFile
.
isDirectory
())
{
log
.
debug
(
dirNames
+
" 目录不存在!"
);
return
true
;
}
boolean
flag
=
true
;
// 列出全部文件及子目录
File
[]
files
=
dirFile
.
listFiles
();
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
// 删除子文件
if
(
files
[
i
].
isFile
())
{
flag
=
FileUtils
.
deleteFile
(
files
[
i
].
getAbsolutePath
());
// 如果删除文件失败,则退出循环
if
(!
flag
)
{
break
;
}
}
// 删除子目录
else
if
(
files
[
i
].
isDirectory
())
{
flag
=
FileUtils
.
deleteDirectory
(
files
[
i
]
.
getAbsolutePath
());
// 如果删除子目录失败,则退出循环
if
(!
flag
)
{
break
;
}
}
}
if
(!
flag
)
{
log
.
debug
(
"删除目录失败!"
);
return
false
;
}
// 删除当前目录
if
(
dirFile
.
delete
())
{
log
.
debug
(
"删除目录 "
+
dirName
+
" 成功!"
);
return
true
;
}
else
{
log
.
debug
(
"删除目录 "
+
dirName
+
" 失败!"
);
return
false
;
}
}
/**
* 创建单个文件
* @param descFileName 文件名,包含路径
* @return 如果创建成功,则返回true,否则返回false
*/
public
static
boolean
createFile
(
String
descFileName
)
{
File
file
=
new
File
(
descFileName
);
if
(
file
.
exists
())
{
log
.
debug
(
"文件 "
+
descFileName
+
" 已存在!"
);
return
false
;
}
if
(
descFileName
.
endsWith
(
File
.
separator
))
{
log
.
debug
(
descFileName
+
" 为目录,不能创建目录!"
);
return
false
;
}
if
(!
file
.
getParentFile
().
exists
())
{
// 如果文件所在的目录不存在,则创建目录
if
(!
file
.
getParentFile
().
mkdirs
())
{
log
.
debug
(
"创建文件所在的目录失败!"
);
return
false
;
}
}
// 创建文件
try
{
if
(
file
.
createNewFile
())
{
log
.
debug
(
descFileName
+
" 文件创建成功!"
);
return
true
;
}
else
{
log
.
debug
(
descFileName
+
" 文件创建失败!"
);
return
false
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
debug
(
descFileName
+
" 文件创建失败!"
);
return
false
;
}
}
/**
* 创建目录
* @param descDirName 目录名,包含路径
* @return 如果创建成功,则返回true,否则返回false
*/
public
static
boolean
createDirectory
(
String
descDirName
)
{
String
descDirNames
=
descDirName
;
if
(!
descDirNames
.
endsWith
(
File
.
separator
))
{
descDirNames
=
descDirNames
+
File
.
separator
;
}
File
descDir
=
new
File
(
descDirNames
);
if
(
descDir
.
exists
())
{
log
.
debug
(
"目录 "
+
descDirNames
+
" 已存在!"
);
return
false
;
}
// 创建目录
if
(
descDir
.
mkdirs
())
{
log
.
debug
(
"目录 "
+
descDirNames
+
" 创建成功!"
);
return
true
;
}
else
{
log
.
debug
(
"目录 "
+
descDirNames
+
" 创建失败!"
);
return
false
;
}
}
/**
* 获取可以创建的文件名(如果有同名文件存在,参照Windows系统重命名为xxx(2).xxx)
* @param name
* @param index
* @return
*/
public
static
File
getAvailableFile
(
String
name
,
int
index
){
File
newFile
=
null
;
String
suffix
=
StrUtil
.
subAfter
(
name
,
"."
,
true
);
String
filePath
=
StrUtil
.
subBefore
(
name
,
"."
,
true
);
if
(
index
==
0
){
newFile
=
new
File
(
filePath
+
"."
+
suffix
);
}
else
{
newFile
=
new
File
(
filePath
+
"("
+
index
+
")"
+
"."
+
suffix
);
}
if
(
newFile
.
exists
()){
return
getAvailableFile
(
name
,
index
+
1
);
}
else
{
return
newFile
;
}
};
/**
* 获取可以创建的目录名(如果有同名目录存在,参照Windows系统重命名为xxx(2))
* @param name
* @param index
* @return
*/
public
static
File
getAvailableFolder
(
String
name
,
int
index
){
File
newFolder
=
null
;
if
(
index
==
0
){
newFolder
=
new
File
(
name
);
}
else
{
newFolder
=
new
File
(
name
+
"("
+
index
+
")"
);
}
if
(
newFolder
.
exists
()){
return
getAvailableFolder
(
name
,
index
+
1
);
}
else
{
return
newFolder
;
}
};
/**
* 写入文件
*/
public
static
void
writeToFile
(
String
fileName
,
String
content
,
boolean
append
)
{
try
{
FileUtils
.
write
(
new
File
(
fileName
),
content
,
"utf-8"
,
append
);
log
.
debug
(
"文件 "
+
fileName
+
" 写入成功!"
);
}
catch
(
IOException
e
)
{
log
.
debug
(
"文件 "
+
fileName
+
" 写入失败! "
+
e
.
getMessage
());
}
}
/**
* 写入文件
*/
public
static
void
writeToFile
(
String
fileName
,
String
content
,
String
encoding
,
boolean
append
)
{
try
{
FileUtils
.
write
(
new
File
(
fileName
),
content
,
encoding
,
append
);
log
.
debug
(
"文件 "
+
fileName
+
" 写入成功!"
);
}
catch
(
IOException
e
)
{
log
.
debug
(
"文件 "
+
fileName
+
" 写入失败! "
+
e
.
getMessage
());
}
}
/**
* 获取待压缩文件在ZIP文件中entry的名字,即相对于跟目录的相对路径名
* @param dirPath 目录名
* @param file entry文件名
* @return
*/
private
static
String
getEntryName
(
String
dirPath
,
File
file
)
{
String
dirPaths
=
dirPath
;
if
(!
dirPaths
.
endsWith
(
File
.
separator
))
{
dirPaths
=
dirPaths
+
File
.
separator
;
}
String
filePath
=
file
.
getAbsolutePath
();
// 对于目录,必须在entry名字后面加上"/",表示它将以目录项存储
if
(
file
.
isDirectory
())
{
filePath
+=
"/"
;
}
int
index
=
filePath
.
indexOf
(
dirPaths
);
return
filePath
.
substring
(
index
+
dirPaths
.
length
());
}
}
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> {
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;
import
com.makeit.module.iot.vo.DeviceState
;
import
com.makeit.module.system.service.SysDictionaryCategoryService
;
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.PlatRoleService
;
import
com.makeit.service.platform.device.PlatDeviceOtherService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.elder.PlatElderService
;
...
...
@@ -60,17 +60,14 @@ import com.makeit.shengwang.agora.service.ShengwangService;
import
com.makeit.shengwang.agora.vo.PlatAlarmCallDeviceVO
;
import
com.makeit.utils.DeviceCacheUtil
;
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.StreamUtil
;
import
com.makeit.utils.old.StringUtils
;
import
com.makeit.utils.request.RequestUtil
;
import
com.makeit.utils.sql.join.JoinUtil
;
import
com.makeit.vo.platform.device.PlatChildDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceActiveVO
;
import
com.makeit.vo.platform.device.PlatDeviceListVO
;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
...
...
@@ -130,6 +127,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private
ShengwangService
shengwangService
;
@Autowired
private
ShengwangProperties
shengwangProperties
;
@Autowired
private
AliyunOSSRepository
aliyunOSSRepository
;
@Override
public
PageVO
<
PlatDeviceListVO
>
page
(
PageReqDTO
<
PlatDeviceQueryDTO
>
pageReqDTO
)
{
...
...
@@ -837,7 +836,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
@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 {
private
String
roomName
;
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:
configuration
:
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
logging
:
level
:
root
:
debug
file
:
filePath
:
file
file
:
D:/pro/${file.filePath}
...
...
@@ -163,6 +168,16 @@ shengwang:
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:
customerSecret
:
bd81828a133140a58dfb04e9d80eba43
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