From 2056775fff6f809388bc6801a4bfbb7e0812dae4 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 19 Mar 2026 15:17:09 +0800 Subject: [PATCH] =?UTF-8?q?vip=E5=BC=80=E5=85=B3=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/vip/UserVipAbilityCmdExe.java | 47 ++++++++++++++----- .../user/vip/UserVipAbilityQryExe.java | 4 +- .../user/profile/UserVipAbilitySetting.java | 11 +++-- .../gateway/user/UserProfileGatewayImpl.java | 6 +-- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityCmdExe.java index 081fb523..94830599 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityCmdExe.java @@ -25,20 +25,31 @@ public class UserVipAbilityCmdExe { // 获取用户 VIP 等级 String vipLevel = userProfileGateway.getUserVipName(userId); - - // 功能开关结合 VIP 等级判断是否可用 - Boolean kickPrevention = VipAbilityType.KICK_PREVENTION.hasAbility(vipLevel) && Boolean.TRUE.equals(cmd.getKickPrevention()); - Boolean mysteriousInvisibility = VipAbilityType.MYSTERIOUS_INVISIBILITY.hasAbility(vipLevel) && Boolean.TRUE.equals(cmd.getMysteriousInvisibility()); - Boolean antiBlock = VipAbilityType.ANTI_BLOCK.hasAbility(vipLevel) && Boolean.TRUE.equals(cmd.getAntiBlock()); - - // ContactMode 单选互斥逻辑,默认 EVERYONE - ContactMode selectedMode = cmd.getContactMode() != null - ? ContactMode.valueOf(cmd.getContactMode()) - : ContactMode.EVERYONE; - - // 获取用户 VIP 等级枚举 SysNobleVipTypeEnum vipEnum = SysNobleVipTypeEnum.getByName(vipLevel); + // 取已有配置,前端未传的字段保持原值 + UserVipAbilitySetting existing = userVipAbilitySettingService.findByUserId(userId); + + // 功能开关:前端传了才更新,没传保持原值;同时结合 VIP 等级限制 + Boolean kickPrevention = resolveSwitch(cmd.getKickPrevention(), + existing != null ? existing.getKickPrevention() : Boolean.TRUE, + VipAbilityType.KICK_PREVENTION.hasAbility(vipLevel)); + Boolean mysteriousInvisibility = resolveSwitch(cmd.getMysteriousInvisibility(), + existing != null ? existing.getMysteriousInvisibility() : Boolean.TRUE, + VipAbilityType.MYSTERIOUS_INVISIBILITY.hasAbility(vipLevel)); + Boolean antiBlock = resolveSwitch(cmd.getAntiBlock(), + existing != null ? existing.getAntiBlock() : Boolean.TRUE, + VipAbilityType.ANTI_BLOCK.hasAbility(vipLevel)); + + // ContactMode:前端未传保持原值 + ContactMode selectedMode; + if (cmd.getContactMode() != null) { + selectedMode = ContactMode.valueOf(cmd.getContactMode()); + } else if (existing != null && existing.getContactMode() != null) { + selectedMode = ContactMode.valueOf(existing.getContactMode()); + } else { + selectedMode = ContactMode.EVERYONE; + } ContactMode finalMode = getContactMode(selectedMode, vipEnum); // 构建 MongoDB 对象 @@ -54,6 +65,18 @@ public class UserVipAbilityCmdExe { userVipAbilitySettingService.upsert(setting); } + /** + * 前端传了值则取前端值(结合VIP等级限制),未传则保持原值. + */ + private Boolean resolveSwitch(Boolean cmdValue, Boolean existingValue, boolean hasVipLevel) { + if (cmdValue == null) { + // 未传:保持原值,但如果VIP等级不够则强制关闭 + return hasVipLevel && Boolean.TRUE.equals(existingValue); + } + // 传了:结合VIP等级 + return hasVipLevel && Boolean.TRUE.equals(cmdValue); + } + @NotNull private static ContactMode getContactMode(ContactMode selectedMode, SysNobleVipTypeEnum vipEnum) { ContactMode finalMode; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityQryExe.java index 42c4fdf5..b973d1d1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/vip/UserVipAbilityQryExe.java @@ -2,6 +2,7 @@ package com.red.circle.other.app.command.user.vip; import com.red.circle.other.app.dto.clientobject.user.vip.UserVipAbilityCO; import com.red.circle.other.app.convertor.user.UserVipAbilityAppConvertor; +import com.red.circle.other.domain.enums.ContactMode; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.infra.database.mongo.entity.user.profile.UserVipAbilitySetting; import com.red.circle.other.infra.database.mongo.service.user.profile.UserVipAbilitySettingService; @@ -9,7 +10,6 @@ import com.red.circle.other.domain.enums.VipAbilityType; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Objects; /** * 查询用户 VIP 设置 @@ -27,7 +27,7 @@ public class UserVipAbilityQryExe { if (setting == null) { setting = new UserVipAbilitySetting(); setting.setUserId(userId); - setting.setContactMode("EVERYONE"); + setting.setContactMode(ContactMode.EVERYONE.name()); setting.setKickPrevention(true); setting.setMysteriousInvisibility(true); setting.setAntiBlock(true); diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserVipAbilitySetting.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserVipAbilitySetting.java index 3e67586f..e6bb7b87 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserVipAbilitySetting.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserVipAbilitySetting.java @@ -13,15 +13,18 @@ public class UserVipAbilitySetting { @Id private Long userId; - /** - * 联系模式枚举: EVERYONE, VIP2_ABOVE, VIP5_ABOVE, DO_NOT_DISTURB - */ + /** 联系权限模式: EVERYONE / VIP2_ABOVE / VIP5_ABOVE / DO_NOT_DISTURB */ private String contactMode; - /** 功能开关 */ + /** 防踢开关 */ private Boolean kickPrevention; + + /** 排行榜隐身开关 */ private Boolean mysteriousInvisibility; + + /** 防拉黑开关 */ private Boolean antiBlock; + /** 最后更新时间 */ private Date updateTime; } \ No newline at end of file diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserProfileGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserProfileGatewayImpl.java index 59a45a83..5467b3ce 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserProfileGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserProfileGatewayImpl.java @@ -506,10 +506,8 @@ public class UserProfileGatewayImpl implements UserProfileGateway { @Override public boolean getUserVipAbility(Long userId, VipAbilityType abilityType) { if (!inWhiteList(userId)) return false; - - boolean hasVipLevel = abilityType.hasAbility(resolveUserVipName(userId)); - boolean switchOn = userVipAbilitySettingService.isEnabled(userId, abilityType); - return hasVipLevel && switchOn; + if (!abilityType.hasAbility(resolveUserVipName(userId))) return false; + return userVipAbilitySettingService.isEnabled(userId, abilityType); } @Override