From 56e36531bf12da9d979d4a1fa25e7fe3a042df6f Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Tue, 11 Nov 2025 16:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=B6=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E7=9A=84VIP=E9=81=93=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserRunProfileTransportGatewayImpl.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java index 909cfdc9..8ccfc155 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java @@ -2,8 +2,10 @@ package com.red.circle.other.infra.gateway.user; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.red.circle.other.domain.gateway.props.PropsNobleVipGateway; import com.red.circle.other.domain.gateway.user.UserRunProfileTransportGateway; import com.red.circle.other.domain.model.user.UserProfile; +import com.red.circle.other.infra.common.props.PropsBackpackCommon; import com.red.circle.other.infra.common.props.UserBadgeCommon; import com.red.circle.other.infra.convertor.material.BadgeInfraConvertor; import com.red.circle.other.infra.convertor.material.PropsResourcesInfraConvertor; @@ -14,6 +16,7 @@ import com.red.circle.other.infra.database.mongo.entity.user.profile.UserRunProf import com.red.circle.other.infra.database.mongo.entity.user.profile.UserSpecialId; import com.red.circle.other.infra.database.mongo.service.user.profile.UserRunProfileService; import com.red.circle.other.infra.database.mongo.service.user.profile.UserSpecialIdService; +import com.red.circle.other.infra.database.rds.entity.props.PropsBackpack; import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo; import com.red.circle.other.infra.database.rds.service.badge.BadgeConfigService; import com.red.circle.other.infra.database.rds.service.badge.BadgePictureConfigService; @@ -33,9 +36,12 @@ import com.red.circle.other.inner.model.dto.material.RoomThemeUserBackpackDTO; import com.red.circle.other.inner.model.dto.material.RoomThemeUserCustomizeDTO; import com.red.circle.other.inner.model.dto.material.UseBadgeDTO; import com.red.circle.other.inner.model.dto.material.UsePropsDTO; +import com.red.circle.other.inner.model.dto.material.props.PropsNobleVipAbilityDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.json.JacksonUtils; + +import java.sql.Timestamp; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -63,6 +69,8 @@ public class UserRunProfileTransportGatewayImpl implements UserRunProfileTranspo private final UserBadgeCommon userBadgeCommon; private final BadgeConfigService badgeConfigService; private final BadgeInfraConvertor badgeInfraConvertor; + private final PropsNobleVipGateway propsNobleVipGateway; + private final PropsBackpackCommon propsBackpackCommon; private final PropsBackpackService propsBackpackService; private final UserSpecialIdService userSpecialIdService; private final UserRunProfileService userRunProfileService; @@ -308,6 +316,9 @@ public class UserRunProfileTransportGatewayImpl implements UserRunProfileTranspo } private Map> mapUserUsePropsEntity(Set userIds) { + // 自动切换过期VIP + autoSwitchExpiredVipBatch(userIds); + return Optional.ofNullable(this.listUserUsePropsEntity(userIds)) .map(userUsePropsEntities -> userUsePropsEntities.stream() .collect(Collectors.groupingBy(UsePropsDTO::getUserId))) @@ -338,6 +349,70 @@ public class UserRunProfileTransportGatewayImpl implements UserRunProfileTranspo .filter(Objects::nonNull).toList(); } + /** + * 批量自动切换用户过期VIP + */ + private void autoSwitchExpiredVipBatch(Set userIds) { + if (CollectionUtils.isEmpty(userIds)) { + return; + } + + for (Long userId : userIds) { + try { + autoSwitchExpiredVip(userId); + } catch (Exception e) { + log.error("批量自动切换VIP失败, userId={}", userId, e); + } + } + } + + /** + * 自动切换用户过期VIP到下一个可用VIP + */ + private void autoSwitchExpiredVip(Long userId) { + if (userId == null) { + return; + } + + // 1. 查询当前正在使用的VIP + PropsBackpack currentVip = propsBackpackService.getUserNotExpiredUseProps(userId, PropsCommodityType.NOBLE_VIP); + + // 2. 检查当前VIP是否过期 + Timestamp now = TimestampUtils.now(); + if (currentVip != null && currentVip.getExpireTime().after(now)) { + // 当前VIP未过期,无需切换 + return; + } + + // 3. 如果当前VIP已过期,卸下它 + if (currentVip != null) { + propsBackpackService.unloadUseProps(userId, PropsCommodityType.NOBLE_VIP); + log.info("用户VIP已过期并卸下, userId={}, propsId={}, expireTime={}", + userId, currentVip.getPropsId(), currentVip.getExpireTime()); + } + + // 4. 使用最高等级的可用VIP + useMaxNobleVip(userId); + } + + /** + * 切换到最高等级VIP + */ + private void useMaxNobleVip(Long userId) { + PropsNobleVipAbilityDTO abilityDTO = propsNobleVipGateway.getUserMaxAbilityDTO(userId); + if (Objects.isNull(abilityDTO)) { + log.info("用户没有可用的VIP道具, userId={}", userId); + return; + } + + propsBackpackCommon.switchUseProps(userId, abilityDTO.getId()); + propsBackpackCommon.switchUseProps(userId, abilityDTO.getAvatarFrameId()); + propsBackpackCommon.switchUseProps(userId, abilityDTO.getDataCardId()); + propsBackpackCommon.switchUseProps(userId, abilityDTO.getCarId()); + + log.info("自动切换到最高等级VIP, userId={}, vipId={}", userId, abilityDTO.getId()); + } + private UsePropsDTO mergeUserUsePropsEntity( Map propsSourceRecordMap, PropsBackpackDTO propsBackpack) { UsePropsDTO entity = new UsePropsDTO();