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
34f714fc
Commit
34f714fc
authored
Nov 12, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
参数处理
parent
17f61a23
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
YzgFileConsumer.java
...main/java/com/yanzuoguang/cloud/file/YzgFileConsumer.java
+79
-0
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+7
-0
No files found.
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileConsumer.java
View file @
34f714fc
...
@@ -2,6 +2,8 @@ package com.yanzuoguang.cloud.file;
...
@@ -2,6 +2,8 @@ package com.yanzuoguang.cloud.file;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.cloud.file.vo.YzgFileMoveReqVo
;
import
com.yanzuoguang.cloud.file.vo.YzgFileMoveReqVo
;
import
com.yanzuoguang.cloud.file.vo.YzgFileVideoImageItemReqVo
;
import
com.yanzuoguang.cloud.file.vo.YzgFileVideoImageReqVo
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
...
@@ -12,6 +14,9 @@ import org.springframework.beans.factory.InitializingBean;
...
@@ -12,6 +14,9 @@ import org.springframework.beans.factory.InitializingBean;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* 文件处理
* 文件处理
*/
*/
...
@@ -85,4 +90,78 @@ public class YzgFileConsumer implements InitializingBean {
...
@@ -85,4 +90,78 @@ public class YzgFileConsumer implements InitializingBean {
mqService
.
basicAck
(
message
,
channel
);
mqService
.
basicAck
(
message
,
channel
);
}
}
}
}
/**
* 处理文件转换
*
* @param json
* @param message
* @param channel
*/
@RabbitListener
(
queues
=
{
YzgFileProcedure
.
YZG_CONVERT_IMAGE
})
public
void
convertImage
(
String
json
,
Message
message
,
Channel
channel
)
{
try
{
YzgFileVideoImageReqVo
req
=
JsonHelper
.
deserialize
(
json
,
YzgFileVideoImageReqVo
.
class
);
// 等待下一次MQ执行
List
<
YzgFileVideoImageItemReqVo
>
cacheList
=
req
.
getList
();
if
(
cacheList
==
null
||
cacheList
.
isEmpty
())
{
return
;
}
// 本次执行的转换操作
List
<
YzgFileVideoImageItemReqVo
>
runList
=
new
ArrayList
<>();
runList
.
add
(
cacheList
.
remove
(
0
));
req
.
setList
(
runList
);
// 执行本次转换
fileService
.
convertImage
(
req
);
// 继续执行下一次转换
if
(!
cacheList
.
isEmpty
())
{
req
.
setList
(
cacheList
);
fileProcedure
.
convertImage
(
req
);
}
}
catch
(
CodeException
ex
)
{
Log
.
error
(
YzgFileConsumer
.
class
,
ex
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
YzgFileConsumer
.
class
,
ex
);
fileProcedure
.
convertImage
(
json
,
60
*
1000
);
}
finally
{
mqService
.
basicAck
(
message
,
channel
);
}
}
/**
* 处理视频转换
*
* @param json
* @param message
* @param channel
*/
@RabbitListener
(
queues
=
{
YzgFileProcedure
.
YZG_CONVERT_VIDEO
})
public
void
convertVideo
(
String
json
,
Message
message
,
Channel
channel
)
{
try
{
YzgFileVideoImageReqVo
req
=
JsonHelper
.
deserialize
(
json
,
YzgFileVideoImageReqVo
.
class
);
// 等待下一次MQ执行
List
<
YzgFileVideoImageItemReqVo
>
cacheList
=
req
.
getList
();
if
(
cacheList
==
null
||
cacheList
.
isEmpty
())
{
return
;
}
// 本次执行的转换操作
List
<
YzgFileVideoImageItemReqVo
>
runList
=
new
ArrayList
<>();
runList
.
add
(
cacheList
.
remove
(
0
));
req
.
setList
(
runList
);
// 执行本次转换
fileService
.
convertVideo
(
req
);
// 继续执行下一次转换
if
(!
cacheList
.
isEmpty
())
{
req
.
setList
(
cacheList
);
fileProcedure
.
convertVideo
(
req
);
}
}
catch
(
CodeException
ex
)
{
Log
.
error
(
YzgFileConsumer
.
class
,
ex
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
YzgFileConsumer
.
class
,
ex
);
fileProcedure
.
convertVideo
(
json
,
60
*
1000
);
}
finally
{
mqService
.
basicAck
(
message
,
channel
);
}
}
}
}
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
34f714fc
...
@@ -261,6 +261,13 @@ public class YzgFileServiceImpl implements YzgFileService {
...
@@ -261,6 +261,13 @@ public class YzgFileServiceImpl implements YzgFileService {
// 来源文件路径
// 来源文件路径
String
from
=
fileConfig
.
getServerFullPath
(
req
.
getFrom
());
String
from
=
fileConfig
.
getServerFullPath
(
req
.
getFrom
());
YzgFileBaseVo
fromInfo
=
new
YzgFileBaseVo
();
fileConfig
.
init
(
fromInfo
,
from
);
if
(
fromInfo
.
getType
()
!=
FileHelper
.
FILE_TYPE_VIDEO
)
{
throw
new
CodeException
(
"请传入视频文件"
);
}
// 循环转换所有文件
for
(
YzgFileVideoImageItemReqVo
item
:
req
.
getList
())
{
for
(
YzgFileVideoImageItemReqVo
item
:
req
.
getList
())
{
String
to
=
fileConfig
.
getServerFullPath
(
item
.
getTo
());
String
to
=
fileConfig
.
getServerFullPath
(
item
.
getTo
());
// 先压缩到临时文件
// 先压缩到临时文件
...
...
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