|
@@ -35,6 +35,7 @@ import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.BiPredicate;
|
|
|
+import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -302,6 +303,9 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
this.createLiveRoomInfo(room, sysUser);
|
|
|
//临时
|
|
|
this.pushLiveCreateRoom(room);
|
|
|
+ //写入临时直播间列表
|
|
|
+ RMap<Long, String> map = redissonClient.getMap(TEACHER_TEMP_LIVE_ROOM);
|
|
|
+ map.put(teacherId, roomUid);
|
|
|
return roomUid;
|
|
|
}
|
|
|
|
|
@@ -447,23 +451,6 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
String speakerIdStr = room.getSpeakerId().toString();
|
|
|
String roomUid = room.getRoomUid();
|
|
|
|
|
|
- //删除房间全部人员缓存
|
|
|
- this.getTotalUserCache(roomUid).deleteAsync();
|
|
|
- //获取在线人员信息
|
|
|
- RMap<Long, String> onlineUserCache = this.getOnlineUserCache(roomUid);
|
|
|
- //删除人员对应直播间编号信息
|
|
|
- onlineUserCache.forEach((id, s) -> redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, id.toString())).deleteAsync());
|
|
|
- //删除房间在线人员缓存
|
|
|
- onlineUserCache.deleteAsync();
|
|
|
- //删除房间信息
|
|
|
- this.getLiveRoomInfo(room.getRoomUid()).deleteAsync();
|
|
|
- //删除点赞数
|
|
|
- redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, room.getRoomUid())).deleteAsync();
|
|
|
- //删除当前主讲人最后一次进入房间的ip
|
|
|
- redissonClient.getBucket(LIVE_USER_LAST_CLIENT_IP.replace(ROOM_UID, roomUid).replace(USER_ID, speakerIdStr)).deleteAsync();
|
|
|
- //删除当前主讲人最后一次心跳
|
|
|
- redissonClient.getBucket(LIVE_ROOM_HEART_BEAT.replace(ROOM_UID, roomUid)).deleteAsync();
|
|
|
-
|
|
|
//关闭直播间发送消息
|
|
|
ImRoomMessage message = new ImRoomMessage();
|
|
|
message.setFromUserId(speakerIdStr);
|
|
@@ -476,8 +463,43 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
} catch (Exception e) {
|
|
|
log.error("destroyLiveRoom>>>> FORCED_OFFLINE {}", e.getMessage());
|
|
|
}
|
|
|
- //删除房间
|
|
|
-// this.ImDestroyLiveRoom(room.getRoomUid());
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+ //删除人员与房间关联关系缓存的方法
|
|
|
+ Consumer<String> deleteUserRoomCache = (id) -> redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, id)).deleteAsync();
|
|
|
+ //给老师签退
|
|
|
+ teacherAttendanceService.update(Wrappers.<TeacherAttendance>lambdaUpdate()
|
|
|
+ .eq(TeacherAttendance::getTeacherId, room.getSpeakerId())
|
|
|
+ .eq(TeacherAttendance::getCourseScheduleId, room.getCourseId())
|
|
|
+ .set(TeacherAttendance::getSignOutTime, now));
|
|
|
+ //删除老师与房间关联关系
|
|
|
+ deleteUserRoomCache.accept(speakerIdStr);
|
|
|
+ //获取在线人员信息
|
|
|
+ RMap<Long, String> onlineUserCache = this.getOnlineUserCache(roomUid);
|
|
|
+ onlineUserCache.forEach((id, s) -> {
|
|
|
+ //删除观看者对应直播间编号的缓存
|
|
|
+ deleteUserRoomCache.accept(id.toString());
|
|
|
+ //观看者签退
|
|
|
+ studentAttendanceService.update(Wrappers.<StudentAttendance>lambdaUpdate()
|
|
|
+ .eq(StudentAttendance::getStudentId, id)
|
|
|
+ .eq(StudentAttendance::getCourseScheduleId, room.getCourseId())
|
|
|
+ .set(StudentAttendance::getSignOutTime, now));
|
|
|
+ });
|
|
|
+ //删除房间在线人员缓存
|
|
|
+ onlineUserCache.deleteAsync();
|
|
|
+ //删除房间信息
|
|
|
+ this.getLiveRoomInfo(roomUid).deleteAsync();
|
|
|
+ //删除点赞数
|
|
|
+ redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, roomUid)).deleteAsync();
|
|
|
+ //删除当前主讲人最后一次进入房间的ip
|
|
|
+ redissonClient.getBucket(LIVE_USER_LAST_CLIENT_IP.replace(ROOM_UID, roomUid).replace(USER_ID, speakerIdStr)).deleteAsync();
|
|
|
+ //删除当前主讲人最后一次心跳
|
|
|
+ redissonClient.getBucket(LIVE_ROOM_HEART_BEAT.replace(ROOM_UID, roomUid)).deleteAsync();
|
|
|
+ //删除房间全部人员缓存
|
|
|
+ this.getTotalUserCache(roomUid).deleteAsync();
|
|
|
+ //删除该临时直播间列表
|
|
|
+ RMap<Long, String> map = redissonClient.getMap(TEACHER_TEMP_LIVE_ROOM);
|
|
|
+ map.remove(room.getSpeakerId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -513,10 +535,17 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
if (StringUtils.isBlank(user.getStatus())) {
|
|
|
return;
|
|
|
}
|
|
|
+ String userIdStr = user.getUserid();
|
|
|
+ //获取当前用户所在房间的uid
|
|
|
+ RBucket<String> userRoom = redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userIdStr));
|
|
|
+ if (!userRoom.isExists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String roomUid = userRoom.get();
|
|
|
+
|
|
|
Date now = new Date();
|
|
|
//获取当前用户状态变更的时间
|
|
|
long userStateTime = Optional.ofNullable(user.getTime()).orElse(now.getTime());
|
|
|
- String userIdStr = user.getUserid();
|
|
|
RBucket<Long> userStateTimeCache = redissonClient.getBucket(LIVE_USER_LAST_TIME.replace(USER_ID, userIdStr));
|
|
|
if (userStateTimeCache.isExists()) {
|
|
|
//缓存的时间比当前传入时间大则放弃这条数据
|
|
@@ -526,13 +555,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
}
|
|
|
}
|
|
|
//将最新的时间写入缓存
|
|
|
- userStateTimeCache.set(userStateTime, 5L, TimeUnit.MINUTES);
|
|
|
- //获取当前用户所在房间的uid
|
|
|
- RBucket<String> userRoom = redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userIdStr));
|
|
|
- if (!userRoom.isExists()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- String roomUid = userRoom.get();
|
|
|
+ userStateTimeCache.set(userStateTime, 60L, TimeUnit.MINUTES);
|
|
|
//根据房间号获取房间信息
|
|
|
RBucket<RoomInfoCache> roomInfoCache = this.getLiveRoomInfo(roomUid);
|
|
|
if (!roomInfoCache.isExists()) {
|
|
@@ -541,7 +564,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
RoomInfoCache roomInfo = roomInfoCache.get();
|
|
|
// 查询userId是不是主讲人 ,如果是主讲人则返回
|
|
|
if (roomInfo.getSpeakerId().toString().equals(userIdStr)) {
|
|
|
- opsSpeaker(roomInfoCache, user, now, userIdStr);
|
|
|
+ this.opsSpeaker(roomInfoCache, user, now, userIdStr);
|
|
|
return;
|
|
|
}
|
|
|
//这里开始只处理观看者的数据,观看者只接受退出消息 status=0 是进入房间
|
|
@@ -553,7 +576,10 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//从房间累计用户信息中查询该用户的信息
|
|
|
RMap<Long, String> roomTotalUser = this.getTotalUserCache(roomUid);
|
|
|
//该房间未查询到用户数据则不处理
|
|
|
- if (!roomTotalUser.isExists() && !roomTotalUser.containsKey(userId)) {
|
|
|
+ if (!roomTotalUser.isExists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!roomTotalUser.containsKey(userId)) {
|
|
|
return;
|
|
|
}
|
|
|
//查询用户数据
|
|
@@ -569,13 +595,10 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//从在线人员列表删除该人员
|
|
|
onlineUserInfo.fastRemove(userId);
|
|
|
//学员退出 写学生考勤表
|
|
|
- StudentAttendance studentAttendance = studentAttendanceService.getOne(Wrappers.<StudentAttendance>lambdaQuery()
|
|
|
+ studentAttendanceService.update(Wrappers.<StudentAttendance>lambdaUpdate()
|
|
|
.eq(StudentAttendance::getStudentId, userId)
|
|
|
- .eq(StudentAttendance::getCourseScheduleId, roomInfo.getCourseId()));
|
|
|
- if (Objects.nonNull(studentAttendance)) {
|
|
|
- studentAttendance.setSignOutTime(now);
|
|
|
- studentAttendanceService.updateById(studentAttendance);
|
|
|
- }
|
|
|
+ .eq(StudentAttendance::getCourseScheduleId, roomInfo.getCourseId())
|
|
|
+ .set(StudentAttendance::getSignOutTime, now));
|
|
|
//向直播间发送当前在线人数消息
|
|
|
this.sendOnlineUserCount(roomUid, userId, onlineUserInfo.size());
|
|
|
log.info("opsRoom>>>> looker userInfo: {}", userJsonStr);
|
|
@@ -713,6 +736,8 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
* @param userId 用户id 观看者id
|
|
|
*/
|
|
|
public RoomInfoCache joinRoom(String roomUid, Long userId) {
|
|
|
+ Optional.ofNullable(roomUid).orElseThrow(() -> new BizException("房间编号不能为空!"));
|
|
|
+ Optional.ofNullable(userId).orElseThrow(() -> new BizException("人员编号不能为空!"));
|
|
|
//获取进入房间人员信息
|
|
|
SysUser sysUser = this.getSysUser(userId);
|
|
|
//校验信息
|
|
@@ -731,9 +756,9 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
userInfo.setUserId(sysUser.getId());
|
|
|
userInfo.setUserName(sysUser.getRealName());
|
|
|
userInfo.setFirstJoinTime(now);
|
|
|
- //查询学生是否有进入过,没有则写学生考勤表的进入时间
|
|
|
- this.setStudentAttendance(userId, roomInfo.getCourseGroupId(), roomInfo.getCourseId());
|
|
|
}
|
|
|
+ //查询学生是否有进入过,没有则写学生考勤表的进入时间
|
|
|
+ this.setStudentAttendance(userId, roomInfo.getCourseGroupId(), roomInfo.getCourseId());
|
|
|
userInfo.setDynamicJoinTime(now);
|
|
|
//用户json信息
|
|
|
String userJsonStr = JSONObject.toJSONString(userInfo);
|
|
@@ -812,6 +837,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
studentAttendance.setSignInTime(now);
|
|
|
studentAttendance.setCreateTime(now);
|
|
|
studentAttendanceService.save(studentAttendance);
|
|
|
+ log.info("SignInTime >>> user {} courseId {}", studentId, courseId);
|
|
|
}
|
|
|
}
|
|
|
|