cpList 新增发送头像框逻辑

(cherry picked from commit 2326e8659bb1805b1821b7086cf60450771099bc)
This commit is contained in:
tianfeng 2026-04-29 19:46:12 +08:00
parent 43ccad87ce
commit 5faf9f0713
3 changed files with 134 additions and 0 deletions

View File

@ -225,4 +225,9 @@ public enum PropsActivityTypeEnum {
GAME_KING_HONOR,
/**
* CP头像框道具配置按性别第0个男第1个女.
*/
CP_AVATAR,
}

View File

@ -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);

View File

@ -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<ActivityResource> resources = activitySourceGroupGateway.listActivityResource(
SysOriginPlatformEnum.valueOf(sysOrigin), PropsActivityTypeEnum.CP_AVATAR);
if (CollectionUtils.isEmpty(resources)) {
log.warn("CP头像框配置为空, sysOrigin={}", sysOrigin);
return;
}
// rewardPropsList: 第0个=男款第1个=女款
List<ActivityRewardProps> 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<ActivityRewardProps> 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);
}
}