fix 领红包加锁
This commit is contained in:
@@ -3,21 +3,22 @@ package com.tailbet.job;
|
||||
import com.tailbet.model.entity.GameRound;
|
||||
import com.tailbet.model.entity.RedPacket;
|
||||
import com.tailbet.model.entity.User;
|
||||
import com.tailbet.mapper.DrawRecordMapper;
|
||||
import com.tailbet.mapper.DigitWhiteMapper;
|
||||
import com.tailbet.mapper.GameRoundMapper;
|
||||
import com.tailbet.mapper.RedPacketMapper;
|
||||
import com.tailbet.mapper.RedPacketRecvMapper;
|
||||
import com.tailbet.mapper.UserMapper;
|
||||
import com.tailbet.mapper.DigitWhiteMapper;
|
||||
import com.tailbet.mapper.DrawRecordMapper;
|
||||
import com.tailbet.mapper.SysConfigMapper;
|
||||
import com.tailbet.mapper.UserMapper;
|
||||
import com.tailbet.model.entity.DigitWhite;
|
||||
import com.tailbet.model.entity.DrawRecord;
|
||||
import com.tailbet.model.entity.RedPacketRecv;
|
||||
import com.tailbet.model.entity.SysConfig;
|
||||
import com.tailbet.openim.OpenIMClient;
|
||||
import com.tailbet.service.IGameService;
|
||||
import com.tailbet.service.IRedPacketService;
|
||||
import com.tailbet.service.IFakeUserService;
|
||||
import com.tailbet.openim.OpenIMClient;
|
||||
import com.tailbet.util.RedisLockUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -161,13 +162,15 @@ public class GameJob {
|
||||
break;
|
||||
}
|
||||
|
||||
final User fakeUser = fakeToUse;
|
||||
try {
|
||||
redPacketService.receiveRp(rp.getId(), fakeToUse.getId());
|
||||
// 使用分布式锁防止多领
|
||||
RedisLockUtil.lock("rp:receive:" + rp.getId(),
|
||||
() -> redPacketService.receiveRp(rp.getId(), fakeUser.getId()));
|
||||
log.info("假人{}领取红包{}剩余份额", fakeToUse.getId(), rp.getId());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("假人领取红包失败: rpId={}, fakeId={}, error={}", rp.getId(), fakeToUse.getId(), e.getMessage());
|
||||
// 可能是红包已领完,退出循环
|
||||
break;
|
||||
log.error("假人领取红包失败: rpId={}, fakeId={}, error={}", rp.getId(), fakeUser.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -493,18 +496,53 @@ public class GameJob {
|
||||
private Integer digit;
|
||||
private LocalDateTime executeTime;
|
||||
|
||||
public String getTaskId() { return taskId; }
|
||||
public void setTaskId(String taskId) { this.taskId = taskId; }
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
public Long getRoundId() { return roundId; }
|
||||
public void setRoundId(Long roundId) { this.roundId = roundId; }
|
||||
public Long getGroupId() { return groupId; }
|
||||
public void setGroupId(Long groupId) { this.groupId = groupId; }
|
||||
public Integer getDigit() { return digit; }
|
||||
public void setDigit(Integer digit) { this.digit = digit; }
|
||||
public LocalDateTime getExecuteTime() { return executeTime; }
|
||||
public void setExecuteTime(LocalDateTime executeTime) { this.executeTime = executeTime; }
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getRoundId() {
|
||||
return roundId;
|
||||
}
|
||||
|
||||
public void setRoundId(Long roundId) {
|
||||
this.roundId = roundId;
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(Long groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Integer getDigit() {
|
||||
return digit;
|
||||
}
|
||||
|
||||
public void setDigit(Integer digit) {
|
||||
this.digit = digit;
|
||||
}
|
||||
|
||||
public LocalDateTime getExecuteTime() {
|
||||
return executeTime;
|
||||
}
|
||||
|
||||
public void setExecuteTime(LocalDateTime executeTime) {
|
||||
this.executeTime = executeTime;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user