Pārlūkot izejas kodu

增加老师进房间检查信息接口

hgw 3 gadi atpakaļ
vecāks
revīzija
5f24975311

+ 11 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/LiveRoomService.java

@@ -30,7 +30,16 @@ public interface LiveRoomService extends IService<LiveRoom> {
      *
      * @param roomUid 房间uid
      */
-    RoomVo studentCheckRoomInfo(String roomUid);
+    RoomInfoCache studentCheckRoomInfo(String roomUid);
+
+    /**
+     * 主讲人查询并校验房间信息
+     *
+     * @param roomUid 房间uid
+     * @param userId  主讲人id
+     * @return
+     */
+    RoomInfoCache speakerCheckRoomInfo(String roomUid);
 
     /**
      * 定时任务创建直播间
@@ -74,7 +83,7 @@ public interface LiveRoomService extends IService<LiveRoom> {
      * @param roomUid 房间uid
      * @param userId  主讲人id
      */
-    RoomInfoCache speakerJoinRoom(String roomUid, Long userId);
+    RoomInfoCache speakerJoinRoom(String roomUid);
 
     /**
      * 观看者-进入房间

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

@@ -14,6 +14,7 @@ import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.support.IMHelper;
 import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
 import com.yonge.cooleshow.biz.dal.vo.RoomVo;
+import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
 import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.utils.date.DateUtil;
 import org.apache.commons.collections.CollectionUtils;
@@ -62,6 +63,8 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
     @Autowired
     private UserAccountService userAccountService;
     @Autowired
+    private UserOrderService userOrderService;
+    @Autowired
     private CourseScheduleTeacherSalaryService courseScheduleTeacherSalaryService;
     @Autowired
     private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
@@ -110,10 +113,35 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
      * @param roomUid 房间uid
      */
     @Override
-    public RoomVo studentCheckRoomInfo(String roomUid) {
-        //校验学生与房间的关系
-        checkStudentRoom(roomUid, getSysUser());
-        return queryRoomInfo(roomUid);
+    public RoomInfoCache studentCheckRoomInfo(String roomUid) {
+        return checkStudentRoom(roomUid, getSysUser());
+    }
+
+    /**
+     * 主讲人查询并校验房间信息
+     *
+     * @param roomUid 房间uid
+     * @param userId  主讲人id
+     * @return
+     */
+    @Override
+    public RoomInfoCache speakerCheckRoomInfo(String roomUid) {
+        Long userId = getSysUser().getId();
+        //校验房间是否存在
+        RBucket<RoomInfoCache> roomInfoCache = redissonClient.getBucket(LIVE_ROOM_INFO.replace(ROOM_UID, roomUid));
+        if (!roomInfoCache.isExists()) {
+            log.error("teacherCheckRoomInfo>>>live not start  roomUid: {} userId:{}", roomUid, userId);
+            throw new BizException("直播还未开始!");
+        }
+        RoomInfoCache roomInfo = roomInfoCache.get();
+        //校验进入房间的是否是该直播间的主讲人
+        if (!roomInfo.getSpeakerId().equals(userId)) {
+            log.error("teacherCheckRoomInfo>>>not speaker  roomUid: {} userId:{}", roomUid, userId);
+            throw new BizException("您不是该直播间的主讲人!");
+        }
+        roomInfo.setLikeNum(getLike(roomUid));
+        roomInfo.setLookNum(getNum.apply(this::getOnlineUserCache, roomUid));
+        return roomInfo;
     }
 
     /**
@@ -185,12 +213,12 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         SysUser sysUser = getSysUser();
         String roomTitle = WrapperUtil.toStr(param, "roomTitle", "房间标题不能为空!");
         String liveRemark = WrapperUtil.toStr(param, "liveRemark", "直播间描述不能为空!");
-        Integer liveTime = WrapperUtil.toInt(param, "liveTime","请选择直播时长!");
+        Integer liveTime = WrapperUtil.toInt(param, "liveTime", "请选择直播时长!");
         Date liveStartTime = new Date();
         Date liveEndTime = DateUtil.addMinutes(liveStartTime, liveTime);
         Long teacherId = sysUser.getId();
         //当前时间有课程则不能开启直播
-        boolean check =  courseScheduleService.checkTeacherCourseTime(teacherId,liveStartTime,liveEndTime);
+        boolean check = courseScheduleService.checkTeacherCourseTime(teacherId, liveStartTime, liveEndTime);
         if (check) {
             //如果当前时间和课程时间有交集则不能开启临时直播
             throw new BizException("当前选择的时间段有课无法开启直播");
@@ -614,29 +642,16 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
      * 主讲人-进入房间
      *
      * @param roomUid 房间uid
-     * @param userId  主讲人id
      */
-    public RoomInfoCache speakerJoinRoom(String roomUid, Long userId) {
-        //校验房间是否存在
-        RBucket<RoomInfoCache> roomInfoCache = redissonClient.getBucket(LIVE_ROOM_INFO.replace(ROOM_UID, roomUid));
-        if (!roomInfoCache.isExists()) {
-            throw new BizException("直播还未开始!");
-        }
-        RoomInfoCache roomInfo = roomInfoCache.get();
+    public RoomInfoCache speakerJoinRoom(String roomUid) {
+        RoomInfoCache roomInfo = speakerCheckRoomInfo(roomUid);
         Date now = new Date();
-        //校验进入房间的是否是该直播间的主讲人
-        if (!roomInfo.getSpeakerId().equals(userId)) {
-            throw new BizException("您不是该直播间的主讲人!");
-        }
         roomInfo.setSpeakerState(0);
         roomInfo.setJoinRoomTime(now);
-        roomInfoCache.set(roomInfo);
         //查询老师是否有进入过,没有则写老师考勤表的进入时间
-        setTeacherAttendance(userId, roomInfo.getCourseGroupId(), roomInfo.getCourseId());
-        roomInfo.setLikeNum(getLike(roomUid));
-        roomInfo.setLookNum(getNum.apply(this::getOnlineUserCache, roomUid));
+        setTeacherAttendance(roomInfo.getSpeakerId(), roomInfo.getCourseGroupId(), roomInfo.getCourseId());
         //记录当前用户对应的房间uid
-        redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString())).set(roomUid, 2L, TimeUnit.DAYS);
+        redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, roomInfo.getSpeakerId().toString())).set(roomUid, 2L, TimeUnit.DAYS);
         return roomInfo;
     }
 
@@ -650,8 +665,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         //获取进入房间人员信息
         SysUser sysUser = getSysUser(userId);
         //校验信息
-        RBucket<RoomInfoCache> roomInfoCache = checkStudentRoom(roomUid, sysUser);
-        RoomInfoCache roomInfo = roomInfoCache.get();
+        RoomInfoCache roomInfo = checkStudentRoom(roomUid, sysUser);
         Date now = new Date();
         //房间累计用户信息-指只要进入到该房间的用户都要记录
         RMap<Long, String> roomTotalUser = getTotalUserCache(roomUid);
@@ -678,10 +692,6 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         RMap<Long, String> onlineUserCache = getOnlineUserCache(roomUid);
         onlineUserCache.fastPut(userId, userJsonStr);
         log.info("joinRoom>>>> userInfo: {}", userJsonStr);
-        //刷新当前房间的点赞及观看人数信息
-        roomInfo.setLikeNum(getLike(roomUid));
-        roomInfo.setLookNum(getNum.apply(this::getOnlineUserCache, roomUid));
-        roomInfoCache.set(roomInfo);
         //向直播间发送当前在线人数消息
         this.sendOnlineUserCount(roomUid, userId, onlineUserCache.size());
         log.info("join sendOnlineUserCount>>>> param is null   roomUid: {}  fromUserId:{}  count:{}", roomUid, userId, onlineUserCache.size());
@@ -692,26 +702,41 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
     }
 
     //校验学生与房间的关系
-    private RBucket<RoomInfoCache> checkStudentRoom(String roomUid, SysUser sysUser) {
+    private RoomInfoCache checkStudentRoom(String roomUid, SysUser sysUser) {
         //校验房间是否存在
         RBucket<RoomInfoCache> roomInfoCache = redissonClient.getBucket(LIVE_ROOM_INFO.replace(ROOM_UID, roomUid));
         if (!roomInfoCache.isExists()) {
             throw new BizException("直播还未开始!");
         }
         RoomInfoCache roomInfo = roomInfoCache.get();
-        //校验观看者是否可以进入该房间,如果是非临时直播间,则校验是否已经买过课
+        //校验观看者是否买过课,如果是非临时直播间,则校验是否已经买过课
         if (!roomInfo.getRoomType().equals(RoomTypeEnum.TEMP.getCode())) {
             // 查询该学员成功购买课程
-            int count = courseScheduleStudentPaymentService.count(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
+            CourseScheduleStudentPayment studentPayment = courseScheduleStudentPaymentService.getOne(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
                     .eq(CourseScheduleStudentPayment::getUserId, sysUser.getId())
                     .eq(CourseScheduleStudentPayment::getCourseId, roomInfo.getCourseId())
                     .eq(CourseScheduleStudentPayment::getCourseGroupId, roomInfo.getCourseGroupId())
                     .eq(CourseScheduleStudentPayment::getCourseType, CourseScheduleEnum.LIVE.getCode()));
-            if (count < 0) {
-                throw new BizException("您还未购买课程!");
+            if (Objects.nonNull(studentPayment)) {
+                UserOrderVo detail = userOrderService.detail(studentPayment.getOrderNo(), studentPayment.getUserId());
+                if (Objects.isNull(detail)) {
+                    throw new BizException("您还未购买该课程.");
+                }
+                //不等于已支付的都是异常
+                if (detail.getStatus().equals(OrderStatusEnum.CLOSE) || detail.getStatus().equals(OrderStatusEnum.FAIL)) {
+                    throw new BizException("您还未购买该课程。");
+                }
+                if (detail.getStatus().equals(OrderStatusEnum.WAIT_PAY) || detail.getStatus().equals(OrderStatusEnum.PAYING)) {
+                    throw new BizException("该课程的订单" + detail.getStatus().getMsg() + ",请先支付完成后再上课。");
+                }
+            } else {
+                throw new BizException("您还未购买该课程!");
             }
         }
-        return roomInfoCache;
+        //刷新当前房间的点赞及观看人数信息
+        roomInfo.setLikeNum(getLike(roomUid));
+        roomInfo.setLookNum(getNum.apply(this::getOnlineUserCache, roomUid));
+        return roomInfo;
     }
 
     /**

+ 4 - 15
cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/controller/StudentLiveRoomController.java

@@ -5,17 +5,16 @@ import com.alibaba.fastjson.JSONObject;
 import com.yonge.cooleshow.biz.dal.entity.ImUserStateSync;
 import com.yonge.cooleshow.biz.dal.entity.RoomInfoCache;
 import com.yonge.cooleshow.biz.dal.service.LiveRoomService;
-import com.yonge.cooleshow.biz.dal.vo.RoomVo;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
-import io.swagger.annotations.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 直播房间与课程的关系表表(LiveRoom)表控制层
@@ -35,26 +34,16 @@ public class StudentLiveRoomController extends BaseController {
     private LiveRoomService liveRoomService;
 
     /**
-     * 根据房间uid查询房间信息
-     *
-     * @param roomUid 房间uid
-     */
-    @GetMapping("queryRoomInfo")
-    public HttpResponseResult<RoomVo> queryRoomInfo(@RequestParam("roomUid") String roomUid) {
-        return succeed(liveRoomService.queryRoomInfo(roomUid));
-    }
-
-    /**
      * 校验房间信息,及个人信息
      *
      * @param roomUid 房间uid
      */
     @GetMapping("/studentCheckRoomInfo")
-    public HttpResponseResult<RoomVo> studentCheckRoomInfo(@RequestParam("roomUid") String roomUid) {
+    public HttpResponseResult<RoomInfoCache> studentCheckRoomInfo(@RequestParam("roomUid") String roomUid) {
         return succeed(liveRoomService.studentCheckRoomInfo(roomUid));
     }
 
-    @ApiOperation("进入房间")
+    @ApiOperation("观看者-进入房间")
     @GetMapping(value = "/joinRoom")
     public HttpResponseResult<RoomInfoCache> joinRoom(String roomUid, Long userId) {
         return succeed(liveRoomService.joinRoom(roomUid, userId));

+ 7 - 8
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/TeacherLiveRoomController.java

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.yonge.cooleshow.biz.dal.entity.ImUserStateSync;
 import com.yonge.cooleshow.biz.dal.entity.RoomInfoCache;
 import com.yonge.cooleshow.biz.dal.service.LiveRoomService;
-import com.yonge.cooleshow.biz.dal.vo.RoomVo;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import io.swagger.annotations.*;
@@ -39,9 +38,9 @@ public class TeacherLiveRoomController extends BaseController {
      *
      * @param roomUid 房间uid
      */
-    @GetMapping("queryRoomInfo")
-    public HttpResponseResult<RoomVo> queryRoomInfo(@RequestParam("roomUid") String roomUid) {
-        return succeed(liveRoomService.queryRoomInfo(roomUid));
+    @GetMapping("/speakerCheckRoomInfo")
+    public HttpResponseResult<RoomInfoCache> speakerCheckRoomInfo(@RequestParam("roomUid") String roomUid) {
+        return succeed(liveRoomService.speakerCheckRoomInfo(roomUid));
     }
 
     @ApiImplicitParams({
@@ -58,15 +57,15 @@ public class TeacherLiveRoomController extends BaseController {
     @ApiOperation("同步点赞数量")
     @GetMapping("/syncLike")
     public HttpResponseResult<Object> syncLike(@ApiParam(value = "房间uid", required = true) String roomUid,
-                                       @ApiParam(value = "点赞数", required = true) Integer likeNum) {
+                                               @ApiParam(value = "点赞数", required = true) Integer likeNum) {
         liveRoomService.syncLike(roomUid, likeNum);
         return succeed();
     }
 
-    @ApiOperation("进入房间")
+    @ApiOperation("主讲人-进入房间")
     @GetMapping(value = "/speakerJoinRoom")
-    public HttpResponseResult<RoomInfoCache> speakerJoinRoom(String roomUid, Long userId) {
-        return succeed(liveRoomService.speakerJoinRoom(roomUid, userId));
+    public HttpResponseResult<RoomInfoCache> speakerJoinRoom(String roomUid) {
+        return succeed(liveRoomService.speakerJoinRoom(roomUid));
     }
 
     @ApiOperation("定时任务-创建房间-直播间")