|  | @@ -7,6 +7,7 @@ import com.yonge.cooleshow.biz.dal.dto.BasicUserInfo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.ImNetworkRoomMember;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.UserRoleEnum;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.service.ImNetworkRoomMemberService;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
	
		
			
				|  | @@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.util.Date;
 | 
	
		
			
				|  |  |  import java.util.Objects;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 网络教室成员(ImNetworkRoomMember)表服务实现类
 | 
	
	
		
			
				|  | @@ -32,6 +34,72 @@ public class ImNetworkRoomMemberServiceImpl extends ServiceImpl<ImNetworkRoomMem
 | 
	
		
			
				|  |  |          return this.baseMapper;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public void leaveRoomSuccess(String roomId, String userId, String deviceNum) throws Exception {
 | 
	
		
			
				|  |  | +        log.info("leaveRoomSuccess: roomId={}, userId={},deviceNum={}", roomId, userId, deviceNum);
 | 
	
		
			
				|  |  | +        Integer firstCourseId = Integer.parseInt(roomId.substring(1));
 | 
	
		
			
				|  |  | +        RoleEnum roleEnum;
 | 
	
		
			
				|  |  | +        int parseInt = Integer.parseInt(userId);
 | 
	
		
			
				|  |  | +        Teacher teacher = teacherDao.get(parseInt);
 | 
	
		
			
				|  |  | +        CourseSchedule courseSchedule = courseScheduleDao.get(firstCourseId.longValue());
 | 
	
		
			
				|  |  | +        if (teacher != null && teacher.getId().equals(courseSchedule.getActualTeacherId())) {
 | 
	
		
			
				|  |  | +            roleEnum = RoleTeacher;
 | 
	
		
			
				|  |  | +            courseScheduleStudentMusicScoreDao.closePlayStatus(courseSchedule.getId(), null, null);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            roleEnum = RoleStudent;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String leaveSuccessKey = "leaveRoomSuccess" + roomId + userId;
 | 
	
		
			
				|  |  | +        Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(leaveSuccessKey, roomId, 1l, TimeUnit.SECONDS);
 | 
	
		
			
				|  |  | +        log.info("leaveRoomSuccess: roomId={}, userId={},deviceNum={},aBoolean={}", roomId, userId, deviceNum, aBoolean);
 | 
	
		
			
				|  |  | +        if (!aBoolean) {
 | 
	
		
			
				|  |  | +            if (StringUtils.isNotEmpty(deviceNum)) {
 | 
	
		
			
				|  |  | +                //如果设备号不为空,更新设备号
 | 
	
		
			
				|  |  | +                if (roleEnum == RoleTeacher) {
 | 
	
		
			
				|  |  | +                    teacherAttendanceService.updateDeviceNum(firstCourseId, userId, null, deviceNum);
 | 
	
		
			
				|  |  | +//                    teacherAttendanceService.addTeacherAttendanceSignOut(firstCourseId.longValue(),parseInt,deviceNum);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String username;
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserById(parseInt);
 | 
	
		
			
				|  |  | +        if (roleEnum == RoleTeacher) {
 | 
	
		
			
				|  |  | +            username = sysUser.getRealName();
 | 
	
		
			
				|  |  | +            courseScheduleStudentPaymentDao.adjustPlayMidi(firstCourseId, null, null);
 | 
	
		
			
				|  |  | +            courseScheduleStudentPaymentDao.adjustExamSong(firstCourseId.longValue(), null, null);
 | 
	
		
			
				|  |  | +            teacherAttendanceService.addTeacherAttendanceSignOut(firstCourseId.longValue(), parseInt, deviceNum);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            username = sysUser.getUsername();
 | 
	
		
			
				|  |  | +            studentAttendanceService.addStudentAttendanceSignOut(firstCourseId.longValue(), parseInt);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Room room = roomDao.findByRid(roomId);
 | 
	
		
			
				|  |  | +        if (room == null) {
 | 
	
		
			
				|  |  | +            roomMemberDao.deleteUserByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  | +            userDao.deleteByUid(userId);
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (roleEnum != RoleStudent && isUserDisplay(room, userId)) {
 | 
	
		
			
				|  |  | +            updateDisplay(roomId, userId, "", 0);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (roomMemberDao.countByRid(roomId) <= 1) {
 | 
	
		
			
				|  |  | +            roomMemberDao.deleteUserByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  | +            roomDao.deleteByRid(roomId);
 | 
	
		
			
				|  |  | +            deleteWhiteboardByUser(roomId, userId);
 | 
	
		
			
				|  |  | +            imHelper.dismiss(userId, roomId);
 | 
	
		
			
				|  |  | +            courseScheduleStudentMusicScoreDao.closePlayStatus(courseSchedule.getId(), null, null);
 | 
	
		
			
				|  |  | +            log.info("leaveRoomSuccess dismiss the room: {},userId: {}", roomId, userId);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            roomMemberDao.deleteUserByRidAndUid(roomId, userId);
 | 
	
		
			
				|  |  | +            MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, userId, roleEnum.getValue());
 | 
	
		
			
				|  |  | +            msg.setUserName(username);
 | 
	
		
			
				|  |  | +            imHelper.publishMessage(userId, roomId, msg);
 | 
	
		
			
				|  |  | +            imHelper.quit(new String[]{userId}, roomId);
 | 
	
		
			
				|  |  | +            log.info("leaveRoomSuccess quit group: roomId={},userId: {}", roomId, userId);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        userDao.deleteByUid(userId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public ImNetworkRoomMember initRoomMember(String roomId, BasicUserInfo sysUser, UserRoleEnum userRole) {
 |