Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
80c7d50e
Commit
80c7d50e
authored
Nov 11, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件处理
parent
cc72aa91
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
0 deletions
+71
-0
pom.xml
yzg-util-cloud/pom.xml
+5
-0
YzgFileProcedure.java
...ain/java/com/yanzuoguang/cloud/file/YzgFileProcedure.java
+61
-0
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+5
-0
No files found.
yzg-util-cloud/pom.xml
View file @
80c7d50e
...
@@ -135,6 +135,11 @@
...
@@ -135,6 +135,11 @@
<artifactId>
yzg-util-db
</artifactId>
<artifactId>
yzg-util-db
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.yanzuoguang
</groupId>
<artifactId>
yzg-util-mq
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<artifactId>
springfox-swagger-ui
</artifactId>
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/YzgFileProcedure.java
0 → 100644
View file @
80c7d50e
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
/**
* 删除目录
*
* @author 颜佐光
*/
@Component
public
class
YzgFileProcedure
implements
InitializingBean
{
public
static
final
String
REMOVE_TEMP_FOLDER
=
"REMOVE_TEMP_FOLDER"
;
@Autowired
private
MqService
mqService
;
/**
* 缓存24小时
*/
private
MemoryCache
<
Boolean
>
folderCache
=
new
MemoryCache
<>(
24
*
60
*
60
);
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an
* exception in the event of misconfiguration.
*
* @throws Exception in the event of misconfiguration (such
* as failure to set an essential property) or if initialization fails.
*/
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
mqService
.
createQueue
(
new
QueueVo
(
REMOVE_TEMP_FOLDER
));
}
public
void
removeFolder
(
String
serverFolder
)
{
if
(
StringHelper
.
toBoolean
(
folderCache
.
get
(
serverFolder
)))
{
return
;
}
// 获取当前时间
Date
dt
=
new
Date
();
Date
dtTo
=
DateHelper
.
addDay
(
dt
,
2
);
String
dtToday
=
DateHelper
.
getToday
(
dtTo
);
// 获取延迟时间
long
time
=
DateHelper
.
getDateTime
(
dtToday
).
getTime
()
-
dt
.
getTime
();
// 发送删除临时目录的命令
mqService
.
message
(
new
MessageVo
(
REMOVE_TEMP_FOLDER
,
serverFolder
,
time
));
}
}
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
80c7d50e
...
@@ -25,6 +25,9 @@ public class YzgFileServiceImpl implements YzgFileService {
...
@@ -25,6 +25,9 @@ public class YzgFileServiceImpl implements YzgFileService {
@Autowired
@Autowired
private
YzgFileConfig
fileConfig
;
private
YzgFileConfig
fileConfig
;
@Autowired
private
YzgFileProcedure
procedure
;
/**
/**
* 压缩文件
* 压缩文件
*
*
...
@@ -57,6 +60,8 @@ public class YzgFileServiceImpl implements YzgFileService {
...
@@ -57,6 +60,8 @@ public class YzgFileServiceImpl implements YzgFileService {
String
serverFolder
=
String
.
format
(
"%s/%s"
,
fileConfig
.
getServerUrl
(),
tempFolder
);
String
serverFolder
=
String
.
format
(
"%s/%s"
,
fileConfig
.
getServerUrl
(),
tempFolder
);
// 创建服务器路径
// 创建服务器路径
FileHelper
.
createDirectory
(
serverFolder
);
FileHelper
.
createDirectory
(
serverFolder
);
// 删除目录
procedure
.
removeFolder
(
serverFolder
);
// 设置保存文件的路径
// 设置保存文件的路径
String
serverFile
=
String
.
format
(
"%s/%s"
,
serverFolder
,
saveFileName
);
String
serverFile
=
String
.
format
(
"%s/%s"
,
serverFolder
,
saveFileName
);
...
...
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