71 lines
2.4 KiB
Java
71 lines
2.4 KiB
Java
|
|
package com.tuoheng.steam.schedule;
|
||
|
|
|
||
|
|
import com.tuoheng.steam.service.IRecordService;
|
||
|
|
import com.tuoheng.steam.service.TaskService;
|
||
|
|
import com.tuoheng.steam.service.dos.DayRecord;
|
||
|
|
import com.tuoheng.steam.service.dos.FlvRecord;
|
||
|
|
import com.tuoheng.steam.service.dos.Mp4Record;
|
||
|
|
import com.tuoheng.steam.service.dos.StreamRecord;
|
||
|
|
import com.tuoheng.steam.util.TimeUtils;
|
||
|
|
import org.slf4j.Logger;
|
||
|
|
import org.slf4j.LoggerFactory;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.beans.factory.annotation.Value;
|
||
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
||
|
|
import org.springframework.stereotype.Component;
|
||
|
|
import java.util.*;
|
||
|
|
|
||
|
|
|
||
|
|
@Component
|
||
|
|
public class Scheduler {
|
||
|
|
|
||
|
|
private static final Logger logger = LoggerFactory.getLogger(Scheduler.class);
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
IRecordService iRecordService;
|
||
|
|
|
||
|
|
@Value("${livedates}")
|
||
|
|
private Integer livedates;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 初次执行延迟6秒执行
|
||
|
|
* 每隔 60 分钟执行一次 60*60*1000
|
||
|
|
*/
|
||
|
|
@Scheduled(fixedRate = 3600000, initialDelay = 6000)
|
||
|
|
public void mergeTask() {
|
||
|
|
System.out.println("开始FLV到MP4的转换 - " + System.currentTimeMillis() / 1000);
|
||
|
|
List<DayRecord> dayRecords = iRecordService.findDaysPath();
|
||
|
|
for (int index = 0; index < dayRecords.size(); index++) {
|
||
|
|
|
||
|
|
DayRecord dayRecord = dayRecords.get(index);
|
||
|
|
if(TimeUtils.isBefore(dayRecord.getDay(),livedates)){
|
||
|
|
dayRecord.clear();
|
||
|
|
} else {
|
||
|
|
List<StreamRecord> streamRecords = dayRecord.getStreamRecords();
|
||
|
|
for(StreamRecord streamRecord : streamRecords){
|
||
|
|
List<FlvRecord> flvRecords = streamRecord.queryFlvRecords();
|
||
|
|
for(FlvRecord flvRecord : flvRecords){
|
||
|
|
iRecordService.mergeMp4(flvRecord);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// public static boolean isWithin15Minutes(String timestamp1, String timestamp2) {
|
||
|
|
// // 将字符串转换为 long 类型
|
||
|
|
// long time1 = Long.parseLong(timestamp1);
|
||
|
|
// long time2 = Long.parseLong(timestamp2);
|
||
|
|
// // 计算时间差的绝对值
|
||
|
|
// long diff = Math.abs(time2 - time1);
|
||
|
|
// // 15 分钟 = 15 * 60 * 1000 毫秒
|
||
|
|
// long fifteenMinutesInMillis = 15 * 60 * 1000;
|
||
|
|
// // 判断是否小于或等于 15 分钟
|
||
|
|
// return diff <= fifteenMinutesInMillis;
|
||
|
|
// }
|
||
|
|
|
||
|
|
}
|