Browse Source

网络教室调整,区分学生端,老师端

Eric 2 years ago
parent
commit
ed87d8f0ec

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/ImNetworkBaseDto.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.dto;
 
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import io.swagger.annotations.ApiModelProperty;
 
 public class ImNetworkBaseDto {
@@ -7,6 +8,9 @@ public class ImNetworkBaseDto {
     @ApiModelProperty(value = "房间号(课程编号)",required = true)
     private Long roomId;
 
+    @ApiModelProperty("客户端类型 ")
+    private ClientEnum clientType;
+
     public Long getRoomId() {
         return roomId;
     }
@@ -14,4 +18,12 @@ public class ImNetworkBaseDto {
     public void setRoomId(Long roomId) {
         this.roomId = roomId;
     }
+
+    public ClientEnum getClientType() {
+        return clientType;
+    }
+
+    public void setClientType(ClientEnum clientType) {
+        this.clientType = clientType;
+    }
 }

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/ImNetworkCustomMessage.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.dto;
 
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import io.rong.messages.BaseMessage;
 import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.lang3.StringUtils;
@@ -23,6 +24,9 @@ public class ImNetworkCustomMessage extends BaseMessage {
     @ApiModelProperty(value = "房间号(课程编号)",required = true)
     private Long roomId;
 
+    @ApiModelProperty("客户端类型")
+    private ClientEnum clientType;
+
     public Long getRoomId() {
         return roomId;
     }
@@ -71,6 +75,14 @@ public class ImNetworkCustomMessage extends BaseMessage {
         this.userId = userId;
     }
 
+    public ClientEnum getClientType() {
+        return clientType;
+    }
+
+    public void setClientType(ClientEnum clientType) {
+        this.clientType = clientType;
+    }
+
     @Override
     public String getType() {
         return "DY:PlayMidiMessage";

+ 16 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/ImNetworkDeviceControlDto.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.dto;
 
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.ImNetworkDeviceTypeEnum;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -13,8 +14,8 @@ public class ImNetworkDeviceControlDto {
 	@ApiModelProperty(value = "房间号",required = true)
 	private String roomId;
 
-	@ApiModelProperty(value = "用户编号",required = true)
-	private Long userId;
+	@ApiModelProperty(value = "IM用户ID",required = true)
+	private String userId;
 
 	@ApiModelProperty(value = "ticket",required = true)
 	private String ticket;
@@ -31,6 +32,9 @@ public class ImNetworkDeviceControlDto {
 	@ApiModelProperty(value = "伴奏音量",required = true)
 	private Integer soundVolume = 100;
 
+	@ApiModelProperty("客户端类型 ")
+	private ClientEnum clientType;
+
 	public ImNetworkDeviceTypeEnum getDeviceType() {
 		return deviceType;
 	}
@@ -55,11 +59,11 @@ public class ImNetworkDeviceControlDto {
 		this.roomId = roomId;
 	}
 
-	public Long getUserId() {
+	public String getUserId() {
 		return userId;
 	}
 
-	public void setUserId(Long userId) {
+	public void setUserId(String userId) {
 		this.userId = userId;
 	}
 
@@ -102,4 +106,12 @@ public class ImNetworkDeviceControlDto {
 	public void setSoundVolume(Integer soundVolume) {
 		this.soundVolume = soundVolume;
 	}
+
+	public ClientEnum getClientType() {
+		return clientType;
+	}
+
+	public void setClientType(ClientEnum clientType) {
+		this.clientType = clientType;
+	}
 }

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/ImNetworkDisplayDataDto.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.dto;
 
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.ImNetworkDisplayEnum;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -17,6 +18,9 @@ public class ImNetworkDisplayDataDto {
 	@ApiModelProperty(value = "display uri",required = true)
     private String uri;
 
+	@ApiModelProperty("客户端类型 ")
+	private ClientEnum clientType;
+
 	public String getRoomId() {
 		return roomId;
 	}
@@ -49,6 +53,14 @@ public class ImNetworkDisplayDataDto {
 		this.uri = uri;
 	}
 
+	public ClientEnum getClientType() {
+		return clientType;
+	}
+
+	public void setClientType(ClientEnum clientType) {
+		this.clientType = clientType;
+	}
+
 	@Override
 	public String toString() {
 		return "ImNetworkDisplayDataDto{" +

+ 14 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/ImNetworkMusicSheetDto.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.dto;
 
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import io.swagger.annotations.ApiModelProperty;
 
 public class ImNetworkMusicSheetDto extends ImNetworkBaseDto{
@@ -10,6 +11,9 @@ public class ImNetworkMusicSheetDto extends ImNetworkBaseDto{
     @ApiModelProperty(value = "伴奏下载状态(1下载成功0下载中2下载失败)",required = true)
     private Integer status;
 
+    @ApiModelProperty("客户端类型 ")
+    private ClientEnum clientType;
+
     public Long getAccompanimentId() {
         return accompanimentId;
     }
@@ -27,6 +31,16 @@ public class ImNetworkMusicSheetDto extends ImNetworkBaseDto{
     }
 
     @Override
+    public ClientEnum getClientType() {
+        return clientType;
+    }
+
+    @Override
+    public void setClientType(ClientEnum clientType) {
+        this.clientType = clientType;
+    }
+
+    @Override
     public String toString() {
         return "ImNetworkMusicSheetDto{" +
                 "accompanimentId=" + accompanimentId +

+ 9 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/ClientEnum.java

@@ -51,4 +51,13 @@ public enum ClientEnum implements BaseEnum<String, ClientEnum> {
 
         return true;
     }
+
+    /**
+     * 客户端类型匹配
+     * @param dataType 数据类型
+     * @return boolean
+     */
+    public boolean match(String dataType) {
+        return getCode().equals(dataType);
+    }
 }

+ 5 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/ImNetworkRoomService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.yonge.cooleshow.biz.dal.dao.ImNetworkRoomDao;
 import com.yonge.cooleshow.biz.dal.dto.*;
 import com.yonge.cooleshow.biz.dal.entity.ImNetworkRoom;
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.UserRoleEnum;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 
@@ -20,16 +21,16 @@ public interface ImNetworkRoomService extends IService<ImNetworkRoom> {
     ImNetworkRoomDao getDao();
 
     //加入网络教室
-    HttpResponseResult<ImNetworkRoomResult> joinRoom(Long courseScheduleId) throws Exception;
+    HttpResponseResult<ImNetworkRoomResult> joinRoom(Long courseScheduleId, ClientEnum clientType) throws Exception;
 
     //加入网络教室成功
-    void joinRoomSuccess(String roomId,Long userId) throws Exception;
+    void joinRoomSuccess(String roomId, String imUserId) throws Exception;
 
     //加入网络教室失败
-    void joinRoomFailure(String roomId);
+    void joinRoomFailure(String roomId, ClientEnum clientType);
 
     //退出房间成功
-    void quitRoomSuccess(String roomId, Long userId) throws Exception;
+    void quitRoomSuccess(String roomId, String imUserId) throws Exception;
 
     //控制用户节拍器
     void sendImPlayMidiMessage(ImNetworkCustomMessage customMessage) throws Exception;

+ 109 - 34
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImNetworkRoomServiceImpl.java

@@ -75,12 +75,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);
@@ -116,7 +120,7 @@ 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));
@@ -153,14 +157,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 {
@@ -174,7 +193,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
         //发送人员变动消息
         publishMemberChangedMessage(roomMember);
         //sendDisplay
-        this.sendDisplay(userId,room);
+        this.sendDisplay(imUserId, room);
     }
 
     //发送人员变动消息
@@ -191,7 +210,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void joinRoomFailure(String roomId) {
+    public void joinRoomFailure(String roomId, ClientEnum clientType) {
         Long userId = sysUserService.getUserId();
         log.info("joinRoomFailure: roomId={}, userId={}", roomId, userId);
         imNetworkRoomMemberService.getDao().delByRidAndUid(roomId, userId);
@@ -199,7 +218,19 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
 
     @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]);
+
+        // 客户端类型
+        ClientEnum clientType = ClientEnum.TEACHER;
+        if (values.length > 1 && ClientEnum.STUDENT.match(values[1])) {
+
+            clientType = ClientEnum.STUDENT;
+        }
+
         log.info("quitRoomSuccess: roomId={}, userId={}", roomId, userId);
         //防止幂等
         StringBuffer sb  = new StringBuffer(QUIT_ROOM_SUCCESS).append(roomId).append(userId);
@@ -215,7 +246,9 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
                 .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 {
@@ -230,20 +263,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);
         }
         //删房间用户信息
@@ -258,11 +291,18 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
         log.info("sendImPlayMidiMessage: roomId={}, userId={}", roomId, userId);
         ImNetworkMetronomeMessage displayMessage = new ImNetworkMetronomeMessage(customMessage);
 
-        // IM用户ID
-        String imUserId = MessageFormat.format("{0}:{1}", String.valueOf(userId), ClientEnum.STUDENT.name());
+        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
@@ -299,7 +339,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
@@ -332,7 +379,13 @@ 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
@@ -348,15 +401,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);
                     }
                 }
@@ -371,12 +424,12 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
         SysUser sysUser = sysUserService.getUser();
         String roomId = deviceControl.getRoomId();
         // 学生信息
-        Long userId = deviceControl.getUserId();
+        Long userId = Long.parseLong(deviceControl.getUserId().split(":")[0]);
         Boolean enable = deviceControl.getEnable();
         log.info("controlDevice: roomId:{} ,deviceType:{} ,enable:{} ,userId:{}", roomId,deviceControl.getDeviceType(),enable,userId);
 
         // IM用户ID
-        String imUserId = MessageFormat.format("{0}:{1}", String.valueOf(userId), ClientEnum.STUDENT.name());
+        String imUserId = deviceControl.getUserId();
 
         if(enable){
             long scheduleId = Long.parseLong(roomId);
@@ -470,6 +523,12 @@ 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();
+
+        String imUserId = String.valueOf(sysUser.getId());
+        if (ClientEnum.STUDENT == deviceControl.getClientType()) {
+            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
+        }
+
         ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().findByRidAndUid(deviceControl.getRoomId(), sysUser.getId())).
                 orElseThrow(()-> new BizException("用户不在房间内"));
         switch (deviceControl.getDeviceType()) {
@@ -498,10 +557,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
@@ -509,6 +568,12 @@ 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();
+
+        String imUserId = String.valueOf(userId);
+        if (ClientEnum.STUDENT == deviceStatusSync.getClientType()) {
+            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
+        }
+
         ImNetworkDeviceTypeEnum deviceType = deviceStatusSync.getDeviceType();
         ImNetworkRoomMember roomMember = Optional.ofNullable(imNetworkRoomMemberService.getDao().
                         findByRidAndUid(deviceStatusSync.getRoomId(), userId))
@@ -540,7 +605,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
             imNetworkRoomMemberService.getDao().updateById(roomMember);
         }
         //发送设备状态同步消息
-        this.sendDeviceStateChangedMessage(deviceStatusSync,userId);
+        this.sendDeviceStateChangedMessage(deviceStatusSync, imUserId);
     }
 
     @Override
@@ -558,12 +623,12 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
     }
 
     //发送设备状态同步消息
-    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
@@ -603,7 +668,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);
     }
 
     //校验用户是否提前进入教室
@@ -646,15 +718,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) {

+ 90 - 5
cooleshow-user/user-classroom/src/main/java/com/yonge/cooleshow/classroom/controller/ImNetworkRoomController.java

@@ -3,6 +3,7 @@ package com.yonge.cooleshow.classroom.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.yonge.cooleshow.biz.dal.dto.*;
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.service.ImNetworkRoomService;
 import com.yonge.cooleshow.biz.dal.service.SysUserService;
 import com.yonge.cooleshow.common.controller.BaseController;
@@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.text.MessageFormat;
+import java.util.Objects;
 import java.util.Optional;
 
 /**
@@ -43,9 +46,15 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation("加入网络教室")
     @PostMapping(value = "/join")
     public HttpResponseResult<ImNetworkRoomResult> joinRoom(@RequestBody ImNetworkBaseDto imNetworkBaseDto) throws Exception {
+
+        // 设置请求客户端来源
+        if (Objects.isNull(imNetworkBaseDto.getClientType())) {
+            imNetworkBaseDto.setClientType(ClientEnum.STUDENT);
+        }
+
         return imNetworkRoomService.joinRoom(Optional.ofNullable(imNetworkBaseDto)
                 .map(ImNetworkBaseDto::getRoomId)
-                .orElseThrow(()->new BizException("房间号不可为空")));
+                .orElseThrow(()->new BizException("房间号不可为空")), imNetworkBaseDto.getClientType());
     }
 
 //    @ApiOperation("加入网络教室状态回调")
@@ -58,9 +67,15 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation("加入网络教室状态回调")
     @PostMapping(value = "joinRoomFailure")
     public HttpResponseResult joinRoomFailure(@RequestBody ImNetworkBaseDto imNetworkBaseDto){
+
+        // 设置请求客户端来源
+        if (Objects.isNull(imNetworkBaseDto.getClientType())) {
+            imNetworkBaseDto.setClientType(ClientEnum.STUDENT);
+        }
+
         imNetworkRoomService.joinRoomFailure(Optional.ofNullable(imNetworkBaseDto)
                 .map(ImNetworkBaseDto::getRoomId)
-                .orElseThrow(()->new BizException("房间号不可为空")).toString());
+                .orElseThrow(()->new BizException("房间号不可为空")).toString(), imNetworkBaseDto.getClientType());
         return succeed();
     }
 
@@ -69,14 +84,15 @@ public class ImNetworkRoomController extends BaseController {
     public void statusSync(@RequestBody String body) throws Exception {
         log.info("statusSync body: {}",body);
         ImChannelStateNotify notify = JSONObject.parseObject(body, ImChannelStateNotify.class);
+
         switch (notify.getEvent()) {
             case 11:
                 //成员加入
-                imNetworkRoomService.joinRoomSuccess(notify.getRoomId(),Long.parseLong(notify.getUserId()));
+                imNetworkRoomService.joinRoomSuccess(notify.getRoomId(), notify.getUserId());
                 break;
             case 12:
                 //成员退出
-                imNetworkRoomService.quitRoomSuccess(notify.getRoomId(),Long.parseLong(notify.getUserId()));
+                imNetworkRoomService.quitRoomSuccess(notify.getRoomId(), notify.getUserId());
                 break;
         }
     }
@@ -84,15 +100,36 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation("退出网络教室")
     @PostMapping(value = "/leave")
     public HttpResponseResult leaveRoom(@RequestBody ImNetworkBaseDto imNetworkBaseDto) throws Exception {
+
+        // 设置请求客户端来源
+        if (Objects.isNull(imNetworkBaseDto.getClientType())) {
+            imNetworkBaseDto.setClientType(ClientEnum.STUDENT);
+        }
+
+        // 用户ID
+        Long userId = sysUserService.getUserId();
+
+        // IM用户ID
+        String imUserId = String.valueOf(userId);
+        if (ClientEnum.STUDENT == imNetworkBaseDto.getClientType()) {
+            imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
+        }
+
         imNetworkRoomService.quitRoomSuccess(Optional.ofNullable(imNetworkBaseDto)
                 .map(ImNetworkBaseDto::getRoomId)
-                .orElseThrow(()->new BizException("房间号不可为空")).toString(),sysUserService.getUserId());
+                .orElseThrow(()->new BizException("房间号不可为空")).toString(), imUserId);
         return succeed();
     }
 
     @ApiOperation("控制学员节拍器")
     @PostMapping(value = "/sendImPlayMidiMessage")
     public HttpResponseResult sendImPlayMidiMessage(@RequestBody ImNetworkCustomMessage customMessage) throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(customMessage.getClientType())) {
+            customMessage.setClientType(ClientEnum.TEACHER);
+        }
+
         imNetworkRoomService.sendImPlayMidiMessage(customMessage);
         return succeed();
     }
@@ -100,6 +137,12 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation("移动端用来渲染页面")
     @PostMapping(value = "/display")
     public HttpResponseResult display(@RequestBody ImNetworkDisplayDataDto displayData) throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(displayData.getClientType())) {
+            displayData.setClientType(ClientEnum.TEACHER);
+        }
+
         imNetworkRoomService.display(displayData);
         return succeed();
     }
@@ -107,6 +150,12 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation(value = "批量控制学员设备开关")
     @PostMapping(value = "/device/batchControl")
     public Object batchControlDevice(@RequestBody ImNetworkDeviceControlDto deviceControl)throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(deviceControl.getClientType())) {
+            deviceControl.setClientType(ClientEnum.TEACHER);
+        }
+
         imNetworkRoomService.batchControlDevice(deviceControl);
         return succeed();
     }
@@ -115,6 +164,12 @@ public class ImNetworkRoomController extends BaseController {
     @PostMapping(value = "/device/control")
     public HttpResponseResult controlDevice(@RequestBody ImNetworkDeviceControlDto deviceControl)
             throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(deviceControl.getClientType())) {
+            deviceControl.setClientType(ClientEnum.TEACHER);
+        }
+
         imNetworkRoomService.controlDevice(deviceControl);
         return succeed();
     }
@@ -123,6 +178,12 @@ public class ImNetworkRoomController extends BaseController {
     @PostMapping(value = "/device/approve")
     public HttpResponseResult approveControlDevice(@RequestBody ImNetworkDeviceControlDto deviceControl) throws Exception {
         deviceControl.setEnable(true);
+
+        // 设置客户端类型
+        if (Objects.isNull(deviceControl.getClientType())) {
+            deviceControl.setClientType(ClientEnum.STUDENT);
+        }
+
         imNetworkRoomService.approveControlDevice(deviceControl);
         return succeed();
     }
@@ -132,6 +193,12 @@ public class ImNetworkRoomController extends BaseController {
     public HttpResponseResult rejectControlDevice(@RequestBody ImNetworkDeviceControlDto deviceControl)
             throws Exception {
         deviceControl.setEnable(false);
+
+        // 设置客户端类型
+        if (Objects.isNull(deviceControl.getClientType())) {
+            deviceControl.setClientType(ClientEnum.STUDENT);
+        }
+
         imNetworkRoomService.rejectControlDevice(deviceControl);
         return succeed();
     }
@@ -140,6 +207,12 @@ public class ImNetworkRoomController extends BaseController {
     @PostMapping(value = "/device/sync")
     public Object deviceStatusSync(@RequestBody ImNetworkDeviceControlDto deviceControl)
             throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(deviceControl.getClientType())) {
+            deviceControl.setClientType(ClientEnum.STUDENT);
+        }
+
         imNetworkRoomService.deviceStatusSync(deviceControl);
         return succeed();
     }
@@ -147,6 +220,12 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation(value = "老师在网络教室选择完伴奏后、通知学员下载伴奏")
     @PostMapping(value = "pushDownloadMusicSheetMsg")
     public HttpResponseResult pushDownloadMusicSheetMsg(@RequestBody ImNetworkMusicSheetDto musicSheetDto) throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(musicSheetDto.getClientType())) {
+            musicSheetDto.setClientType(ClientEnum.TEACHER);
+        }
+
         imNetworkRoomService.pushDownloadMusicSheetMsg(musicSheetDto);
         return succeed();
     }
@@ -154,6 +233,12 @@ public class ImNetworkRoomController extends BaseController {
     @ApiOperation(value = "学员伴奏下载状态回调")
     @PostMapping(value = "musicSheetDownNotify")
     public HttpResponseResult adjustMusicScore(@RequestBody ImNetworkMusicSheetDto musicSheetDto) throws Exception {
+
+        // 设置客户端类型
+        if (Objects.isNull(musicSheetDto.getClientType())) {
+            musicSheetDto.setClientType(ClientEnum.STUDENT);
+        }
+
         imNetworkRoomService.musicSheetDownNotify(musicSheetDto);
         return succeed();
     }