|  | @@ -11,8 +11,11 @@ import com.ym.mec.biz.dal.dto.ImLiveBroadcastRoomDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoom;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.vo.ImLiveBroadcastRoomVo;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.vo.RoomUserInfoVo;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.ImLiveBroadcastRoomService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SysMessageService;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.entity.ImRoomMessage;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.entity.ImUserState;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageUtil;
 | 
	
	
		
			
				|  | @@ -24,6 +27,7 @@ import com.ym.mec.util.http.HttpUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.redisson.api.RBucket;
 | 
	
		
			
				|  |  |  import org.redisson.api.RList;
 | 
	
		
			
				|  |  | +import org.redisson.api.RMap;
 | 
	
		
			
				|  |  |  import org.redisson.api.RedissonClient;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @@ -32,7 +36,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.io.Serializable;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -60,18 +63,10 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //直播间用户列表
 | 
	
		
			
				|  |  |      public static final String LIVE_ROOM_USER_LIST = "IM:LIVE_ROOM_USER_LIST:" + ROOM_UID;
 | 
	
		
			
				|  |  | +    //直播间累计用户信息-指只要进入到该房间的用户都要记录
 | 
	
		
			
				|  |  | +    public static final String LIVE_ROOM_TOTAL_USER_LIST = "IM:LIVE_ROOM_TOTAL_USER_LIST:" + ROOM_UID;
 | 
	
		
			
				|  |  |      //用户对应的直播间Uid
 | 
	
		
			
				|  |  |      public static final String LIVE_USER_ROOM = "IM:LIVE_ROOM_USER:" + USER_ID;
 | 
	
		
			
				|  |  | -    //用户进入房间时间
 | 
	
		
			
				|  |  | -    public static final String LIVE_ROOM_USER_JOIN_TIME = "IM:LIVE_ROOM_USER_JOIN_TIME:" + USER_ID;
 | 
	
		
			
				|  |  | -    //用户退出房间时间
 | 
	
		
			
				|  |  | -    public static final String LIVE_ROOM_USER_QUIT_TIME = "IM:LIVE_ROOM_USER_QUIT_TIME:" + USER_ID;
 | 
	
		
			
				|  |  | -    //房间信息
 | 
	
		
			
				|  |  | -    public static final String LIVE_ROOM_INFO = "IM:LIVE_ROOM_INFO:" + ROOM_UID;
 | 
	
		
			
				|  |  | -    //房间当前人数
 | 
	
		
			
				|  |  | -    public static final String LIVE_ROOM_LOOK = "IM:LIVE_ROOM_LOOK:" + ROOM_UID;
 | 
	
		
			
				|  |  | -    //房间累计人数
 | 
	
		
			
				|  |  | -    public static final String LIVE_ROOM_TOTAL_LOOK = "IM:LIVE_ROOM_TOTAL_LOOK:" + ROOM_UID;
 | 
	
		
			
				|  |  |      //房间点赞数
 | 
	
		
			
				|  |  |      public static final String LIVE_ROOM_LIKE = "IM:LIVE_ROOM_LIKE:" + ROOM_UID;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -82,7 +77,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |       * @param userId  用户id
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public ImLiveBroadcastRoomVo queryRoom(String roomUid, Integer userId) {
 | 
	
		
			
				|  |  | +    public ImLiveBroadcastRoomVo queryRoomAndCheck(String roomUid, Integer userId) {
 | 
	
		
			
				|  |  |          SysUser sysUser;
 | 
	
		
			
				|  |  |          if (Objects.isNull(userId)) {
 | 
	
		
			
				|  |  |              sysUser = getSysUser();
 | 
	
	
		
			
				|  | @@ -120,7 +115,9 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |          if (CollectionUtils.isEmpty(list)) {
 | 
	
		
			
				|  |  |              return null;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return list.get(0);
 | 
	
		
			
				|  |  | +        ImLiveBroadcastRoomVo roomVo = list.get(0);
 | 
	
		
			
				|  |  | +        getRoomData(roomVo);
 | 
	
		
			
				|  |  | +        return roomVo;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -164,13 +161,32 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public void update(ImLiveBroadcastRoomDto dto) {
 | 
	
		
			
				|  |  | -        ImLiveBroadcastRoom obj = new ImLiveBroadcastRoom();
 | 
	
		
			
				|  |  | +        ImLiveBroadcastRoom obj = this.getById(dto.getId());
 | 
	
		
			
				|  |  | +        if (obj.getLiveState() == 1) {
 | 
	
		
			
				|  |  | +            throw new BizException("直播已经开始,无法修改");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          BeanUtils.copyProperties(dto, obj);
 | 
	
		
			
				|  |  |          log.info("update room  >>>  :{}", JSONObject.toJSONString(obj));
 | 
	
		
			
				|  |  |          this.updateById(obj);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  | +     * 删除直播间
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param id 直播间id
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void delete(Integer id) {
 | 
	
		
			
				|  |  | +        ImLiveBroadcastRoom obj = this.getById(id);
 | 
	
		
			
				|  |  | +        if (obj.getLiveState() == 1) {
 | 
	
		
			
				|  |  | +            throw new BizException("直播已经开始,无法删除");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        obj.setId(id);
 | 
	
		
			
				|  |  | +        obj.setRoomState(1);
 | 
	
		
			
				|  |  | +        this.updateById(obj);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  |       * 关闭房间
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param id 直播房间表id
 | 
	
	
		
			
				|  | @@ -190,7 +206,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |              log.error(e.getMessage(), e.getCause());
 | 
	
		
			
				|  |  |              throw new BizException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //todo 向聊天室发自定义消息提出所有学生
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //todo 将房间redis的数据写入数据库后在删除缓存
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -201,26 +216,17 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |          room.setUpdatedTime(date);
 | 
	
		
			
				|  |  |          room.setLiveEndTime(date);
 | 
	
		
			
				|  |  |          this.updateById(room);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 删除直播间
 | 
	
		
			
				|  |  | -     *
 | 
	
		
			
				|  |  | -     * @param id 直播间id
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    public void delete(Integer id) {
 | 
	
		
			
				|  |  | -        ImLiveBroadcastRoom obj = new ImLiveBroadcastRoom();
 | 
	
		
			
				|  |  | -        if (obj.getLiveState() == 1) {
 | 
	
		
			
				|  |  | -            throw new BizException("直播已经开始,无法删除");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        obj.setId(id);
 | 
	
		
			
				|  |  | -        obj.setRoomState(1);
 | 
	
		
			
				|  |  | -        this.updateById(obj);
 | 
	
		
			
				|  |  | +        //向聊天室发自定义消息踢出所有人
 | 
	
		
			
				|  |  | +        ImRoomMessage message = new ImRoomMessage();
 | 
	
		
			
				|  |  | +        message.setFromUserId(room.getSpeakerId().toString());
 | 
	
		
			
				|  |  | +        message.setToChatroomId(room.getRoomUid());
 | 
	
		
			
				|  |  | +        message.setObjectName(ImRoomMessage.FORCED_OFFLINE);
 | 
	
		
			
				|  |  | +        imFeignService.publishRoomMsg(message);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  | -     * 同步点赞数量-修改房间信息
 | 
	
		
			
				|  |  | +     * 同步点赞数量
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param roomUid 房间uid
 | 
	
		
			
				|  |  |       * @param likeNum 点赞数
 | 
	
	
		
			
				|  | @@ -230,81 +236,101 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  | -     * 进入房间-修改用户对应的房间号信息
 | 
	
		
			
				|  |  | +     * 退出房间-修改用户对应的房间号信息
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  | -     * @param roomUid 房间uid
 | 
	
		
			
				|  |  | -     * @param userId  用户id
 | 
	
		
			
				|  |  | +     * @param userState 用户状态数据
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public void joinRoom(String roomUid, Integer userId) {
 | 
	
		
			
				|  |  | -        //用户对应的直播间信息
 | 
	
		
			
				|  |  | -        RBucket<String> roomUserCache = redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString()));
 | 
	
		
			
				|  |  | -        //获取原有房间信息
 | 
	
		
			
				|  |  | -        if (roomUserCache.isExists()) {
 | 
	
		
			
				|  |  | -            //原有的房间uid
 | 
	
		
			
				|  |  | -            String lodRoomUid = roomUserCache.get();
 | 
	
		
			
				|  |  | -            //如果房间相同直接返回
 | 
	
		
			
				|  |  | -            if (roomUid.equals(lodRoomUid)) {
 | 
	
		
			
				|  |  | +    public void quitRoom(List<ImUserState> userState) {
 | 
	
		
			
				|  |  | +        userState.forEach(user -> {
 | 
	
		
			
				|  |  | +            if (StringUtils.isBlank(user.getStatus()) || user.getStatus().equals("0")) {
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                //如果不同就把原房间的当前人员数量-1
 | 
	
		
			
				|  |  | -                redissonClient.getAtomicLong(LIVE_ROOM_LOOK.replace(ROOM_UID, lodRoomUid)).decrementAndGet();
 | 
	
		
			
				|  |  | -                //将用户数据从老直播间用户列表删除
 | 
	
		
			
				|  |  | -                RList<UserInfo> list = redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, lodRoomUid));
 | 
	
		
			
				|  |  | -                UserInfo userInfo = getUserInfo(userId);
 | 
	
		
			
				|  |  | -                list.remove(userInfo);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //写入用户房间uid
 | 
	
		
			
				|  |  | -        roomUserCache.set(roomUid);
 | 
	
		
			
				|  |  | -        //写入用户进入房间时间缓存
 | 
	
		
			
				|  |  | -        redissonClient.getBucket(LIVE_ROOM_USER_JOIN_TIME.replace(USER_ID, userId.toString())).set(new Date());
 | 
	
		
			
				|  |  | -        //添加房间中用户数量
 | 
	
		
			
				|  |  | -        redissonClient.getAtomicLong(LIVE_ROOM_LOOK.replace(ROOM_UID, roomUid)).incrementAndGet();
 | 
	
		
			
				|  |  | -        //添加房间中累计总用户数量
 | 
	
		
			
				|  |  | -        redissonClient.getAtomicLong(LIVE_ROOM_TOTAL_LOOK.replace(ROOM_UID, roomUid)).incrementAndGet();
 | 
	
		
			
				|  |  | -        //将用户数据写入直播间
 | 
	
		
			
				|  |  | -        RList<UserInfo> list = redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, roomUid));
 | 
	
		
			
				|  |  | -        UserInfo userInfo = getUserInfo(userId);
 | 
	
		
			
				|  |  | -        list.add(userInfo);
 | 
	
		
			
				|  |  | -        //如果是主播,录制视频
 | 
	
		
			
				|  |  | -//        imFeignService.startRecord(roomUid);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    private UserInfo getUserInfo(Integer userId) {
 | 
	
		
			
				|  |  | -        UserInfo userInfo = new UserInfo();
 | 
	
		
			
				|  |  | -        userInfo.setUserId(userId);
 | 
	
		
			
				|  |  | -        SysUser sysUser = sysUserFeignService.queryUserById(userId);
 | 
	
		
			
				|  |  | -        String name = userId.toString();
 | 
	
		
			
				|  |  | -        if (Objects.nonNull(sysUser)) {
 | 
	
		
			
				|  |  | -            if (StringUtils.isNotBlank(sysUser.getRealName())) {
 | 
	
		
			
				|  |  | -                name = sysUser.getRealName();
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                name = sysUser.getPhone();
 | 
	
		
			
				|  |  | +            //获取当前用户所在房间的uid
 | 
	
		
			
				|  |  | +            RBucket<String> userRoom = redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, user.getUserid()));
 | 
	
		
			
				|  |  | +            if (!userRoom.isExists()) {
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            String roomUid = userRoom.get();
 | 
	
		
			
				|  |  | +            Integer userId = Integer.valueOf(user.getUserid());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //只有离线-发送退出房间消息给主讲人
 | 
	
		
			
				|  |  | +            if (user.getStatus().equals("1")) {
 | 
	
		
			
				|  |  | +                ImRoomMessage message = new ImRoomMessage();
 | 
	
		
			
				|  |  | +                message.setFromUserId(userId.toString());
 | 
	
		
			
				|  |  | +                message.setToChatroomId(roomUid);
 | 
	
		
			
				|  |  | +                message.setObjectName(ImRoomMessage.LOOKER_LOGIN_OUT);
 | 
	
		
			
				|  |  | +                imFeignService.publishRoomMsg(message);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        userInfo.setUserName(name);
 | 
	
		
			
				|  |  | -        return userInfo;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    static class UserInfo implements Serializable {
 | 
	
		
			
				|  |  | -        private Integer userId;
 | 
	
		
			
				|  |  | -        private String userName;
 | 
	
		
			
				|  |  | +            //从房间累计用户信息中查询该用户的信息
 | 
	
		
			
				|  |  | +            RMap<Integer, RoomUserInfoVo> roomTotalUser = redissonClient.getMap(LIVE_ROOM_TOTAL_USER_LIST.replace(ROOM_UID, roomUid));
 | 
	
		
			
				|  |  | +            Date now = new Date();
 | 
	
		
			
				|  |  | +            RoomUserInfoVo userInfo;
 | 
	
		
			
				|  |  | +            //该房间未查询到用户数据则不处理
 | 
	
		
			
				|  |  | +            if (!roomTotalUser.containsKey(userId)) {
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //查询到用户数据
 | 
	
		
			
				|  |  | +            userInfo = roomTotalUser.get(userId);
 | 
	
		
			
				|  |  | +            //将用户从该房间当前直播间用户列表移除
 | 
	
		
			
				|  |  | +            redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, roomUid)).remove(userInfo);
 | 
	
		
			
				|  |  | +            //每次退出房间计算当前用户观看时长
 | 
	
		
			
				|  |  | +            int minutesBetween = getMinutesBetween(userInfo.getDynamicJoinTime(), now);
 | 
	
		
			
				|  |  | +            userInfo.setTotalViewTime(userInfo.getTotalViewTime() + minutesBetween);
 | 
	
		
			
				|  |  | +            //记录退出时间 并写入缓存
 | 
	
		
			
				|  |  | +            userInfo.setLastOutTime(now);
 | 
	
		
			
				|  |  | +            roomTotalUser.put(userId, userInfo);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public Integer getUserId() {
 | 
	
		
			
				|  |  | -            return userId;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public void setUserId(Integer userId) {
 | 
	
		
			
				|  |  | -            this.userId = userId;
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 进入房间-修改用户对应的房间号信息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param roomUid 房间uid
 | 
	
		
			
				|  |  | +     * @param userId  用户id
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void joinRoom(String roomUid, Integer userId) {
 | 
	
		
			
				|  |  | +        //记录用户当前房间uid
 | 
	
		
			
				|  |  | +        redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString())).set(roomUid);
 | 
	
		
			
				|  |  | +        //房间累计用户信息-指只要进入到该房间的用户都要记录
 | 
	
		
			
				|  |  | +        RMap<Integer, RoomUserInfoVo> roomTotalUser = redissonClient.getMap(LIVE_ROOM_TOTAL_USER_LIST.replace(ROOM_UID, roomUid));
 | 
	
		
			
				|  |  | +        //判断是否第一次进房间
 | 
	
		
			
				|  |  | +        Date now = new Date();
 | 
	
		
			
				|  |  | +        RoomUserInfoVo userInfo;
 | 
	
		
			
				|  |  | +        if (roomTotalUser.containsKey(userId)) {
 | 
	
		
			
				|  |  | +            //多次进入更新动态进入时间
 | 
	
		
			
				|  |  | +            userInfo = roomTotalUser.get(userId);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            //第一次进该房间 写入用户首次进入时间
 | 
	
		
			
				|  |  | +            userInfo = getUserInfo(userId);
 | 
	
		
			
				|  |  | +            userInfo.setFirstJoinTime(now);
 | 
	
		
			
				|  |  | +            userInfo.setTotalViewTime(0);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        userInfo.setDynamicJoinTime(now);
 | 
	
		
			
				|  |  | +        roomTotalUser.put(userId, userInfo);
 | 
	
		
			
				|  |  | +        //添加到直播间当前用户数据缓存中
 | 
	
		
			
				|  |  | +        redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, roomUid)).add(userInfo);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public String getUserName() {
 | 
	
		
			
				|  |  | -            return userName;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 开始直播
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param roomUid
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void startLive(String roomUid) {
 | 
	
		
			
				|  |  | +        //开始录制视频
 | 
	
		
			
				|  |  | +        imFeignService.startRecord(roomUid);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public void setUserName(String userName) {
 | 
	
		
			
				|  |  | -            this.userName = userName;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 关闭直播
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param roomUid
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void closeLive(String roomUid) {
 | 
	
		
			
				|  |  | +        //停止录制视频
 | 
	
		
			
				|  |  | +        imFeignService.stopRecord(roomUid);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -327,6 +353,38 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |          list.forEach(this::createLiveRoom);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    //移除
 | 
	
		
			
				|  |  | +    private void removeUserCache(Integer userId, String lodRoomUid) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private RoomUserInfoVo getUserInfo(Integer userId) {
 | 
	
		
			
				|  |  | +        RoomUserInfoVo userInfo = new RoomUserInfoVo();
 | 
	
		
			
				|  |  | +        userInfo.setUserId(userId);
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserById(userId);
 | 
	
		
			
				|  |  | +        String name = userId.toString();
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(sysUser)) {
 | 
	
		
			
				|  |  | +            if (StringUtils.isNotBlank(sysUser.getRealName())) {
 | 
	
		
			
				|  |  | +                name = sysUser.getRealName();
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                name = sysUser.getPhone();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        userInfo.setUserName(name);
 | 
	
		
			
				|  |  | +        return userInfo;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    //计算时间差-分钟数不满一分钟为0
 | 
	
		
			
				|  |  | +    private int getMinutesBetween(Date startDT, Date endDT) {
 | 
	
		
			
				|  |  | +        if (Objects.isNull(startDT) || Objects.isNull(endDT)) {
 | 
	
		
			
				|  |  | +            return 0;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //课程结束时间-课程开始时间
 | 
	
		
			
				|  |  | +        long durationTime = endDT.getTime() - startDT.getTime();
 | 
	
		
			
				|  |  | +        //相差多少分钟
 | 
	
		
			
				|  |  | +        return new Long(durationTime / 1000 / 60).intValue();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 去融云创建房间
 | 
	
		
			
				|  |  |       */
 | 
	
	
		
			
				|  | @@ -335,11 +393,31 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |              //去融云创建房间
 | 
	
		
			
				|  |  |              Object liveRoom = imFeignService.createLiveRoom(room.getRoomUid(), room.getRoomTitle());
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +            throw new BizException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //初始化房间数据  点赞 人数 等 为0
 | 
	
		
			
				|  |  | -        //修改房间状态
 | 
	
		
			
				|  |  | +        //生成0点赞
 | 
	
		
			
				|  |  | +        redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, room.getRoomUid())).set(0);
 | 
	
		
			
				|  |  | +        //todo 修改房间状态
 | 
	
		
			
				|  |  | +        room.setLiveState(1);
 | 
	
		
			
				|  |  | +        room.setUpdatedTime(new Date());
 | 
	
		
			
				|  |  | +        room.setUpdatedBy(-1);
 | 
	
		
			
				|  |  | +        baseMapper.updateById(room);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private void getRoomData(ImLiveBroadcastRoomVo roomVo) {
 | 
	
		
			
				|  |  | +        //生成0点赞
 | 
	
		
			
				|  |  | +        Object like = redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, roomVo.getRoomUid())).get();
 | 
	
		
			
				|  |  | +        if (Objects.isNull(like)) {
 | 
	
		
			
				|  |  | +            like = 0;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        roomVo.setLikeNum((int) like);
 | 
	
		
			
				|  |  | +        //0用户数量
 | 
	
		
			
				|  |  | +        RList<Object> list = redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, roomVo.getRoomUid()));
 | 
	
		
			
				|  |  | +        int size = list.size();
 | 
	
		
			
				|  |  | +        roomVo.setLookNum(size);
 | 
	
		
			
				|  |  | +        //0累计总用户数量
 | 
	
		
			
				|  |  | +        int totalLook = redissonClient.getMap(LIVE_ROOM_TOTAL_USER_LIST.replace(ROOM_UID, roomVo.getRoomUid())).size();
 | 
	
		
			
				|  |  | +        roomVo.setTotalLookNum(totalLook);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private SysUser getSysUser(Integer userId) {
 | 
	
	
		
			
				|  | @@ -358,15 +436,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |       * 分享直播间
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public void test() {
 | 
	
		
			
				|  |  | -        //将用户数据写入直播间
 | 
	
		
			
				|  |  | -        RList<UserInfo> list = redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, "roomUid"));
 | 
	
		
			
				|  |  | -        UserInfo userInfo = new UserInfo();
 | 
	
		
			
				|  |  | -        userInfo.setUserId(1);
 | 
	
		
			
				|  |  | -        userInfo.setUserName("1");
 | 
	
		
			
				|  |  | -        boolean contains = list.contains(userInfo);
 | 
	
		
			
				|  |  | -        if (!contains) {
 | 
	
		
			
				|  |  | -            list.add(userInfo);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -381,5 +450,15 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 | 
	
		
			
				|  |  |                  DateUtil.format(imLiveBroadcastRoomVo.getLiveStartTime(), DateUtil.CHINESE_DATA_FORMAT_1),
 | 
	
		
			
				|  |  |                  imLiveBroadcastRoomVo.getLiveRemark(), HttpUtil.getSortUrl("https://test.dayaedu.com/"));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查询直播间用户信息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param roomUid 直播间uid
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public List<RoomUserInfoVo> queryRoomUserInfo(String roomUid) {
 | 
	
		
			
				|  |  | +        return redissonClient.getList(LIVE_ROOM_USER_LIST.replace(ROOM_UID, roomUid));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |