fix
This commit is contained in:
@@ -7,7 +7,11 @@ import com.tailbet.mapper.GameRoundMapper;
|
||||
import com.tailbet.mapper.RedPacketMapper;
|
||||
import com.tailbet.mapper.UserMapper;
|
||||
import com.tailbet.mapper.DigitWhiteMapper;
|
||||
import com.tailbet.mapper.DrawRecordMapper;
|
||||
import com.tailbet.mapper.SysConfigMapper;
|
||||
import com.tailbet.model.entity.DigitWhite;
|
||||
import com.tailbet.model.entity.DrawRecord;
|
||||
import com.tailbet.model.entity.SysConfig;
|
||||
import com.tailbet.service.IGameService;
|
||||
import com.tailbet.service.IRedPacketService;
|
||||
import com.tailbet.service.IFakeUserService;
|
||||
@@ -34,6 +38,8 @@ public class GameJob {
|
||||
|
||||
private final GameRoundMapper gameRoundMapper;
|
||||
private final RedPacketMapper redPacketMapper;
|
||||
private final DrawRecordMapper drawRecordMapper;
|
||||
private final SysConfigMapper sysConfigMapper;
|
||||
private final UserMapper userMapper;
|
||||
private final DigitWhiteMapper digitWhiteMapper;
|
||||
private final IGameService gameService;
|
||||
@@ -44,12 +50,51 @@ public class GameJob {
|
||||
// 局状态监控(使用内存缓存,实际生产应使用Redis)
|
||||
private final Map<Long, RoundTask> roundTasks = new ConcurrentHashMap<>();
|
||||
|
||||
// 配置缓存
|
||||
private final Map<String, String> configCache = new ConcurrentHashMap<>();
|
||||
|
||||
// 延迟任务队列
|
||||
private final Map<String, PendingTask> pendingTasks = new ConcurrentHashMap<>();
|
||||
|
||||
// 任务ID生成器
|
||||
private java.util.concurrent.atomic.AtomicLong taskIdGenerator = new java.util.concurrent.atomic.AtomicLong(1);
|
||||
|
||||
/**
|
||||
* 启动时加载配置缓存
|
||||
*/
|
||||
@jakarta.annotation.PostConstruct
|
||||
public void loadConfig() {
|
||||
try {
|
||||
List<SysConfig> configs = sysConfigMapper.selectList(null);
|
||||
for (SysConfig config : configs) {
|
||||
configCache.put(config.getCfgKey(), config.getCfgValue());
|
||||
}
|
||||
log.info("配置缓存加载完成,共 {} 条配置", configs.size());
|
||||
} catch (Exception e) {
|
||||
log.error("配置缓存加载失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置值
|
||||
*/
|
||||
private String getConfig(String key) {
|
||||
return configCache.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取整型配置值
|
||||
*/
|
||||
public int getConfigInt(String key, int defaultValue) {
|
||||
String value = configCache.get(key);
|
||||
if (value == null) return defaultValue;
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查红包是否需要托领取(每3秒执行)
|
||||
*/
|
||||
@@ -63,8 +108,9 @@ public class GameJob {
|
||||
|
||||
for (RedPacket rp : ongoingRps) {
|
||||
LocalDateTime createTime = rp.getCreateTime();
|
||||
// 发出超过5秒未领完,让托领取
|
||||
if (createTime.plusSeconds(5).isBefore(LocalDateTime.now())) {
|
||||
// 发出超过配置时间未领完,让托领取
|
||||
int fakeRecvTimeout = getConfigInt("fake_recv_seconds", 5);
|
||||
if (createTime.plusSeconds(fakeRecvTimeout).isBefore(LocalDateTime.now())) {
|
||||
// 查找未领取的用户,随机选一个托领取
|
||||
try {
|
||||
fakeUserReceiveRemaining(rp);
|
||||
@@ -111,14 +157,15 @@ public class GameJob {
|
||||
.eq(GameRound::getStatus, 0));
|
||||
|
||||
for (GameRound round : ongoingRounds) {
|
||||
// 检查是否超过接注时间(默认60秒)
|
||||
// 检查是否超过接注时间
|
||||
RoundTask task = roundTasks.get(round.getId());
|
||||
if (task != null && task.endBetTime.isBefore(LocalDateTime.now())) {
|
||||
// 自动结束接注
|
||||
try {
|
||||
gameService.endBet(round.getGroupId(), 0L); // 0L表示系统自动触发
|
||||
// 触发开始发红包
|
||||
scheduleStartRp(round.getId(), round.getGroupId(), 20); // 20秒后开始发红包
|
||||
// 触发开始发红包,延迟时间从配置读取
|
||||
int sendRpDelay = getConfigInt("send_rp_delay", 20);
|
||||
scheduleStartRp(round.getId(), round.getGroupId(), sendRpDelay);
|
||||
} catch (Exception e) {
|
||||
log.error("自动结束接注失败: roundId={}, error={}", round.getId(), e.getMessage());
|
||||
}
|
||||
@@ -233,8 +280,9 @@ public class GameJob {
|
||||
// 通知白名单用户尾数试算完成
|
||||
notifyWhiteUsers(roundId);
|
||||
|
||||
// 安排20秒后开始发红包
|
||||
scheduleStartRp(roundId, groupId, 20);
|
||||
// 安排延迟后开始发红包
|
||||
int sendRpDelay = getConfigInt("send_rp_delay", 20);
|
||||
scheduleStartRp(roundId, groupId, sendRpDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,8 +297,9 @@ public class GameJob {
|
||||
// 广播开始发红包
|
||||
broadcastStartRp(groupId, round.getRoundNo());
|
||||
|
||||
// 安排10秒后如果没人发包则机器人自动发
|
||||
scheduleBotSendRp(roundId, groupId, 10);
|
||||
// 安排超时后如果没人发包则机器人自动发
|
||||
int autoRpTimeout = getConfigInt("auto_rp_timeout", 10);
|
||||
scheduleBotSendRp(roundId, groupId, autoRpTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,9 +417,37 @@ public class GameJob {
|
||||
String message = roundNo + "期开奖\n" +
|
||||
"尾数: " + digit + "\n" +
|
||||
"中奖玩法: " + playWinDesc;
|
||||
|
||||
// 查询近30期历史
|
||||
String history = getRecentHistory(groupId);
|
||||
if (history != null && !history.isEmpty()) {
|
||||
message += "\n\n近30期:\n" + history;
|
||||
}
|
||||
|
||||
openIMClient.sendGroupMessage(String.valueOf(groupId), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取近30期历史开奖记录
|
||||
*/
|
||||
private String getRecentHistory(Long groupId) {
|
||||
List<DrawRecord> records = drawRecordMapper.selectList(
|
||||
new LambdaQueryWrapper<DrawRecord>()
|
||||
.eq(DrawRecord::getGroupId, groupId)
|
||||
.orderByDesc(DrawRecord::getCreateTime)
|
||||
.last("LIMIT 30"));
|
||||
|
||||
if (records == null || records.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (DrawRecord record : records) {
|
||||
sb.append(record.getRoundNo()).append(":").append(record.getDigit()).append("\n");
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 局任务信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user