|
@@ -5,15 +5,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.beust.jcommander.internal.Lists;
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.LiveRoomDao;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.RoomTypeEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.TeacherSalaryEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.*;
|
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
import com.yonge.cooleshow.biz.dal.support.IMHelper;
|
|
|
import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
|
|
@@ -21,6 +17,7 @@ import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.base.page.PageInfo;
|
|
|
import com.yonge.toolset.mybatis.support.PageUtil;
|
|
|
+import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -37,6 +34,7 @@ import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.BiFunction;
|
|
|
+import java.util.function.BiPredicate;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -76,6 +74,8 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
private StudentAttendanceService studentAttendanceService;
|
|
|
@Autowired
|
|
|
private TeacherAttendanceService teacherAttendanceService;
|
|
|
+ @Autowired
|
|
|
+ private SysMessageService sysMessageService;
|
|
|
|
|
|
/**
|
|
|
* 生成房间UID
|
|
@@ -104,7 +104,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
public PageInfo<LiveRoom> queryPageRoom(Map<String, Object> param) {
|
|
|
String roomType = WrapperUtil.toStr(param, "roomType");
|
|
|
Integer liveState = WrapperUtil.toInt(param, "liveState");
|
|
|
- Long userId = getSysUser().getId();
|
|
|
+ Long userId = this.getSysUser().getId();
|
|
|
Page<LiveRoom> pageInfo = PageUtil.getPageInfo(param);
|
|
|
IPage<LiveRoom> page = this.page(pageInfo, Wrappers.<LiveRoom>lambdaQuery()
|
|
|
.eq(WrapperUtil.StrPredicate.test(roomType), LiveRoom::getType, roomType)
|
|
@@ -122,7 +122,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public RoomInfoCache studentCheckRoomInfo(String roomUid) {
|
|
|
- return checkStudentRoom(roomUid, getSysUser());
|
|
|
+ return this.checkStudentRoom(roomUid, this.getSysUser());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -133,7 +133,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public RoomInfoCache speakerCheckRoomInfo(String roomUid) {
|
|
|
- Long userId = getSysUser().getId();
|
|
|
+ Long userId = this.getSysUser().getId();
|
|
|
LiveRoom liveRoom = this.getOne(Wrappers.<LiveRoom>lambdaQuery()
|
|
|
.eq(LiveRoom::getRoomUid, roomUid));
|
|
|
if (Objects.isNull(liveRoom)) {
|
|
@@ -169,7 +169,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//查询房间提前创建的时间
|
|
|
String preCreateRoomMinute = sysConfigService.findConfigValue(PRE_CREATE_LIVE_ROOM_MINUTE);
|
|
|
if (StringUtils.isEmpty(preCreateRoomMinute)) {
|
|
|
- log.info("roomDestroy>>>> 未查询到配置:{}", PRE_CREATE_LIVE_ROOM_MINUTE);
|
|
|
+ log.info("createCourseLiveRoom>>>> 未查询到配置:{}", PRE_CREATE_LIVE_ROOM_MINUTE);
|
|
|
return;
|
|
|
}
|
|
|
//查询课时表生成直播间
|
|
@@ -224,18 +224,40 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
room.setCreatedTime(now);
|
|
|
this.save(room);
|
|
|
//去融云创建房间及创建房间缓存信息
|
|
|
- createLiveRoomInfo(room);
|
|
|
+ this.createLiveRoomInfo(room);
|
|
|
+ //开课提醒
|
|
|
+ this.pushLiveCreateRoom(room);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 开课提醒
|
|
|
+ */
|
|
|
+ private void pushLiveCreateRoom(LiveRoom room) {
|
|
|
+ try {
|
|
|
+ //查询老师信息
|
|
|
+ SysUser teacherInfo = this.getSysUser(room.getSpeakerId());
|
|
|
+ //极光-消息推送
|
|
|
+ Map<Long, String> teacherMap = new HashMap<>();
|
|
|
+ teacherMap.put(teacherInfo.getId(), teacherInfo.getPhone());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.LIVE_REMINDER,
|
|
|
+ teacherMap, null, 0, null, ClientEnum.TEACHER.getCode(),
|
|
|
+ teacherInfo.getUsername(), room.getRoomTitle());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("pushLiveCreateRoom JIGUANG error param : {}", JSONObject.toJSONString(room));
|
|
|
+ log.error("pushLiveCreateRoom JIGUANG error", e.getCause());
|
|
|
+ }
|
|
|
+ log.info("pushLiveCreateRoom JIGUANG ok param : {}", JSONObject.toJSONString(room));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 创建临时房间-直播间
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String createTempLiveRoom(Map<String, Object> param) {
|
|
|
//查询主讲人信息
|
|
|
- SysUser sysUser = getSysUser();
|
|
|
+ SysUser sysUser = this.getSysUser();
|
|
|
Long teacherId = sysUser.getId();
|
|
|
List<LiveRoom> liveRoomList = this.list(Wrappers.<LiveRoom>lambdaQuery()
|
|
|
.eq(LiveRoom::getSpeakerId, teacherId)
|
|
@@ -285,7 +307,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
*/
|
|
|
private void createLiveRoomInfo(LiveRoom room) {
|
|
|
//查询主讲人信息
|
|
|
- SysUser sysUser = getSysUser(room.getSpeakerId());
|
|
|
+ SysUser sysUser = this.getSysUser(room.getSpeakerId());
|
|
|
this.createLiveRoomInfo(room, sysUser);
|
|
|
}
|
|
|
|
|
@@ -423,15 +445,15 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
String roomUid = room.getRoomUid();
|
|
|
|
|
|
//删除房间全部人员缓存
|
|
|
- getTotalUserCache(roomUid).deleteAsync();
|
|
|
+ this.getTotalUserCache(roomUid).deleteAsync();
|
|
|
//获取在线人员信息
|
|
|
- RMap<Long, String> onlineUserCache = getOnlineUserCache(roomUid);
|
|
|
+ RMap<Long, String> onlineUserCache = this.getOnlineUserCache(roomUid);
|
|
|
//删除人员对应直播间编号信息
|
|
|
onlineUserCache.forEach((id, s) -> redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, id.toString())).deleteAsync());
|
|
|
//删除房间在线人员缓存
|
|
|
onlineUserCache.deleteAsync();
|
|
|
//删除房间信息
|
|
|
- getLiveRoomInfo(room.getRoomUid()).deleteAsync();
|
|
|
+ this.getLiveRoomInfo(room.getRoomUid()).deleteAsync();
|
|
|
//删除点赞数
|
|
|
redissonClient.getBucket(LIVE_ROOM_LIKE.replace(ROOM_UID, room.getRoomUid())).deleteAsync();
|
|
|
//删除当前主讲人最后一次进入房间的ip
|
|
@@ -463,8 +485,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
private void ImDestroyLiveRoom(String roomId) {
|
|
|
try {
|
|
|
//删除服务器房间
|
|
|
- List<String> deleteRoomIds = Lists.newArrayList(roomId);
|
|
|
- IMApiResultInfo resultInfo = imHelper.deleteChrm(deleteRoomIds);
|
|
|
+ IMApiResultInfo resultInfo = imHelper.deleteChrm(Collections.singletonList(roomId));
|
|
|
if (!resultInfo.isSuccess()) {
|
|
|
log.error("destroyLiveRoom error" + resultInfo.getErrorMessage());
|
|
|
}
|
|
@@ -510,7 +531,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
}
|
|
|
String roomUid = userRoom.get();
|
|
|
//根据房间号获取房间信息
|
|
|
- RBucket<RoomInfoCache> roomInfoCache = getLiveRoomInfo(roomUid);
|
|
|
+ RBucket<RoomInfoCache> roomInfoCache = this.getLiveRoomInfo(roomUid);
|
|
|
if (!roomInfoCache.isExists()) {
|
|
|
return;
|
|
|
}
|
|
@@ -527,7 +548,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//用户id
|
|
|
Long userId = Long.valueOf(userIdStr);
|
|
|
//从房间累计用户信息中查询该用户的信息
|
|
|
- RMap<Long, String> roomTotalUser = getTotalUserCache(roomUid);
|
|
|
+ RMap<Long, String> roomTotalUser = this.getTotalUserCache(roomUid);
|
|
|
//该房间未查询到用户数据则不处理
|
|
|
if (!roomTotalUser.isExists() && !roomTotalUser.containsKey(userId)) {
|
|
|
return;
|
|
@@ -538,7 +559,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
String userJsonStr = JSONObject.toJSONString(userInfo);
|
|
|
roomTotalUser.fastPut(userId, userJsonStr);
|
|
|
//查询在线人员列表
|
|
|
- RMap<Long, String> onlineUserInfo = getOnlineUserCache(roomUid);
|
|
|
+ RMap<Long, String> onlineUserInfo = this.getOnlineUserCache(roomUid);
|
|
|
if (!onlineUserInfo.isExists()) {
|
|
|
return;
|
|
|
}
|
|
@@ -613,7 +634,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
}
|
|
|
}
|
|
|
//如果退出时间大于进入时间就无需再次退出-直接返回
|
|
|
- if (compareDate.apply(roomInfo.getExitRoomTime(), roomInfo.getJoinRoomTime())) {
|
|
|
+ if (compareDate.test(roomInfo.getExitRoomTime(), roomInfo.getJoinRoomTime())) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -644,7 +665,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
* <p>- date1 时间1
|
|
|
* <p>- date2 时间2
|
|
|
*/
|
|
|
- private final BiFunction<Date, Date, Boolean> compareDate = (date1, date2) -> {
|
|
|
+ private final BiPredicate<Date, Date> compareDate = (date1, date2) -> {
|
|
|
if (Objects.nonNull(date1) && Objects.nonNull(date2)) {
|
|
|
return date1.getTime() > date2.getTime();
|
|
|
} else {
|
|
@@ -731,7 +752,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//校验学生与房间的关系
|
|
|
private RoomInfoCache checkStudentRoom(String roomUid, SysUser sysUser) {
|
|
|
//校验房间是否存在
|
|
|
- RBucket<RoomInfoCache> roomInfoCache = getLiveRoomInfo(roomUid);
|
|
|
+ RBucket<RoomInfoCache> roomInfoCache = this.getLiveRoomInfo(roomUid);
|
|
|
if (!roomInfoCache.isExists()) {
|
|
|
throw new BizException("直播还未开始!");
|
|
|
}
|
|
@@ -965,7 +986,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
//result
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
//获取房间信息
|
|
|
- RBucket<RoomInfoCache> speakerCache = getLiveRoomInfo(roomUid);
|
|
|
+ RBucket<RoomInfoCache> speakerCache = this.getLiveRoomInfo(roomUid);
|
|
|
if (speakerCache.isExists()) {
|
|
|
result.put("房间信息信息", speakerCache.get());
|
|
|
} else {
|
|
@@ -991,7 +1012,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
int look = 0;
|
|
|
|
|
|
//累计总观看的用户数量
|
|
|
- List<RoomUserInfoCache> totalUserInfo = getTotalUserInfo(roomUid);
|
|
|
+ List<RoomUserInfoCache> totalUserInfo = this.getTotalUserInfo(roomUid);
|
|
|
if (CollectionUtils.isNotEmpty(totalUserInfo)) {
|
|
|
totalLook = totalUserInfo.size();
|
|
|
result.put("总人员数据", totalUserInfo);
|
|
@@ -1000,7 +1021,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
|
|
|
}
|
|
|
result.put("总观看人数", totalLook);
|
|
|
//正在房间观看的用户数据
|
|
|
- List<RoomUserInfoCache> onlineUserInfo = getOnlineUserInfo(roomUid);
|
|
|
+ List<RoomUserInfoCache> onlineUserInfo = this.getOnlineUserInfo(roomUid);
|
|
|
if (CollectionUtils.isNotEmpty(onlineUserInfo)) {
|
|
|
look = onlineUserInfo.size();
|
|
|
result.put("正在观看的人员信息", onlineUserInfo);
|