|
@@ -16,6 +16,7 @@ import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.redisson.api.RedissonClient;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -25,6 +26,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -58,6 +60,10 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
private IMHelper imHelper;
|
|
private IMHelper imHelper;
|
|
@Resource
|
|
@Resource
|
|
private MusicSheetAccompanimentService musicSheetAccompanimentService;
|
|
private MusicSheetAccompanimentService musicSheetAccompanimentService;
|
|
|
|
+ @Resource
|
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
+
|
|
|
|
+ private String QUIT_ROOM_SUCCESS = "quitRoomSuccess:";
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ImNetworkRoomDao getDao() {
|
|
public ImNetworkRoomDao getDao() {
|
|
@@ -180,40 +186,16 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public void leaveRoom(String roomId) throws Exception {
|
|
|
|
- Long userId = sysUserService.getUserId();
|
|
|
|
- log.info("leaveRoom: roomId={}, userId={}", roomId, userId);
|
|
|
|
- long courseScheduleId = Long.parseLong(roomId);
|
|
|
|
- Long teacherId = Optional.ofNullable(courseScheduleService.getById(courseScheduleId)).
|
|
|
|
- map(CourseSchedule::getTeacherId).
|
|
|
|
- orElseThrow(()->new BizException("房间信息不存在"));
|
|
|
|
- UserRoleEnum userRole = UserRoleEnum.STUDENT;
|
|
|
|
- if(teacherId.equals(userId)){
|
|
|
|
- userRole = UserRoleEnum.TEACHER;
|
|
|
|
- }
|
|
|
|
- if (userRole == UserRoleEnum.TEACHER){
|
|
|
|
- //如果老师退出房间,关闭伴奏
|
|
|
|
- courseScheduleStudentMusicSheetService.getDao().closePlayStatus(courseScheduleId,null);
|
|
|
|
- courseScheduleStudentPaymentService.getDao().adjustPlayMidi(courseScheduleId, null, null);
|
|
|
|
- courseScheduleStudentPaymentService.getDao().adjustExamSong(courseScheduleId, null, null);
|
|
|
|
|
|
+ public void quitRoomSuccess(String roomId, Long userId) throws Exception {
|
|
|
|
+ log.info("quitRoomSuccess: roomId={}, userId={}", roomId, userId);
|
|
|
|
+ //防止幂等
|
|
|
|
+ StringBuffer sb = new StringBuffer(QUIT_ROOM_SUCCESS).append(roomId).append(userId);
|
|
|
|
+ if (!redissonClient.getBucket(sb.toString()).setIfExists(userId,3, TimeUnit.SECONDS)){
|
|
|
|
+ log.info("quitRoomSuccess break: roomId={}, userId={}", roomId, userId);
|
|
}
|
|
}
|
|
- ImNetworkRoomMember roomMember = imNetworkRoomMemberService.getDao().findByRidAndUid(roomId, userId);
|
|
|
|
- //删除用户信息
|
|
|
|
- imNetworkRoomMemberService.getDao().delByRidAndUid(roomId,userId);
|
|
|
|
- //发送退出房间的消息
|
|
|
|
- ImNetworkRoomMemberChangedMessage msg = new ImNetworkRoomMemberChangedMessage(roomMember,ImNetworkRoomMemberChangedEnum.JOIN);
|
|
|
|
- imHelper.publishMessage(userId.toString(), roomId, msg);
|
|
|
|
- imHelper.quit(new String[]{userId.toString()}, roomId);
|
|
|
|
- //记录考勤信息
|
|
|
|
- //是否删除房间信息
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public void leaveRoomSuccess(String roomId, Long userId) throws Exception {
|
|
|
|
- log.info("leaveRoomSuccess: roomId={}, userId={}", roomId, userId);
|
|
|
|
CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(roomId))
|
|
CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(roomId))
|
|
.orElseThrow(()->new BizException("房间信息不存在"));
|
|
.orElseThrow(()->new BizException("房间信息不存在"));
|
|
|
|
+ Long courseScheduleId = courseSchedule.getId();
|
|
UserRoleEnum roleEnum = UserRoleEnum.STUDENT;
|
|
UserRoleEnum roleEnum = UserRoleEnum.STUDENT;
|
|
if(Objects.equals(courseSchedule.getTeacherId(),userId)){
|
|
if(Objects.equals(courseSchedule.getTeacherId(),userId)){
|
|
roleEnum = UserRoleEnum.TEACHER;
|
|
roleEnum = UserRoleEnum.TEACHER;
|
|
@@ -222,6 +204,10 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
|
|
|
ImNetworkRoom room = baseMapper.findByRoomId(roomId);
|
|
ImNetworkRoom room = baseMapper.findByRoomId(roomId);
|
|
if (roleEnum == UserRoleEnum.TEACHER){
|
|
if (roleEnum == UserRoleEnum.TEACHER){
|
|
|
|
+ //如果老师退出房间,关闭伴奏
|
|
|
|
+ courseScheduleStudentMusicSheetService.getDao().closePlayStatus(courseScheduleId,null);
|
|
|
|
+ courseScheduleStudentPaymentService.getDao().adjustPlayMidi(courseScheduleId, null, null);
|
|
|
|
+ courseScheduleStudentPaymentService.getDao().adjustExamSong(courseScheduleId, null, null);
|
|
if (isUserDisplay(room.getDisplay(), userId)) {
|
|
if (isUserDisplay(room.getDisplay(), userId)) {
|
|
room.setDisplay("");
|
|
room.setDisplay("");
|
|
this.updateDisplay(userId,room);
|
|
this.updateDisplay(userId,room);
|