VIP过期导致与设置不匹配问题修复
This commit is contained in:
parent
f8d01ec784
commit
fcc8985d9a
@ -51,8 +51,11 @@ public class FriendCheckQryExe {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
// 3. 取目标用户的 ContactMode设置
|
||||
ContactMode contactMode = userVipAbilitySettingService.getContactMode(targetUserId);
|
||||
// 3. 取目标用户的 ContactMode,结合其 VIP 等级修正后取实际生效的配置
|
||||
ContactMode rawContactMode = userVipAbilitySettingService.getContactMode(targetUserId);
|
||||
String targetVipName = userProfileGateway.getUserVipName(targetUserId);
|
||||
SysNobleVipTypeEnum targetVipEnum = SysNobleVipTypeEnum.getByName(targetVipName);
|
||||
ContactMode contactMode = resolveContactMode(rawContactMode, targetVipEnum);
|
||||
|
||||
// 4. 拒绝联系
|
||||
if (ContactMode.DO_NOT_DISTURB.equals(contactMode)) {
|
||||
@ -76,4 +79,19 @@ public class FriendCheckQryExe {
|
||||
.checkFriend(cmd.requiredReqUserId(), cmd.getUserId());
|
||||
}
|
||||
|
||||
private ContactMode resolveContactMode(ContactMode mode, SysNobleVipTypeEnum vipEnum) {
|
||||
if (mode == null || mode == ContactMode.EVERYONE) {
|
||||
return ContactMode.EVERYONE;
|
||||
}
|
||||
if (mode == ContactMode.DO_NOT_DISTURB) {
|
||||
return (vipEnum != null && vipEnum.ordinal() >= SysNobleVipTypeEnum.DUKE.ordinal())
|
||||
? mode : ContactMode.EVERYONE;
|
||||
}
|
||||
if (mode.getMinTargetVipLevel() != null) {
|
||||
return (vipEnum != null && vipEnum.ordinal() >= mode.getMinTargetVipLevel().ordinal())
|
||||
? mode : ContactMode.EVERYONE;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,8 +7,10 @@ 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;
|
||||
import com.red.circle.other.domain.enums.VipAbilityType;
|
||||
import com.red.circle.other.inner.enums.material.SysNobleVipTypeEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
@ -35,24 +37,79 @@ public class UserVipAbilityQryExe {
|
||||
|
||||
// 从 Gateway 获取 VIP 等级
|
||||
String vipLevel = userProfileGateway.getUserVipName(userId);
|
||||
SysNobleVipTypeEnum vipEnum = SysNobleVipTypeEnum.getByName(vipLevel);
|
||||
|
||||
// 权限开关结合等级判断是否真正可用
|
||||
boolean kickPrevention;
|
||||
boolean mysteriousInvisibility;
|
||||
boolean antiBlock;
|
||||
ContactMode finalContactMode;
|
||||
|
||||
if (vipLevel != null) {
|
||||
setting.setKickPrevention(VipAbilityType.KICK_PREVENTION.hasAbility(vipLevel)
|
||||
&& Boolean.TRUE.equals(setting.getKickPrevention()));
|
||||
setting.setMysteriousInvisibility(VipAbilityType.MYSTERIOUS_INVISIBILITY.hasAbility(vipLevel)
|
||||
&& Boolean.TRUE.equals(setting.getMysteriousInvisibility()));
|
||||
setting.setAntiBlock(VipAbilityType.ANTI_BLOCK.hasAbility(vipLevel)
|
||||
&& Boolean.TRUE.equals(setting.getAntiBlock()));
|
||||
kickPrevention = VipAbilityType.KICK_PREVENTION.hasAbility(vipLevel)
|
||||
&& Boolean.TRUE.equals(setting.getKickPrevention());
|
||||
mysteriousInvisibility = VipAbilityType.MYSTERIOUS_INVISIBILITY.hasAbility(vipLevel)
|
||||
&& Boolean.TRUE.equals(setting.getMysteriousInvisibility());
|
||||
antiBlock = VipAbilityType.ANTI_BLOCK.hasAbility(vipLevel)
|
||||
&& Boolean.TRUE.equals(setting.getAntiBlock());
|
||||
finalContactMode = resolveContactMode(setting.getContactMode(), vipEnum);
|
||||
} else {
|
||||
setting.setContactMode(ContactMode.EVERYONE.name());
|
||||
setting.setKickPrevention(false);
|
||||
setting.setMysteriousInvisibility(false);
|
||||
setting.setAntiBlock(false);
|
||||
kickPrevention = false;
|
||||
mysteriousInvisibility = false;
|
||||
antiBlock = false;
|
||||
finalContactMode = ContactMode.EVERYONE;
|
||||
}
|
||||
|
||||
// 配置与实际不一致时持久化修正
|
||||
boolean changed = !Objects.equals(setting.getKickPrevention(), kickPrevention)
|
||||
|| !Objects.equals(setting.getMysteriousInvisibility(), mysteriousInvisibility)
|
||||
|| !Objects.equals(setting.getAntiBlock(), antiBlock)
|
||||
|| !finalContactMode.name().equals(setting.getContactMode());
|
||||
|
||||
setting.setKickPrevention(kickPrevention);
|
||||
setting.setMysteriousInvisibility(mysteriousInvisibility);
|
||||
setting.setAntiBlock(antiBlock);
|
||||
setting.setContactMode(finalContactMode.name());
|
||||
|
||||
if (changed) {
|
||||
userVipAbilitySettingService.upsert(setting);
|
||||
}
|
||||
|
||||
UserVipAbilityCO co = convertor.toUserVipAbilityCO(setting);
|
||||
co.setVipLevel(vipLevel);
|
||||
return co;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验当前 ContactMode 是否匹配用户 VIP 等级,不够则回退 EVERYONE.
|
||||
* DO_NOT_DISTURB 需要 VIP4(DUKE) 及以上,带 minTargetVipLevel 的模式需要对应等级.
|
||||
*/
|
||||
private ContactMode resolveContactMode(String contactModeStr, SysNobleVipTypeEnum vipEnum) {
|
||||
if (contactModeStr == null) {
|
||||
return ContactMode.EVERYONE;
|
||||
}
|
||||
ContactMode mode;
|
||||
try {
|
||||
mode = ContactMode.valueOf(contactModeStr);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ContactMode.EVERYONE;
|
||||
}
|
||||
if (mode == ContactMode.EVERYONE) {
|
||||
return ContactMode.EVERYONE;
|
||||
}
|
||||
// DO_NOT_DISTURB 需要 VIP4(DUKE) 及以上
|
||||
if (mode == ContactMode.DO_NOT_DISTURB) {
|
||||
if (vipEnum == null || vipEnum.ordinal() < SysNobleVipTypeEnum.DUKE.ordinal()) {
|
||||
return ContactMode.EVERYONE;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
// VIP2_ABOVE / VIP3_ABOVE / VIP4_ABOVE / VIP5_ABOVE:自身等级需 >= minTargetVipLevel
|
||||
if (mode.getMinTargetVipLevel() != null) {
|
||||
if (vipEnum == null || vipEnum.ordinal() < mode.getMinTargetVipLevel().ordinal()) {
|
||||
return ContactMode.EVERYONE;
|
||||
}
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user