|  | @@ -13,6 +13,7 @@ import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.support.IMHelper;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.constant.SysConfigConstant;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.common.enums.EStatus;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.utils.date.DateUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
	
		
			
				|  | @@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import java.text.MessageFormat;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
	
		
			
				|  | @@ -74,12 +76,16 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public HttpResponseResult<ImNetworkRoomResult> joinRoom(Long courseScheduleId) throws Exception {
 | 
	
		
			
				|  |  | +    public HttpResponseResult<ImNetworkRoomResult> joinRoom(Long courseScheduleId, ClientEnum clientType) throws Exception {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 当前登录用户ID
 | 
	
		
			
				|  |  |          Long userId = sysUserService.getUserId();
 | 
	
		
			
				|  |  |          CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(courseScheduleId)).
 | 
	
		
			
				|  |  |                  orElseThrow(()->new BizException("房间信息不存在"));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          UserRoleEnum userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | -        if(courseSchedule.getTeacherId().equals(userId)){
 | 
	
		
			
				|  |  | +        if(courseSchedule.getTeacherId().equals(userId) && ClientEnum.TEACHER == clientType){
 | 
	
		
			
				|  |  | +            // 与老师帐号匹配,且来自老师客户端
 | 
	
		
			
				|  |  |              userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          log.info("joinRoom params:courseScheduleId:{},userRole:{},userId:{}",courseScheduleId,userRole,userId);
 | 
	
	
		
			
				|  | @@ -104,6 +110,16 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          joinRoomResult.setSurplusTime(DateUtil.secondsBetween(now, courseSchedule.getEndTime()));
 | 
	
		
			
				|  |  |          //获取房间所有成员
 | 
	
		
			
				|  |  |          List<ImNetworkRoomMember> roomMemberList = imNetworkRoomMemberService.getDao().queryByRoomId(roomId);
 | 
	
		
			
				|  |  | +        for (ImNetworkRoomMember item : roomMemberList) {
 | 
	
		
			
				|  |  | +            if (EStatus.ENABLE.match(item.getRole())) {
 | 
	
		
			
				|  |  | +                // 老师
 | 
	
		
			
				|  |  | +                item.setImUserId(String.valueOf(item.getUserId()));
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                // 学生
 | 
	
		
			
				|  |  | +                item.setImUserId(MessageFormat.format("{0}:{1}", String.valueOf(item.getUserId()), ClientEnum.STUDENT.name()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          joinRoomResult.setRoomMemberList(roomMemberList);
 | 
	
		
			
				|  |  |          //如果是老师,重置节拍器数据
 | 
	
		
			
				|  |  |          if(userRole == UserRoleEnum.TEACHER){
 | 
	
	
		
			
				|  | @@ -112,12 +128,20 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |              setMusicSheetList(roomMemberList,courseScheduleId);
 | 
	
		
			
				|  |  |          }else {
 | 
	
		
			
				|  |  |              //获取节拍器信息
 | 
	
		
			
				|  |  | -            joinRoomResult.setMidiJson(courseScheduleStudentPaymentService.getMemberMidi(courseScheduleId,sysUser.getUserId()));
 | 
	
		
			
				|  |  | +            joinRoomResult.setMidiJson(courseScheduleStudentPaymentService.getMemberMidi(courseScheduleId, sysUser.getUserId()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //课程结束后关闭教室的时间
 | 
	
		
			
				|  |  |          joinRoomResult.setAutoCloseNetworkRoomTime(sysConfigDao.findConfigValue(SysConfigConstant.DESTROY_EXPIRED_PRACTICE_ROOM_MINUTE));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // IM用户ID
 | 
	
		
			
				|  |  | +        String imUserId = sysUser.getUserId().toString();
 | 
	
		
			
				|  |  | +        if (UserRoleEnum.STUDENT == userRole) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        roomMember.setImUserId(imUserId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //创建、加入群聊
 | 
	
		
			
				|  |  | -        IMApiResultInfo resultInfo = imHelper.joinGroup(new String[]{sysUser.getUserId().toString()}, roomId, roomId);
 | 
	
		
			
				|  |  | +        IMApiResultInfo resultInfo = imHelper.joinGroup(new String[]{imUserId}, roomId, roomId);
 | 
	
		
			
				|  |  |          if(resultInfo.getCode() != 200){
 | 
	
		
			
				|  |  |              log.error("加入群聊失败 resultInfo:{}",resultInfo);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -141,14 +165,29 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public void joinRoomSuccess(String roomId,Long userId) throws Exception {
 | 
	
		
			
				|  |  | +    public void joinRoomSuccess(String roomId, String imUserId) throws Exception {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String[] values = imUserId.split(":");
 | 
	
		
			
				|  |  | +        // 用户ID
 | 
	
		
			
				|  |  | +        long userId = Long.parseLong(values[0]);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 客户端类型
 | 
	
		
			
				|  |  | +        ClientEnum clientType = ClientEnum.TEACHER;
 | 
	
		
			
				|  |  | +        if (values.length > 1 && ClientEnum.STUDENT.match(values[1])) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            clientType = ClientEnum.STUDENT;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          log.info("joinRoomSuccess: roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  |          CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(roomId)).
 | 
	
		
			
				|  |  |                  orElseThrow(()->new BizException("房间信息不存在"));
 | 
	
		
			
				|  |  |          BasicUserInfo sysUser = Optional.ofNullable(teacherDao.getBasicUserInfo(userId)).
 | 
	
		
			
				|  |  |                  orElseThrow(()-> new BizException("用户信息不存在"));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          UserRoleEnum userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | -        if(Objects.equals(courseSchedule.getTeacherId(),userId)){
 | 
	
		
			
				|  |  | +        if(Objects.equals(courseSchedule.getTeacherId(),userId)
 | 
	
		
			
				|  |  | +                && ClientEnum.TEACHER == clientType){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  |              teacherAttendanceService.signIn(userId,courseSchedule);
 | 
	
		
			
				|  |  |          }else {
 | 
	
	
		
			
				|  | @@ -159,10 +198,12 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          ImNetworkRoom room = this.initRoom(roomId, Long.parseLong(roomId), userRole, userId, now);
 | 
	
		
			
				|  |  |          //获取房间用户信息
 | 
	
		
			
				|  |  |          ImNetworkRoomMember roomMember = imNetworkRoomMemberService.initRoomMember(roomId,sysUser,userRole);
 | 
	
		
			
				|  |  | +        // IM用户ID
 | 
	
		
			
				|  |  | +        roomMember.setImUserId(imUserId);
 | 
	
		
			
				|  |  |          //发送人员变动消息
 | 
	
		
			
				|  |  |          publishMemberChangedMessage(roomMember);
 | 
	
		
			
				|  |  |          //sendDisplay
 | 
	
		
			
				|  |  | -        this.sendDisplay(userId,room);
 | 
	
		
			
				|  |  | +        this.sendDisplay(imUserId, room);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //发送人员变动消息
 | 
	
	
		
			
				|  | @@ -174,20 +215,46 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          //获取伴奏信息
 | 
	
		
			
				|  |  |          ImNetworkRoomMusicSheetDownloadData musicSheetDownloadData = courseScheduleStudentPaymentService.getMemberExamSong(Long.parseLong(roomMember.getRoomId()), roomMember.getUserId());
 | 
	
		
			
				|  |  |          msg.setExamSongSwitch(musicSheetDownloadData.getEnable());
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(roomMember.getUserId().toString(), roomMember.getRoomId(), msg);
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(roomMember.getImUserId(), roomMember.getRoomId(), msg);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public void joinRoomFailure(String roomId) {
 | 
	
		
			
				|  |  | +    public void joinRoomFailure(String roomId, ClientEnum clientType) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 当前登录用户ID
 | 
	
		
			
				|  |  |          Long userId = sysUserService.getUserId();
 | 
	
		
			
				|  |  |          log.info("joinRoomFailure: roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  | -        imNetworkRoomMemberService.getDao().delByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 网络教室用户身份
 | 
	
		
			
				|  |  | +        UserRoleEnum userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == clientType) {
 | 
	
		
			
				|  |  | +            userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 删除网络教室学员
 | 
	
		
			
				|  |  | +        imNetworkRoomMemberService.getDao().delByRidAndUid(roomId, userId, userRole.ordinal());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public void quitRoomSuccess(String roomId, Long userId) throws Exception {
 | 
	
		
			
				|  |  | +    public void quitRoomSuccess(String roomId, String imUserId) throws Exception {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String[] values = imUserId.split(":");
 | 
	
		
			
				|  |  | +        // 用户ID
 | 
	
		
			
				|  |  | +        long userId = Long.parseLong(values[0]);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 客户端类型
 | 
	
		
			
				|  |  | +        UserRoleEnum userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  | +        ClientEnum clientType = ClientEnum.TEACHER;
 | 
	
		
			
				|  |  | +        if (values.length > 1 && ClientEnum.STUDENT.match(values[1])) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            clientType = ClientEnum.STUDENT;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          log.info("quitRoomSuccess: roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  |          //防止幂等
 | 
	
		
			
				|  |  |          StringBuffer sb  = new StringBuffer(QUIT_ROOM_SUCCESS).append(roomId).append(userId);
 | 
	
	
		
			
				|  | @@ -195,15 +262,21 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |              log.info("quitRoomSuccess break: roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        ImNetworkRoomMember roomMember = imNetworkRoomMemberService.getDao().findByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        ImNetworkRoomMember roomMember = imNetworkRoomMemberService.getDao().findByRidAndUid(roomId, userId, userRole.ordinal());
 | 
	
		
			
				|  |  |          if(Objects.isNull(roomMember)){
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        // 设置IM用户ID
 | 
	
		
			
				|  |  | +        roomMember.setImUserId(imUserId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          CourseSchedule courseSchedule = Optional.ofNullable(courseScheduleService.getById(roomId))
 | 
	
		
			
				|  |  |                  .orElseThrow(()->new BizException("房间信息不存在"));
 | 
	
		
			
				|  |  |          Long courseScheduleId = courseSchedule.getId();
 | 
	
		
			
				|  |  |          UserRoleEnum roleEnum = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | -        if(Objects.equals(courseSchedule.getTeacherId(),userId)){
 | 
	
		
			
				|  |  | +        if(Objects.equals(courseSchedule.getTeacherId(),userId)
 | 
	
		
			
				|  |  | +                && ClientEnum.TEACHER == clientType){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              roleEnum = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  |              teacherAttendanceService.signOut(userId,courseSchedule);
 | 
	
		
			
				|  |  |          }else {
 | 
	
	
		
			
				|  | @@ -218,20 +291,20 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |              courseScheduleStudentPaymentService.getDao().adjustExamSong(courseScheduleId, null, null);
 | 
	
		
			
				|  |  |              if (isUserDisplay(room.getDisplay(), userId)) {
 | 
	
		
			
				|  |  |                  room.setDisplay("");
 | 
	
		
			
				|  |  | -                this.updateDisplay(userId,room);
 | 
	
		
			
				|  |  | +                this.updateDisplay(imUserId,room);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //老师退出房间,初始化节拍器和伴奏播放配置
 | 
	
		
			
				|  |  |              courseScheduleStudentPaymentService.adjustPlayMidiAndMusicSheet(courseSchedule.getId(), null, null,"");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          int memberNum = imNetworkRoomMemberService.getDao().countByRoomId(roomId);
 | 
	
		
			
				|  |  |          if (memberNum <= 1) {
 | 
	
		
			
				|  |  | -            imHelper.dismiss(userId.toString(), roomId);
 | 
	
		
			
				|  |  | +            imHelper.dismiss(imUserId, roomId);
 | 
	
		
			
				|  |  |              courseScheduleStudentMusicSheetService.getDao().closePlayStatus(courseSchedule.getId(),null);
 | 
	
		
			
				|  |  |              log.info("leaveRoomSuccess dismiss the room: {},userId: {}", roomId, userId);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              ImNetworkRoomMemberChangedMessage msg = new ImNetworkRoomMemberChangedMessage(roomMember,ImNetworkRoomMemberChangedEnum.LEAVE);
 | 
	
		
			
				|  |  | -            imHelper.publishMessage(userId.toString(), roomId, msg);
 | 
	
		
			
				|  |  | -            imHelper.quit(new String[]{userId.toString()}, roomId);
 | 
	
		
			
				|  |  | +            imHelper.publishMessage(imUserId, roomId, msg);
 | 
	
		
			
				|  |  | +            imHelper.quit(new String[]{imUserId}, roomId);
 | 
	
		
			
				|  |  |              log.info("leaveRoomSuccess quit group: roomId={},userId: {}", roomId, userId);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //删房间用户信息
 | 
	
	
		
			
				|  | @@ -245,9 +318,19 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          Long roomId = customMessage.getRoomId();
 | 
	
		
			
				|  |  |          log.info("sendImPlayMidiMessage: roomId={}, userId={}", roomId, userId);
 | 
	
		
			
				|  |  |          ImNetworkMetronomeMessage displayMessage = new ImNetworkMetronomeMessage(customMessage);
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(userId.toString(), roomId.toString(), displayMessage, 1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String imUserId = String.valueOf(userId);
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == customMessage.getClientType()) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 用户ID
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(imUserId, roomId.toString(), displayMessage, 1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //记录节拍器信息
 | 
	
		
			
				|  |  | -        courseScheduleStudentPaymentService.getDao().adjustPlayMidi(roomId,customMessage.getUserId(),customMessage.toString());
 | 
	
		
			
				|  |  | +        String collect = Arrays.stream(customMessage.getUserId().split(","))
 | 
	
		
			
				|  |  | +                .map(x -> x.split(":")[0]).collect(Collectors.joining(","));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        courseScheduleStudentPaymentService.getDao().adjustPlayMidi(roomId, collect, customMessage.toString());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -284,7 +367,14 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          ImNetworkMusicSheetDownloadMessage msg = new ImNetworkMusicSheetDownloadMessage(
 | 
	
		
			
				|  |  |                  JSON.parseObject(JSON.toJSONString(accompaniment), ImNetworkMusicSheetDownloadMessageContent.class));
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(userId.toString(), courseScheduleId.toString(), msg, 0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // IM用户ID
 | 
	
		
			
				|  |  | +        String imUserId = String.valueOf(userId);
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == musicSheetDto.getClientType()) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(imUserId, courseScheduleId.toString(), msg, 0);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -317,14 +407,20 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          ImNetworkRoom room = baseMapper.findByRoomId(displayData.getRoomId());
 | 
	
		
			
				|  |  |          room.setDisplay(display.toString());
 | 
	
		
			
				|  |  | -        this.updateDisplay(userId,room);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String imUserId = String.valueOf(userId);
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == displayData.getClientType()) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        this.updateDisplay(imUserId,room);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void batchControlDevice(ImNetworkDeviceControlDto deviceControl) throws Exception {
 | 
	
		
			
				|  |  |          ImNetworkDeviceTypeEnum deviceType = deviceControl.getDeviceType();
 | 
	
		
			
				|  |  | -        if (deviceControl.getUserId() != null) {
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotEmpty(deviceControl.getUserId())) {
 | 
	
		
			
				|  |  |              controlDevice(deviceControl);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              if (deviceType == ImNetworkDeviceTypeEnum.EXAM_SONG ||
 | 
	
	
		
			
				|  | @@ -333,15 +429,15 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |                  List<CourseScheduleStudentPayment> studentPayments = courseScheduleStudentPaymentService.getDao().queryByCourseId(Long.parseLong(deviceControl.getRoomId()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  for (CourseScheduleStudentPayment studentPayment : studentPayments) {
 | 
	
		
			
				|  |  | -                    deviceControl.setUserId(studentPayment.getUserId());
 | 
	
		
			
				|  |  | +                    deviceControl.setUserId(MessageFormat.format("{0}:{1}", String.valueOf(studentPayment.getUserId()), ClientEnum.STUDENT.name()));
 | 
	
		
			
				|  |  |                      controlDevice(deviceControl);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              }else {
 | 
	
		
			
				|  |  |                  List<ImNetworkRoomMember> roomMembers = imNetworkRoomMemberService.getDao().findByRoomAndRole(deviceControl.getRoomId(), 0);
 | 
	
		
			
				|  |  |                  if (!CollectionUtils.isEmpty(roomMembers)) {
 | 
	
		
			
				|  |  |                      for (ImNetworkRoomMember roomMember : roomMembers) {
 | 
	
		
			
				|  |  | -                        deviceControl.setUserId(roomMember.getUserId());
 | 
	
		
			
				|  |  | +                        deviceControl.setUserId(MessageFormat.format("{0}:{1}", String.valueOf(roomMember.getUserId()), ClientEnum.STUDENT.name()));
 | 
	
		
			
				|  |  |                          controlDevice(deviceControl);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -352,21 +448,34 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void controlDevice(ImNetworkDeviceControlDto deviceControl) throws Exception {
 | 
	
		
			
				|  |  | +        // 老师信息
 | 
	
		
			
				|  |  |          SysUser sysUser = sysUserService.getUser();
 | 
	
		
			
				|  |  |          String roomId = deviceControl.getRoomId();
 | 
	
		
			
				|  |  | -        Long userId = deviceControl.getUserId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String[] values = deviceControl.getUserId().split(":");
 | 
	
		
			
				|  |  | +        // 学生信息
 | 
	
		
			
				|  |  | +        Long userId = Long.parseLong(values[0]);
 | 
	
		
			
				|  |  |          Boolean enable = deviceControl.getEnable();
 | 
	
		
			
				|  |  |          log.info("controlDevice: roomId:{} ,deviceType:{} ,enable:{} ,userId:{}", roomId,deviceControl.getDeviceType(),enable,userId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        UserRoleEnum userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  | +        if (values.length > 1 && ClientEnum.STUDENT.match(values[1])) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // IM用户ID
 | 
	
		
			
				|  |  | +        String imUserId = deviceControl.getUserId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          if(enable){
 | 
	
		
			
				|  |  |              long scheduleId = Long.parseLong(roomId);
 | 
	
		
			
				|  |  |              ImNetworkDeviceStateChangedMessage deviceResourceMessage = new ImNetworkDeviceStateChangedMessage(deviceControl.getDeviceType().ordinal(),enable);
 | 
	
		
			
				|  |  | -            deviceResourceMessage.setUserId(userId.toString());
 | 
	
		
			
				|  |  | +            deviceResourceMessage.setUserId(imUserId);
 | 
	
		
			
				|  |  |              switch (deviceControl.getDeviceType()) {
 | 
	
		
			
				|  |  |                  case EXAM_SONG:
 | 
	
		
			
				|  |  |                      ImNetworkRoomMusicSheetDownloadData msg = courseScheduleStudentPaymentService.getMemberExamSong(scheduleId, userId);
 | 
	
		
			
				|  |  |                      msg.setEnable(enable);
 | 
	
		
			
				|  |  |                      courseScheduleStudentPaymentService.getDao().adjustExamSong(scheduleId,userId, JSON.toJSONString(msg));
 | 
	
		
			
				|  |  | -                    imHelper.publishMessage(userId.toString(), roomId, deviceResourceMessage, 1);
 | 
	
		
			
				|  |  | +                    imHelper.publishMessage(imUserId, roomId, deviceResourceMessage, 1);
 | 
	
		
			
				|  |  |                      break;
 | 
	
		
			
				|  |  |                  case MUSIC_SHEET:
 | 
	
		
			
				|  |  |                      Integer musicSheetId = Optional.ofNullable(deviceControl.getMusicSheetAccompanimentId()).
 | 
	
	
		
			
				|  | @@ -376,7 +485,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |                      //打开原音
 | 
	
		
			
				|  |  |                      courseScheduleStudentMusicSheetService.getDao().openPlayStatus(scheduleId,musicSheetId,userId);
 | 
	
		
			
				|  |  |                      deviceResourceMessage.setMusicSheetAccompanimentId(musicSheetId);
 | 
	
		
			
				|  |  | -                    deviceResourceMessage.setUserId(userId.toString());
 | 
	
		
			
				|  |  | +                    deviceResourceMessage.setUserId(imUserId);
 | 
	
		
			
				|  |  |                      deviceResourceMessage.setSoundVolume(deviceControl.getSoundVolume());
 | 
	
		
			
				|  |  |                      imHelper.publishMessage(sysUser.getId().toString(), roomId, deviceResourceMessage, 1);
 | 
	
		
			
				|  |  |                      break;
 | 
	
	
		
			
				|  | @@ -388,7 +497,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |                      //打开伴奏
 | 
	
		
			
				|  |  |                      courseScheduleStudentMusicSheetService.getDao().openAccompanimentPlayStatus(scheduleId,musicSheetAccompanimentId,userId);
 | 
	
		
			
				|  |  |                      deviceResourceMessage.setMusicSheetAccompanimentId(musicSheetAccompanimentId);
 | 
	
		
			
				|  |  | -                    deviceResourceMessage.setUserId(userId.toString());
 | 
	
		
			
				|  |  | +                    deviceResourceMessage.setUserId(imUserId);
 | 
	
		
			
				|  |  |                      deviceResourceMessage.setSoundVolume(deviceControl.getSoundVolume());
 | 
	
		
			
				|  |  |                      imHelper.publishMessage(sysUser.getId().toString(), roomId, deviceResourceMessage, 1);
 | 
	
		
			
				|  |  |                      break;
 | 
	
	
		
			
				|  | @@ -398,11 +507,11 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |                      message.setType(deviceControl.getDeviceType().ordinal());
 | 
	
		
			
				|  |  |                      message.setOpUserId(sysUser.getId().toString());
 | 
	
		
			
				|  |  |                      message.setOpUserName(sysUser.getUsername());
 | 
	
		
			
				|  |  | -                    imHelper.publishMessage(sysUser.getId().toString(), userId.toString(), roomId, message);
 | 
	
		
			
				|  |  | +                    imHelper.publishMessage(sysUser.getId().toString(), imUserId, roomId, message);
 | 
	
		
			
				|  |  |                      break;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }else {
 | 
	
		
			
				|  |  | -            ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().findByRidAndUid(roomId, userId))
 | 
	
		
			
				|  |  | +            ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().findByRidAndUid(roomId, userId, userRole.ordinal()))
 | 
	
		
			
				|  |  |                      .orElseThrow(()-> new BizException("用户不在房间内"));
 | 
	
		
			
				|  |  |              long scheduleId = Long.parseLong(roomId);
 | 
	
		
			
				|  |  |              switch (deviceControl.getDeviceType()) {
 | 
	
	
		
			
				|  | @@ -435,7 +544,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |                  imNetworkRoomMemberService.getDao().updateById(roomMember);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              ImNetworkDeviceStateChangedMessage deviceResourceMessage = new ImNetworkDeviceStateChangedMessage(deviceControl.getDeviceType().ordinal(),deviceControl.getEnable());
 | 
	
		
			
				|  |  | -            deviceResourceMessage.setUserId(userId.toString());
 | 
	
		
			
				|  |  | +            deviceResourceMessage.setUserId(imUserId);
 | 
	
		
			
				|  |  |              BasicUserInfo basicUserInfo = teacherDao.getBasicUserInfo(userId);
 | 
	
		
			
				|  |  |              if (Objects.nonNull(basicUserInfo)) {
 | 
	
		
			
				|  |  |                  deviceResourceMessage.setUserName(basicUserInfo.getUsername());
 | 
	
	
		
			
				|  | @@ -449,7 +558,17 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |      public void approveControlDevice(ImNetworkDeviceControlDto deviceControl) throws Exception {
 | 
	
		
			
				|  |  |          log.info("approveControlDevice: roomId:{} ,deviceType:{} ,enable:{}", deviceControl.getRoomId(),deviceControl.getDeviceType(),deviceControl.getEnable());
 | 
	
		
			
				|  |  |          SysUser sysUser = sysUserService.getUser();
 | 
	
		
			
				|  |  | -        ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().findByRidAndUid(deviceControl.getRoomId(), sysUser.getId())).
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String imUserId = String.valueOf(sysUser.getId());
 | 
	
		
			
				|  |  | +        UserRoleEnum userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == deviceControl.getClientType()) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().findByRidAndUid(deviceControl.getRoomId(), sysUser.getId(),
 | 
	
		
			
				|  |  | +                        userRole.ordinal())).
 | 
	
		
			
				|  |  |                  orElseThrow(()-> new BizException("用户不在房间内"));
 | 
	
		
			
				|  |  |          switch (deviceControl.getDeviceType()) {
 | 
	
		
			
				|  |  |              case CAMERA:
 | 
	
	
		
			
				|  | @@ -477,10 +596,10 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          Long teacherId = Optional.ofNullable(courseScheduleService.getById(deviceControl.getRoomId())).
 | 
	
		
			
				|  |  |                  map(CourseSchedule::getTeacherId).
 | 
	
		
			
				|  |  |                  orElseThrow(()->new BizException("房间信息不存在"));
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(sysUser.getId().toString(),teacherId.toString(), deviceControl.getRoomId(), msg);
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(imUserId, teacherId.toString(), deviceControl.getRoomId(), msg);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //发送设备状态变更消息
 | 
	
		
			
				|  |  | -        this.sendDeviceStateChangedMessage(deviceControl, sysUser.getId());
 | 
	
		
			
				|  |  | +        this.sendDeviceStateChangedMessage(deviceControl, imUserId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -488,9 +607,18 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |      public void deviceStatusSync(ImNetworkDeviceControlDto deviceStatusSync) throws Exception {
 | 
	
		
			
				|  |  |          log.info("deviceStatusSync: enable:{} ,roomId:{} ,deviceType:{}", deviceStatusSync.getEnable(),deviceStatusSync.getRoomId(),deviceStatusSync.getDeviceType());
 | 
	
		
			
				|  |  |          Long userId = sysUserService.getUserId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        UserRoleEnum userRole = UserRoleEnum.TEACHER;
 | 
	
		
			
				|  |  | +        String imUserId = String.valueOf(userId);
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == deviceStatusSync.getClientType()) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userRole = UserRoleEnum.STUDENT;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          ImNetworkDeviceTypeEnum deviceType = deviceStatusSync.getDeviceType();
 | 
	
		
			
				|  |  |          ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().
 | 
	
		
			
				|  |  | -                        findByRidAndUid(deviceStatusSync.getRoomId(), userId))
 | 
	
		
			
				|  |  | +                        findByRidAndUid(deviceStatusSync.getRoomId(), userId, userRole.ordinal()))
 | 
	
		
			
				|  |  |                  .orElseThrow(()-> new BizException("用户不在房间内"));
 | 
	
		
			
				|  |  |          switch (deviceType) {
 | 
	
		
			
				|  |  |              case CAMERA:
 | 
	
	
		
			
				|  | @@ -519,21 +647,30 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |              imNetworkRoomMemberService.getDao().updateById(roomMember);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //发送设备状态同步消息
 | 
	
		
			
				|  |  | -        this.sendDeviceStateChangedMessage(deviceStatusSync,userId);
 | 
	
		
			
				|  |  | +        this.sendDeviceStateChangedMessage(deviceStatusSync, imUserId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public List<BasicUserInfo> queryNoJoinStu(Long roomId) {
 | 
	
		
			
				|  |  | -        return courseScheduleStudentPaymentService.getDao().queryNoJoinStu(roomId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<BasicUserInfo> userInfos = courseScheduleStudentPaymentService.getDao().queryNoJoinStu(roomId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for (BasicUserInfo item : userInfos) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            item.setImUserId(MessageFormat.format("{0}:{1}", String.valueOf(item.getUserId()),
 | 
	
		
			
				|  |  | +                    ClientEnum.STUDENT.name()));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return userInfos;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //发送设备状态同步消息
 | 
	
		
			
				|  |  | -    private void sendDeviceStateChangedMessage(ImNetworkDeviceControlDto deviceStatusSync,Long userId) throws Exception {
 | 
	
		
			
				|  |  | +    private void sendDeviceStateChangedMessage(ImNetworkDeviceControlDto deviceStatusSync,String imUserId) throws Exception {
 | 
	
		
			
				|  |  |          ImNetworkRoom room = baseMapper.findByRoomId(deviceStatusSync.getRoomId());
 | 
	
		
			
				|  |  |          ImNetworkDeviceStateChangedMessage deviceResourceMessage = new ImNetworkDeviceStateChangedMessage(deviceStatusSync.getDeviceType().ordinal(),deviceStatusSync.getEnable());
 | 
	
		
			
				|  |  | -        deviceResourceMessage.setUserId(userId.toString());
 | 
	
		
			
				|  |  | +        deviceResourceMessage.setUserId(imUserId);
 | 
	
		
			
				|  |  |          deviceResourceMessage.setSoundVolume(room.getSoundVolume());
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(userId.toString(), deviceStatusSync.getRoomId(), deviceResourceMessage, 1);
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(imUserId, deviceStatusSync.getRoomId(), deviceResourceMessage, 1);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -573,7 +710,14 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |          //给老师发送学员曲目下载状态
 | 
	
		
			
				|  |  |          CourseSchedule courseSchedule = courseScheduleService.getById(roomId);
 | 
	
		
			
				|  |  |          ImNetworkMusicSheetDownloadStatusMessage statusMessage = new ImNetworkMusicSheetDownloadStatusMessage(status,studentMusicSheetResults);
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(userId.toString(), courseSchedule.getTeacherId().toString(), roomId.toString(), statusMessage);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // IM用户ID
 | 
	
		
			
				|  |  | +        String imUserId = String.valueOf(userId);
 | 
	
		
			
				|  |  | +        if (ClientEnum.STUDENT == musicSheetDto.getClientType()) {
 | 
	
		
			
				|  |  | +            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(imUserId, courseSchedule.getTeacherId().toString(), roomId.toString(), statusMessage);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //校验用户是否提前进入教室
 | 
	
	
		
			
				|  | @@ -616,15 +760,18 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //修改节拍器
 | 
	
		
			
				|  |  | -    public void updateDisplay(Long userId,ImNetworkRoom room) throws Exception {
 | 
	
		
			
				|  |  | +    public void updateDisplay(String imUserId,ImNetworkRoom room) throws Exception {
 | 
	
		
			
				|  |  |          baseMapper.updateById(room);
 | 
	
		
			
				|  |  | -        this.sendDisplay(userId,room);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // IM发送用户消息
 | 
	
		
			
				|  |  | +        this.sendDisplay(imUserId,room);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void sendDisplay(Long userId,ImNetworkRoom room) throws Exception {
 | 
	
		
			
				|  |  | +    public void sendDisplay(String imUserId,ImNetworkRoom room) throws Exception {
 | 
	
		
			
				|  |  |          //发送display改动通知
 | 
	
		
			
				|  |  |          ImNetworkDisplayMessage displayMessage = new ImNetworkDisplayMessage(room.getDisplay());
 | 
	
		
			
				|  |  | -        imHelper.publishMessage(userId.toString(), room.getRoomId(), displayMessage, 0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        imHelper.publishMessage(imUserId, room.getRoomId(), displayMessage, 0);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public boolean isUserDisplay(String display, Long userId) {
 |