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
f93f94fe
Commit
f93f94fe
authored
Nov 11, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件处理
parent
80c7d50e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
0 deletions
+106
-0
YzgFileService.java
.../main/java/com/yanzuoguang/cloud/file/YzgFileService.java
+8
-0
YzgFileConsumer.java
...main/java/com/yanzuoguang/cloud/file/YzgFileConsumer.java
+64
-0
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+34
-0
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/YzgFileService.java
View file @
f93f94fe
...
...
@@ -18,4 +18,12 @@ public interface YzgFileService {
*/
YzgFileUploadResVo
upload
(
YzgFileUploadReqVo
req
);
/**
* 立即删除临时路径
*
* @param tempFolder
*/
void
removeTempFolder
(
String
tempFolder
);
}
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileConsumer.java
0 → 100644
View file @
f93f94fe
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.log.Log
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* 文件处理
*/
@Component
public
class
YzgFileConsumer
implements
InitializingBean
{
@Autowired
private
MqService
mqService
;
@Autowired
private
YzgFileService
fileService
;
@Autowired
private
YzgFileProcedure
fileProcedure
;
/**
* 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
{
}
/**
* 删除临时木经
*
* @param tempFolder
* @param message
* @param channel
*/
@RabbitListener
(
queues
=
{
YzgFileProcedure
.
REMOVE_TEMP_FOLDER
})
public
void
notesCheckBack
(
String
tempFolder
,
Message
message
,
Channel
channel
)
{
try
{
fileService
.
removeTempFolder
(
tempFolder
);
}
catch
(
CodeException
ex
)
{
Log
.
error
(
YzgFileConsumer
.
class
,
ex
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
YzgFileConsumer
.
class
,
ex
);
fileProcedure
.
removeFolder
(
tempFolder
);
}
finally
{
mqService
.
basicAck
(
message
,
channel
);
}
}
}
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
f93f94fe
...
...
@@ -3,6 +3,7 @@ package com.yanzuoguang.cloud.file;
import
com.yanzuoguang.cloud.file.vo.YzgFileUploadItemResVo
;
import
com.yanzuoguang.cloud.file.vo.YzgFileUploadReqVo
;
import
com.yanzuoguang.cloud.file.vo.YzgFileUploadResVo
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.FileHelper
;
...
...
@@ -28,6 +29,9 @@ public class YzgFileServiceImpl implements YzgFileService {
@Autowired
private
YzgFileProcedure
procedure
;
@Autowired
private
MemoryCache
<
Boolean
>
cacheRemoveTempFolder
=
new
MemoryCache
<>(
10
*
60
);
/**
* 压缩文件
*
...
...
@@ -81,6 +85,36 @@ public class YzgFileServiceImpl implements YzgFileService {
return
res
;
}
/**
* 立即删除临时路径
*
* @param tempFolder
*/
@Override
public
void
removeTempFolder
(
String
tempFolder
)
{
// 设置标记
synchronized
(
cacheRemoveTempFolder
)
{
if
(
StringHelper
.
toBoolean
(
cacheRemoveTempFolder
.
get
(
tempFolder
)))
{
return
;
}
cacheRemoveTempFolder
.
put
(
tempFolder
,
true
);
}
try
{
// 删除当前临时目录
FileHelper
.
deleteFolder
(
tempFolder
);
// 父文件夹不存在子文件时则删除
File
file
=
new
File
(
tempFolder
);
File
parentFile
=
file
.
getParentFile
();
if
(
parentFile
.
listFiles
()
==
null
||
parentFile
.
listFiles
().
length
==
0
)
{
removeTempFolder
(
parentFile
.
getAbsolutePath
());
}
}
finally
{
// 设置已经删除完成
cacheRemoveTempFolder
.
remove
(
tempFolder
);
}
}
/**
* 获取行记的显示的图片
*
...
...
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