|
@@ -12,6 +12,8 @@ import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
import com.fs.his.service.IFsUserService;
|
|
|
|
|
+import com.fs.hisStore.domain.FsUserScrm;
|
|
|
|
|
+import com.fs.hisStore.service.IFsUserScrmService;
|
|
|
import com.fs.live.domain.Live;
|
|
import com.fs.live.domain.Live;
|
|
|
import com.fs.live.domain.LiveVideo;
|
|
import com.fs.live.domain.LiveVideo;
|
|
|
import com.fs.live.domain.LiveWatchUser;
|
|
import com.fs.live.domain.LiveWatchUser;
|
|
@@ -43,7 +45,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private IFsUserService fsUserService;
|
|
|
|
|
|
|
+ private IFsUserScrmService fsUserService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private LiveWatchUserMapper baseMapper;
|
|
private LiveWatchUserMapper baseMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -153,38 +155,60 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public LiveWatchUser join(long liveId, long userId, String location) {
|
|
public LiveWatchUser join(long liveId, long userId, String location) {
|
|
|
- LiveWatchUser liveWatchUser = getByLiveIdAndUserId(liveId, userId);
|
|
|
|
|
- FsUser fsUserVO = fsUserService.selectFsUserByUserId(userId);
|
|
|
|
|
|
|
+ FsUserScrm fsUserVO = fsUserService.selectFsUserByUserId(userId);
|
|
|
Date now = DateUtils.getNowDate();
|
|
Date now = DateUtils.getNowDate();
|
|
|
|
|
|
|
|
// 查询直播间信息
|
|
// 查询直播间信息
|
|
|
Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
|
|
|
+ if (live == null) {
|
|
|
|
|
+ throw new RuntimeException("直播间不存在");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 判断用户进入时间:如果进入时间大于直播结束时间,说明是回放
|
|
|
|
|
- boolean isReplay = false;
|
|
|
|
|
- if (live != null && live.getFinishTime() != null) {
|
|
|
|
|
- Date finishTime = java.sql.Timestamp.valueOf(live.getFinishTime());
|
|
|
|
|
- isReplay = now.after(finishTime);
|
|
|
|
|
|
|
+ // 查询直播间录播视频时长(video_type IN (1, 2))
|
|
|
|
|
+ List<LiveVideo> videos = liveVideoMapper.selectByLiveIdAndType(liveId,1);
|
|
|
|
|
+ long totalDuration = 0L;
|
|
|
|
|
+ if (videos != null && !videos.isEmpty()) {
|
|
|
|
|
+ totalDuration = videos.stream()
|
|
|
|
|
+ .filter(v -> v.getVideoType() != null && (v.getVideoType() == 1 || v.getVideoType() == 2))
|
|
|
|
|
+ .filter(v -> v.getDuration() != null)
|
|
|
|
|
+ .mapToLong(LiveVideo::getDuration)
|
|
|
|
|
+ .sum();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(liveWatchUser != null) {
|
|
|
|
|
- liveWatchUser.setUpdateTime(now);
|
|
|
|
|
- liveWatchUser.setOnline(0);
|
|
|
|
|
|
|
+ // 判断是直播还是回放:开播时间 + 视频时长
|
|
|
|
|
+ Integer liveFlag = 0;
|
|
|
|
|
+ Integer replayFlag = 0;
|
|
|
|
|
|
|
|
- // 更新location
|
|
|
|
|
- if (StringUtils.isNotEmpty(location)) {
|
|
|
|
|
- liveWatchUser.setLocation(location);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (live.getStartTime() != null) {
|
|
|
|
|
+ // 将 LocalDateTime 转换为 Date
|
|
|
|
|
+ Date startTime = java.sql.Timestamp.valueOf(live.getStartTime());
|
|
|
|
|
+ // 计算结束时间:开播时间 + 视频时长(秒)
|
|
|
|
|
+ Date endTime = new Date(startTime.getTime() + totalDuration * 1000);
|
|
|
|
|
|
|
|
- // 更新进入标记
|
|
|
|
|
- if (isReplay) {
|
|
|
|
|
- liveWatchUser.setReplayFlag(1);
|
|
|
|
|
|
|
+ if (now.before(endTime)) {
|
|
|
|
|
+ // 当前时间 < 开播时间 + 视频时长,说明是直播
|
|
|
|
|
+ liveFlag = 1;
|
|
|
|
|
+ replayFlag = 0;
|
|
|
} else {
|
|
} else {
|
|
|
- liveWatchUser.setLiveFlag(1);
|
|
|
|
|
|
|
+ // 当前时间 >= 开播时间 + 视频时长,说明是回放
|
|
|
|
|
+ liveFlag = 0;
|
|
|
|
|
+ replayFlag = 1;
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 使用唯一索引查询:live_id, user_id, live_flag, replay_flag
|
|
|
|
|
+ LiveWatchUser liveWatchUser = baseMapper.selectByUniqueIndex(liveId, userId, liveFlag, replayFlag);
|
|
|
|
|
|
|
|
|
|
+ if (liveWatchUser != null) {
|
|
|
|
|
+ // 存在则更新
|
|
|
|
|
+ liveWatchUser.setUpdateTime(now);
|
|
|
|
|
+ liveWatchUser.setOnline(0);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(location)) {
|
|
|
|
|
+ liveWatchUser.setLocation(location);
|
|
|
|
|
+ }
|
|
|
baseMapper.updateLiveWatchUser(liveWatchUser);
|
|
baseMapper.updateLiveWatchUser(liveWatchUser);
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 不存在则插入
|
|
|
liveWatchUser = new LiveWatchUser();
|
|
liveWatchUser = new LiveWatchUser();
|
|
|
liveWatchUser.setLiveId(liveId);
|
|
liveWatchUser.setLiveId(liveId);
|
|
|
liveWatchUser.setUserId(userId);
|
|
liveWatchUser.setUserId(userId);
|
|
@@ -192,23 +216,16 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
liveWatchUser.setMsgStatus(0);
|
|
liveWatchUser.setMsgStatus(0);
|
|
|
liveWatchUser.setOnline(0);
|
|
liveWatchUser.setOnline(0);
|
|
|
liveWatchUser.setLocation(location);
|
|
liveWatchUser.setLocation(location);
|
|
|
-
|
|
|
|
|
- // 设置进入标记
|
|
|
|
|
- if (isReplay) {
|
|
|
|
|
- liveWatchUser.setReplayFlag(1);
|
|
|
|
|
- liveWatchUser.setLiveFlag(0);
|
|
|
|
|
- } else {
|
|
|
|
|
- liveWatchUser.setLiveFlag(1);
|
|
|
|
|
- liveWatchUser.setReplayFlag(0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ liveWatchUser.setLiveFlag(liveFlag);
|
|
|
|
|
+ liveWatchUser.setReplayFlag(replayFlag);
|
|
|
liveWatchUser.setCreateTime(now);
|
|
liveWatchUser.setCreateTime(now);
|
|
|
liveWatchUser.setUpdateTime(now);
|
|
liveWatchUser.setUpdateTime(now);
|
|
|
baseMapper.insertLiveWatchUser(liveWatchUser);
|
|
baseMapper.insertLiveWatchUser(liveWatchUser);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
liveWatchUser.setAvatar(fsUserVO.getAvatar());
|
|
liveWatchUser.setAvatar(fsUserVO.getAvatar());
|
|
|
liveWatchUser.setNickName(fsUserVO.getNickname());
|
|
liveWatchUser.setNickName(fsUserVO.getNickname());
|
|
|
- String hashKey = String.format(LiveKeysConstant.LIVE_WATCH_USERS, liveId);
|
|
|
|
|
|
|
+ String hashKey = String.format(LiveKeysConstant.LIVE_WATCH_USERS, liveId);
|
|
|
redisCache.hashPut(hashKey, String.valueOf(userId), JSON.toJSONString(liveWatchUser));
|
|
redisCache.hashPut(hashKey, String.valueOf(userId), JSON.toJSONString(liveWatchUser));
|
|
|
return liveWatchUser;
|
|
return liveWatchUser;
|
|
|
}
|
|
}
|
|
@@ -216,7 +233,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
@Override
|
|
@Override
|
|
|
public LiveWatchUser joinWithoutLocation(long liveId, long userId) {
|
|
public LiveWatchUser joinWithoutLocation(long liveId, long userId) {
|
|
|
LiveWatchUser liveWatchUser = getByLiveIdAndUserId(liveId, userId);
|
|
LiveWatchUser liveWatchUser = getByLiveIdAndUserId(liveId, userId);
|
|
|
- FsUser fsUserVO = fsUserService.selectFsUserByUserId(userId);
|
|
|
|
|
|
|
+ FsUserScrm fsUserVO = fsUserService.selectFsUserByUserId(userId);
|
|
|
Date now = DateUtils.getNowDate();
|
|
Date now = DateUtils.getNowDate();
|
|
|
|
|
|
|
|
// 查询直播间信息
|
|
// 查询直播间信息
|
|
@@ -337,7 +354,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int blockUser(Long userId) {
|
|
public int blockUser(Long userId) {
|
|
|
- FsUser fsUser = new FsUser();
|
|
|
|
|
|
|
+ FsUserScrm fsUser = new FsUserScrm();
|
|
|
fsUser.setUserId(userId);
|
|
fsUser.setUserId(userId);
|
|
|
fsUser.setStatus(0);
|
|
fsUser.setStatus(0);
|
|
|
return fsUserService.updateFsUser(fsUser);
|
|
return fsUserService.updateFsUser(fsUser);
|