|
|
@@ -93,24 +93,32 @@ public class Task {
|
|
|
return;
|
|
|
List<Long> liveIdLists = list.stream().map(Live::getLiveId).collect(Collectors.toList());
|
|
|
List<LiveAutoTask> liveAutoTasks = liveAutoTaskService.selectLiveAutoTaskByLiveIds(liveIdLists);
|
|
|
- List<Live> activeLiveList = new ArrayList<>();
|
|
|
- LocalDateTime now = LocalDateTime.now().minusSeconds(2L);
|
|
|
+ LocalDateTime now = LocalDateTime.now().plusSeconds(2L);
|
|
|
+ List<Live> startLiveList = new ArrayList<>();
|
|
|
+ List<Live> endLiveList = new ArrayList<>();
|
|
|
list.forEach(live -> {
|
|
|
if (live.getLiveType() != 3) {
|
|
|
if (live.getFinishTime() == null) {
|
|
|
if (now.isAfter(live.getStartTime().minusSeconds(2L))){
|
|
|
+ if(live.getStatus() != 2){
|
|
|
+ startLiveList.add(live);
|
|
|
+ }
|
|
|
live.setStatus(2);
|
|
|
- activeLiveList.add( live);
|
|
|
} else if (now.isBefore(live.getStartTime())) {
|
|
|
live.setStatus(1);
|
|
|
}
|
|
|
} else {
|
|
|
if (now.isAfter(live.getStartTime().minusSeconds(2L)) && now.isBefore(live.getFinishTime())) {
|
|
|
+ if(live.getStatus() != 2){
|
|
|
+ startLiveList.add(live);
|
|
|
+ }
|
|
|
live.setStatus(2);
|
|
|
- activeLiveList.add( live);
|
|
|
} else if (now.isBefore(live.getStartTime().minusSeconds(2L))) {
|
|
|
live.setStatus(1);
|
|
|
} else if (now.isAfter(live.getFinishTime().minusSeconds(2L))) {
|
|
|
+ if(live.getStatus() != 3){
|
|
|
+ endLiveList.add(live);
|
|
|
+ }
|
|
|
live.setStatus(3);
|
|
|
}
|
|
|
}
|
|
|
@@ -120,6 +128,9 @@ public class Task {
|
|
|
if (liveReplayParam.getIsPlaybackOpen()) {
|
|
|
if (liveReplayParam.getFinishTime() != null) {
|
|
|
if (now.isAfter(live.getFinishTime().minusSeconds(2L))) {
|
|
|
+ if(live.getStatus() != 3){
|
|
|
+ endLiveList.add(live);
|
|
|
+ }
|
|
|
live.setStatus(3);
|
|
|
}
|
|
|
}
|
|
|
@@ -128,8 +139,14 @@ public class Task {
|
|
|
|
|
|
});
|
|
|
String key = "live:auto_task:";
|
|
|
- if(!activeLiveList.isEmpty()){
|
|
|
- activeLiveList.forEach(live -> {
|
|
|
+
|
|
|
+ if(!list.isEmpty()){
|
|
|
+ for (Live live : list) {
|
|
|
+ liveService.updateLive(live);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!startLiveList.isEmpty()) {
|
|
|
+ for (Live live : startLiveList) {
|
|
|
List<LiveAutoTask> collect = liveAutoTasks.stream().filter(liveAutoTask -> liveAutoTask.getLiveId().equals(live.getLiveId())).collect(Collectors.toList());
|
|
|
if (!collect.isEmpty()) {
|
|
|
collect.forEach(liveAutoTask -> {
|
|
|
@@ -139,23 +156,27 @@ public class Task {
|
|
|
redisCache.redisTemplate.expire(key+live.getLiveId(), 30, java.util.concurrent.TimeUnit.MINUTES);
|
|
|
});
|
|
|
}
|
|
|
- });
|
|
|
+ liveService.asyncToCacheLiveDetail(live.getLiveId());
|
|
|
+ SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
+ sendMsgVo.setMsg("开始直播");
|
|
|
+ sendMsgVo.setCmd("live_start");
|
|
|
+ webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if(!list.isEmpty()){
|
|
|
- for (Live live : list) {
|
|
|
- liveService.updateLive(live);
|
|
|
- if (live.getStatus() == 2) {
|
|
|
- SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
- sendMsgVo.setMsg("开始直播");
|
|
|
- sendMsgVo.setCmd("live_start");
|
|
|
- webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
|
|
|
- }else if (live.getStatus() == 3) {
|
|
|
- SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
- sendMsgVo.setMsg("结束直播");
|
|
|
- sendMsgVo.setCmd("live_end");
|
|
|
- webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
|
|
|
+ if (!endLiveList.isEmpty()) {
|
|
|
+ for (Live live : endLiveList) {
|
|
|
+ List<LiveAutoTask> collect = liveAutoTasks.stream().filter(liveAutoTask -> liveAutoTask.getLiveId().equals(live.getLiveId())).collect(Collectors.toList());
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
+ collect.forEach(liveAutoTask -> {
|
|
|
+ liveAutoTask.setCreateTime(null);
|
|
|
+ liveAutoTask.setUpdateTime(null);
|
|
|
+ redisCache.redisTemplate.opsForZSet().remove(key + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
|
|
|
+ });
|
|
|
}
|
|
|
+ SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
+ sendMsgVo.setMsg("开始直播");
|
|
|
+ sendMsgVo.setCmd("live_start");
|
|
|
+ webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
|
|
|
}
|
|
|
}
|
|
|
}
|