Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
liyaoting
/
update-video
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 11c7072c
authored
2023-03-20 11:57:04 +0800
by
liyaoting
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化
1 parent
b5d5f243
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
15 deletions
src/main/java/cn/bxe/updatevideo/UpdateVideoApplication.java
src/main/java/cn/bxe/updatevideo/util/VersionUtil.java
src/main/java/cn/bxe/updatevideo/UpdateVideoApplication.java
View file @
11c7072
...
...
@@ -13,13 +13,11 @@ import cn.bxe.updatevideo.service.impl.TbxXrChapterServiceImpl;
import
cn.bxe.updatevideo.service.impl.TbxXrModuleServiceImpl
;
import
cn.bxe.updatevideo.service.impl.TbxXrVideoServiceImpl
;
import
cn.bxe.updatevideo.util.JsonUtil
;
import
cn.zhxu.okhttps.Download
;
import
cn.zhxu.okhttps.HTTP
;
import
cn.zhxu.okhttps.HttpResult
;
import
cn.zhxu.okhttps.gson.GsonMsgConvertor
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
org.mybatis.spring.annotation.MapperScan
;
...
...
@@ -55,7 +53,7 @@ public class UpdateVideoApplication {
.
addMsgConvertor
(
new
GsonMsgConvertor
())
.
build
();
private
static
ThreadPoolExecutor
pool
=
new
ThreadPoolExecutor
(
20
,
20
,
private
static
final
ThreadPoolExecutor
pool
=
new
ThreadPoolExecutor
(
20
,
20
,
0
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
30
),
new
ThreadPoolExecutor
.
DiscardPolicy
());
...
...
@@ -80,6 +78,7 @@ public class UpdateVideoApplication {
System
.
out
.
println
(
"5: 下载封面"
);
System
.
out
.
println
(
"6: 更新数据库视频封面链接"
);
System
.
out
.
println
(
"7: 补充视频时长"
);
System
.
out
.
println
(
"8: 计算数量"
);
System
.
out
.
println
(
"0: 退出"
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"请输入功能代码: "
);
...
...
@@ -114,6 +113,10 @@ public class UpdateVideoApplication {
System
.
out
.
println
(
"补充视频时长咯"
);
updateVideoDuration
();
break
;
case
"8"
:
System
.
out
.
println
(
"计算"
);
countSubjectVideo
();
break
;
case
"0"
:
System
.
out
.
println
(
"退出咯"
);
System
.
exit
(
0
);
...
...
@@ -126,7 +129,7 @@ public class UpdateVideoApplication {
menu
();
}
private
static
void
updateTextbook
()
throws
InterruptedException
{
private
static
void
updateTextbook
()
{
String
url
=
"https://api.bendiclass.com/external/api/textbook/v1/getTextbookListByLabel"
;
HttpResult
.
Body
body
=
http
.
sync
(
url
)
...
...
@@ -426,8 +429,6 @@ public class UpdateVideoApplication {
//获取视频 整理需要更新的视频
AtomicInteger
chapterCount
=
new
AtomicInteger
();
int
allModuleNum
=
chapterAndModuleIdMap
.
values
().
stream
().
mapToInt
(
List:
:
size
).
sum
();
AtomicInteger
moduleCount
=
new
AtomicInteger
();
chapterAndModuleIdMap
.
forEach
((
chapterId
,
moduleIdList
)
->
{
int
currentChapterNum
=
chapterCount
.
addAndGet
(
1
);
...
...
@@ -438,7 +439,6 @@ public class UpdateVideoApplication {
for
(
Integer
moduleId
:
moduleIdList
)
{
pool
.
submit
(()
->
{
try
{
int
currentModuleNum
=
moduleCount
.
addAndGet
(
1
);
List
<
TbxXrVideo
>
moduleVideoList
=
new
ArrayList
<>();
String
baseUrl
=
"https://api.bendiclass.com/external/textbookVideo/v1/queryTextbookVideo"
;
HttpResult
.
Body
body
=
http
...
...
@@ -470,11 +470,7 @@ public class UpdateVideoApplication {
}
videoIdList
.
addAll
(
moduleVideoList
.
stream
().
map
(
TbxXrVideo:
:
getVideoId
).
collect
(
Collectors
.
toList
()));
if
(
moduleVideoList
.
size
()
>
0
)
{
chapterVideoList
.
addAll
(
moduleVideoList
);
}
else
{
logger
.
info
(
"书籍进度{}/{},章节进度{}/{},无更新视频"
,
currentBookNum
,
bookList
.
size
(),
currentChapterNum
,
chapterAndModuleIdMap
.
size
());
}
chapterVideoList
.
addAll
(
moduleVideoList
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -551,7 +547,7 @@ public class UpdateVideoApplication {
}
//下载封面
try
{
Download
.
Ctrl
start
=
http
.
sync
(
coverUrl
)
http
.
sync
(
coverUrl
)
.
get
()
.
getBody
()
.
toFile
(
filePath
)
...
...
@@ -609,7 +605,7 @@ public class UpdateVideoApplication {
private
static
void
updateDbVideoCoverUrl
()
throws
InterruptedException
{
LambdaQueryWrapper
<
TbxXrVideo
>
qw
=
new
LambdaQueryWrapper
<>();
qw
.
select
(
TbxXrVideo:
:
getVideoId
,
TbxXrVideo:
:
getId
);
qw
.
select
(
TbxXrVideo:
:
getVideoId
,
TbxXrVideo:
:
getId
);
qw
.
eq
(
TbxXrVideo:
:
getStatus
,
10
);
qw
.
notLike
(
TbxXrVideo:
:
getUrl
,
"https://oss.5rs.me"
);
qw
.
isNull
(
TbxXrVideo:
:
getCoverUrl
);
...
...
@@ -617,7 +613,7 @@ public class UpdateVideoApplication {
int
size
=
list
.
size
();
AtomicInteger
counter
=
new
AtomicInteger
();
for
(
TbxXrVideo
video
:
list
)
{
pool
.
execute
(()
->
{
pool
.
execute
(()
->
{
video
.
setCoverUrl
(
"https://pics-cos.banxiaoer.net/tbx/xrv/covers_images/xrv_"
+
video
.
getVideoId
()
+
".jpg"
);
video
.
updateById
();
int
count
=
counter
.
addAndGet
(
1
);
...
...
@@ -627,6 +623,27 @@ public class UpdateVideoApplication {
}
}
private
static
void
countSubjectVideo
()
{
SUBJECT_MAP
.
forEach
((
k
,
v
)
->
{
LambdaQueryWrapper
<
TbxXrBook
>
qw
=
new
LambdaQueryWrapper
<>();
qw
.
eq
(
TbxXrBook:
:
getSubject
,
v
);
List
<
TbxXrBook
>
list
=
bookService
.
list
(
qw
);
List
<
Integer
>
collect
=
list
.
stream
().
map
(
TbxXrBook:
:
getTextbookId
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
TbxXrModule
>
moduleQW
=
new
LambdaQueryWrapper
<>();
if
(
collect
.
size
()
>
0
){
moduleQW
.
in
(
TbxXrModule:
:
getTextbookId
,
collect
);
List
<
TbxXrModule
>
list1
=
moduleService
.
list
(
moduleQW
);
LambdaQueryWrapper
<
TbxXrVideo
>
videoQW
=
new
LambdaQueryWrapper
<>();
list1
.
forEach
(
obj
->
{
videoQW
.
or
().
eq
(
TbxXrVideo:
:
getChapterId
,
obj
.
getChapterId
()).
eq
(
TbxXrVideo:
:
getModuleId
,
obj
.
getModuleId
());
});
List
<
TbxXrVideo
>
list2
=
videoService
.
list
(
videoQW
);
System
.
out
.
println
(
v
+
","
+
list2
.
size
());
}
});
}
private
static
TbxXrModule
moduleConvert
(
Module
module
)
{
TbxXrModule
tbxXrModule
=
new
TbxXrModule
();
...
...
src/main/java/cn/bxe/updatevideo/util/VersionUtil.java
View file @
11c7072
package
cn
.
bxe
.
updatevideo
.
util
;
import
cn.bxe.updatevideo.model.TbxXrBook
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
public
class
VersionUtil
{
...
...
@@ -52,6 +55,7 @@ public class VersionUtil {
VERSION_MAP
.
put
(
"WAI_YAN"
,
"waiyan"
);
VERSION_MAP
.
put
(
"XIANG_SHAO"
,
"xiangshao"
);
VERSION_MAP
.
put
(
"RENJIAOJINGTONG"
,
"renjiaojingtong"
);
VERSION_MAP
.
put
(
"WAI_YAN_TOGETHER"
,
"waiyanyiqi"
);
//学年
SCHOOL_YEAR_MAP
.
put
(
"ALL_BOOKS"
,
5
);
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment