|  | @@ -13,18 +13,17 @@ import java.util.concurrent.CompletableFuture;
 | 
	
		
			
				|  |  |  import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  import java.util.function.BiFunction;
 | 
	
		
			
				|  |  |  import java.util.function.BiPredicate;
 | 
	
		
			
				|  |  | -import java.util.function.Consumer;
 | 
	
		
			
				|  |  |  import java.util.function.Function;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.fasterxml.jackson.annotation.JsonFormat;
 | 
	
		
			
				|  |  | -import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.live.LivePluginContext;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.live.LivePluginService;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.live.impl.RongCloudLivePlugin;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.live.impl.TencentCloudLivePlugin;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.live.message.*;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.api.feign.dto.RoomConfig;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.LiveRoomStatus;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.TencentData;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.*;
 | 
	
	
		
			
				|  | @@ -36,6 +35,7 @@ import com.yonge.cooleshow.biz.dal.redisson.RedissonMessageService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.wrapper.liveroom.ImLiveBroadcastRoomMemberWrapper;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.wrapper.liveroom.LiveRoomWrapper;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.common.constant.SysConfigConstant;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.enums.EGroupDefinedDataType;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.payment.util.DistributedLock;
 | 
	
		
			
				|  |  |  import lombok.Data;
 | 
	
	
		
			
				|  | @@ -222,33 +222,37 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |              log.error("teacherCheckRoomInfo>>>not speaker  roomUid: {} userId:{}", roomUid, userId);
 | 
	
		
			
				|  |  |              throw new BizException("您不是该直播间的主讲人!");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        speakCache(room, userId);
 | 
	
		
			
				|  |  | +        return liveRoom;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void speakCache(LiveRoom room, Long userId) {
 | 
	
		
			
				|  |  |          //获取直播间信息
 | 
	
		
			
				|  |  | -        RBucket<RoomSpeakerInfo> speakerCache = getRoomSpeakerInfoCache(roomUid, userId.toString());
 | 
	
		
			
				|  |  | +        RBucket<RoomSpeakerInfo> speakerCache = getRoomSpeakerInfoCache(room.getRoomUid(), userId.toString());
 | 
	
		
			
				|  |  |          if (!speakerCache.isExists()) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //没有主讲人信息则生成一个
 | 
	
		
			
				|  |  | -            createSpeakerInfo(this.getById(liveRoom.getId()), sysUser);
 | 
	
		
			
				|  |  | +            createSpeakerInfo(this.getById(room.getId()), userId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              // 查询主播缓存信息
 | 
	
		
			
				|  |  | -            speakerCache = getRoomSpeakerInfoCache(roomUid, userId.toString());
 | 
	
		
			
				|  |  | +            speakerCache = getRoomSpeakerInfoCache(room.getRoomUid(), userId.toString());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          RoomSpeakerInfo speakerInfo = speakerCache.get();
 | 
	
		
			
				|  |  | -        speakerInfo.setJoinRoomTime(now);
 | 
	
		
			
				|  |  | +        speakerInfo.setJoinRoomTime(new Date());
 | 
	
		
			
				|  |  |          speakerCache.set(speakerInfo);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //记录用户当前房间uid
 | 
	
		
			
				|  |  | -        redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString())).set(roomUid, 12L, TimeUnit.HOURS);
 | 
	
		
			
				|  |  | +        redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString())).set(room.getRoomUid(), 12L, TimeUnit.HOURS);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 更新直播间主播状态
 | 
	
		
			
				|  |  |          lambdaUpdate()
 | 
	
		
			
				|  |  | -                .eq(LiveRoom::getRoomUid, roomUid)
 | 
	
		
			
				|  |  | +                .eq(LiveRoom::getRoomUid, room.getRoomUid())
 | 
	
		
			
				|  |  |                  .eq(LiveRoom::getSpeakerId, userId)
 | 
	
		
			
				|  |  |                  .set(LiveRoom::getSpeakerStatus, 1)
 | 
	
		
			
				|  |  |                  .update();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 设置直播群组自定义数据
 | 
	
		
			
				|  |  |          setGroupDefinedData(room,EGroupDefinedDataType.ANCHOR_STATUS,EAnchorStatus.ONLINE.getCode());
 | 
	
		
			
				|  |  | -        return liveRoom;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -263,7 +267,10 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //生成主讲人信息
 | 
	
		
			
				|  |  | -    private void createSpeakerInfo(LiveRoom room, SysUser sysUser) {
 | 
	
		
			
				|  |  | +    private void createSpeakerInfo(LiveRoom room, Long userId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserById(userId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          Date now = new Date();
 | 
	
		
			
				|  |  |          RoomSpeakerInfo speakerInfo = new RoomSpeakerInfo();
 | 
	
		
			
				|  |  |          speakerInfo.setSpeakerId(sysUser.getId());
 | 
	
	
		
			
				|  | @@ -332,7 +339,8 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |          Date now = new Date();
 | 
	
		
			
				|  |  |          courseScheduleList.forEach(c -> {
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | -                liveRoomService.updateLiveCourseSchedule(preCreateRoomMinute, titleMap, remarkMap, en, now, c);
 | 
	
		
			
				|  |  | +                DistributedLock.of(redissonClient).runIfLockCanGet("LIVE_COURSE_CREATE:"+c.getId(), () ->
 | 
	
		
			
				|  |  | +                    liveRoomService.updateLiveCourseSchedule(preCreateRoomMinute, titleMap, remarkMap, en, now, c));
 | 
	
		
			
				|  |  |              } catch (Exception e) {
 | 
	
		
			
				|  |  |                  log.error("createCourseLiveRoom>>>生成直播间失败:{}", c, e);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -348,12 +356,38 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //避免重复创建直播间
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 如果是同时在管乐迷和酷乐秀直播的老师
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        LiveRoom room = new LiveRoom();
 | 
	
		
			
				|  |  | +        String teacherIds = sysConfigService.findConfigValue(SysConfigConstant.LIVE_TEACHER_IDS);
 | 
	
		
			
				|  |  |          if (StringUtils.isNotBlank(c.getRoomUid())) {
 | 
	
		
			
				|  |  | -            log.info("createCourseLiveRoom>>>roomUid:{} 已存在", c.getRoomUid());
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | +            if ((StringUtils.isBlank(teacherIds) || !Arrays.asList(teacherIds.split(",")).contains(c.getTeacherId().toString()))) {
 | 
	
		
			
				|  |  | +                log.info("createCourseLiveRoom>>>roomUid:{} 已存在", c.getRoomUid());
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                LiveRoom liveRoom = getByRoomUid(c.getRoomUid());
 | 
	
		
			
				|  |  | +                if (liveRoom != null) {
 | 
	
		
			
				|  |  | +                    log.info("createCourseLiveRoom>>>roomUid:{} 已存在", c.getRoomUid());
 | 
	
		
			
				|  |  | +                   return;
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    // 设置直播间不显示购物车
 | 
	
		
			
				|  |  | +                    RoomConfig roomConfig = new RoomConfig();
 | 
	
		
			
				|  |  | +                    // 1:是隐藏, 和管乐迷一样
 | 
	
		
			
				|  |  | +                    roomConfig.setWhether_view_shop_cart(1);
 | 
	
		
			
				|  |  | +                    room.setRoomConfig(JSON.toJSONString(roomConfig));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (StringUtils.isBlank(c.getRoomUid())) {
 | 
	
		
			
				|  |  | +            room.setRoomUid(GenRoomUid.apply(c.getTeacherId(), en));
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            room.setRoomUid(c.getRoomUid());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotBlank(teacherIds) && Arrays.asList(teacherIds.split(",")).contains(c.getTeacherId().toString())) {
 | 
	
		
			
				|  |  | +            room.setOs("pc");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        LiveRoom room = new LiveRoom();
 | 
	
		
			
				|  |  | -        room.setRoomUid(GenRoomUid.apply(c.getTeacherId(), en));
 | 
	
		
			
				|  |  |          room.setRoomTitle(titleMap.get(c.getCourseGroupId()));
 | 
	
		
			
				|  |  |          room.setLiveRemark(remarkMap.get(c.getCourseGroupId()));
 | 
	
		
			
				|  |  |          room.setSpeakerId(c.getTeacherId());
 | 
	
	
		
			
				|  | @@ -372,6 +406,10 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |          this.createLiveRoomInfo(room);
 | 
	
		
			
				|  |  |          //开课提醒
 | 
	
		
			
				|  |  |          this.pushLiveCreateRoom(room);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotBlank(teacherIds) && Arrays.asList(teacherIds.split(",")).contains(room.getSpeakerId().toString())) {
 | 
	
		
			
				|  |  | +            speakCache(room, room.getSpeakerId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -492,20 +530,28 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      // 生成录制任务
 | 
	
		
			
				|  |  |                      log.info("createLiveRoom>>>>>> recordStart:{}", recordStart.jsonString());
 | 
	
		
			
				|  |  | -                    RTCRoom.RecordResp resp = pluginService.rtcRoomRecordStart(recordStart);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    // 设置录制任务Id
 | 
	
		
			
				|  |  | -                    LiveRoom update = new LiveRoom();
 | 
	
		
			
				|  |  | -                    update.setId(room.getId());
 | 
	
		
			
				|  |  | -                    if (StringUtils.isBlank(room.getVideoRecord())) {
 | 
	
		
			
				|  |  | -                        update.setVideoRecord(resp.getRecordId());
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        update.setVideoRecord(room.getVideoRecord() + "," + resp.getRecordId());
 | 
	
		
			
				|  |  | +                    try {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        RTCRoom.RecordResp resp = pluginService.rtcRoomRecordStart(recordStart);
 | 
	
		
			
				|  |  | +                        // 设置录制任务Id
 | 
	
		
			
				|  |  | +                        LiveRoom update = new LiveRoom();
 | 
	
		
			
				|  |  | +                        update.setId(room.getId());
 | 
	
		
			
				|  |  | +                        if (StringUtils.isBlank(room.getVideoRecord())) {
 | 
	
		
			
				|  |  | +                            update.setVideoRecord(resp.getRecordId());
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            update.setVideoRecord(room.getVideoRecord() + "," + resp.getRecordId());
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        updateById(update);
 | 
	
		
			
				|  |  | +                    }catch (Exception e) {
 | 
	
		
			
				|  |  | +                        log.error("createLiveRoom>>>>>> recordStart error:{}", e.getMessage());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    updateById(update);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  // 设置直播间房间属性默认值
 | 
	
		
			
				|  |  | -                setDefaultRoomDefinedInfo(room);
 | 
	
		
			
				|  |  | +                List<TencentWrapper.ChatRoomGroupCounter> chatRoomGroupDefinedData = pluginService.getChatRoomGroupDefinedData(room.getRoomUid());
 | 
	
		
			
				|  |  | +                if (CollectionUtils.isEmpty(chatRoomGroupDefinedData)) {
 | 
	
		
			
				|  |  | +                    setDefaultRoomDefinedInfo(room);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  |              throw new BizException("创建直播间失败!", e);
 | 
	
	
		
			
				|  | @@ -1265,7 +1311,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |          message.setContent(sendMap);
 | 
	
		
			
				|  |  |          //发送消息
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  | -            this.publishRoomMessage(message);
 | 
	
		
			
				|  |  | +//            this.publishRoomMessage(message);
 | 
	
		
			
				|  |  |              log.info("sendOnlineUserCount>>>> message: {}", JSONObject.toJSONString(message));
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  |              log.error("sendOnlineUserCount>>>> error {}", e.getMessage());
 | 
	
	
		
			
				|  | @@ -2134,12 +2180,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |          roomVo.setTotalLookNum(0);
 | 
	
		
			
				|  |  |          roomVo.setLookNum(0);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        ImLiveBroadcastRoomMemberWrapper.RoomMemberNumDto roomMemberNumDto = imLiveBroadcastRoomMemberMapper.queryMemberNum(roomVo.getRoomUid());
 | 
	
		
			
				|  |  | -        if (roomMemberNumDto == null) {
 | 
	
		
			
				|  |  | -            roomMemberNumDto = new ImLiveBroadcastRoomMemberWrapper.RoomMemberNumDto();
 | 
	
		
			
				|  |  | -            roomMemberNumDto.setTotalNum(0);
 | 
	
		
			
				|  |  | -            roomMemberNumDto.setOnlineNum(0);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        ImLiveBroadcastRoomMemberWrapper.RoomMemberNumDto roomMemberNumDto = getRoomMemberNumDto(roomVo.getRoomUid());
 | 
	
		
			
				|  |  |          roomVo.setTotalLookNum(roomMemberNumDto.getTotalNum() == null? 0 : roomMemberNumDto.getTotalNum());
 | 
	
		
			
				|  |  |          roomVo.setLookNum(roomMemberNumDto.getOnlineNum() == null? 0 : roomMemberNumDto.getOnlineNum());
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -2163,6 +2204,18 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public ImLiveBroadcastRoomMemberWrapper.RoomMemberNumDto getRoomMemberNumDto(String roomUid) {
 | 
	
		
			
				|  |  | +        ImLiveBroadcastRoomMemberWrapper.RoomMemberNumDto roomMemberNumDto = imLiveBroadcastRoomMemberMapper.queryMemberNum(roomUid);
 | 
	
		
			
				|  |  | +        if (roomMemberNumDto == null) {
 | 
	
		
			
				|  |  | +            roomMemberNumDto = new ImLiveBroadcastRoomMemberWrapper.RoomMemberNumDto();
 | 
	
		
			
				|  |  | +            roomMemberNumDto.setTotalNum(0);
 | 
	
		
			
				|  |  | +            roomMemberNumDto.setOnlineNum(0);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return roomMemberNumDto;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 同步直播间点赞数
 | 
	
		
			
				|  |  |       *
 |