|
|
@@ -93,6 +93,7 @@ public class Task {
|
|
|
return;
|
|
|
List<Long> liveIdLists = list.stream().map(Live::getLiveId).collect(Collectors.toList());
|
|
|
List<LiveAutoTask> liveAutoTasks = liveAutoTaskService.selectLiveAutoTaskByLiveIds(liveIdLists);
|
|
|
+ List<Live> liveList = new ArrayList<>();
|
|
|
LocalDateTime now = LocalDateTime.now().plusSeconds(2L);
|
|
|
List<Live> startLiveList = new ArrayList<>();
|
|
|
List<Live> endLiveList = new ArrayList<>();
|
|
|
@@ -101,25 +102,36 @@ public class Task {
|
|
|
if (live.getFinishTime() == null) {
|
|
|
if (now.isAfter(live.getStartTime().minusSeconds(2L))){
|
|
|
if(live.getStatus() != 2){
|
|
|
+ live.setStatus(2);
|
|
|
startLiveList.add(live);
|
|
|
+ liveList.add(live);
|
|
|
}
|
|
|
- live.setStatus(2);
|
|
|
} else if (now.isBefore(live.getStartTime())) {
|
|
|
- live.setStatus(1);
|
|
|
+ if (live.getStatus() != 1) {
|
|
|
+ live.setStatus(1);
|
|
|
+ liveList.add(live);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
} else {
|
|
|
if (now.isAfter(live.getStartTime().minusSeconds(2L)) && now.isBefore(live.getFinishTime())) {
|
|
|
if(live.getStatus() != 2){
|
|
|
startLiveList.add(live);
|
|
|
+ live.setStatus(2);
|
|
|
+ liveList.add(live);
|
|
|
}
|
|
|
live.setStatus(2);
|
|
|
} else if (now.isBefore(live.getStartTime().minusSeconds(2L))) {
|
|
|
- live.setStatus(1);
|
|
|
+ if (live.getStatus() != 1) {
|
|
|
+ live.setStatus(1);
|
|
|
+ liveList.add(live);
|
|
|
+ }
|
|
|
} else if (now.isAfter(live.getFinishTime().minusSeconds(2L))) {
|
|
|
if(live.getStatus() != 3){
|
|
|
endLiveList.add(live);
|
|
|
+ live.setStatus(3);
|
|
|
+ liveList.add(live);
|
|
|
}
|
|
|
- live.setStatus(3);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
@@ -127,26 +139,25 @@ public class Task {
|
|
|
LiveReplayParam liveReplayParam = JSON.parseObject(live.getLiveConfig(), LiveReplayParam.class);
|
|
|
if (liveReplayParam.getIsPlaybackOpen()) {
|
|
|
if (liveReplayParam.getFinishTime() != null) {
|
|
|
- if (now.isAfter(live.getFinishTime().minusSeconds(2L))) {
|
|
|
+ if (now.isAfter(liveReplayParam.getFinishTime().minusSeconds(2L))) {
|
|
|
if(live.getStatus() != 3){
|
|
|
endLiveList.add(live);
|
|
|
+ live.setStatus(3);
|
|
|
+ liveList.add(live);
|
|
|
}
|
|
|
- live.setStatus(3);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
String key = "live:auto_task:";
|
|
|
-
|
|
|
- if(!list.isEmpty()){
|
|
|
- for (Live live : list) {
|
|
|
- liveService.updateLive(live);
|
|
|
- }
|
|
|
- }
|
|
|
if (!startLiveList.isEmpty()) {
|
|
|
for (Live live : startLiveList) {
|
|
|
+ redisUtil.zSetAdd(LiveKeysConstant.LIVE_HOME_PAGE_LIST, JSON.toJSONString(live), live.getCreateTime().getTime());
|
|
|
+ SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
+ sendMsgVo.setMsg("开始直播");
|
|
|
+ sendMsgVo.setCmd("live_start");
|
|
|
+ webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
|
|
|
List<LiveAutoTask> collect = liveAutoTasks.stream().filter(liveAutoTask -> liveAutoTask.getLiveId().equals(live.getLiveId())).collect(Collectors.toList());
|
|
|
if (!collect.isEmpty()) {
|
|
|
collect.forEach(liveAutoTask -> {
|
|
|
@@ -156,15 +167,14 @@ 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 (!endLiveList.isEmpty()) {
|
|
|
for (Live live : endLiveList) {
|
|
|
+ SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
+ sendMsgVo.setMsg("结束直播");
|
|
|
+ sendMsgVo.setCmd("live_end");
|
|
|
+ webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
|
|
|
List<LiveAutoTask> collect = liveAutoTasks.stream().filter(liveAutoTask -> liveAutoTask.getLiveId().equals(live.getLiveId())).collect(Collectors.toList());
|
|
|
if (!collect.isEmpty()) {
|
|
|
collect.forEach(liveAutoTask -> {
|
|
|
@@ -173,10 +183,11 @@ public class Task {
|
|
|
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)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!liveList.isEmpty()){
|
|
|
+ for (Live live : liveList) {
|
|
|
+ liveService.updateLiveEntity(live);
|
|
|
}
|
|
|
}
|
|
|
}
|