liujc 1 year ago
parent
commit
cb0588b337

+ 58 - 13
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/LiveRoomServiceImpl.java

@@ -481,8 +481,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
                 DateTime now = DateTime.now();
 
                 RTCRequest.RecordStart recordStart = RTCRequest.RecordStart.builder()
-                        .streamName(MessageFormat.format("{0}_{1}", room.getRoomUid(),
-                                imGroupService.getImUserId(room.getSpeakerId().toString(),ClientEnum.TEACHER.getCode())))
+                        .streamName(getStreamId(room.getRoomUid(),room.getSpeakerId()))
                         .extra("")
                         .startTime(now.toDateTime().getMillis())
                         .endTime(now.plusDays(1).toDateTime().getMillis())
@@ -1706,24 +1705,51 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
                 return false;
             }
             if (pluginService.pluginName().equals(TencentCloudLivePlugin.PLUGIN_NAME)) {
+//                TencentWrapper.LiveStreamState liveStreamState = pluginService.liveStreamState(
+//                        getStreamId(liveRoom.getRoomUid(), liveRoom.getSpeakerId()));
+//                if (liveStreamState == null) {
+//                    log.error("查询直播间流失败,返回结果为空");
+//                    return false;
+//                }
+//                log.info("查询直播间流状态:{},roomUid:{}", JSON.toJSONString(liveStreamState), liveRoom.getRoomUid());
+//                if (!"active".equals(liveStreamState.getStreamState())) {
+//                    pluginService.liveStreamStop(getStreamId(liveRoom.getRoomUid(), liveRoom.getSpeakerId()));
+//                }
+
+                //销毁直播间
+                pluginService.chatRoomDestroy(liveRoom.getRoomUid());
+
                 TencentWrapper.LiveStreamState liveStreamState = pluginService.liveStreamState(
                         getStreamId(liveRoom.getRoomUid(), liveRoom.getSpeakerId()));
                 if (liveStreamState == null) {
                     log.error("查询直播间流失败,返回结果为空");
-                    return false;
-                }
-                log.info("查询直播间流状态:{},roomUid:{}", JSON.toJSONString(liveStreamState), liveRoom.getRoomUid());
-                if (!"active".equals(liveStreamState.getStreamState())) {
+                } else if ("active".equals(liveStreamState.getStreamState())) {
                     pluginService.liveStreamStop(getStreamId(liveRoom.getRoomUid(), liveRoom.getSpeakerId()));
                 }
+
+                // 录制任务Id
+                if (liveRoom.getServiceProvider().equals(TencentCloudLivePlugin.PLUGIN_NAME)) {
+
+                    List<String> collect = liveRoomService.lambdaQuery()
+                            .eq(LiveRoom::getRoomUid, liveRoom.getRoomUid()).list().stream()
+                            .map(LiveRoom::getVideoRecord)
+                            .filter(StringUtils::isNotEmpty)
+                            .distinct().collect(Collectors.toList());
+
+                    for (String taskId : collect) {
+                        // 删除录制任务
+                        pluginService.rtcRoomRecordStop(taskId);
+                    }
+                }
+
             } else if (pluginService.pluginName().equals(RongCloudLivePlugin.PLUGIN_NAME)) {
                 // 融云走原有逻辑 融云自动销毁
-                // 销毁状态改为2
-                LiveRoom liveRoomUpdate = new LiveRoom();
-                liveRoomUpdate.setId(liveRoom.getId());
-                liveRoomUpdate.setRoomState(2);
-                liveRoomService.updateById(liveRoomUpdate);
             }
+            // 销毁状态改为2
+            LiveRoom liveRoomUpdate = new LiveRoom();
+            liveRoomUpdate.setId(liveRoom.getId());
+            liveRoomUpdate.setRoomState(2);
+            liveRoomService.updateById(liveRoomUpdate);
         } catch (Exception e) {
 
             log.error("查询直播间流失败", e);
@@ -1733,7 +1759,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
     }
 
     private String getStreamId(String roomUid, Long speakerId) {
-        return roomUid + "_" + speakerId;
+        return roomUid + "_" + imGroupService.getImUserId(speakerId,ClientEnum.TEACHER);
     }
 
 
@@ -1958,6 +1984,16 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
                 .map(this::getSysUser)
                 .orElseGet(this::getSysUser);
 
+
+        // 如果是直播课程,判断是否已经结束
+        Integer count = courseScheduleService.lambdaQuery()
+                .eq(CourseSchedule::getRoomUid, roomUid)
+                .eq(CourseSchedule::getStatus, "COMPLETE")
+                .count();
+        if (count >0 ) {
+            throw new BizException("直播课已结束");
+        }
+
         // 默认学生端查询
         osType = Optional.ofNullable(osType).orElse(1);
         ClientEnum clientEnum = ClientEnum.TEACHER;
@@ -2202,6 +2238,15 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         Optional.ofNullable(roomUid).orElseThrow(() -> new BizException("房间编号不能为空!"));
         Optional.ofNullable(userId).orElseThrow(() -> new BizException("人员编号不能为空!"));
 
+        // 如果是直播课程,判断是否已经结束
+        Integer count = courseScheduleService.lambdaQuery()
+                .eq(CourseSchedule::getRoomUid, roomUid)
+                .eq(CourseSchedule::getStatus, "COMPLETE")
+                .count();
+        if (count >0 ) {
+            throw new BizException("直播课已结束");
+        }
+
         // 设置进入时间
         RBucket<Long> userStateTimeCache = redissonClient.getBucket(LIVE_USER_LAST_TIME.replace(USER_ID, userId.toString()));
         long time = DateTime.now().plusSeconds(1).getMillis();
@@ -2313,7 +2358,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         RoomSpeakerInfo roomSpeakerInfo = speakerCache.get();
 
         //关闭直播
-        if (sequence.equals(roomSpeakerInfo.getSequence())) {
+        if (StringUtils.isNotBlank(sequence) && sequence.equals(roomSpeakerInfo.getSequence())) {
             setPushStatus(roomSpeakerInfo.getRoomUid(), 0);
         }
 

+ 38 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java

@@ -80,6 +80,21 @@ import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
 import com.yonge.cooleshow.biz.dal.service.UserAccountService;
 import com.yonge.cooleshow.biz.dal.service.UserFirstTimeService;
 import com.yonge.cooleshow.biz.dal.service.im.ImGroupCoreService;
+import com.yonge.cooleshow.biz.dal.queryInfo.TeacherQueryInfo;
+import com.yonge.cooleshow.biz.dal.service.ImGroupService;
+import com.yonge.cooleshow.biz.dal.service.StudentService;
+import com.yonge.cooleshow.biz.dal.service.StudentStarService;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
+import com.yonge.cooleshow.biz.dal.service.SysConfigService;
+import com.yonge.cooleshow.biz.dal.service.SysMessageService;
+import com.yonge.cooleshow.biz.dal.service.TeacherAuthEntryRecordService;
+import com.yonge.cooleshow.biz.dal.service.TeacherAuthMusicianRecordService;
+import com.yonge.cooleshow.biz.dal.service.TeacherService;
+import com.yonge.cooleshow.biz.dal.service.TeacherStyleVideoService;
+import com.yonge.cooleshow.biz.dal.service.TeacherTotalService;
+import com.yonge.cooleshow.biz.dal.service.UserAccountService;
+import com.yonge.cooleshow.biz.dal.service.UserFirstTimeService;
+import com.yonge.cooleshow.biz.dal.service.im.ImGroupCoreService;
 import com.yonge.cooleshow.biz.dal.vo.HotTeacherVo;
 import com.yonge.cooleshow.biz.dal.vo.MusicSheetUploadCountVo;
 import com.yonge.cooleshow.biz.dal.vo.MyFens;
@@ -113,6 +128,28 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static com.yonge.cooleshow.biz.dal.constant.LiveRoomConstant.TEACHER_TEMP_LIVE_ROOM;
+import org.redisson.api.RMap;
+import org.redisson.api.RedissonClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -286,7 +323,7 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 
         try {
             ImGroupWrapper.ImUserInfo register = imGroupCoreService.register(teacher.getUserId().toString(),
-                    ClientEnum.STUDENT.getCode(),
+                    ClientEnum.TEACHER.getCode(),
                     teacher.getUsername(),
                     teacher.getAvatar());
             teacherHomeVo.setImToken(register.getImToken());