|  | @@ -3,6 +3,7 @@ package com.ym.service.Impl;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.ym.common.ApiException;
 | 
	
		
			
				|  |  | +import com.ym.common.BaseResponse;
 | 
	
		
			
				|  |  |  import com.ym.common.DisplayEnum;
 | 
	
		
			
				|  |  |  import com.ym.common.ErrorEnum;
 | 
	
		
			
				|  |  |  import com.ym.config.IMProperties;
 | 
	
	
		
			
				|  | @@ -201,8 +202,15 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |          } else if (roleEnum == RoleEnum.RoleAssistant && display.isEmpty()) {
 | 
	
		
			
				|  |  |              display = "display://type=0?userId=" + userId + "?uri=";
 | 
	
		
			
				|  |  |          }else {
 | 
	
		
			
				|  |  | +            ExamSongDownloadData examSongDownloadData;
 | 
	
		
			
				|  |  | +            String json = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(courseId, sysUser.getId());
 | 
	
		
			
				|  |  | +            if(StringUtils.isEmpty(json)){
 | 
	
		
			
				|  |  | +                examSongDownloadData = new ExamSongDownloadData();
 | 
	
		
			
				|  |  | +            }else {
 | 
	
		
			
				|  |  | +                examSongDownloadData = JSON.parseObject(json,ExamSongDownloadData.class);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //获取学员曲目下载状态
 | 
	
		
			
				|  |  | -            userResult.setExamSongDownloadJson(courseScheduleStudentPaymentDao.getExamSongDownloadStatus(courseId,userId));
 | 
	
		
			
				|  |  | +            userResult.setExamSongDownloadJson(examSongDownloadData);
 | 
	
		
			
				|  |  |              Room room = roomDao.findByRid(roomId);
 | 
	
		
			
				|  |  |              if (room != null) {
 | 
	
		
			
				|  |  |                  display = room.getDisplay();
 | 
	
	
		
			
				|  | @@ -237,15 +245,36 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |          return roomResult;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public void joinRoomSuccess(String roomId,String userId) throws Exception {
 | 
	
		
			
				|  |  | +    public void joinRoomFailure(String roomId, String userId) {
 | 
	
		
			
				|  |  |          RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  |          if(roomMember == null){
 | 
	
		
			
				|  |  |              return ;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        log.info("joinRoomFailure : roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  | +        //如果加入失败,删除该用户数据
 | 
	
		
			
				|  |  | +        roomMemberDao.deleteUserByRidAndUid(roomId,userId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void joinRoomSuccess(String roomId,String userId) throws Exception {
 | 
	
		
			
				|  |  | +        RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  | +        if(roomMember == null){
 | 
	
		
			
				|  |  | +            return ;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        String joinSuccessKey = "joinRoomSuccess"+ roomId + userId;
 | 
	
		
			
				|  |  | +        if(redisTemplate.hasKey(joinSuccessKey)){
 | 
	
		
			
				|  |  | +            //兼容旧版本,防止重复调用
 | 
	
		
			
				|  |  | +            redisTemplate.delete(joinSuccessKey);
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        redisTemplate.opsForValue().set("joinRoomSuccess"+ roomId + userId,roomId);
 | 
	
		
			
				|  |  |          log.info("joinRoomSuccess : roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          RoleEnum roleEnum = RoleEnum.getEnumByValue(roomMember.getRole());
 | 
	
		
			
				|  |  |          CourseSchedule schedule = courseScheduleDao.getLock(Long.parseLong(roomId.substring(1)));
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -260,17 +289,16 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |          Date curTime = DateTimeUtils.currentUTC();
 | 
	
		
			
				|  |  |          Room room = roomDao.findByRid(roomId);
 | 
	
		
			
				|  |  |          if (room == null) {
 | 
	
		
			
				|  |  | -            //如果房间不存在,删除除了自己之外的其他用户
 | 
	
		
			
				|  |  | -//            roomMemberDao.deleteRoomMember(roomId,userId);
 | 
	
		
			
				|  |  |              saveRoom(roomId, roomId, curTime, display);
 | 
	
		
			
				|  |  |              IMApiResultInfo resultInfo = imHelper.createGroup(new String[]{userId}, roomId, roomId);
 | 
	
		
			
				|  |  |              if (!resultInfo.isSuccess()) {
 | 
	
		
			
				|  |  |                  log.error("joinRoomSuccess createGroup error: roomId={}, {}", roomId, resultInfo.getErrorMessage());
 | 
	
		
			
				|  |  |                  throw new ApiException(ErrorEnum.ERR_CREATE_ROOM_ERROR, resultInfo.getErrorMessage());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if(roleEnum == RoleTeacher || roleEnum == RoleEnum.RoleAssistant){
 | 
	
		
			
				|  |  | -            updateDisplay(roomId, userId, display, 0);
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            if(roleEnum == RoleTeacher || roleEnum == RoleEnum.RoleAssistant){
 | 
	
		
			
				|  |  | +                updateDisplay(roomId, userId, display, 0);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          UserInfo userInfo = userDao.findByUid(userId);
 | 
	
	
		
			
				|  | @@ -353,6 +381,10 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |          if(roomMember == null){
 | 
	
		
			
				|  |  |              return ;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        String joinSuccessKey = "joinRoomSuccess"+ roomId + userId;
 | 
	
		
			
				|  |  | +        if(redisTemplate.hasKey(joinSuccessKey)){
 | 
	
		
			
				|  |  | +            redisTemplate.delete(joinSuccessKey);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          log.info("leaveRoomSuccess: roomId={}, userId={}", roomId,userId);
 | 
	
		
			
				|  |  |          RoleEnum roleEnum = RoleEnum.getEnumByValue(roomMember.getRole());
 | 
	
		
			
				|  |  |          Integer firstCourseId = Integer.parseInt(roomId.substring(1));
 | 
	
	
		
			
				|  | @@ -727,6 +759,17 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |                  roomMemberDao.updateMicByRidAndUid(roomId, userId, false);
 | 
	
		
			
				|  |  |              } else if (typeEnum.equals(DeviceTypeEnum.HandUp)){
 | 
	
		
			
				|  |  |                  roomMemberDao.updateHandByRidAndUid(roomId, userId, false);
 | 
	
		
			
				|  |  | +            } else if (typeEnum.equals(DeviceTypeEnum.PlaySong)){
 | 
	
		
			
				|  |  | +                long scheduleId = Long.parseLong(roomId.substring(1));
 | 
	
		
			
				|  |  | +                ExamSongDownloadData msg;
 | 
	
		
			
				|  |  | +                String examJson = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(scheduleId, authUser.getId());
 | 
	
		
			
				|  |  | +                if(StringUtils.isEmpty(examJson)){
 | 
	
		
			
				|  |  | +                    throw new BizException("学员伴奏信息异常");
 | 
	
		
			
				|  |  | +                }else {
 | 
	
		
			
				|  |  | +                    msg = JSON.parseObject(examJson, ExamSongDownloadData.class);
 | 
	
		
			
				|  |  | +                    msg.setEnable(enable);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                courseScheduleStudentPaymentDao.adjustExamSong(scheduleId,authUser.getId(),JSON.toJSONString(msg));
 | 
	
		
			
				|  |  |              }else {
 | 
	
		
			
				|  |  |                  roomMemberDao.updateMusicByRidAndUid(roomId, userId, false);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -827,19 +870,26 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |          String userId = authUser.getId().toString();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          int result;
 | 
	
		
			
				|  |  | -        DeviceStateChangedMessage deviceResourceMessage;
 | 
	
		
			
				|  |  | +        DeviceStateChangedMessage deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
 | 
	
		
			
				|  |  |          if (type.equals(DeviceTypeEnum.Camera)) {
 | 
	
		
			
				|  |  |              result = roomMemberDao.updateCameraByRidAndUid(roomId, userId, enable);
 | 
	
		
			
				|  |  | -            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
 | 
	
		
			
				|  |  |          } else if (type.equals(DeviceTypeEnum.Microphone)){
 | 
	
		
			
				|  |  |              result = roomMemberDao.updateMicByRidAndUid(roomId, userId, enable);
 | 
	
		
			
				|  |  | -            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
 | 
	
		
			
				|  |  |          } else if (type.equals(DeviceTypeEnum.HandUp)){
 | 
	
		
			
				|  |  |              result = roomMemberDao.updateHandByRidAndUid(roomId, userId, enable);
 | 
	
		
			
				|  |  | -            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
 | 
	
		
			
				|  |  | +        } else if (type.equals(DeviceTypeEnum.PlaySong)){
 | 
	
		
			
				|  |  | +            long scheduleId = Long.parseLong(roomId.substring(1));
 | 
	
		
			
				|  |  | +            ExamSongDownloadData msg;
 | 
	
		
			
				|  |  | +            String examJson = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(scheduleId, authUser.getId());
 | 
	
		
			
				|  |  | +            if(StringUtils.isEmpty(examJson)){
 | 
	
		
			
				|  |  | +                throw new BizException("学员伴奏信息异常");
 | 
	
		
			
				|  |  | +            }else {
 | 
	
		
			
				|  |  | +                msg = JSON.parseObject(examJson, ExamSongDownloadData.class);
 | 
	
		
			
				|  |  | +                msg.setEnable(enable);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            result = courseScheduleStudentPaymentDao.adjustExamSong(scheduleId,authUser.getId(),JSON.toJSONString(msg));
 | 
	
		
			
				|  |  |          }else {
 | 
	
		
			
				|  |  |              result = roomMemberDao.updateMusicByRidAndUid(roomId, userId, enable);
 | 
	
		
			
				|  |  | -            deviceResourceMessage = new DeviceStateChangedMessage(type.ordinal(), enable);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          deviceResourceMessage.setUserId(userId);
 | 
	
		
			
				|  |  |          imHelper.publishMessage(userId, roomId, deviceResourceMessage, 1);
 | 
	
	
		
			
				|  | @@ -1276,32 +1326,33 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public List<RongyunBasicUserDto> queryNoJoinStu(String roomId) {
 | 
	
		
			
				|  |  | -        return courseScheduleStudentPaymentDao.queryNoJoinStu(roomId,roomId.substring(1));
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void pushDownloadExamSongMsg(String roomId, Integer examSongId) throws Exception {
 | 
	
		
			
				|  |  |          SysUser authUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  | -        ExamSongDownloadMessageMessage msg = new ExamSongDownloadMessageMessage();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          SysExamSong sysExamSong = sysExamSongDao.get(examSongId);
 | 
	
		
			
				|  |  |          if(sysExamSong == null){
 | 
	
		
			
				|  |  |              throw new BizException("曲目信息不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        ExamSongMessage examSongMessage = new ExamSongMessage();
 | 
	
		
			
				|  |  | -        examSongMessage.setSongName(sysExamSong.getName());
 | 
	
		
			
				|  |  | -        examSongMessage.setUrl(sysExamSong.getUrl());
 | 
	
		
			
				|  |  | -        examSongMessage.setSongId(examSongId);
 | 
	
		
			
				|  |  | -        msg.setContent(examSongMessage);
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(authUser.getId().toString(), roomId, msg, 0);
 | 
	
		
			
				|  |  |          //学员曲目下载状态改为未下载
 | 
	
		
			
				|  |  |          ExamSongDownloadData json = new ExamSongDownloadData();
 | 
	
		
			
				|  |  | -        json.setSongName(sysExamSong.getName());
 | 
	
		
			
				|  |  | +        json.setExamSongName(sysExamSong.getName());
 | 
	
		
			
				|  |  |          json.setUrl(sysExamSong.getUrl());
 | 
	
		
			
				|  |  |          json.setStatus(0);
 | 
	
		
			
				|  |  | -        json.setSongId(examSongId);
 | 
	
		
			
				|  |  | +        json.setExamSongId(examSongId);
 | 
	
		
			
				|  |  |          courseScheduleStudentPaymentDao.adjustExamSong(Long.parseLong(roomId.substring(1)),null, JSON.toJSONString(json));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        ExamSongMessage examSongMessage = new ExamSongMessage();
 | 
	
		
			
				|  |  | +        examSongMessage.setExamSongName(sysExamSong.getName());
 | 
	
		
			
				|  |  | +        examSongMessage.setUrl(sysExamSong.getUrl());
 | 
	
		
			
				|  |  | +        examSongMessage.setExamSongId(examSongId);
 | 
	
		
			
				|  |  | +        ExamSongDownloadMessageMessage msg = new ExamSongDownloadMessageMessage(examSongMessage);
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(authUser.getId().toString(), roomId, msg, 0);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<RongyunBasicUserDto> queryNoJoinStu(String roomId) {
 | 
	
		
			
				|  |  | +        return courseScheduleStudentPaymentDao.queryNoJoinStu(roomId,roomId.substring(1));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -1312,23 +1363,29 @@ public class RoomServiceImpl implements RoomService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          SysUser authUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  |          long scheduleId = Long.parseLong(roomId.substring(1));
 | 
	
		
			
				|  |  | -        CourseSchedule courseSchedule = courseScheduleDao.get(scheduleId);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        //给老师发送学员曲目下载状态
 | 
	
		
			
				|  |  | -        DeviceStateChangedMessage deviceResourceMessage = new DeviceStateChangedMessage(DeviceTypeEnum.ExamSong.ordinal(), status==0?false:true);
 | 
	
		
			
				|  |  | -        deviceResourceMessage.setUserId(courseSchedule.getActualTeacherId().toString());
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(authUser.getId().toString(), roomId, deviceResourceMessage, 1);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          SysExamSong sysExamSong = sysExamSongDao.get(examSongId);
 | 
	
		
			
				|  |  |          if(sysExamSong == null){
 | 
	
		
			
				|  |  |              throw new BizException("曲目信息不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        ExamSongDownloadData msg = new ExamSongDownloadData();
 | 
	
		
			
				|  |  | -        msg.setSongName(sysExamSong.getName());
 | 
	
		
			
				|  |  | -        msg.setUrl(sysExamSong.getUrl());
 | 
	
		
			
				|  |  | -        msg.setStatus(status);
 | 
	
		
			
				|  |  | -        msg.setSongId(examSongId);
 | 
	
		
			
				|  |  | +        ExamSongDownloadData msg;
 | 
	
		
			
				|  |  | +        String examJson = courseScheduleStudentPaymentDao.getExamJsonByCourseIdAndUserId(scheduleId, authUser.getId());
 | 
	
		
			
				|  |  | +        if(StringUtils.isEmpty(examJson)){
 | 
	
		
			
				|  |  | +            msg = new ExamSongDownloadData();
 | 
	
		
			
				|  |  | +            msg.setExamSongName(sysExamSong.getName());
 | 
	
		
			
				|  |  | +            msg.setUrl(sysExamSong.getUrl());
 | 
	
		
			
				|  |  | +            msg.setStatus(status);
 | 
	
		
			
				|  |  | +            msg.setExamSongId(examSongId);
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            msg = JSON.parseObject(examJson, ExamSongDownloadData.class);
 | 
	
		
			
				|  |  | +            msg.setStatus(status);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          courseScheduleStudentPaymentDao.adjustExamSong(scheduleId,authUser.getId(),JSON.toJSONString(msg));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //给老师发送学员曲目下载状态
 | 
	
		
			
				|  |  | +        CourseSchedule courseSchedule = courseScheduleDao.get(scheduleId);
 | 
	
		
			
				|  |  | +        ExamSongDownloadStatusMessage deviceResourceMessage = new ExamSongDownloadStatusMessage(status,authUser.getId(),examSongId);
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(authUser.getId().toString(),courseSchedule.getActualTeacherId().toString(), roomId, deviceResourceMessage);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void updateDisplay(String roomId, String senderId, String display, Integer isIncludeSender) throws Exception {
 |