Commit 0a3540e0 by liyaoting

整理&优化

1 parent 44d9b2be
...@@ -16,6 +16,7 @@ import cn.bxe.updatevideo.util.JsonUtil; ...@@ -16,6 +16,7 @@ import cn.bxe.updatevideo.util.JsonUtil;
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.JSONArray;
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.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
...@@ -35,10 +36,8 @@ import ws.schild.jave.MultimediaInfo; ...@@ -35,10 +36,8 @@ import ws.schild.jave.MultimediaInfo;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -46,6 +45,15 @@ import java.util.stream.Collectors; ...@@ -46,6 +45,15 @@ import java.util.stream.Collectors;
import static cn.bxe.updatevideo.util.VersionUtil.*; import static cn.bxe.updatevideo.util.VersionUtil.*;
/**
* @deprecated 用于更新知识点精讲视频(其实是新增 一般不修改旧的)
* 1.一般来说操作流程是: 获取新书籍->获取新章节->获取新模块->获取新视频->下载视频封面->更新数据库视频封面链接
* 2.如果只是某本版本更新了内容,并没有新增书籍,也可以单独更新章节/模块/视频
* 3.他们存储有几个域名,其中有一个oss.5rs.com得域名,这个域名下的视频封面不可以直接访问的,所以需要特殊处理来下载
* 更新完视频后检查下有无此域名的,如果有需要使用功能6单独下载
* 4.视频可能没有时长,使用功能8单独获取
*
*/
@SpringBootApplication @SpringBootApplication
@MapperScan("cn.bxe.updatevideo.mapper") @MapperScan("cn.bxe.updatevideo.mapper")
public class UpdateVideoApplication { public class UpdateVideoApplication {
...@@ -84,10 +92,10 @@ public class UpdateVideoApplication { ...@@ -84,10 +92,10 @@ public class UpdateVideoApplication {
System.out.println("3: 更新模块"); System.out.println("3: 更新模块");
System.out.println("4: 更新视频"); System.out.println("4: 更新视频");
System.out.println("5: 下载封面"); System.out.println("5: 下载封面");
System.out.println("6: 更新数据库视频封面链接"); System.out.println("6: 下载oss.5rs.me视频封面");
System.out.println("7: 补充视频时长"); System.out.println("7: 更新数据库视频封面链接");
System.out.println("8: 计算数量"); System.out.println("8: 补充视频时长");
System.out.println("9: 下载oss5rsme视频封面"); System.out.println("9: 计算数量");
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("请输入功能代码: ");
...@@ -115,21 +123,21 @@ public class UpdateVideoApplication { ...@@ -115,21 +123,21 @@ public class UpdateVideoApplication {
downloadCoverPic(); downloadCoverPic();
break; break;
case "6": case "6":
System.out.println("下载oss5rsme视频封面");
getOss5rsmeCover();
break;
case "7":
System.out.println("更新数据库视频封面链接咯"); System.out.println("更新数据库视频封面链接咯");
updateDbVideoCoverUrl(); updateDbVideoCoverUrl();
break; break;
case "7": case "8":
System.out.println("补充视频时长咯"); System.out.println("补充视频时长咯");
updateVideoDuration(); updateVideoDuration();
break; break;
case "8": case "9":
System.out.println("计算"); System.out.println("计算");
countSubjectVideo(); countSubjectVideo();
break; break;
case "9":
System.out.println("下载oss5rsme视频封面");
getOss5rsmeCover();
break;
case "0": case "0":
System.out.println("退出咯"); System.out.println("退出咯");
System.exit(0); System.exit(0);
...@@ -144,8 +152,7 @@ public class UpdateVideoApplication { ...@@ -144,8 +152,7 @@ public class UpdateVideoApplication {
private static void updateTextbook() { 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)
.addHeader("authorize", "banxiaoer") .addHeader("authorize", "banxiaoer")
.setBodyPara(new Object()) .setBodyPara(new Object())
.post() .post()
...@@ -154,34 +161,33 @@ public class UpdateVideoApplication { ...@@ -154,34 +161,33 @@ public class UpdateVideoApplication {
boolean hasData = jsonObject.containsKey("data"); boolean hasData = jsonObject.containsKey("data");
if (hasData) { if (hasData) {
String data = jsonObject.getObject("data", String.class); String data = jsonObject.getString("data");
List<Textbook> textbooks = JsonUtil.tranJsonStrToArray(data, Textbook.class); List<Textbook> textbooks = JSONArray.parseArray(data, Textbook.class);
List<TbxXrBook> tbxXrBookList = new ArrayList<>(); List<TbxXrBook> tbxXrBookList = new ArrayList<>();
for (Textbook original : textbooks) { for (Textbook original : textbooks) {
if (original.getGradeName().contains("修")) {
//过滤掉选修啥的 目前大概不需要
continue;
}
TbxXrBook pojo = new TbxXrBook(); TbxXrBook pojo = new TbxXrBook();
pojo.setBookName(original.getSubjectName() + original.getTextbookVersionName() + original.getGradeName() + original.getSchoolYearName()); pojo.setBookName(original.getSubjectName() + original.getTextbookVersionName() + original.getGradeName() + original.getSchoolYearName());
pojo.setTextbookId((int) original.getId()); pojo.setTextbookId(Math.toIntExact(original.getId()));
pojo.setSubject(SUBJECT_MAP.get(original.getSubject())); pojo.setSubject(SUBJECT_MAP.get(original.getSubject()));
pojo.setGradeCode(GRADE_MAP.get(original.getGrade())); pojo.setGradeCode(GRADE_MAP.get(original.getGrade()));
pojo.setTerm(SCHOOL_YEAR_MAP.get(original.getSchoolYear())); pojo.setTerm(SCHOOL_YEAR_MAP.get(original.getSchoolYear()));
pojo.setStatus(10); pojo.setStatus(10);
pojo.setTextbookVersion(VERSION_MAP.get(original.getTextbookVersion())); String textBookVersion = VERSION_MAP.get(original.getTextbookVersion());
if (textBookVersion == null) {
logger.warn("版本未登记: {} {}", original.getTextbookVersion(), pojo.getBookName());
logger.warn(JsonUtil.tranObjectToJsonStr(original));
}
pojo.setTextbookVersion(textBookVersion);
pojo.setCreateTime(System.currentTimeMillis()); pojo.setCreateTime(System.currentTimeMillis());
tbxXrBookList.add(pojo); tbxXrBookList.add(pojo);
} }
if (tbxXrBookList.size() > 0) { if (!tbxXrBookList.isEmpty()) {
//查询已存在的book // 查询已存在的book
LambdaQueryWrapper<TbxXrBook> qw = new LambdaQueryWrapper<>(); Set<Integer> textBookSet = bookService.lambdaQuery().select(TbxXrBook::getTextbookId).list()
qw.select(TbxXrBook::getTextbookId); .stream().map(TbxXrBook::getTextbookId).collect(Collectors.toSet());
List<TbxXrBook> list = bookService.list(qw); // 根据textbookId过滤已存在的
//根据textbookId过滤已存在的
Set<Integer> textBookSet = list.stream().map(TbxXrBook::getTextbookId).collect(Collectors.toSet());
tbxXrBookList = tbxXrBookList.stream().filter(o -> !textBookSet.contains(o.getTextbookId())).collect(Collectors.toList()); tbxXrBookList = tbxXrBookList.stream().filter(o -> !textBookSet.contains(o.getTextbookId())).collect(Collectors.toList());
//保存新增的 // 保存新增的
bookService.saveBatch(tbxXrBookList); bookService.saveBatch(tbxXrBookList);
} }
} }
...@@ -577,7 +583,7 @@ public class UpdateVideoApplication { ...@@ -577,7 +583,7 @@ public class UpdateVideoApplication {
private static void updateVideoDuration() throws InterruptedException { private static void updateVideoDuration() throws InterruptedException {
LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>();
qw.select(TbxXrVideo::getId, TbxXrVideo::getUrl); qw.select(TbxXrVideo::getId, TbxXrVideo::getUrl);
qw.eq(TbxXrVideo::getTimeDuration, ""); qw.in(TbxXrVideo::getTimeDuration,"","--");
qw.eq(TbxXrVideo::getStatus, 10); qw.eq(TbxXrVideo::getStatus, 10);
List<TbxXrVideo> list = videoService.list(qw); List<TbxXrVideo> list = videoService.list(qw);
int size = list.size(); int size = list.size();
...@@ -620,7 +626,7 @@ public class UpdateVideoApplication { ...@@ -620,7 +626,7 @@ public class UpdateVideoApplication {
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);
List<TbxXrVideo> list = videoService.list(qw); List<TbxXrVideo> list = videoService.list(qw);
int size = list.size(); int size = list.size();
...@@ -666,6 +672,7 @@ public class UpdateVideoApplication { ...@@ -666,6 +672,7 @@ public class UpdateVideoApplication {
private static void getOss5rsmeCover() throws IOException, InterruptedException { private static void getOss5rsmeCover() throws IOException, InterruptedException {
LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>();
qw.like(TbxXrVideo::getUrl, "https://oss.5rs.me"); qw.like(TbxXrVideo::getUrl, "https://oss.5rs.me");
qw.isNull(TbxXrVideo::getCoverUrl);
List<TbxXrVideo> list = videoService.list(qw); List<TbxXrVideo> list = videoService.list(qw);
for (TbxXrVideo tbxXrVideo : list) { for (TbxXrVideo tbxXrVideo : list) {
//如果已存在则跳过 //如果已存在则跳过
......
...@@ -56,6 +56,9 @@ public class VersionUtil { ...@@ -56,6 +56,9 @@ public class VersionUtil {
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"); VERSION_MAP.put("WAI_YAN_TOGETHER","waiyanyiqi");
VERSION_MAP.put("POPULARIZE_SCIENCE","kepu");
VERSION_MAP.put("PEP_A","pep_a");
VERSION_MAP.put("PEP_B","pep_b");
//学年 //学年
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!