From 5faf9f07136f2bdd1d2bff8fbb8393d6f60a9462 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 29 Apr 2026 19:46:12 +0800 Subject: [PATCH] =?UTF-8?q?cpList=20=E6=96=B0=E5=A2=9E=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=A1=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 2326e8659bb1805b1821b7086cf60450771099bc) --- .../enums/activity/PropsActivityTypeEnum.java | 5 + .../gift/strategy/RankCountStrategy.java | 6 + .../user/CpLevelUpAvatarFrameService.java | 123 ++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/CpLevelUpAvatarFrameService.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/activity/PropsActivityTypeEnum.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/activity/PropsActivityTypeEnum.java index 03516a16..cce905df 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/activity/PropsActivityTypeEnum.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/activity/PropsActivityTypeEnum.java @@ -225,4 +225,9 @@ public enum PropsActivityTypeEnum { GAME_KING_HONOR, + /** + * CP头像框道具配置(按性别,第0个男第1个女). + */ + CP_AVATAR, + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java index 810f16ef..6c7d437e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java @@ -38,6 +38,7 @@ import com.red.circle.other.infra.database.rds.entity.user.user.CpGiftRecord; import com.red.circle.other.infra.database.rds.service.user.user.CpGiftRecordService; import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; import com.red.circle.other.app.service.user.CpGiftWindowBroadcastService; +import com.red.circle.other.app.service.user.CpLevelUpAvatarFrameService; import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; import com.red.circle.other.inner.enums.activity.KingQueenType; import com.red.circle.other.inner.enums.material.GiftCurrencyType; @@ -91,6 +92,7 @@ public class RankCountStrategy implements GiftStrategy { private final CpRelationshipCacheService cpRelationshipCacheService; private final ActivityConfigCacheService activityConfigCacheService; private final CpGiftWindowBroadcastService cpGiftWindowBroadcastService; + private final CpLevelUpAvatarFrameService cpLevelUpAvatarFrameService; @Override public void processor(OfflineProcessGiftEvent event) { @@ -310,8 +312,12 @@ public class RankCountStrategy implements GiftStrategy { cpRelationshipList.stream() .filter(cp -> acceptUserIds.contains(cp.getCpUserId())) .forEach(cp -> { + BigDecimal beforeValue = cpValueService.getCpVal(cp.getCpValId()); cpValueService.incrValue(cp.getCpValId(), acceptAmount); + // CP值累加后检测升级并发放头像框 + cpLevelUpAvatarFrameService.grantIfLevelUp(cp, beforeValue, runningWater.getSysOrigin()); + // 写入CP道具赠送记录 saveCpGiftRecord(runningWater, cp, acceptAmount); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/CpLevelUpAvatarFrameService.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/CpLevelUpAvatarFrameService.java new file mode 100644 index 00000000..404a11d3 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/CpLevelUpAvatarFrameService.java @@ -0,0 +1,123 @@ +package com.red.circle.other.app.service.user; + +import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; +import com.red.circle.other.domain.gateway.props.ActivitySourceGroupGateway; +import com.red.circle.other.domain.gateway.props.PropsStoreGateway; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.model.user.UserProfile; +import com.red.circle.other.infra.database.rds.entity.user.user.CpLevelConfig; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum; +import com.red.circle.other.inner.model.dto.activity.props.ActivityResource; +import com.red.circle.other.inner.model.dto.activity.props.ActivityRewardProps; +import com.red.circle.other.inner.model.dto.material.props.ProductProps; +import com.red.circle.other.inner.model.dto.material.props.PropsResources; +import com.red.circle.tool.core.collection.CollectionUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Objects; + +/** + * CP等级升级发放头像框道具. + * + * @author tf + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class CpLevelUpAvatarFrameService { + + private static final int DAYS = 36500; + + private final CpValueService cpValueService; + private final UserProfileGateway userProfileGateway; + private final ActivitySourceGroupGateway activitySourceGroupGateway; + private final PropsStoreGateway propsStoreGateway; + + /** + * CP值累加后调用,检测是否升级并发放对应头像框. + * + * @param cp CP关系 + * @param beforeValue 累加前的CP值 + * @param sysOrigin 系统来源 + */ + public void grantIfLevelUp(CpRelationship cp, BigDecimal beforeValue, String sysOrigin) { + try { + BigDecimal afterValue = cpValueService.getCpVal(cp.getCpValId()); + if (afterValue == null) { + return; + } + + int beforeLevel = CpLevelConfig.of(beforeValue).getLevel(); + CpLevelConfig afterConfig = CpLevelConfig.of(afterValue); + int afterLevel = afterConfig.getLevel(); + + if (afterLevel <= beforeLevel) { + return; + } + + if (!afterConfig.isHasCpHeadwear()) { + return; + } + + List resources = activitySourceGroupGateway.listActivityResource( + SysOriginPlatformEnum.valueOf(sysOrigin), PropsActivityTypeEnum.CP_AVATAR); + if (CollectionUtils.isEmpty(resources)) { + log.warn("CP头像框配置为空, sysOrigin={}", sysOrigin); + return; + } + + // rewardPropsList: 第0个=男款,第1个=女款 + List rewardPropsList = resources.get(0).getPropsGroupActivityRewardProps(); + if (CollectionUtils.isEmpty(rewardPropsList) || rewardPropsList.size() < 2) { + log.warn("CP头像框配置不足2项, sysOrigin={}", sysOrigin); + return; + } + + grantAvatarFrame(cp.getUserId(), rewardPropsList, sysOrigin, cp.getCpUserId()); + grantAvatarFrame(cp.getCpUserId(), rewardPropsList, sysOrigin, cp.getUserId()); + + } catch (Exception e) { + log.error("CP升级发放头像框失败, cpValId={}", cp.getCpValId(), e); + } + } + + private void grantAvatarFrame(Long userId, List rewardPropsList, + String sysOrigin, Long cpUserId) { + UserProfile profile = userProfileGateway.getByUserId(userId); + if (profile == null) { + return; + } + // 0=女(userSex=0) -> index 1, 1=男(userSex=1) -> index 0 + int index = Objects.equals(profile.getUserSex(), 1) ? 0 : 1; + ActivityRewardProps reward = rewardPropsList.get(index); + if (reward == null || reward.getContent() == null) { + return; + } + + Long propsSourceId = Long.parseLong(reward.getContent()); + PropsResources propsResources = propsStoreGateway.getPropsResourcesById(propsSourceId); + if (propsResources == null) { + log.warn("CP头像框资源不存在, propsSourceId={}", propsSourceId); + return; + } + + propsStoreGateway.shippingProductProps(new ProductProps() + .setInitiateUserId(userId) + .setAcceptUserId(userId) + .setDays(DAYS) + .setPropsOrigin("CP_LEVEL_UP_AVATAR_FRAME") + .setPropsOriginDesc("CP level up avatar frame grant") + .setPropsResources(propsResources) + .setPropsPrices(BigDecimal.ZERO) + .setFree(Boolean.TRUE) + ); + log.info("CP升级发放头像框, userId={}, cpUserId={}, propsSourceId={}", userId, cpUserId, propsSourceId); + } + +}