diff --git a/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/enums/SendPropsOrigin.java b/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/enums/SendPropsOrigin.java index a3e7870b..078a6407 100644 --- a/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/enums/SendPropsOrigin.java +++ b/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/enums/SendPropsOrigin.java @@ -279,7 +279,7 @@ public enum SendPropsOrigin { /** * 每赛季CP相互赠送礼物榜单. */ - SEASON_CP_GIFT(""), + SEASON_CP_GIFT("Season cp gift"), /** * 签到奖励 diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/award/CpRankingRewardManager.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/award/CpRankingRewardManager.java index 1c5f4d58..382be423 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/award/CpRankingRewardManager.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/award/CpRankingRewardManager.java @@ -5,12 +5,17 @@ import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.common.business.enums.SendPropsOrigin; import com.red.circle.other.infra.common.activity.PropsActivitySendCommon; import com.red.circle.other.infra.common.activity.send.SendRewardGroup; +import com.red.circle.other.infra.common.props.PropsSendCommon; import com.red.circle.other.infra.database.mongo.entity.user.count.WeekCpValueCount; import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService; +import com.red.circle.other.infra.database.rds.entity.activity.PropsActivityRewardConfig; import com.red.circle.other.infra.database.rds.entity.activity.PropsActivityRuleConfig; +import com.red.circle.other.infra.database.rds.service.activity.PropsActivityRewardConfigService; import com.red.circle.other.infra.database.rds.service.activity.PropsActivityRuleConfigService; import com.red.circle.other.infra.utils.SeasonUtils; import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum; +import com.red.circle.other.inner.model.cmd.material.PrizeDescribe; +import com.red.circle.other.inner.model.cmd.material.PrizeDescribeRewardCmd; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.DateFormatConstant; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; @@ -33,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * CP排行榜奖励发送管理器. @@ -47,6 +53,8 @@ public class CpRankingRewardManager { private final PropsActivitySendCommon sendPropsManager; private final WalletGoldClient walletGoldClient; private final StringRedisTemplate stringRedisTemplate; + private final PropsActivityRewardConfigService propsActivityRewardConfigService; + private final PropsSendCommon propsSendCommon; /** * 发送上周周榜前三名奖励 @@ -161,7 +169,7 @@ public class CpRankingRewardManager { String eventIdOne = String.format("WK_CP_RW_%s_%d_%d", weekDate, userOne, rank); if (checkAndSetIdempotent(eventIdOne, 15)) { sendGoldAndProps(sysOrigin, userOne, goldReward, rewardConfig.getResourceGroupId(), - rewardConfig.getId(), SendPropsOrigin.WEEK_CP_GIFT, eventIdOne); + rewardConfig.getId(), SendPropsOrigin.WEEK_CP_GIFT, eventIdOne, 0); log.info("[CP周榜] 排名 {} 用户 {} 奖励发放成功, 金币: {}, 道具组: {}", rank, userOne, goldReward, rewardConfig.getResourceGroupId()); } @@ -170,7 +178,7 @@ public class CpRankingRewardManager { String eventIdTwo = String.format("WK_CP_RW_%s_%d_%d", weekDate, userTwo, rank); if (checkAndSetIdempotent(eventIdTwo, 15)) { sendGoldAndProps(sysOrigin, userTwo, goldReward, rewardConfig.getResourceGroupId(), - rewardConfig.getId(), SendPropsOrigin.WEEK_CP_GIFT, eventIdTwo); + rewardConfig.getId(), SendPropsOrigin.WEEK_CP_GIFT, eventIdTwo, 0); log.info("[CP周榜] 排名 {} 用户 {} 奖励发放成功, 金币: {}, 道具组: {}", rank, userTwo, goldReward, rewardConfig.getResourceGroupId()); } @@ -217,12 +225,87 @@ public class CpRankingRewardManager { Long resourceGroupId, Long trackId, SendPropsOrigin origin, - String eventId) { + String eventId, + int sendIndex) { // 发送金币 addUserGold(userId, sysOrigin.name(), goldAmount, eventId); + SendRewardGroup param = SendRewardGroup.builder() + .trackId(trackId) + .sysOrigin(sysOrigin) + .acceptUserId(userId) + .resourceGroupId(resourceGroupId) + .origin(origin) + .build(); // 发送道具 - sendProps(sysOrigin, userId, resourceGroupId, trackId, origin); + List configs = propsActivityRewardConfigService.listByGroupId( + param.getResourceGroupId()); + + if (CollectionUtils.isEmpty(configs)) { + return; + } + + // 根据 sendIndex 筛选要发送的配置 + List filteredConfigs = filterConfigsBySendIndex(configs, sendIndex); + + if (CollectionUtils.isEmpty(filteredConfigs)) { + log.warn("根据 sendIndex={} 筛选后没有可发送的配置, resourceGroupId={}", sendIndex, resourceGroupId); + return; + } + + propsSendCommon.send(new PrizeDescribeRewardCmd() + .setTrackId(param.getTrackId()) + .setAcceptUserId(param.getAcceptUserId()) + .setOrigin(param.getOrigin()) + .setSysOrigin(param.getSysOrigin()) + .setPrizes(toListPrizeDescribe(filteredConfigs)) + ); + } + + /** + * 根据 sendIndex 筛选配置 + * AVATAR_FRAME 类型根据 sendIndex 只保留第 sendIndex 个,其他类型正常返回 + * 例如: configs = [AVATAR_FRAME, AVATAR_FRAME, CHAT_BUBBLE] + * sendIndex = 0 -> 返回 [第一个 AVATAR_FRAME, CHAT_BUBBLE] + * sendIndex = 1 -> 返回 [第二个 AVATAR_FRAME, CHAT_BUBBLE] + */ + private List filterConfigsBySendIndex( + List configs, int sendIndex) { + if (sendIndex < 0 || CollectionUtils.isEmpty(configs)) { + return configs; + } + + List result = Lists.newArrayList(); + String avatarFrameType = "AVATAR_FRAME"; + int avatarFrameCount = 0; + + for (PropsActivityRewardConfig config : configs) { + if (Objects.equals(avatarFrameType, config.getType())) { + // AVATAR_FRAME 类型只保留第 sendIndex 个 + if (avatarFrameCount == sendIndex) { + result.add(config); + } + avatarFrameCount++; + } else { + // 其他类型正常添加 + result.add(config); + } + } + + return result; + } + + private List toListPrizeDescribe(List configs) { + return configs.stream().map(this::toPrizeDescribe).collect(Collectors.toList()); + } + + private PrizeDescribe toPrizeDescribe(PropsActivityRewardConfig config) { + return new PrizeDescribe() + .setTrackId(config.getGroupId()) + .setType(config.getType()) + .setDetailType(config.getDetailType()) + .setContent(config.getContent()) + .setQuantity(config.getQuantity()); } /**