Commit 11c7072c by liyaoting

优化

1 parent b5d5f243
...@@ -13,13 +13,11 @@ import cn.bxe.updatevideo.service.impl.TbxXrChapterServiceImpl; ...@@ -13,13 +13,11 @@ import cn.bxe.updatevideo.service.impl.TbxXrChapterServiceImpl;
import cn.bxe.updatevideo.service.impl.TbxXrModuleServiceImpl; import cn.bxe.updatevideo.service.impl.TbxXrModuleServiceImpl;
import cn.bxe.updatevideo.service.impl.TbxXrVideoServiceImpl; import cn.bxe.updatevideo.service.impl.TbxXrVideoServiceImpl;
import cn.bxe.updatevideo.util.JsonUtil; import cn.bxe.updatevideo.util.JsonUtil;
import cn.zhxu.okhttps.Download;
import cn.zhxu.okhttps.HTTP; import cn.zhxu.okhttps.HTTP;
import cn.zhxu.okhttps.HttpResult; import cn.zhxu.okhttps.HttpResult;
import cn.zhxu.okhttps.gson.GsonMsgConvertor; import cn.zhxu.okhttps.gson.GsonMsgConvertor;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
...@@ -55,7 +53,7 @@ public class UpdateVideoApplication { ...@@ -55,7 +53,7 @@ public class UpdateVideoApplication {
.addMsgConvertor(new GsonMsgConvertor()) .addMsgConvertor(new GsonMsgConvertor())
.build(); .build();
private static ThreadPoolExecutor pool = new ThreadPoolExecutor(20, 20, private static final ThreadPoolExecutor pool = new ThreadPoolExecutor(20, 20,
0, TimeUnit.SECONDS, 0, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(30), new ArrayBlockingQueue<>(30),
new ThreadPoolExecutor.DiscardPolicy()); new ThreadPoolExecutor.DiscardPolicy());
...@@ -80,6 +78,7 @@ public class UpdateVideoApplication { ...@@ -80,6 +78,7 @@ public class UpdateVideoApplication {
System.out.println("5: 下载封面"); System.out.println("5: 下载封面");
System.out.println("6: 更新数据库视频封面链接"); System.out.println("6: 更新数据库视频封面链接");
System.out.println("7: 补充视频时长"); System.out.println("7: 补充视频时长");
System.out.println("8: 计算数量");
System.out.println("0: 退出"); System.out.println("0: 退出");
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
System.out.print("请输入功能代码: "); System.out.print("请输入功能代码: ");
...@@ -114,6 +113,10 @@ public class UpdateVideoApplication { ...@@ -114,6 +113,10 @@ public class UpdateVideoApplication {
System.out.println("补充视频时长咯"); System.out.println("补充视频时长咯");
updateVideoDuration(); updateVideoDuration();
break; break;
case "8":
System.out.println("计算");
countSubjectVideo();
break;
case "0": case "0":
System.out.println("退出咯"); System.out.println("退出咯");
System.exit(0); System.exit(0);
...@@ -126,7 +129,7 @@ public class UpdateVideoApplication { ...@@ -126,7 +129,7 @@ public class UpdateVideoApplication {
menu(); menu();
} }
private static void updateTextbook() throws InterruptedException { private static void updateTextbook() {
String url = "https://api.bendiclass.com/external/api/textbook/v1/getTextbookListByLabel"; String url = "https://api.bendiclass.com/external/api/textbook/v1/getTextbookListByLabel";
HttpResult.Body body = http HttpResult.Body body = http
.sync(url) .sync(url)
...@@ -426,8 +429,6 @@ public class UpdateVideoApplication { ...@@ -426,8 +429,6 @@ public class UpdateVideoApplication {
//获取视频 整理需要更新的视频 //获取视频 整理需要更新的视频
AtomicInteger chapterCount = new AtomicInteger(); AtomicInteger chapterCount = new AtomicInteger();
int allModuleNum = chapterAndModuleIdMap.values().stream().mapToInt(List::size).sum();
AtomicInteger moduleCount = new AtomicInteger();
chapterAndModuleIdMap.forEach((chapterId, moduleIdList) -> { chapterAndModuleIdMap.forEach((chapterId, moduleIdList) -> {
int currentChapterNum = chapterCount.addAndGet(1); int currentChapterNum = chapterCount.addAndGet(1);
...@@ -438,7 +439,6 @@ public class UpdateVideoApplication { ...@@ -438,7 +439,6 @@ public class UpdateVideoApplication {
for (Integer moduleId : moduleIdList) { for (Integer moduleId : moduleIdList) {
pool.submit(() -> { pool.submit(() -> {
try { try {
int currentModuleNum = moduleCount.addAndGet(1);
List<TbxXrVideo> moduleVideoList = new ArrayList<>(); List<TbxXrVideo> moduleVideoList = new ArrayList<>();
String baseUrl = "https://api.bendiclass.com/external/textbookVideo/v1/queryTextbookVideo"; String baseUrl = "https://api.bendiclass.com/external/textbookVideo/v1/queryTextbookVideo";
HttpResult.Body body = http HttpResult.Body body = http
...@@ -470,11 +470,7 @@ public class UpdateVideoApplication { ...@@ -470,11 +470,7 @@ public class UpdateVideoApplication {
} }
videoIdList.addAll(moduleVideoList.stream().map(TbxXrVideo::getVideoId).collect(Collectors.toList())); videoIdList.addAll(moduleVideoList.stream().map(TbxXrVideo::getVideoId).collect(Collectors.toList()));
if (moduleVideoList.size() > 0) { chapterVideoList.addAll(moduleVideoList);
chapterVideoList.addAll(moduleVideoList);
} else {
logger.info("书籍进度{}/{},章节进度{}/{},无更新视频", currentBookNum, bookList.size(), currentChapterNum, chapterAndModuleIdMap.size());
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -551,7 +547,7 @@ public class UpdateVideoApplication { ...@@ -551,7 +547,7 @@ public class UpdateVideoApplication {
} }
//下载封面 //下载封面
try { try {
Download.Ctrl start = http.sync(coverUrl) http.sync(coverUrl)
.get() .get()
.getBody() .getBody()
.toFile(filePath) .toFile(filePath)
...@@ -609,7 +605,7 @@ public class UpdateVideoApplication { ...@@ -609,7 +605,7 @@ public class UpdateVideoApplication {
private static void updateDbVideoCoverUrl() throws InterruptedException { private static void updateDbVideoCoverUrl() throws InterruptedException {
LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>();
qw.select(TbxXrVideo::getVideoId,TbxXrVideo::getId); qw.select(TbxXrVideo::getVideoId, TbxXrVideo::getId);
qw.eq(TbxXrVideo::getStatus, 10); qw.eq(TbxXrVideo::getStatus, 10);
qw.notLike(TbxXrVideo::getUrl, "https://oss.5rs.me"); qw.notLike(TbxXrVideo::getUrl, "https://oss.5rs.me");
qw.isNull(TbxXrVideo::getCoverUrl); qw.isNull(TbxXrVideo::getCoverUrl);
...@@ -617,7 +613,7 @@ public class UpdateVideoApplication { ...@@ -617,7 +613,7 @@ public class UpdateVideoApplication {
int size = list.size(); int size = list.size();
AtomicInteger counter = new AtomicInteger(); AtomicInteger counter = new AtomicInteger();
for (TbxXrVideo video : list) { for (TbxXrVideo video : list) {
pool.execute(()->{ pool.execute(() -> {
video.setCoverUrl("https://pics-cos.banxiaoer.net/tbx/xrv/covers_images/xrv_" + video.getVideoId() + ".jpg"); video.setCoverUrl("https://pics-cos.banxiaoer.net/tbx/xrv/covers_images/xrv_" + video.getVideoId() + ".jpg");
video.updateById(); video.updateById();
int count = counter.addAndGet(1); int count = counter.addAndGet(1);
...@@ -627,6 +623,27 @@ public class UpdateVideoApplication { ...@@ -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) { private static TbxXrModule moduleConvert(Module module) {
TbxXrModule tbxXrModule = new TbxXrModule(); TbxXrModule tbxXrModule = new TbxXrModule();
......
package cn.bxe.updatevideo.util; package cn.bxe.updatevideo.util;
import cn.bxe.updatevideo.model.TbxXrBook;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class VersionUtil { public class VersionUtil {
...@@ -52,6 +55,7 @@ public class VersionUtil { ...@@ -52,6 +55,7 @@ public class VersionUtil {
VERSION_MAP.put("WAI_YAN","waiyan"); VERSION_MAP.put("WAI_YAN","waiyan");
VERSION_MAP.put("XIANG_SHAO","xiangshao"); VERSION_MAP.put("XIANG_SHAO","xiangshao");
VERSION_MAP.put("RENJIAOJINGTONG","renjiaojingtong"); VERSION_MAP.put("RENJIAOJINGTONG","renjiaojingtong");
VERSION_MAP.put("WAI_YAN_TOGETHER","waiyanyiqi");
//学年 //学年
SCHOOL_YEAR_MAP.put("ALL_BOOKS",5); SCHOOL_YEAR_MAP.put("ALL_BOOKS",5);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!