|
@@ -24,6 +24,7 @@ import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.live.domain.*;
|
|
import com.fs.live.domain.*;
|
|
|
import com.fs.live.service.*;
|
|
import com.fs.live.service.*;
|
|
|
|
|
+import com.fs.live.vo.LiveConsoleOpLogVo;
|
|
|
import com.fs.live.vo.LiveGoodsVo;
|
|
import com.fs.live.vo.LiveGoodsVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
@@ -102,6 +103,7 @@ public class WebSocketServer {
|
|
|
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 final LiveCouponMapper liveCouponMapper = SpringUtils.getBean(LiveCouponMapper.class);
|
|
|
|
|
+ private final ILiveConsoleOpLogService liveConsoleOpLogService = SpringUtils.getBean(ILiveConsoleOpLogService.class);
|
|
|
private final ILiveWatchLogService liveWatchLogService = SpringUtils.getBean(ILiveWatchLogService.class);
|
|
private final ILiveWatchLogService liveWatchLogService = SpringUtils.getBean(ILiveWatchLogService.class);
|
|
|
private final ILiveVideoService liveVideoService = SpringUtils.getBean(ILiveVideoService.class);
|
|
private final ILiveVideoService liveVideoService = SpringUtils.getBean(ILiveVideoService.class);
|
|
|
private final ILiveCompletionPointsRecordService completionPointsRecordService = SpringUtils.getBean(ILiveCompletionPointsRecordService.class);
|
|
private final ILiveCompletionPointsRecordService completionPointsRecordService = SpringUtils.getBean(ILiveCompletionPointsRecordService.class);
|
|
@@ -659,6 +661,8 @@ public class WebSocketServer {
|
|
|
} else {
|
|
} else {
|
|
|
redisCache.deleteObject(String.format(LiveKeysConstant.LIVE_COUPON_NUM , couponIssueId));
|
|
redisCache.deleteObject(String.format(LiveKeysConstant.LIVE_COUPON_NUM , couponIssueId));
|
|
|
}
|
|
}
|
|
|
|
|
+ LiveConsoleOpLog opLog = saveConsoleCouponOpLog(liveId, couponIssueId, status);
|
|
|
|
|
+ attachOpLog(msg, opLog);
|
|
|
// 管理员消息插队
|
|
// 管理员消息插队
|
|
|
enqueueMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)), true);
|
|
enqueueMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)), true);
|
|
|
}
|
|
}
|
|
@@ -690,6 +694,8 @@ public class WebSocketServer {
|
|
|
if (Objects.nonNull(liveRedConf)) {
|
|
if (Objects.nonNull(liveRedConf)) {
|
|
|
liveService.asyncToCacheLiveConfig(liveId);
|
|
liveService.asyncToCacheLiveConfig(liveId);
|
|
|
msg.setData(JSONObject.toJSONString(liveRedConf));
|
|
msg.setData(JSONObject.toJSONString(liveRedConf));
|
|
|
|
|
+ LiveConsoleOpLog opLog = saveConsoleRedOpLog(liveId, liveRedConf, status);
|
|
|
|
|
+ attachOpLog(msg, opLog);
|
|
|
// 管理员消息插队
|
|
// 管理员消息插队
|
|
|
enqueueMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)), true);
|
|
enqueueMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)), true);
|
|
|
}
|
|
}
|
|
@@ -706,11 +712,89 @@ public class WebSocketServer {
|
|
|
if (Objects.nonNull(liveLotteryConf)) {
|
|
if (Objects.nonNull(liveLotteryConf)) {
|
|
|
liveService.asyncToCacheLiveConfig(liveId);
|
|
liveService.asyncToCacheLiveConfig(liveId);
|
|
|
msg.setData(JSONObject.toJSONString(liveLotteryConf));
|
|
msg.setData(JSONObject.toJSONString(liveLotteryConf));
|
|
|
|
|
+ LiveConsoleOpLog opLog = saveConsoleLotteryOpLog(liveId, liveLotteryConf, status);
|
|
|
|
|
+ attachOpLog(msg, opLog);
|
|
|
// 管理员消息插队
|
|
// 管理员消息插队
|
|
|
enqueueMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)), true);
|
|
enqueueMessage(liveId, JSONObject.toJSONString(R.ok().put("data", msg)), true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 中控台红包操作留存(发放 / 结算)
|
|
|
|
|
+ */
|
|
|
|
|
+ private LiveConsoleOpLog saveConsoleRedOpLog(Long liveId, LiveRedConf liveRedConf, Integer status) {
|
|
|
|
|
+ if (liveRedConf == null || status == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status == 1) {
|
|
|
|
|
+ return liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ liveId,
|
|
|
|
|
+ LiveConsoleOpLog.OP_RED_SEND,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_CONSOLE,
|
|
|
|
|
+ liveRedConf.getRedId(),
|
|
|
|
|
+ liveRedConf.getDesc()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status == 2 || status == -1) {
|
|
|
|
|
+ return liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ liveId,
|
|
|
|
|
+ LiveConsoleOpLog.OP_RED_SETTLE,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_CONSOLE,
|
|
|
|
|
+ liveRedConf.getRedId(),
|
|
|
|
|
+ liveRedConf.getDesc()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 中控台抽奖操作留存(发放 / 结算)
|
|
|
|
|
+ */
|
|
|
|
|
+ private LiveConsoleOpLog saveConsoleLotteryOpLog(Long liveId, LiveLotteryConf liveLotteryConf, Integer status) {
|
|
|
|
|
+ if (liveLotteryConf == null || status == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status == 1) {
|
|
|
|
|
+ return liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ liveId,
|
|
|
|
|
+ LiveConsoleOpLog.OP_LOTTERY_SEND,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_CONSOLE,
|
|
|
|
|
+ liveLotteryConf.getLotteryId(),
|
|
|
|
|
+ liveLotteryConf.getDesc()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status == 2 || status == -1) {
|
|
|
|
|
+ return liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ liveId,
|
|
|
|
|
+ LiveConsoleOpLog.OP_LOTTERY_SETTLE,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_CONSOLE,
|
|
|
|
|
+ liveLotteryConf.getLotteryId(),
|
|
|
|
|
+ liveLotteryConf.getDesc()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 中控台优惠券展示留存
|
|
|
|
|
+ */
|
|
|
|
|
+ private LiveConsoleOpLog saveConsoleCouponOpLog(Long liveId, Long couponIssueId, Integer status) {
|
|
|
|
|
+ if (status == null || status != 1 || couponIssueId == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveCouponIssue liveCouponIssue = liveCouponIssueService.selectLiveCouponIssueById(couponIssueId);
|
|
|
|
|
+ if (liveCouponIssue == null || liveCouponIssue.getCouponId() == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveCoupon liveCoupon = liveCouponMapper.selectLiveCouponById(liveCouponIssue.getCouponId());
|
|
|
|
|
+ return liveConsoleOpLogService.saveCouponShowLog(
|
|
|
|
|
+ liveId,
|
|
|
|
|
+ couponIssueId,
|
|
|
|
|
+ liveCoupon,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_CONSOLE
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//错误时调用
|
|
//错误时调用
|
|
|
@OnError
|
|
@OnError
|
|
|
public void onError(Session session, Throwable throwable) {
|
|
public void onError(Session session, Throwable throwable) {
|
|
@@ -906,7 +990,20 @@ public class WebSocketServer {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void sendIntegralMessage(Long liveId, Long userId,Long scoreAmount) {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将中控台操作留存挂载到 WebSocket 消息体,供 App 端展示
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void attachOpLog(SendMsgVo msg, LiveConsoleOpLog opLog) {
|
|
|
|
|
+ if (msg != null && opLog != null) {
|
|
|
|
|
+ msg.setOpLog(LiveConsoleOpLogVo.from(opLog));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void sendIntegralMessage(Long liveId, Long userId, Long scoreAmount) {
|
|
|
|
|
+ sendIntegralMessage(liveId, userId, scoreAmount, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void sendIntegralMessage(Long liveId, Long userId, Long scoreAmount, LiveConsoleOpLog opLog) {
|
|
|
ConcurrentHashMap<Long, Session> room = getRoom(liveId);
|
|
ConcurrentHashMap<Long, Session> room = getRoom(liveId);
|
|
|
Session session = room.get(userId);
|
|
Session session = room.get(userId);
|
|
|
if (session == null || !session.isOpen()) {
|
|
if (session == null || !session.isOpen()) {
|
|
@@ -919,6 +1016,7 @@ public class WebSocketServer {
|
|
|
sendMsgVo.setCmd("Integral");
|
|
sendMsgVo.setCmd("Integral");
|
|
|
sendMsgVo.setMsg("恭喜你成功获得观看奖励:" + scoreAmount + "积分");
|
|
sendMsgVo.setMsg("恭喜你成功获得观看奖励:" + scoreAmount + "积分");
|
|
|
sendMsgVo.setData(String.valueOf(scoreAmount));
|
|
sendMsgVo.setData(String.valueOf(scoreAmount));
|
|
|
|
|
+ attachOpLog(sendMsgVo, opLog);
|
|
|
|
|
|
|
|
if(Objects.isNull(session)) return;
|
|
if(Objects.isNull(session)) return;
|
|
|
sendMessage(session, JSONObject.toJSONString(R.ok().put("data", sendMsgVo)));
|
|
sendMessage(session, JSONObject.toJSONString(R.ok().put("data", sendMsgVo)));
|
|
@@ -1276,6 +1374,13 @@ public class WebSocketServer {
|
|
|
liveRedConf.setUpdateTime( now);
|
|
liveRedConf.setUpdateTime( now);
|
|
|
msg.setData(JSON.toJSONString(liveRedConf));
|
|
msg.setData(JSON.toJSONString(liveRedConf));
|
|
|
liveRedConfService.updateLiveRedConf(liveRedConf);
|
|
liveRedConfService.updateLiveRedConf(liveRedConf);
|
|
|
|
|
+ attachOpLog(msg, liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ task.getLiveId(),
|
|
|
|
|
+ LiveConsoleOpLog.OP_RED_SEND,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_AUTO,
|
|
|
|
|
+ liveRedConf.getRedId(),
|
|
|
|
|
+ liveRedConf.getDesc()
|
|
|
|
|
+ ));
|
|
|
liveService.asyncToCacheLiveConfig(task.getLiveId());
|
|
liveService.asyncToCacheLiveConfig(task.getLiveId());
|
|
|
}else if (task.getTaskType() == 4L) {
|
|
}else if (task.getTaskType() == 4L) {
|
|
|
msg.setCmd("lottery");
|
|
msg.setCmd("lottery");
|
|
@@ -1288,6 +1393,13 @@ public class WebSocketServer {
|
|
|
liveLotteryConf.setUpdateTime( now);
|
|
liveLotteryConf.setUpdateTime( now);
|
|
|
msg.setData(JSON.toJSONString(liveLotteryConf));
|
|
msg.setData(JSON.toJSONString(liveLotteryConf));
|
|
|
liveLotteryConfService.updateLiveLotteryConf(liveLotteryConf);
|
|
liveLotteryConfService.updateLiveLotteryConf(liveLotteryConf);
|
|
|
|
|
+ attachOpLog(msg, liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ task.getLiveId(),
|
|
|
|
|
+ LiveConsoleOpLog.OP_LOTTERY_SEND,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_AUTO,
|
|
|
|
|
+ liveLotteryConf.getLotteryId(),
|
|
|
|
|
+ liveLotteryConf.getDesc()
|
|
|
|
|
+ ));
|
|
|
liveService.asyncToCacheLiveConfig(task.getLiveId());
|
|
liveService.asyncToCacheLiveConfig(task.getLiveId());
|
|
|
}else if (task.getTaskType() == 3L) {
|
|
}else if (task.getTaskType() == 3L) {
|
|
|
msg.setCmd("sendMsg");
|
|
msg.setCmd("sendMsg");
|
|
@@ -1329,6 +1441,12 @@ public class WebSocketServer {
|
|
|
data.put("couponTime", liveCoupon.getCouponTime());
|
|
data.put("couponTime", liveCoupon.getCouponTime());
|
|
|
msg.setData(JSON.toJSONString(data));
|
|
msg.setData(JSON.toJSONString(data));
|
|
|
liveCouponMapper.updateChangeShow(task.getLiveId(), liveCouponIssue.getId());
|
|
liveCouponMapper.updateChangeShow(task.getLiveId(), liveCouponIssue.getId());
|
|
|
|
|
+ attachOpLog(msg, liveConsoleOpLogService.saveCouponShowLog(
|
|
|
|
|
+ task.getLiveId(),
|
|
|
|
|
+ liveCouponIssue.getId(),
|
|
|
|
|
+ liveCoupon,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_AUTO
|
|
|
|
|
+ ));
|
|
|
} else if (task.getTaskType() == 6L) {
|
|
} else if (task.getTaskType() == 6L) {
|
|
|
// 上架/下架商品
|
|
// 上架/下架商品
|
|
|
msg.setCmd("goods");
|
|
msg.setCmd("goods");
|
|
@@ -1622,7 +1740,8 @@ public class WebSocketServer {
|
|
|
log.debug("[实时完课检查] liveId={}, userId={}, duration={}秒", liveId, userId, duration);
|
|
log.debug("[实时完课检查] liveId={}, userId={}, duration={}秒", liveId, userId, duration);
|
|
|
|
|
|
|
|
// 1. 调用完课记录服务检查并创建完课记录
|
|
// 1. 调用完课记录服务检查并创建完课记录
|
|
|
- completionPointsRecordService.checkAndCreateCompletionRecord(liveId, userId, duration);
|
|
|
|
|
|
|
+ LiveCompletionPointsRecord createdRecord =
|
|
|
|
|
+ completionPointsRecordService.checkAndCreateCompletionRecord(liveId, userId, duration);
|
|
|
|
|
|
|
|
// 2. 查询是否有新的未领取完课记录
|
|
// 2. 查询是否有新的未领取完课记录
|
|
|
List<LiveCompletionPointsRecord> unreceivedRecords =
|
|
List<LiveCompletionPointsRecord> unreceivedRecords =
|
|
@@ -1633,19 +1752,32 @@ public class WebSocketServer {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ LiveCompletionPointsRecord notifyRecord = unreceivedRecords.get(0);
|
|
|
|
|
+
|
|
|
// 3. 构建推送消息
|
|
// 3. 构建推送消息
|
|
|
SendMsgVo sendMsgVo = new SendMsgVo();
|
|
SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
sendMsgVo.setLiveId(liveId);
|
|
sendMsgVo.setLiveId(liveId);
|
|
|
sendMsgVo.setUserId(userId);
|
|
sendMsgVo.setUserId(userId);
|
|
|
sendMsgVo.setCmd("completionPoints");
|
|
sendMsgVo.setCmd("completionPoints");
|
|
|
sendMsgVo.setMsg("完成任务!");
|
|
sendMsgVo.setMsg("完成任务!");
|
|
|
- sendMsgVo.setData(JSONObject.toJSONString(unreceivedRecords.get(0)));
|
|
|
|
|
|
|
+ sendMsgVo.setData(JSONObject.toJSONString(notifyRecord));
|
|
|
|
|
+ if (createdRecord != null) {
|
|
|
|
|
+ LiveConsoleOpLog opLog = liveConsoleOpLogService.saveLog(
|
|
|
|
|
+ liveId,
|
|
|
|
|
+ LiveConsoleOpLog.OP_COMPLETION_POINTS,
|
|
|
|
|
+ LiveConsoleOpLog.HANDLE_AUTO,
|
|
|
|
|
+ createdRecord.getId(),
|
|
|
|
|
+ "完课积分" + createdRecord.getPointsAwarded() + "分"
|
|
|
|
|
+ );
|
|
|
|
|
+ liveConsoleOpLogService.bindOpLogUser(opLog.getId(), liveId, userId);
|
|
|
|
|
+ attachOpLog(sendMsgVo, opLog);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 4. 实时推送完课积分弹窗
|
|
// 4. 实时推送完课积分弹窗
|
|
|
sendCompletionPointsMessage(liveId, userId, sendMsgVo);
|
|
sendCompletionPointsMessage(liveId, userId, sendMsgVo);
|
|
|
|
|
|
|
|
log.info("[实时完课推送] 发送完课积分弹窗通知, liveId={}, userId={}, points={}, duration={}秒",
|
|
log.info("[实时完课推送] 发送完课积分弹窗通知, liveId={}, userId={}, points={}, duration={}秒",
|
|
|
- liveId, userId, unreceivedRecords.get(0).getPointsAwarded(), duration);
|
|
|
|
|
|
|
+ liveId, userId, notifyRecord.getPointsAwarded(), duration);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("[实时完课推送] 实时检查完课积分失败, liveId={}, userId={}, duration={}",
|
|
log.error("[实时完课推送] 实时检查完课积分失败, liveId={}, userId={}, duration={}",
|