手动领取消息处理

This commit is contained in:
tianfeng 2025-11-13 22:26:52 +08:00
parent 1ca118c07b
commit 910dfb5a84

View File

@ -16,10 +16,12 @@ import com.red.circle.other.domain.gateway.RocketHistoryGateway;
import com.red.circle.other.domain.gateway.RocketRewardLogGateway;
import com.red.circle.other.domain.gateway.RocketStatusGateway;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.domain.propcoupon.PropCouponSource;
import com.red.circle.other.domain.rocket.*;
import com.red.circle.other.infra.common.props.PropsSendCommon;
import com.red.circle.other.infra.database.cache.key.RocketKeys;
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
import com.red.circle.other.inner.endpoint.material.props.BadgeBackpackClient;
import com.red.circle.other.inner.endpoint.material.props.PropsBackpackClient;
import com.red.circle.other.inner.enums.material.BadgeBackpackExpireTypeEnum;
@ -64,6 +66,7 @@ public class RocketRewardClaimCmdExe {
private final RocketHistoryGateway rocketHistoryGateway;
private final PropsSendCommon propsSendCommon;
private final UserProfileGateway userProfileGateway;
private final RoomProfileManagerService roomProfileManagerService;
private final Random random = new Random();
/**
@ -72,8 +75,28 @@ public class RocketRewardClaimCmdExe {
public RocketRewardCO execute(RocketRewardClaimCmd cmd) {
Long userId = cmd.getReqUserId();
String lockKey = RocketKeys.LOCK.getKey(cmd.getRoomId(), "claim", userId);
return distributedLockUtil.executeWithLock(lockKey, 5L, () -> doClaim(cmd), "Reward collection operations are too frequent. Please try again later");
RocketRewardCO result = distributedLockUtil.executeWithLock(lockKey, 5L, () -> doClaim(cmd), "Reward collection operations are too frequent. Please try again later");
if (result != null) {
UserProfile userProfile = userProfileGateway.getByUserId(userId);
String roomAccount = roomProfileManagerService.getRoomAccount(cmd.getRoomId());
Map<String, Object> map = new HashMap<>();
map.put("rewardType", result.getRewardType());
map.put("cover", result.getCover());
map.put("rocketLevel", result.getRocketLevel());
map.put("userId", userId);
map.put("userNickname", userProfile.getUserNickname());
imGroupClient.sendCustomMessage(roomAccount,
CustomGroupMsgBodyCmd.builder()
.type(GroupMessageTypeEnum.ROCKET_REWARD_USER)
.data(map)
.build());
}
return result;
}
/**
@ -88,22 +111,8 @@ public class RocketRewardClaimCmdExe {
RocketRewardClaimCmd cmd = new RocketRewardClaimCmd();
cmd.setRoomId(roomId);
cmd.setReqUserId(userId);
RocketRewardCO result = execute(cmd);
if (result != null) {
Map<String, Object> map = new HashMap<>();
map.put("rewardType", result.getRewardType());
map.put("cover", result.getCover());
map.put("rocketLevel", result.getRocketLevel());
map.put("userId", userId);
map.put("userNickname", userNickname);
imGroupClient.sendCustomMessage(roomAccount,
CustomGroupMsgBodyCmd.builder()
.type(GroupMessageTypeEnum.ROCKET_REWARD_USER)
.data(map)
.build());
}
execute(cmd);
} catch (Exception e) {
// 静默失败不影响进房
log.error("异步自动领取火箭奖励失败: roomId={}, userId={}", roomId, userId, e);
@ -157,10 +166,7 @@ public class RocketRewardClaimCmdExe {
// 7. 递增领取人数发放成功后再递增
try {
boolean success = rocketHistoryGateway.tryIncrementClaimCount(historyId, rewardQuantity);
if (!success) {
return null;
}
rocketHistoryGateway.incrementClaimCount(historyId);
} catch (Exception e) {
log.error("递增领取人数失败: historyId={}", historyId, e);
}