|
@@ -8,6 +8,7 @@ import com.fs.common.exception.base.BaseException;
|
|
|
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.live.config.ProductionWordFilter;
|
|
import com.fs.live.config.ProductionWordFilter;
|
|
|
|
|
+import com.fs.live.mapper.LiveCouponMapper;
|
|
|
import com.fs.live.websocket.auth.WebSocketConfigurator;
|
|
import com.fs.live.websocket.auth.WebSocketConfigurator;
|
|
|
import com.fs.live.websocket.bean.SendMsgVo;
|
|
import com.fs.live.websocket.bean.SendMsgVo;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
@@ -57,6 +58,8 @@ public class WebSocketServer {
|
|
|
private final ILiveGoodsService liveGoodsService = SpringUtils.getBean(ILiveGoodsService.class);
|
|
private final ILiveGoodsService liveGoodsService = SpringUtils.getBean(ILiveGoodsService.class);
|
|
|
private final ILiveUserFirstEntryService liveUserFirstEntryService = SpringUtils.getBean(ILiveUserFirstEntryService.class);
|
|
private final ILiveUserFirstEntryService liveUserFirstEntryService = SpringUtils.getBean(ILiveUserFirstEntryService.class);
|
|
|
private final ILiveCouponIssueService liveCouponIssueService = SpringUtils.getBean(ILiveCouponIssueService.class);
|
|
private final ILiveCouponIssueService liveCouponIssueService = SpringUtils.getBean(ILiveCouponIssueService.class);
|
|
|
|
|
+ private final LiveCouponMapper liveCouponMapper = SpringUtils.getBean(LiveCouponMapper.class);
|
|
|
|
|
+
|
|
|
// 直播间在线用户缓存
|
|
// 直播间在线用户缓存
|
|
|
// private static final ConcurrentHashMap<Long, Integer> liveOnlineUsers = new ConcurrentHashMap<>();
|
|
// private static final ConcurrentHashMap<Long, Integer> liveOnlineUsers = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
@@ -103,9 +106,14 @@ public class WebSocketServer {
|
|
|
|
|
|
|
|
// 记录在线人数
|
|
// 记录在线人数
|
|
|
redisCache.incr(ONLINE_USERS_KEY + liveId, 1);
|
|
redisCache.incr(ONLINE_USERS_KEY + liveId, 1);
|
|
|
- Integer currentOnline = redisCache.getCacheObject(ONLINE_USERS_KEY + liveId);
|
|
|
|
|
- //最大同时在线人数
|
|
|
|
|
|
|
+ // 将用户ID添加到在线用户Set中
|
|
|
|
|
+ String onlineUsersSetKey = ONLINE_USERS_SET_KEY + liveId;
|
|
|
|
|
+ redisCache.redisTemplate.opsForSet().add(onlineUsersSetKey, String.valueOf(userId));
|
|
|
|
|
+ // 获取Set的大小作为当前在线人数
|
|
|
|
|
+ Long currentOnlineCount = redisCache.redisTemplate.opsForSet().size(onlineUsersSetKey);
|
|
|
|
|
+ //最大同时在线人数 - 使用Set大小来判断
|
|
|
Integer maxOnline = redisCache.getCacheObject(MAX_ONLINE_USERS_KEY + liveId);
|
|
Integer maxOnline = redisCache.getCacheObject(MAX_ONLINE_USERS_KEY + liveId);
|
|
|
|
|
+ int currentOnline = currentOnlineCount != null ? currentOnlineCount.intValue() : 0;
|
|
|
if (maxOnline == null || currentOnline > maxOnline) {
|
|
if (maxOnline == null || currentOnline > maxOnline) {
|
|
|
redisCache.setCacheObject(MAX_ONLINE_USERS_KEY + liveId, currentOnline);
|
|
redisCache.setCacheObject(MAX_ONLINE_USERS_KEY + liveId, currentOnline);
|
|
|
}
|
|
}
|
|
@@ -197,6 +205,10 @@ public class WebSocketServer {
|
|
|
|
|
|
|
|
// 直播间在线人数 -1
|
|
// 直播间在线人数 -1
|
|
|
redisCache.incr(ONLINE_USERS_KEY + liveId, -1);
|
|
redisCache.incr(ONLINE_USERS_KEY + liveId, -1);
|
|
|
|
|
+ // 从在线用户Set中移除用户ID
|
|
|
|
|
+ String onlineUsersSetKey = ONLINE_USERS_SET_KEY + liveId;
|
|
|
|
|
+ redisCache.redisTemplate.opsForSet().remove(onlineUsersSetKey, String.valueOf(userId));
|
|
|
|
|
+
|
|
|
SendMsgVo sendMsgVo = new SendMsgVo();
|
|
SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
sendMsgVo.setLiveId(liveId);
|
|
sendMsgVo.setLiveId(liveId);
|
|
|
sendMsgVo.setUserId(userId);
|
|
sendMsgVo.setUserId(userId);
|
|
@@ -597,6 +609,26 @@ public class WebSocketServer {
|
|
|
liveMsg.setCreateTime(now);
|
|
liveMsg.setCreateTime(now);
|
|
|
liveMsg.setUpdateTime(now);
|
|
liveMsg.setUpdateTime(now);
|
|
|
liveMsgService.insertLiveMsg(liveMsg);
|
|
liveMsgService.insertLiveMsg(liveMsg);
|
|
|
|
|
+ } else if (task.getTaskType() == 5L) {
|
|
|
|
|
+ msg.setCmd("coupon");
|
|
|
|
|
+ LiveCoupon liveCoupon = JSON.parseObject(task.getContent(), LiveCoupon.class);
|
|
|
|
|
+ if(liveCoupon.getStatus() != 1 ){
|
|
|
|
|
+ log.error("优惠券状态已经关闭");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveCouponIssue liveCouponIssue = liveCouponIssueService.selectLiveCouponIssueByCouponId(liveCoupon.getCouponId());
|
|
|
|
|
+ LiveCouponIssueRelation relation = liveCouponMapper.selectCouponRelation(task.getLiveId(), liveCouponIssue.getId());
|
|
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
|
|
+ data.put("liveId", task.getLiveId());
|
|
|
|
|
+ data.put("couponIssueId", liveCouponIssue.getId());
|
|
|
|
|
+ data.put("status", 1);
|
|
|
|
|
+ data.put("goodsId", relation.getGoodsId());
|
|
|
|
|
+ data.put("couponName", liveCoupon.getTitle());
|
|
|
|
|
+ data.put("couponPrice", liveCoupon.getCouponPrice());
|
|
|
|
|
+ data.put("useMinPrice", liveCoupon.getUseMinPrice());
|
|
|
|
|
+ data.put("couponTime", liveCoupon.getCouponTime());
|
|
|
|
|
+ msg.setData(JSON.toJSONString(data));
|
|
|
|
|
+ liveCouponMapper.updateChangeShow(task.getLiveId(), liveCouponIssue.getId());
|
|
|
}
|
|
}
|
|
|
msg.setStatus(1);
|
|
msg.setStatus(1);
|
|
|
broadcastMessage(task.getLiveId(), JSONObject.toJSONString(R.ok().put("data", msg)));
|
|
broadcastMessage(task.getLiveId(), JSONObject.toJSONString(R.ok().put("data", msg)));
|