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
4c4d285f
Commit
4c4d285f
authored
Aug 06, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
a7a18976
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
22 deletions
+87
-22
MemoryCache.java
...src/main/java/com/yanzuoguang/util/cache/MemoryCache.java
+4
-3
YzgFileProcedure.java
...ain/java/com/yanzuoguang/cloud/file/YzgFileProcedure.java
+25
-6
YzgFileConsumer.java
...main/java/com/yanzuoguang/cloud/file/YzgFileConsumer.java
+28
-8
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+30
-5
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/cache/MemoryCache.java
View file @
4c4d285f
...
...
@@ -3,7 +3,8 @@ package com.yanzuoguang.util.cache;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.Date
;
import
java.util.Hashtable
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 内存缓存
...
...
@@ -16,7 +17,7 @@ public class MemoryCache<T> {
/**
* 缓存的对象
*/
private
Hashtable
<
String
,
MemoryCacheItem
<
T
>>
cache
=
new
Hashtable
<
String
,
MemoryCacheItem
<
T
>
>();
private
Map
<
String
,
MemoryCacheItem
<
T
>>
cache
=
new
ConcurrentHashMap
<
>();
/**
* 清除时间
...
...
@@ -231,7 +232,7 @@ public class MemoryCache<T> {
* @throws Throwable
*/
@Override
protected
void
finalize
(){
protected
void
finalize
()
{
this
.
close
();
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/YzgFileProcedure.java
View file @
4c4d285f
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.util.vo.file.YzgFileMoveReqVo
;
import
com.yanzuoguang.util.vo.file.YzgFileVideoImageReqVo
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.mq.vo.QueueVo
;
...
...
@@ -9,8 +7,12 @@ import com.yanzuoguang.util.cache.MemoryCache;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.file.YzgFileMoveReqVo
;
import
com.yanzuoguang.util.vo.file.YzgFileVideoImageReqVo
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanInitializationException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.
beans.factory.annotation.Autowired
;
import
org.springframework.
context.*
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
...
...
@@ -21,14 +23,13 @@ import java.util.Date;
* @author 颜佐光
*/
@Component
public
class
YzgFileProcedure
implements
InitializingBean
{
public
class
YzgFileProcedure
implements
InitializingBean
,
ApplicationContextAware
{
public
static
final
String
YZG_REMOVE_TEMP_FOLDER
=
"YZG_REMOVE_TEMP_FOLDER"
;
public
static
final
String
YZG_MOVE_FILE
=
"YZG_MOVE_FILE"
;
public
static
final
String
YZG_CONVERT_IMAGE
=
"YZG_CONVERT_IMAGE"
;
public
static
final
String
YZG_CONVERT_VIDEO
=
"YZG_CONVERT_VIDEO"
;
@Autowired
private
MqService
mqService
;
/**
...
...
@@ -36,6 +37,25 @@ public class YzgFileProcedure implements InitializingBean {
*/
private
MemoryCache
<
Boolean
>
folderCache
=
new
MemoryCache
<>(
24
*
60
*
60
);
/**
* Set the ApplicationContext that this object runs in.
* Normally this call will be used to initialize the object.
* <p>Invoked after population of normal bean properties but before an init callback such
* as {@link InitializingBean#afterPropertiesSet()}
* or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
* {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
* {@link MessageSourceAware}, if applicable.
*
* @param applicationContext the ApplicationContext object to be used by this object
* @throws ApplicationContextException in case of context initialization errors
* @throws BeansException if thrown by application context methods
* @see BeanInitializationException
*/
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
mqService
=
applicationContext
.
getBean
(
MqService
.
class
);
}
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
...
...
@@ -133,5 +153,4 @@ public class YzgFileProcedure implements InitializingBean {
public
void
convertVideo
(
String
json
,
int
dedTime
)
{
mqService
.
message
(
new
MessageVo
(
YZG_CONVERT_VIDEO
,
json
,
dedTime
));
}
}
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileConsumer.java
View file @
4c4d285f
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.util.vo.file.YzgFileMoveReqVo
;
import
com.yanzuoguang.util.vo.file.YzgFileVideoImageItemReqVo
;
import
com.yanzuoguang.util.vo.file.YzgFileVideoImageReqVo
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.file.YzgFileMoveReqVo
;
import
com.yanzuoguang.util.vo.file.YzgFileVideoImageItemReqVo
;
import
com.yanzuoguang.util.vo.file.YzgFileVideoImageReqVo
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanInitializationException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.
beans.factory.annotation.Autowired
;
import
org.springframework.
context.*
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
...
...
@@ -21,17 +23,35 @@ import java.util.List;
* 文件处理
*/
@Component
public
class
YzgFileConsumer
implements
InitializingBean
{
public
class
YzgFileConsumer
implements
InitializingBean
,
ApplicationContextAware
{
@Autowired
private
MqService
mqService
;
@Autowired
private
YzgFileService
fileService
;
@Autowired
private
YzgFileProcedure
fileProcedure
;
/**
* Set the ApplicationContext that this object runs in.
* Normally this call will be used to initialize the object.
* <p>Invoked after population of normal bean properties but before an init callback such
* as {@link InitializingBean#afterPropertiesSet()}
* or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
* {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
* {@link MessageSourceAware}, if applicable.
*
* @param applicationContext the ApplicationContext object to be used by this object
* @throws ApplicationContextException in case of context initialization errors
* @throws BeansException if thrown by application context methods
* @see BeanInitializationException
*/
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
mqService
=
applicationContext
.
getBean
(
MqService
.
class
);
fileService
=
applicationContext
.
getBean
(
YzgFileService
.
class
);
fileProcedure
=
applicationContext
.
getBean
(
YzgFileProcedure
.
class
);
}
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
...
...
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
4c4d285f
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.cloud.vo.YzgFileUploadReqVo
;
import
com.yanzuoguang.util.MediaHelper
;
...
...
@@ -10,7 +11,10 @@ import com.yanzuoguang.util.helper.DateHelper;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.file.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanInitializationException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.context.*
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -32,16 +36,37 @@ import java.util.List;
* @author 颜佐光
*/
@Component
public
class
YzgFileServiceImpl
implements
YzgFileService
{
public
class
YzgFileServiceImpl
implements
YzgFileService
,
ApplicationContextAware
{
private
CloudConfig
cloudConfig
;
@Autowired
private
YzgFileConfig
fileConfig
;
@Autowired
private
YzgFileProcedure
procedure
;
private
MemoryCache
<
Boolean
>
cacheRemoveTempFolder
=
new
MemoryCache
<>(
10
*
60
);
/**
* Set the ApplicationContext that this object runs in.
* Normally this call will be used to initialize the object.
* <p>Invoked after population of normal bean properties but before an init callback such
* as {@link InitializingBean#afterPropertiesSet()}
* or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
* {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
* {@link MessageSourceAware}, if applicable.
*
* @param applicationContext the ApplicationContext object to be used by this object
* @throws ApplicationContextException in case of context initialization errors
* @throws BeansException if thrown by application context methods
* @see BeanInitializationException
*/
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
cloudConfig
=
applicationContext
.
getBean
(
CloudConfig
.
class
);
fileConfig
=
applicationContext
.
getBean
(
YzgFileConfig
.
class
);
procedure
=
applicationContext
.
getBean
(
YzgFileProcedure
.
class
);
}
/**
* 压缩文件
*
...
...
@@ -64,7 +89,7 @@ public class YzgFileServiceImpl implements YzgFileService {
// 获取临时文件路径
String
tempFolder
=
getTempFolder
(
folder
);
String
serverFolder
=
String
.
format
(
"%s/%s"
,
file
Config
.
getServerUrl
(),
tempFolder
);
String
serverFolder
=
String
.
format
(
"%s/%s"
,
cloud
Config
.
getServerUrl
(),
tempFolder
);
// 创建服务器路径
FileHelper
.
createDirectory
(
serverFolder
);
// 删除目录
...
...
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