Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
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
徐少华
midjourney-proxy
Commits
8880737a
Commit
8880737a
authored
Sep 21, 2022
by
李传峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hotfix/jedis' into 'release'
Hotfix/jedis See merge request rays/pcloud-book!1684
parents
93a8d9f9
679155e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
56 deletions
+29
-56
ConvertFileListener.java
...in/java/com/pcloud/book/mq/topic/ConvertFileListener.java
+29
-56
No files found.
pcloud-service-book/src/main/java/com/pcloud/book/mq/topic/ConvertFileListener.java
View file @
8880737a
package
com
.
pcloud
.
book
.
mq
.
topic
;
import
com.google.common.collect.Maps
;
import
com.pcloud.book.advertising.biz.AdvertisingSpaceBiz
;
import
com.pcloud.book.advertising.entity.AdvertisingSpace
;
import
com.pcloud.common.core.aspect.ParamLog
;
...
...
@@ -12,20 +11,18 @@ import com.pcloud.common.exceptions.BizException;
import
com.pcloud.common.utils.FileUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.contentcenter.resource.enums.ResourceTypeEnum
;
import
org.apache.commons.collections.MapUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.amqp.rabbit.annotation.RabbitHandler
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
import
javax.annotation.PostConstruct
;
/**
* @描述:文件转码
* @作者:zhuyajie
...
...
@@ -37,7 +34,6 @@ import javax.annotation.PostConstruct;
public
class
ConvertFileListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ConvertFileListener
.
class
);
private
static
ConvertFileListener
convertFileListener
;
@Autowired
private
AdvertisingSpaceBiz
advertisingSpaceBiz
;
...
...
@@ -46,56 +42,41 @@ public class ConvertFileListener {
*/
private
static
Map
<
String
,
ConvertQueueDto
>
cqds
=
Maps
.
newHashMap
();
private
static
Thread
t1
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
while
(
true
)
{
//如果cqds没有记录,休眠60秒
if
(
MapUtils
.
isEmpty
(
cqds
))
{
try
{
Thread
.
sleep
(
1000
*
60
);
}
catch
(
InterruptedException
e
)
{
LOGGER
.
error
(
"pmrismap线程执行出错"
,
e
);
}
}
else
{
for
(
Map
.
Entry
<
String
,
ConvertQueueDto
>
e
:
cqds
.
entrySet
())
{
if
(
e
.
getValue
()
!=
null
)
{
ConvertQueueDto
convertFileDto
=
e
.
getValue
();
LOGGER
.
info
(
"转码后信息>>>>>"
+
convertFileDto
.
toString
());
String
fileCategory
=
FileUtils
.
getGatherName
(
convertFileDto
.
getFileType
());
String
fileId
=
convertFileDto
.
getFileId
();
String
fileUrl
=
convertFileDto
.
getFileUrl
();
if
(
ResourceTypeEnum
.
AUDIO
.
code
.
equals
(
fileCategory
)
||
ResourceTypeEnum
.
VIDEO
.
code
.
equals
(
fileCategory
))
{
List
<
AdvertisingSpace
>
filelist
=
convertFileListener
.
advertisingSpaceBiz
.
getUnConvertFile
(
fileId
);
if
(!
ListUtils
.
isEmpty
(
filelist
))
{
//更新
convertFileListener
.
advertisingSpaceBiz
.
updateFile
(
filelist
,
fileUrl
);
cqds
.
remove
(
e
.
getKey
());
}
else
{
if
(
convertFileDto
.
getProcessTimes
()
<
10
)
{
convertFileDto
.
setProcessTimes
(
convertFileDto
.
getProcessTimes
()
+
1
);
LOGGER
.
info
(
"音频资源 ,未找到对应记录,进入下一个循环!fileid="
+
convertFileDto
.
getFileId
());
}
else
{
cqds
.
remove
(
e
.
getKey
());
}
}
}
@Scheduled
(
fixedDelay
=
1000
*
60
)
public
void
run
()
{
//如果cqds没有记录,休眠60秒
if
(
MapUtils
.
isEmpty
(
cqds
))
{
return
;
}
for
(
Map
.
Entry
<
String
,
ConvertQueueDto
>
e
:
cqds
.
entrySet
())
{
if
(
e
.
getValue
()
!=
null
)
{
ConvertQueueDto
convertFileDto
=
e
.
getValue
();
LOGGER
.
info
(
"转码后信息>>>>>"
+
convertFileDto
.
toString
());
String
fileCategory
=
FileUtils
.
getGatherName
(
convertFileDto
.
getFileType
());
String
fileId
=
convertFileDto
.
getFileId
();
String
fileUrl
=
convertFileDto
.
getFileUrl
();
if
(
ResourceTypeEnum
.
AUDIO
.
code
.
equals
(
fileCategory
)
||
ResourceTypeEnum
.
VIDEO
.
code
.
equals
(
fileCategory
))
{
List
<
AdvertisingSpace
>
filelist
=
advertisingSpaceBiz
.
getUnConvertFile
(
fileId
);
if
(!
ListUtils
.
isEmpty
(
filelist
))
{
//更新
advertisingSpaceBiz
.
updateFile
(
filelist
,
fileUrl
);
cqds
.
remove
(
e
.
getKey
());
}
else
{
if
(
convertFileDto
.
getProcessTimes
()
<
10
)
{
convertFileDto
.
setProcessTimes
(
convertFileDto
.
getProcessTimes
()
+
1
);
LOGGER
.
info
(
"音频资源 ,未找到对应记录,进入下一个循环!fileid="
+
convertFileDto
.
getFileId
());
}
else
{
// 当该key内无实体时,即清除
cqds
.
remove
(
e
.
getKey
());
}
}
}
}
else
{
// 当该key内无实体时,即清除
cqds
.
remove
(
e
.
getKey
());
}
}
});
// 开始缓存处理
static
{
t1
.
start
();
}
@RabbitHandler
@ParamLog
(
"文件转码"
)
public
void
process
(
ConvertQueueDto
convertQueueDto
)
throws
BizException
{
...
...
@@ -120,22 +101,14 @@ public class ConvertFileListener {
String
fileUrl
=
convertFileDto
.
getFileUrl
();
// 修改点读书音频转码后的地址
if
(
ResourceTypeEnum
.
AUDIO
.
code
.
equals
(
fileCategory
))
{
List
<
AdvertisingSpace
>
filelist
=
convertFileListener
.
advertisingSpaceBiz
.
getUnConvertFile
(
fileId
);
List
<
AdvertisingSpace
>
filelist
=
advertisingSpaceBiz
.
getUnConvertFile
(
fileId
);
if
(
ListUtils
.
isEmpty
(
filelist
))
{
LOGGER
.
info
(
"接收到转码状态时,数据库还未插入记录,先将音频转码信息放到缓存fileId="
+
fileId
+
"convertFileDto="
+
convertFileDto
.
toString
());
cqds
.
put
(
fileId
,
convertFileDto
);
}
else
{
convertFileListener
.
advertisingSpaceBiz
.
updateFile
(
filelist
,
fileUrl
);
advertisingSpaceBiz
.
updateFile
(
filelist
,
fileUrl
);
}
}
}
}
@PostConstruct
public
void
init
()
{
convertFileListener
=
this
;
convertFileListener
.
advertisingSpaceBiz
=
this
.
advertisingSpaceBiz
;
}
}
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