手动领取消息处理

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.RocketRewardLogGateway;
import com.red.circle.other.domain.gateway.RocketStatusGateway; import com.red.circle.other.domain.gateway.RocketStatusGateway;
import com.red.circle.other.domain.gateway.user.UserProfileGateway; 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.propcoupon.PropCouponSource;
import com.red.circle.other.domain.rocket.*; import com.red.circle.other.domain.rocket.*;
import com.red.circle.other.infra.common.props.PropsSendCommon; 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.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.BadgeBackpackClient;
import com.red.circle.other.inner.endpoint.material.props.PropsBackpackClient; import com.red.circle.other.inner.endpoint.material.props.PropsBackpackClient;
import com.red.circle.other.inner.enums.material.BadgeBackpackExpireTypeEnum; import com.red.circle.other.inner.enums.material.BadgeBackpackExpireTypeEnum;
@ -64,6 +66,7 @@ public class RocketRewardClaimCmdExe {
private final RocketHistoryGateway rocketHistoryGateway; private final RocketHistoryGateway rocketHistoryGateway;
private final PropsSendCommon propsSendCommon; private final PropsSendCommon propsSendCommon;
private final UserProfileGateway userProfileGateway; private final UserProfileGateway userProfileGateway;
private final RoomProfileManagerService roomProfileManagerService;
private final Random random = new Random(); private final Random random = new Random();
/** /**
@ -73,7 +76,27 @@ public class RocketRewardClaimCmdExe {
Long userId = cmd.getReqUserId(); Long userId = cmd.getReqUserId();
String lockKey = RocketKeys.LOCK.getKey(cmd.getRoomId(), "claim", userId); 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;
} }
/** /**
@ -89,21 +112,7 @@ public class RocketRewardClaimCmdExe {
cmd.setRoomId(roomId); cmd.setRoomId(roomId);
cmd.setReqUserId(userId); cmd.setReqUserId(userId);
RocketRewardCO result = execute(cmd); 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());
}
} catch (Exception e) { } catch (Exception e) {
// 静默失败不影响进房 // 静默失败不影响进房
log.error("异步自动领取火箭奖励失败: roomId={}, userId={}", roomId, userId, e); log.error("异步自动领取火箭奖励失败: roomId={}, userId={}", roomId, userId, e);
@ -157,10 +166,7 @@ public class RocketRewardClaimCmdExe {
// 7. 递增领取人数发放成功后再递增 // 7. 递增领取人数发放成功后再递增
try { try {
boolean success = rocketHistoryGateway.tryIncrementClaimCount(historyId, rewardQuantity); rocketHistoryGateway.incrementClaimCount(historyId);
if (!success) {
return null;
}
} catch (Exception e) { } catch (Exception e) {
log.error("递增领取人数失败: historyId={}", historyId, e); log.error("递增领取人数失败: historyId={}", historyId, e);
} }