|
@@ -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("当前选择的时间段有课无法开启直播");
|
|
@@ -309,43 +337,67 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
Date expiredDate = DateUtil.addMinutes(room.getLiveEndTime(), Integer.parseInt(expiredMinuteStr));
|
|
|
//当前时间 大于(结束播时间 + 设置的过期分钟数)
|
|
|
if (now.getTime() >= expiredDate.getTime()) {
|
|
|
- //删除房间
|
|
|
- destroyLiveRoom(room.getRoomUid());
|
|
|
- //查询老师分润表
|
|
|
- List<CourseScheduleTeacherSalary> salaryList = courseScheduleTeacherSalaryService.list(Wrappers.<CourseScheduleTeacherSalary>lambdaQuery()
|
|
|
- .eq(CourseScheduleTeacherSalary::getCourseScheduleId, room.getCourseId())
|
|
|
- );
|
|
|
- if (CollectionUtils.isEmpty(salaryList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- salaryList.forEach(salary -> {
|
|
|
- //查询该学生及课程id 对应的支付订单号
|
|
|
- CourseScheduleStudentPayment payment = courseScheduleStudentPaymentService.getOne(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
|
|
|
- .eq(CourseScheduleStudentPayment::getCourseId, room.getCourseId())
|
|
|
- .eq(CourseScheduleStudentPayment::getUserId, salary.getStudentId())
|
|
|
- );
|
|
|
- if (Objects.isNull(payment)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //获取教师课酬写入到金额变更表
|
|
|
- UserAccountRecordDto userAccountRecord = new UserAccountRecordDto();
|
|
|
- userAccountRecord.setUserId(room.getSpeakerId());
|
|
|
- userAccountRecord.setInOrOut(InOrOutEnum.IN);
|
|
|
- userAccountRecord.setBizType(AccountBizTypeEnum.LIVE);
|
|
|
- userAccountRecord.setBizId(room.getCourseId());
|
|
|
- userAccountRecord.setBizName(room.getRoomTitle());
|
|
|
- userAccountRecord.setTransAmount(salary.getActualSalary());//扣除手续费后所得金额
|
|
|
- userAccountRecord.setOrderNo(payment.getOrderNo());
|
|
|
- userAccountService.accountChange(userAccountRecord);
|
|
|
- //修改教师课酬状态-已结算
|
|
|
- salary.setStatus(TeacherSalaryEnum.COMPLETE.getCode());
|
|
|
- courseScheduleTeacherSalaryService.updateById(salary);
|
|
|
- });
|
|
|
+ destroyLiveRoom(room);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 关闭直播间
|
|
|
+ *
|
|
|
+ * @param roomUId 房间uid
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void destroyLiveRoom(String roomUId) {
|
|
|
+ LiveRoom liveRoom = this.getOne(Wrappers.<LiveRoom>lambdaQuery().eq(LiveRoom::getRoomUid, roomUId));
|
|
|
+ destroyLiveRoom(liveRoom);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭直播间
|
|
|
+ *
|
|
|
+ * @param room 房间信息
|
|
|
+ */
|
|
|
+ private void destroyLiveRoom(LiveRoom room) {
|
|
|
+ if (Objects.isNull(room)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //查询老师分润表
|
|
|
+ List<CourseScheduleTeacherSalary> salaryList = courseScheduleTeacherSalaryService.list(Wrappers.<CourseScheduleTeacherSalary>lambdaQuery()
|
|
|
+ .eq(CourseScheduleTeacherSalary::getCourseScheduleId, room.getCourseId())
|
|
|
+ );
|
|
|
+ if (CollectionUtils.isEmpty(salaryList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ salaryList.forEach(salary -> {
|
|
|
+ //查询该学生及课程id 对应的支付订单号
|
|
|
+ CourseScheduleStudentPayment payment = courseScheduleStudentPaymentService.getOne(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
|
|
|
+ .eq(CourseScheduleStudentPayment::getCourseId, room.getCourseId())
|
|
|
+ .eq(CourseScheduleStudentPayment::getUserId, salary.getStudentId())
|
|
|
+ );
|
|
|
+ if (Objects.isNull(payment)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取教师课酬写入到金额变更表
|
|
|
+ UserAccountRecordDto userAccountRecord = new UserAccountRecordDto();
|
|
|
+ userAccountRecord.setUserId(room.getSpeakerId());
|
|
|
+ userAccountRecord.setInOrOut(InOrOutEnum.IN);
|
|
|
+ userAccountRecord.setBizType(AccountBizTypeEnum.LIVE);
|
|
|
+ userAccountRecord.setBizId(room.getCourseId());
|
|
|
+ userAccountRecord.setBizName(room.getRoomTitle());
|
|
|
+ userAccountRecord.setTransAmount(salary.getActualSalary());//扣除手续费后所得金额
|
|
|
+ userAccountRecord.setOrderNo(payment.getOrderNo());
|
|
|
+ userAccountService.accountChange(userAccountRecord);
|
|
|
+ //修改教师课酬状态-已结算
|
|
|
+ salary.setStatus(TeacherSalaryEnum.COMPLETE.getCode());
|
|
|
+ courseScheduleTeacherSalaryService.updateById(salary);
|
|
|
+ });
|
|
|
+ //删除房间
|
|
|
+ ImDestroyLiveRoom(room.getRoomUid());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 定时任务-清理过期的房间-陪练课
|
|
|
*/
|
|
|
public void destroyExpiredPracticeRoom() {
|
|
@@ -370,7 +422,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//当前时间 大于(结束播时间 + 设置的过期分钟数)
|
|
|
if (now.getTime() >= expiredDate.getTime()) {
|
|
|
//删除房间
|
|
|
- destroyLiveRoom(room.getRoomUid());
|
|
|
+ ImDestroyLiveRoom(room.getRoomUid());
|
|
|
//查询老师分润表
|
|
|
CourseScheduleTeacherSalary salary = courseScheduleTeacherSalaryService.getOne(Wrappers.<CourseScheduleTeacherSalary>lambdaQuery()
|
|
|
.eq(CourseScheduleTeacherSalary::getCourseScheduleId, room.getCourseId())
|
|
@@ -405,7 +457,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
*
|
|
|
* @param roomId 房间Uid
|
|
|
*/
|
|
|
- private void destroyLiveRoom(String roomId) {
|
|
|
+ private void ImDestroyLiveRoom(String roomId) {
|
|
|
try {
|
|
|
//删除服务器房间
|
|
|
List<String> deleteRoomIds = Lists.newArrayList(roomId);
|
|
@@ -614,29 +666,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 +689,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 +716,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 +726,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;
|
|
|
}
|
|
|
|
|
|
/**
|