红包事件监听器
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.tailbet.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 红包领完事件,触发开奖结算
|
||||
*/
|
||||
@Getter
|
||||
public class RedPacketFinishedEvent extends ApplicationEvent {
|
||||
|
||||
private final Long roundId;
|
||||
private final Long groupId;
|
||||
private final Long rpId;
|
||||
private final Integer luckyDigit;
|
||||
|
||||
public RedPacketFinishedEvent(Object source, Long roundId, Long groupId, Long rpId, Integer luckyDigit) {
|
||||
super(source);
|
||||
this.roundId = roundId;
|
||||
this.groupId = groupId;
|
||||
this.rpId = rpId;
|
||||
this.luckyDigit = luckyDigit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.tailbet.listener;
|
||||
|
||||
import com.tailbet.event.RedPacketFinishedEvent;
|
||||
import com.tailbet.job.GameJob;
|
||||
import com.tailbet.service.IGameService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 红包事件监听器
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RedPacketEventListener {
|
||||
|
||||
private final IGameService gameService;
|
||||
private final GameJob gameJob;
|
||||
|
||||
/**
|
||||
* 监听红包领完事件,触发开奖结算
|
||||
*/
|
||||
@EventListener
|
||||
public void onRedPacketFinished(RedPacketFinishedEvent event) {
|
||||
log.info("收到红包领完事件: roundId={}, groupId={}, rpId={}, luckyDigit={}",
|
||||
event.getRoundId(), event.getGroupId(), event.getRpId(), event.getLuckyDigit());
|
||||
|
||||
try {
|
||||
// 调用 GameJob.onSettle 进行开奖结算和广播
|
||||
gameJob.onSettle(event.getRoundId(), event.getGroupId(), event.getLuckyDigit());
|
||||
} catch (Exception e) {
|
||||
log.error("开奖结算失败: roundId={}, error={}", event.getRoundId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user