cp头像报错问题修复

(cherry picked from commit 787424065a6c8d73a96a7263c6d916c20dd57ee7)
This commit is contained in:
tianfeng 2026-04-30 11:31:01 +08:00
parent 88056e3ea2
commit 5696e6fe60

View File

@ -1,17 +1,25 @@
package com.red.circle.other.infra.database.cache.service.cp.impl;
import com.alibaba.fastjson.JSON;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.other.domain.gateway.props.ActivitySourceGroupGateway;
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.cache.key.user.UserKey;
import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService;
import com.red.circle.other.infra.database.rds.entity.props.CpRingBackpack;
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo;
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.props.CpRingBackpackService;
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService;
import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService;
import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService;
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.user.CpRingDTO;
import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO;
import com.red.circle.tool.core.collection.CollectionUtils;
@ -40,6 +48,9 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic
private final BaseInfoService baseInfoService;
private final CpValueService cpValueService;
private final PropsSourceRecordService propsSourceRecordService;
private final ActivitySourceGroupGateway activitySourceGroupGateway;
private final CpRingBackpackService cpRingBackpackService;
private final UserProfileGateway userProfileGateway;
private static final long CACHE_EXPIRE_SECONDS = 7200L;
@ -76,6 +87,22 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic
.collect(Collectors.toSet());
Map<Long, BigDecimal> cpValueMap = cpValueService.mapCpVal(cpValIds);
// 批量获取CP用户头像框
Map<Long, UserProfile> longUserProfileMap = userProfileGateway.mapByUserIds(cpUserIds);
Map<Long, String> avatarFrameMap = new HashMap<>();
longUserProfileMap.forEach((uid, profile) -> {
if (profile == null || CollectionUtils.isEmpty(profile.getUseProps())) {
return;
}
String frameUrl = profile.getUseProps().stream()
.filter(p -> p.getPropsResources() != null
&& "AVATAR_FRAME".equals(p.getPropsResources().getType()))
.map(p -> p.getPropsResources().getSourceUrl())
.findFirst()
.orElse(null);
avatarFrameMap.put(uid, frameUrl);
});
// 组装CP列表
List<CpSimpleUserProfileCO> cpList = cpRelationshipList.stream()
.map(cpRelationship -> {
@ -97,7 +124,9 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic
.setCpUserId(cpUser.getId())
.setCpAccount(cpUser.getAccount())
.setCpUserAvatar(cpUser.getUserAvatar())
.setCpUserAvatarFrame(avatarFrameMap.get(cpUser.getId()))
.setCpUserNickname(cpUser.getUserNickname())
.setStatus(cpRelationship.getStatus())
.setCpValId(cpRelationship.getCpValId())
.setCpValue(cpValue)
.setCreateTime(cpRelationship.getCreateTime())
@ -106,20 +135,16 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic
// 填充等级权益
CpLevelConfig levelConfig = CpLevelConfig.of(cpValue);
if (levelConfig != null) {
co.setCpLevel(levelConfig.getLevel())
.setNextLevelExp(levelConfig.nextExpThreshold())
.setLoveHeartLevel(levelConfig.getLoveHeartLevel())
.setMicEffectLevel(levelConfig.getMicEffectLevel())
.setProfileCardLevel(levelConfig.getProfileCardLevel())
.setGiftWindowLevel(levelConfig.getGiftWindowLevel())
.setHasNonMicEffect(levelConfig.isHasNonMicEffect())
.setHasCpHeadwear(levelConfig.isHasCpHeadwear());
}
co.setCpLevel(levelConfig.getLevel())
.setNextLevelExp(CpLevelConfig.nextExpThreshold(cpValue))
.setLoveHeartLevel(levelConfig.getLoveHeartLevel())
.setMicEffectLevel(levelConfig.getMicEffectLevel())
.setProfileCardLevel(levelConfig.getProfileCardLevel())
.setGiftWindowLevel(levelConfig.getGiftWindowLevel())
.setHasNonMicEffect(levelConfig.isHasNonMicEffect());
// 实时查当前CP组生效的戒指 ring_props_id 为准
co.setSelfRing(buildCpRing(cpRelationship.getRingPropsId()));
co.setCpRing(buildCpRing(cpRelationship.getRingPropsId()));
// 实时查当前CP组生效的戒指 ring_props_id 为准无戒指时取 CP 爱心兜底
co.setSelfRing(buildCpRing(userId, cpRelationship.getCpUserId(), cpRelationship.getRingPropsId(), cpRelationship.getSysOrigin(), co.getLoveHeartLevel()));
return co;
})
@ -141,19 +166,61 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic
return UserKey.CP.getKey(userId);
}
private CpRingDTO buildCpRing(Long ringPropsId) {
if (ringPropsId == null) {
private CpRingDTO buildCpRing(Long userId, Long cpUserId, Long ringPropsId, String sysOrigin, Integer loveHeartLevel) {
// 查用户背包中对应CP的未过期戒指匹配 ringPropsId
if (ringPropsId != null) {
List<CpRingBackpack> rings = cpRingBackpackService.listNotExpired(userId, cpUserId);
CpRingBackpack matched = rings.stream()
.filter(r -> ringPropsId.equals(r.getPropsId()))
.findFirst()
.orElse(null);
if (matched != null) {
PropsSourceRecord source = propsSourceRecordService.getById(matched.getPropsId());
if (source != null) {
return new CpRingDTO()
.setPropsId(source.getId())
.setName(source.getName())
.setCover(source.getCover())
.setSourceUrl(source.getSourceUrl())
.setExpireTime(matched.getExpireTime().getTime());
}
}
}
// 无戒指时根据 loveHeartLevel 取对应等级的 CP 爱心样式
if (loveHeartLevel == null || loveHeartLevel <= 0) {
return null;
}
PropsSourceRecord source = propsSourceRecordService.getById(ringPropsId);
if (source == null) {
try {
List<ActivityResource> resources = activitySourceGroupGateway.listActivityResource(
SysOriginPlatformEnum.valueOf(sysOrigin), PropsActivityTypeEnum.CP_LOVE_HEART);
if (CollectionUtils.isEmpty(resources)) {
return null;
}
// content PropsSourceRecord idamount 对应等级 1/2/3
var rewardPropsList = resources.get(0).getPropsGroupActivityRewardProps();
if (CollectionUtils.isEmpty(rewardPropsList) || loveHeartLevel > rewardPropsList.size()) {
return null;
}
var rewardProps = rewardPropsList.get(loveHeartLevel - 1);
if (rewardProps == null || rewardProps.getContent() == null) {
return null;
}
PropsSourceRecord source = propsSourceRecordService.getById(
Long.parseLong(rewardProps.getContent()));
if (source == null) {
return null;
}
return new CpRingDTO()
.setPropsId(source.getId())
.setName(source.getName())
.setCover(source.getCover())
.setSourceUrl(source.getSourceUrl())
.setExpireTime(null);
} catch (Exception e) {
log.warn("获取CP爱心样式失败, sysOrigin={}, loveHeartLevel={}", sysOrigin, loveHeartLevel, e);
return null;
}
return new CpRingDTO()
.setPropsId(ringPropsId)
.setName(source.getName())
.setCover(source.getCover())
.setExpireTime(null);
}
@Override