|
|
@@ -720,57 +720,75 @@ public class WebSocketServer {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 中控台红包操作留存(发放 / 结算)
|
|
|
+ * 中控台红包:仅结算时挂载 REST/定时任务已写入的留存,不在 WebSocket 侧新建记录
|
|
|
*/
|
|
|
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 findRecentRedSettleOpLog(liveId, liveRedConf.getRedId());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 中控台抽奖操作留存(发放 / 结算)
|
|
|
+ * 查询 REST 结算接口刚写入的红包结算留存,供 WebSocket 挂载 opLog
|
|
|
+ */
|
|
|
+ private LiveConsoleOpLog findRecentRedSettleOpLog(Long liveId, Long redId) {
|
|
|
+ LiveConsoleOpLog query = new LiveConsoleOpLog();
|
|
|
+ query.setLiveId(liveId);
|
|
|
+ query.setBizId(redId);
|
|
|
+ List<LiveConsoleOpLog> list = liveConsoleOpLogService.selectLiveConsoleOpLogList(query);
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ for (LiveConsoleOpLog item : list) {
|
|
|
+ if (item.getCreateTime() == null
|
|
|
+ || !Objects.equals(item.getOpType(), LiveConsoleOpLog.OP_RED_SETTLE)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (now - item.getCreateTime().getTime() <= 30000) {
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 中控台抽奖:仅结算时挂载 REST 已写入的留存,不在 WebSocket 侧新建记录
|
|
|
*/
|
|
|
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 findRecentLotterySettleOpLog(liveId, liveLotteryConf.getLotteryId());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询 REST 结算接口刚写入的抽奖结算留存,供 WebSocket 挂载 opLog
|
|
|
+ */
|
|
|
+ private LiveConsoleOpLog findRecentLotterySettleOpLog(Long liveId, Long lotteryId) {
|
|
|
+ LiveConsoleOpLog query = new LiveConsoleOpLog();
|
|
|
+ query.setLiveId(liveId);
|
|
|
+ query.setBizId(lotteryId);
|
|
|
+ List<LiveConsoleOpLog> list = liveConsoleOpLogService.selectLiveConsoleOpLogList(query);
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ for (LiveConsoleOpLog item : list) {
|
|
|
+ if (item.getCreateTime() == null
|
|
|
+ || !Objects.equals(item.getOpType(), LiveConsoleOpLog.OP_LOTTERY_SETTLE)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (now - item.getCreateTime().getTime() <= 30000) {
|
|
|
+ return item;
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -782,6 +800,10 @@ public class WebSocketServer {
|
|
|
if (status == null || status != 1 || couponIssueId == null) {
|
|
|
return null;
|
|
|
}
|
|
|
+ LiveConsoleOpLog recent = findRecentCouponShowOpLog(liveId, couponIssueId);
|
|
|
+ if (recent != null) {
|
|
|
+ return recent;
|
|
|
+ }
|
|
|
LiveCouponIssue liveCouponIssue = liveCouponIssueService.selectLiveCouponIssueById(couponIssueId);
|
|
|
if (liveCouponIssue == null || liveCouponIssue.getCouponId() == null) {
|
|
|
return null;
|
|
|
@@ -795,6 +817,33 @@ public class WebSocketServer {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 中控台展示券时 REST 已写入留存,WebSocket 复用近期记录避免重复插入
|
|
|
+ */
|
|
|
+ private LiveConsoleOpLog findRecentCouponShowOpLog(Long liveId, Long couponIssueId) {
|
|
|
+ LiveConsoleOpLog query = new LiveConsoleOpLog();
|
|
|
+ query.setLiveId(liveId);
|
|
|
+ query.setBizId(couponIssueId);
|
|
|
+ List<LiveConsoleOpLog> list = liveConsoleOpLogService.selectLiveConsoleOpLogList(query);
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LiveConsoleOpLog latest = list.get(0);
|
|
|
+ if (latest.getCreateTime() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ long ageMs = System.currentTimeMillis() - latest.getCreateTime().getTime();
|
|
|
+ if (ageMs > 5000) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Integer opType = latest.getOpType();
|
|
|
+ if (opType != null
|
|
|
+ && (opType == LiveConsoleOpLog.OP_COUPON_SHOW || opType == LiveConsoleOpLog.OP_VERIFY_COUPON_SHOW)) {
|
|
|
+ return latest;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
//错误时调用
|
|
|
@OnError
|
|
|
public void onError(Session session, Throwable throwable) {
|
|
|
@@ -1374,13 +1423,6 @@ public class WebSocketServer {
|
|
|
liveRedConf.setUpdateTime( now);
|
|
|
msg.setData(JSON.toJSONString(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());
|
|
|
}else if (task.getTaskType() == 4L) {
|
|
|
msg.setCmd("lottery");
|
|
|
@@ -1393,13 +1435,6 @@ public class WebSocketServer {
|
|
|
liveLotteryConf.setUpdateTime( now);
|
|
|
msg.setData(JSON.toJSONString(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());
|
|
|
}else if (task.getTaskType() == 3L) {
|
|
|
msg.setCmd("sendMsg");
|