|
|
@@ -72,6 +72,8 @@ public class WebSocketServer {
|
|
|
long liveId = (long) userProperties.get("liveId");
|
|
|
long userId = (long) userProperties.get("userId");
|
|
|
long userType = (long) userProperties.get("userType");
|
|
|
+ String location = (String) userProperties.get("location"); // 获取location参数
|
|
|
+
|
|
|
Live live = liveService.selectLiveByLiveId(liveId);
|
|
|
if (live == null) {
|
|
|
throw new BaseException("未找到直播间");
|
|
|
@@ -96,7 +98,7 @@ public class WebSocketServer {
|
|
|
throw new BaseException("用户信息错误");
|
|
|
}
|
|
|
|
|
|
- LiveWatchUser liveWatchUserVO = liveWatchUserService.join(liveId, userId);
|
|
|
+ LiveWatchUser liveWatchUserVO = liveWatchUserService.join(liveId, userId, location);
|
|
|
room.put(userId, session);
|
|
|
// 直播间浏览量 +1
|
|
|
redisCache.incr(PAGE_VIEWS_KEY + liveId, 1);
|
|
|
@@ -262,6 +264,22 @@ public class WebSocketServer {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 根据直播状态设置live_flag或replay_flag
|
|
|
+ Live msgLive = liveService.selectLiveByLiveId(msg.getLiveId());
|
|
|
+ if (msgLive != null && msgLive.getFinishTime() != null) {
|
|
|
+ Date finishTime = java.sql.Timestamp.valueOf(msgLive.getFinishTime());
|
|
|
+ if (new Date().after(finishTime)) {
|
|
|
+ liveMsg.setReplayFlag(1);
|
|
|
+ liveMsg.setLiveFlag(0);
|
|
|
+ } else {
|
|
|
+ liveMsg.setLiveFlag(1);
|
|
|
+ liveMsg.setReplayFlag(0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ liveMsg.setLiveFlag(1);
|
|
|
+ liveMsg.setReplayFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
liveMsgService.insertLiveMsg(liveMsg);
|
|
|
}
|
|
|
|
|
|
@@ -281,6 +299,23 @@ public class WebSocketServer {
|
|
|
liveMsg.setAvatar(msg.getAvatar());
|
|
|
liveMsg.setMsg(msg.getMsg());
|
|
|
liveMsg.setCreateTime(new Date());
|
|
|
+
|
|
|
+ // 根据直播状态设置live_flag或replay_flag
|
|
|
+ Live normalMsgLive = liveService.selectLiveByLiveId(msg.getLiveId());
|
|
|
+ if (normalMsgLive != null && normalMsgLive.getFinishTime() != null) {
|
|
|
+ Date finishTime = java.sql.Timestamp.valueOf(normalMsgLive.getFinishTime());
|
|
|
+ if (new Date().after(finishTime)) {
|
|
|
+ liveMsg.setReplayFlag(1);
|
|
|
+ liveMsg.setLiveFlag(0);
|
|
|
+ } else {
|
|
|
+ liveMsg.setLiveFlag(1);
|
|
|
+ liveMsg.setReplayFlag(0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ liveMsg.setLiveFlag(1);
|
|
|
+ liveMsg.setReplayFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
liveMsgService.insertLiveMsg(liveMsg);
|
|
|
msg.setOn(true);
|
|
|
msg.setData(JSONObject.toJSONString(liveMsg));
|
|
|
@@ -302,6 +337,20 @@ public class WebSocketServer {
|
|
|
// 广播消息
|
|
|
broadcastMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)));
|
|
|
break;
|
|
|
+ case "sendTopMsg":
|
|
|
+ msg.setMsg(productionWordFilter.filter(msg.getMsg()).getFilteredText());
|
|
|
+ if(StringUtils.isEmpty(msg.getMsg())) return;
|
|
|
+ liveMsg = new LiveMsg();
|
|
|
+ liveMsg.setLiveId(msg.getLiveId());
|
|
|
+ liveMsg.setUserId(msg.getUserId());
|
|
|
+ liveMsg.setNickName(msg.getNickName());
|
|
|
+ liveMsg.setAvatar(msg.getAvatar());
|
|
|
+ liveMsg.setMsg(msg.getMsg());
|
|
|
+ msg.setOn(true);
|
|
|
+ msg.setData(JSONObject.toJSONString(liveMsg));
|
|
|
+ // 广播消息
|
|
|
+ broadcastMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)));
|
|
|
+ break;
|
|
|
case "globalVisible":
|
|
|
msg.setOn(true);
|
|
|
liveWatchUserService.updateGlobalVisible(liveId, msg.getStatus());
|
|
|
@@ -629,6 +678,27 @@ public class WebSocketServer {
|
|
|
data.put("couponTime", liveCoupon.getCouponTime());
|
|
|
msg.setData(JSON.toJSONString(data));
|
|
|
liveCouponMapper.updateChangeShow(task.getLiveId(), liveCouponIssue.getId());
|
|
|
+ } else if (task.getTaskType() == 6L) {
|
|
|
+ // 上架/下架商品
|
|
|
+ msg.setCmd("goods");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(task.getContent());
|
|
|
+ Long goodsId = jsonObject.getLong("goodsId");
|
|
|
+ Integer status = jsonObject.getInteger("status");
|
|
|
+ if (goodsId == null || status == null) {
|
|
|
+ log.error("商品ID或状态为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 更新商品上下架状态
|
|
|
+ liveGoodsService.updateLiveGoodsStatus(goodsId, status);
|
|
|
+ return ;
|
|
|
+ // 更新直播间配置缓存
|
|
|
+// liveService.asyncToCacheLiveConfig(task.getLiveId());
|
|
|
+ // 查询商品信息并广播
|
|
|
+// LiveGoodsVo liveGoodsVo = liveGoodsService.selectLiveGoodsVoByGoodsId(goodsId);
|
|
|
+// if (liveGoodsVo != null) {
|
|
|
+// msg.setData(JSON.toJSONString(liveGoodsVo));
|
|
|
+// msg.setStatus(status);
|
|
|
+// }
|
|
|
}
|
|
|
msg.setStatus(1);
|
|
|
broadcastMessage(task.getLiveId(), JSONObject.toJSONString(R.ok().put("data", msg)));
|