|
@@ -325,6 +325,102 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
log.info("destroyLiveRoom success: {}", roomId);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <p>主讲人处理进入和退出房间数据
|
|
|
+ * <p>观看者只处理退出房间数据
|
|
|
+ *
|
|
|
+ * @param userState 用户状态数据
|
|
|
+ */
|
|
|
+ public void opsRoom(List<ImUserStateSync> userState) {
|
|
|
+ if (CollectionUtils.isEmpty(userState)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ userState.forEach(user -> {
|
|
|
+ log.info("opsRoom>>>> {}", JSONObject.toJSONString(user));
|
|
|
+ if (StringUtils.isBlank(user.getStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ //获取当前用户状态变更的时间
|
|
|
+ long userStateTime = Optional.ofNullable(user.getTime()).orElse(now.getTime());
|
|
|
+ String userIdStr = user.getUserid();
|
|
|
+ RBucket<Long> userStateTimeCache = redissonClient.getBucket(LIVE_TEACHER_LAST_TIME.replace(USER_ID, userIdStr));
|
|
|
+ if (userStateTimeCache.isExists()) {
|
|
|
+ //缓存的时间比当前传入时间大则放弃这条数据
|
|
|
+ long cacheTime = userStateTimeCache.get();
|
|
|
+ if (cacheTime > userStateTime) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //将最新的时间写入缓存
|
|
|
+ userStateTimeCache.set(userStateTime, 5L, TimeUnit.MINUTES);
|
|
|
+ //直播间号
|
|
|
+ String roomUid;
|
|
|
+ //根据用户id获取用户当前房间号
|
|
|
+ RBucket<String> roomUidCache = redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userIdStr));
|
|
|
+ if (!roomUidCache.isExists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ roomUid = roomUidCache.get();
|
|
|
+ //根据房间号获取房间信息
|
|
|
+ RBucket<RoomInfoCache> roomInfoCache = redissonClient.getBucket(LIVE_ROOM_INFO.replace(ROOM_UID, roomUid));
|
|
|
+ if (!roomInfoCache.isExists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ RoomInfoCache roomInfo = roomInfoCache.get();
|
|
|
+ //主讲人
|
|
|
+ if (roomInfo.getSpeakerId().toString().equals(userIdStr)) {
|
|
|
+ //主讲人进入房间
|
|
|
+ if (user.getStatus().equals("0")) {
|
|
|
+ roomInfo.setSpeakerState(0);
|
|
|
+ roomInfo.setJoinRoomTime(now);
|
|
|
+ log.info("opsRoom>>>> join roomInfo {}", JSONObject.toJSONString(roomInfo));
|
|
|
+ roomInfoCache.set(roomInfo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ roomInfo.setExitRoomTime(now);
|
|
|
+ log.info("opsRoom>>>> exit roomInfo {}", JSONObject.toJSONString(roomInfo));
|
|
|
+ roomInfoCache.set(roomInfo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //观看者只接受退出消息 status=0 是进入房间
|
|
|
+ if (user.getStatus().equals("0")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //观看者
|
|
|
+ Long userId = Long.valueOf(userIdStr);
|
|
|
+ //从房间累计用户信息中查询该用户的信息
|
|
|
+ RMap<Long, RoomUserInfoCache> roomTotalUser = redissonClient.getMap(LIVE_ROOM_TOTAL_USER_LIST.replace(ROOM_UID, roomUid));
|
|
|
+ //该房间未查询到用户数据则不处理
|
|
|
+ if (!roomTotalUser.isExists() && !roomTotalUser.containsKey(userId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //查询到用户数据
|
|
|
+ RoomUserInfoCache userInfo = roomTotalUser.get(userId);
|
|
|
+ //用户是在房间的状态 并且 突然离线 - 那么融云会发送用户离线消息-此刻就发送退出房间消息给主讲人
|
|
|
+ if (userInfo.getState() == 0 && user.getStatus().equals("1")) {
|
|
|
+ ImRoomMessage message = new ImRoomMessage();
|
|
|
+ message.setFromUserId(userId.toString());
|
|
|
+ message.setToChatroomId(roomUid);
|
|
|
+ message.setObjectName(ImRoomMessage.RC_CHATROOM_LEAVE);
|
|
|
+ try {
|
|
|
+ publishRoomMessage(message);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("opsRoom>>>> looker error {}", e.getMessage());
|
|
|
+ log.error("opsRoom>>>> looker error sendMessage {} : leave : {}", message, JSONObject.toJSONString(userInfo));
|
|
|
+ }
|
|
|
+ log.info("opsRoom>>>> looker leave : {}", JSONObject.toJSONString(userInfo));
|
|
|
+ }
|
|
|
+ //记录退出时间 并写入缓存
|
|
|
+ userInfo.setLastOutTime(now);
|
|
|
+ userInfo.setState(1);
|
|
|
+ roomTotalUser.fastPut(userId, userInfo);
|
|
|
+ log.info("opsRoom>>>> looker userInfo: {}", JSONObject.toJSONString(userInfo));
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 同步点赞数量
|
|
|
*
|
|
@@ -352,7 +448,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
roomInfo.setLikeNum(getLike(roomUid));
|
|
|
roomInfo.setLookNum(getLooker(roomUid));
|
|
|
|
|
|
- //记录当前对应的房间uid
|
|
|
+ //记录当前用户对应的房间uid
|
|
|
redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString())).set(roomUid, 2L, TimeUnit.DAYS);
|
|
|
|
|
|
Date now = new Date();
|
|
@@ -484,7 +580,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
param.put("year", "2022");
|
|
|
param.put("singleCourseMinutes", 60);
|
|
|
param.put("teacherId", 4);
|
|
|
- List<CourseCalendarEntity> courseTimeEntities = courseScheduleService.createLiveCourseCalendar(param);
|
|
|
+ List<CourseCalendarEntity> courseTimeEntities = courseScheduleService.createLiveCourseCalendar(param);
|
|
|
result.put("自动生成课时", courseTimeEntities);
|
|
|
|
|
|
//获取房间信息
|