浏览代码

直播代码 创建直播的时候添加直播数据

yuhongqi 2 周之前
父节点
当前提交
88bcbd9812

+ 2 - 1
fs-live-app/src/main/java/com/fs/app/websocket/service/WebSocketServer.java

@@ -19,6 +19,7 @@ import com.fs.live.domain.LiveWatchUser;
 import com.fs.live.service.*;
 import com.fs.live.vo.LiveWatchUserVO;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.*;
@@ -283,7 +284,7 @@ public class WebSocketServer {
     /**
      *定期将缓存的数据写入数据库
      */
-//    @Scheduled(fixedRate = 60000) // 每分钟执行一次
+    @Scheduled(fixedRate = 60000) // 每分钟执行一次
     public void syncLiveDataToDB() {
         List<LiveData> liveDatas = liveDataService.getAllLiveDatas(); // 获取所有正在直播的直播间数据
         if(liveDatas == null)

+ 12 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -228,6 +228,18 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
         live.setStatus(2);
         live.setLiveType(1);
         this.updateLive(live);
+        LiveData liveData = new LiveData();
+        liveData.setLiveId(liveId);
+        liveData.setPageViews(0L);
+        liveData.setUniqueVisitors(0L);
+        liveData.setTotalViews(0L);
+        liveData.setUniqueViewers(0L);
+        liveData.setPeakConcurrentViewers(0L);
+        liveData.setLikes(0L);
+        liveData.setFavourite_num(0L);
+        liveData.setFollow_num(0L);
+        liveDataService.insertLiveData(liveData);
+
         return R.ok().put("rtmpUrl", rtmpPushUrl);
     }