|
@@ -22,8 +22,10 @@ import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.cooleshow.common.entity.BaseResponse;
|
|
|
import com.yonge.cooleshow.common.enums.ErrorEnum;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
+import com.yonge.toolset.payment.util.DistributedLock;
|
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -76,6 +78,8 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
@Resource
|
|
|
private RedisTemplate<String,Object> redisTemplate;
|
|
|
@Resource
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+ @Resource
|
|
|
private ImGroupService imGroupService;
|
|
|
@Resource
|
|
|
private RoomService roomService;
|
|
@@ -180,6 +184,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
|
|
|
joinRoomResult.setGroupId(roomId);
|
|
|
joinRoomResult.setStudentNums(studentIds.size());
|
|
|
+ redisTemplate.opsForValue().set("joinRoomSuccess:"+roomId+imUserId,imUserId,1L,TimeUnit.DAYS);
|
|
|
return BaseResponse.success(joinRoomResult);
|
|
|
}
|
|
|
|
|
@@ -297,7 +302,6 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
public void joinRoomFailure(String roomId, ClientEnum clientType) {
|
|
|
// 当前登录用户ID
|
|
|
Long userId = sysUserService.getUserId();
|
|
@@ -310,6 +314,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
}
|
|
|
// 删除网络教室学员
|
|
|
String imUserId = imGroupService.getImUserId(userId, userRole);
|
|
|
+ redisTemplate.delete("joinRoomSuccess:"+roomId+imUserId);
|
|
|
imNetworkRoomMemberService.lambdaUpdate().eq(ImNetworkRoomMember::getRoomId,roomId)
|
|
|
.eq(ImNetworkRoomMember::getUserId,imUserId)
|
|
|
.eq(ImNetworkRoomMember::getRole,userRole.getValue()).remove();
|
|
@@ -317,41 +322,43 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
|
|
|
@Override
|
|
|
public void quitRoomSuccess(String roomId, String imUserId) {
|
|
|
- // 客户端类型
|
|
|
- ClientEnum clientType = ClientEnum.valueOf(imGroupService.analysisImUserClient(imUserId));
|
|
|
- // 网络教室用户身份
|
|
|
- RoleEnum userRole = clientType == ClientEnum.TEACHER ? RoleEnum.RoleTeacher : RoleEnum.RoleStudent;
|
|
|
-
|
|
|
- log.info("quitRoomSuccess: roomId={}, imUserId={}", roomId, imUserId);
|
|
|
- //防止幂等
|
|
|
- String QUIT_ROOM_SUCCESS = "quitRoomSuccess:";
|
|
|
- StringBuilder sb = new StringBuilder(QUIT_ROOM_SUCCESS).append(roomId).append(imUserId);
|
|
|
- if (Boolean.FALSE.equals(redisTemplate.opsForValue().setIfAbsent(sb.toString(), imUserId, 1L, TimeUnit.SECONDS))){
|
|
|
- log.info("quitRoomSuccess break: roomId={}, imUserId={}", roomId, imUserId);
|
|
|
+ if(redisTemplate.opsForValue().get("joinRoomSuccess:"+roomId+imUserId) == null){
|
|
|
+ log.info("quitRoomSuccess: roomId={}, imUserId={} 未进入房间", roomId, imUserId);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(roomId))
|
|
|
- .orElseThrow(()->new BizException("房间信息不存在"));
|
|
|
- Long courseScheduleId = courseSchedule.getId();
|
|
|
- Long userId = Long.parseLong(imGroupService.analysisImUserId(imUserId));
|
|
|
-
|
|
|
- this.transaction(()->{
|
|
|
- if(RoleEnum.RoleTeacher == userRole){
|
|
|
- teacherAttendanceService.signOut(userId,courseSchedule);
|
|
|
- //如果老师退出房间,初始化节拍器和伴奏播放配置
|
|
|
- courseScheduleStudentMusicSheetService.getDao().closePlayStatus(courseScheduleId,null);
|
|
|
- }else {
|
|
|
- //记录考勤签退
|
|
|
- studentAttendanceService.signOut(userId,courseSchedule);
|
|
|
- }
|
|
|
- //退出房间
|
|
|
- try {
|
|
|
- roomService.quitRoomSuccess(userRole,imUserId,roomId,courseSchedule.getServiceProvider());
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
+ log.info("quitRoomSuccess: roomId={}, imUserId={}", roomId, imUserId);
|
|
|
+ try {
|
|
|
+ // 客户端类型
|
|
|
+ ClientEnum clientType = ClientEnum.valueOf(imGroupService.analysisImUserClient(imUserId));
|
|
|
+ // 网络教室用户身份
|
|
|
+ RoleEnum userRole = clientType == ClientEnum.TEACHER ? RoleEnum.RoleTeacher : RoleEnum.RoleStudent;
|
|
|
+
|
|
|
+ CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(roomId))
|
|
|
+ .orElseThrow(()->new BizException("房间信息不存在"));
|
|
|
+ Long courseScheduleId = courseSchedule.getId();
|
|
|
+ Long userId = Long.parseLong(imGroupService.analysisImUserId(imUserId));
|
|
|
+
|
|
|
+ this.transaction(()->{
|
|
|
+ if(RoleEnum.RoleTeacher == userRole){
|
|
|
+ teacherAttendanceService.signOut(userId,courseSchedule);
|
|
|
+ //如果老师退出房间,初始化节拍器和伴奏播放配置
|
|
|
+ courseScheduleStudentMusicSheetService.getDao().closePlayStatus(courseScheduleId,null);
|
|
|
+ }else {
|
|
|
+ //记录考勤签退
|
|
|
+ studentAttendanceService.signOut(userId,courseSchedule);
|
|
|
+ }
|
|
|
+ //退出房间
|
|
|
+ try {
|
|
|
+ roomService.quitRoomSuccess(userRole,imUserId,roomId,courseSchedule.getServiceProvider());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ redisTemplate.delete("joinRoomSuccess:"+roomId+imUserId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|