|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.live.service.impl;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -975,7 +976,38 @@ public class LiveServiceImpl implements ILiveService
|
|
|
redisCache.redisTemplate.opsForZSet().add("live:auto_task:" + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
|
|
|
redisCache.redisTemplate.expire("live:auto_task:"+live.getLiveId(), 1, TimeUnit.DAYS);
|
|
|
});
|
|
|
+ String cacheKey = String.format(LiveKeysConstant.LIVE_DATA_CACHE, live.getLiveId());
|
|
|
+ redisCache.deleteObject(cacheKey);
|
|
|
+ String cacheKey2 = String.format(LiveKeysConstant.LIVE_FLAG_CACHE, live.getLiveId());
|
|
|
+ redisCache.deleteObject(cacheKey2);
|
|
|
|
|
|
+ // 将开启的直播间信息写入Redis缓存,用于打标签定时任务
|
|
|
+ try {
|
|
|
+ // 获取视频时长
|
|
|
+ Long videoDuration = 0L;
|
|
|
+ List<LiveVideo> videos = liveVideoService.listByLiveId(live.getLiveId(), 1);
|
|
|
+ if (CollUtil.isNotEmpty(videos)) {
|
|
|
+ videoDuration = videos.stream()
|
|
|
+ .filter(v -> v.getDuration() != null)
|
|
|
+ .mapToLong(LiveVideo::getDuration)
|
|
|
+ .sum();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果视频时长大于0,将直播间信息存入Redis
|
|
|
+ if (videoDuration > 0 && live.getStartTime() != null) {
|
|
|
+ Map<String, Object> tagMarkInfo = new HashMap<>();
|
|
|
+ tagMarkInfo.put("liveId", live.getLiveId());
|
|
|
+ tagMarkInfo.put("startTime", live.getStartTime().atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli());
|
|
|
+ tagMarkInfo.put("videoDuration", videoDuration);
|
|
|
+
|
|
|
+ String tagMarkKey = String.format(LiveKeysConstant.LIVE_TAG_MARK_CACHE, live.getLiveId());
|
|
|
+ redisCache.setCacheObject(tagMarkKey, JSON.toJSONString(tagMarkInfo), 24, TimeUnit.HOURS);
|
|
|
+ log.info("手动开直播间开启,已加入打标签缓存: liveId={}, startTime={}, videoDuration={}",
|
|
|
+ live.getLiveId(), live.getStartTime(), videoDuration);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("手动开写入直播间打标签缓存失败: liveId={}, error={}", live.getLiveId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
|
|
|
return R.ok();
|
|
|
}
|