|
|
@@ -9,11 +9,15 @@ import com.fs.common.constant.LiveKeysConstant;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.live.domain.Live;
|
|
|
+import com.fs.live.domain.LiveVideo;
|
|
|
import com.fs.live.domain.LiveWatchUser;
|
|
|
import com.fs.live.mapper.LiveWatchUserMapper;
|
|
|
+import com.fs.live.mapper.LiveMapper;
|
|
|
+import com.fs.live.mapper.LiveVideoMapper;
|
|
|
import com.fs.live.service.ILiveWatchUserService;
|
|
|
import com.fs.live.vo.LiveWatchUserStatistics;
|
|
|
import com.fs.live.vo.LiveWatchUserVO;
|
|
|
@@ -42,6 +46,10 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
private IFsUserService fsUserService;
|
|
|
@Autowired
|
|
|
private LiveWatchUserMapper baseMapper;
|
|
|
+ @Autowired
|
|
|
+ private LiveMapper liveMapper;
|
|
|
+ @Autowired
|
|
|
+ private LiveVideoMapper liveVideoMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -144,12 +152,37 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public LiveWatchUser join(long liveId, long userId) {
|
|
|
+ public LiveWatchUser join(long liveId, long userId, String location) {
|
|
|
LiveWatchUser liveWatchUser = getByLiveIdAndUserId(liveId, userId);
|
|
|
FsUser fsUserVO = fsUserService.selectFsUserByUserId(userId);
|
|
|
+ Date now = DateUtils.getNowDate();
|
|
|
+
|
|
|
+ // 查询直播间信息
|
|
|
+ Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
|
+
|
|
|
+ // 判断用户进入时间:如果进入时间大于直播结束时间,说明是回放
|
|
|
+ boolean isReplay = false;
|
|
|
+ if (live != null && live.getFinishTime() != null) {
|
|
|
+ Date finishTime = java.sql.Timestamp.valueOf(live.getFinishTime());
|
|
|
+ isReplay = now.after(finishTime);
|
|
|
+ }
|
|
|
+
|
|
|
if(liveWatchUser != null) {
|
|
|
- liveWatchUser.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ liveWatchUser.setUpdateTime(now);
|
|
|
liveWatchUser.setOnline(0);
|
|
|
+
|
|
|
+ // 更新location
|
|
|
+ if (StringUtils.isNotEmpty(location)) {
|
|
|
+ liveWatchUser.setLocation(location);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新进入标记
|
|
|
+ if (isReplay) {
|
|
|
+ liveWatchUser.setReplayFlag(1);
|
|
|
+ } else {
|
|
|
+ liveWatchUser.setLiveFlag(1);
|
|
|
+ }
|
|
|
+
|
|
|
baseMapper.updateLiveWatchUser(liveWatchUser);
|
|
|
}else{
|
|
|
liveWatchUser = new LiveWatchUser();
|
|
|
@@ -158,8 +191,75 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
|
|
|
liveWatchUser.setAvatar(fsUserVO.getAvatar());
|
|
|
liveWatchUser.setMsgStatus(0);
|
|
|
liveWatchUser.setOnline(0);
|
|
|
- liveWatchUser.setCreateTime(DateUtils.getNowDate());
|
|
|
- liveWatchUser.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ liveWatchUser.setLocation(location);
|
|
|
+
|
|
|
+ // 设置进入标记
|
|
|
+ if (isReplay) {
|
|
|
+ liveWatchUser.setReplayFlag(1);
|
|
|
+ liveWatchUser.setLiveFlag(0);
|
|
|
+ } else {
|
|
|
+ liveWatchUser.setLiveFlag(1);
|
|
|
+ liveWatchUser.setReplayFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ liveWatchUser.setCreateTime(now);
|
|
|
+ liveWatchUser.setUpdateTime(now);
|
|
|
+ baseMapper.insertLiveWatchUser(liveWatchUser);
|
|
|
+ }
|
|
|
+ liveWatchUser.setAvatar(fsUserVO.getAvatar());
|
|
|
+ liveWatchUser.setNickName(fsUserVO.getNickname());
|
|
|
+ String hashKey = String.format(LiveKeysConstant.LIVE_WATCH_USERS, liveId);
|
|
|
+ redisCache.hashPut(hashKey, String.valueOf(userId), JSON.toJSONString(liveWatchUser));
|
|
|
+ return liveWatchUser;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LiveWatchUser joinWithoutLocation(long liveId, long userId) {
|
|
|
+ LiveWatchUser liveWatchUser = getByLiveIdAndUserId(liveId, userId);
|
|
|
+ FsUser fsUserVO = fsUserService.selectFsUserByUserId(userId);
|
|
|
+ Date now = DateUtils.getNowDate();
|
|
|
+
|
|
|
+ // 查询直播间信息
|
|
|
+ Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
|
+
|
|
|
+ // 判断用户进入时间:如果进入时间大于直播结束时间,说明是回放
|
|
|
+ boolean isReplay = false;
|
|
|
+ if (live != null && live.getFinishTime() != null) {
|
|
|
+ Date finishTime = java.sql.Timestamp.valueOf(live.getFinishTime());
|
|
|
+ isReplay = now.after(finishTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(liveWatchUser != null) {
|
|
|
+ liveWatchUser.setUpdateTime(now);
|
|
|
+ liveWatchUser.setOnline(0);
|
|
|
+
|
|
|
+ // 更新进入标记
|
|
|
+ if (isReplay) {
|
|
|
+ liveWatchUser.setReplayFlag(1);
|
|
|
+ } else {
|
|
|
+ liveWatchUser.setLiveFlag(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ baseMapper.updateLiveWatchUser(liveWatchUser);
|
|
|
+ }else{
|
|
|
+ liveWatchUser = new LiveWatchUser();
|
|
|
+ liveWatchUser.setLiveId(liveId);
|
|
|
+ liveWatchUser.setUserId(userId);
|
|
|
+ liveWatchUser.setAvatar(fsUserVO.getAvatar());
|
|
|
+ liveWatchUser.setMsgStatus(0);
|
|
|
+ liveWatchUser.setOnline(0);
|
|
|
+
|
|
|
+ // 设置进入标记
|
|
|
+ if (isReplay) {
|
|
|
+ liveWatchUser.setReplayFlag(1);
|
|
|
+ liveWatchUser.setLiveFlag(0);
|
|
|
+ } else {
|
|
|
+ liveWatchUser.setLiveFlag(1);
|
|
|
+ liveWatchUser.setReplayFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ liveWatchUser.setCreateTime(now);
|
|
|
+ liveWatchUser.setUpdateTime(now);
|
|
|
baseMapper.insertLiveWatchUser(liveWatchUser);
|
|
|
}
|
|
|
liveWatchUser.setAvatar(fsUserVO.getAvatar());
|