diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/material/SysNobleVipTypeEnum.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/material/SysNobleVipTypeEnum.java index 1e3d2094..f7b62b4f 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/material/SysNobleVipTypeEnum.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/material/SysNobleVipTypeEnum.java @@ -65,6 +65,14 @@ public enum SysNobleVipTypeEnum { .orElse(StringUtils.UNKNOWN); } + /** 根据名称返回枚举对象,找不到返回 null */ + public static SysNobleVipTypeEnum getByName(String name) { + return Arrays.stream(SysNobleVipTypeEnum.values()) + .filter(v -> Objects.equals(v.getName(), name)) + .findFirst() + .orElse(null); + } + public String getDesc() { return desc; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/FriendCheckQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/FriendCheckQryExe.java index 02ce59c7..2ed415d1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/FriendCheckQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/FriendCheckQryExe.java @@ -1,14 +1,19 @@ package com.red.circle.other.app.command.user.query; import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; +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.sys.CustomerServiceConfig; import com.red.circle.other.infra.database.mongo.service.sys.CustomerServiceConfigService; +import com.red.circle.other.infra.database.mongo.service.user.profile.UserVipAbilitySettingService; import com.red.circle.other.infra.database.rds.service.sys.AdministratorService; import com.red.circle.other.infra.database.rds.service.user.user.RelationshipFriendService; import java.util.List; import java.util.Objects; import java.util.Set; + +import com.red.circle.other.inner.enums.material.SysNobleVipTypeEnum; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -24,8 +29,14 @@ public class FriendCheckQryExe { private final AdministratorService administratorService; private final RelationshipFriendService relationshipFriendService; private final CustomerServiceConfigService customerServiceConfigService; + private final UserVipAbilitySettingService userVipAbilitySettingService; + private final UserProfileGateway userProfileGateway; public Boolean execute(AppUserIdCmd cmd) { + Long reqUserId = cmd.requiredReqUserId(); + Long targetUserId = cmd.getUserId(); + + // 1. 管理员优先 Boolean isAdmin = administratorService.existsAvailable( Set.of(cmd.requiredReqUserId(), cmd.getUserId())); @@ -33,12 +44,35 @@ public class FriendCheckQryExe { return Boolean.TRUE; } + // 2. 客服配置优先 List configList = customerServiceConfigService.list(cmd.getReqSysOrigin().getOrigin(), ""); boolean match = configList.stream().anyMatch(c -> c.getUserId().equals(cmd.getUserId()) || c.getUserId().equals(cmd.getReqUserId())); if (match) { return Boolean.TRUE; } + // 3. ContactMode + ContactMode contactMode = userVipAbilitySettingService.getContactMode(reqUserId); + + // 4. 拒绝联系 + if (ContactMode.DO_NOT_DISTURB.equals(contactMode)) { + // 检查是否好友 + boolean isFriend = relationshipFriendService.checkFriend(reqUserId, targetUserId); + if (!isFriend) { + return Boolean.FALSE; + } + // 好友可以联系 + return Boolean.TRUE; + } + + // 5. VIP2_ABOVE / VIP5_ABOVE → 限制联系对象 VIP 等级 + String targetVipLevel = userProfileGateway.getUserVipName(targetUserId); + // 检查联系对象 VIP 等级 + SysNobleVipTypeEnum targetVip = SysNobleVipTypeEnum.getByName(targetVipLevel); + if (contactMode.getMinTargetVipLevel() != null && (targetVip == null || targetVip.ordinal() < contactMode.getMinTargetVipLevel().ordinal())) { + return false; // 目标等级不够 + } + return relationshipFriendService .checkFriend(cmd.requiredReqUserId(), cmd.getUserId()); } 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 2d926c86..081fb523 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 @@ -6,7 +6,9 @@ import com.red.circle.other.infra.database.mongo.entity.user.profile.UserVipAbil import com.red.circle.other.infra.database.mongo.service.user.profile.UserVipAbilitySettingService; import com.red.circle.other.domain.enums.VipAbilityType; import com.red.circle.other.domain.enums.ContactMode; +import com.red.circle.other.inner.enums.material.SysNobleVipTypeEnum; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; import java.util.Date; @@ -29,29 +31,20 @@ public class UserVipAbilityCmdExe { 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 单选互斥逻辑 - String contactMode = cmd.getContactMode(); - if (contactMode == null) { - contactMode = ContactMode.EVERYONE.name(); - } + // ContactMode 单选互斥逻辑,默认 EVERYONE + ContactMode selectedMode = cmd.getContactMode() != null + ? ContactMode.valueOf(cmd.getContactMode()) + : ContactMode.EVERYONE; - // DO_NOT_DISTURB 与其他模式互斥 - if (ContactMode.DO_NOT_DISTURB.name().equals(contactMode)) { - // 用户选择拒绝所有人联系 - contactMode = ContactMode.DO_NOT_DISTURB.name(); - } else { - // 非 VIP 等级不可选择高级模式 - if (ContactMode.VIP2_ABOVE.name().equals(contactMode) && (vipLevel == null || vipLevel.compareTo("EARL") < 0)) { - contactMode = ContactMode.EVERYONE.name(); - } else if (ContactMode.VIP5_ABOVE.name().equals(contactMode) && (vipLevel == null || vipLevel.compareTo("KING") < 0)) { - contactMode = ContactMode.EVERYONE.name(); - } - } + // 获取用户 VIP 等级枚举 + SysNobleVipTypeEnum vipEnum = SysNobleVipTypeEnum.getByName(vipLevel); + + ContactMode finalMode = getContactMode(selectedMode, vipEnum); // 构建 MongoDB 对象 UserVipAbilitySetting setting = new UserVipAbilitySetting(); setting.setUserId(userId); - setting.setContactMode(contactMode); + setting.setContactMode(String.valueOf(finalMode)); setting.setKickPrevention(kickPrevention); setting.setMysteriousInvisibility(mysteriousInvisibility); setting.setAntiBlock(antiBlock); @@ -60,4 +53,25 @@ public class UserVipAbilityCmdExe { // 执行 upsert userVipAbilitySettingService.upsert(setting); } + + @NotNull + private static ContactMode getContactMode(ContactMode selectedMode, SysNobleVipTypeEnum vipEnum) { + ContactMode finalMode; + + if (selectedMode == ContactMode.DO_NOT_DISTURB) { + // 用户选择拒绝所有人联系,直接生效 + finalMode = ContactMode.DO_NOT_DISTURB; + } else if (selectedMode.getMinTargetVipLevel() != null) { + // 高等级模式,检查 VIP 等级是否满足要求 + if (vipEnum == null || vipEnum.ordinal() < selectedMode.getMinTargetVipLevel().ordinal()) { + finalMode = ContactMode.EVERYONE; // 等级不足回退 + } else { + finalMode = selectedMode; // 等级足够 + } + } else { + // 普通模式或没有限制 + finalMode = selectedMode; + } + return finalMode; + } } \ No newline at end of file diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/enums/ContactMode.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/enums/ContactMode.java index c5a60946..8176362e 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/enums/ContactMode.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/enums/ContactMode.java @@ -1,8 +1,32 @@ package com.red.circle.other.domain.enums; +import com.red.circle.other.inner.enums.material.SysNobleVipTypeEnum; + +/** + * 联系权限模式 + */ public enum ContactMode { - EVERYONE, - VIP2_ABOVE, - VIP5_ABOVE, - DO_NOT_DISTURB + + /** 所有人可联系 */ + EVERYONE(null), + + /** 仅 VIP2 及以上可联系 */ + VIP2_ABOVE(SysNobleVipTypeEnum.EARL), + + /** 仅 VIP5 及以上可联系 */ + VIP5_ABOVE(SysNobleVipTypeEnum.KING), + + /** 拒绝非好友联系 */ + DO_NOT_DISTURB(null); + + /** 最低允许被联系的 VIP 等级,null 表示不限制 */ + private final SysNobleVipTypeEnum minTargetVipLevel; + + ContactMode(SysNobleVipTypeEnum minTargetVipLevel) { + this.minTargetVipLevel = minTargetVipLevel; + } + + public SysNobleVipTypeEnum getMinTargetVipLevel() { + return minTargetVipLevel; + } } \ No newline at end of file