vip开关设置更改
This commit is contained in:
parent
ad741c84c5
commit
2056775fff
@ -25,20 +25,31 @@ public class UserVipAbilityCmdExe {
|
|||||||
|
|
||||||
// 获取用户 VIP 等级
|
// 获取用户 VIP 等级
|
||||||
String vipLevel = userProfileGateway.getUserVipName(userId);
|
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);
|
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);
|
ContactMode finalMode = getContactMode(selectedMode, vipEnum);
|
||||||
|
|
||||||
// 构建 MongoDB 对象
|
// 构建 MongoDB 对象
|
||||||
@ -54,6 +65,18 @@ public class UserVipAbilityCmdExe {
|
|||||||
userVipAbilitySettingService.upsert(setting);
|
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
|
@NotNull
|
||||||
private static ContactMode getContactMode(ContactMode selectedMode, SysNobleVipTypeEnum vipEnum) {
|
private static ContactMode getContactMode(ContactMode selectedMode, SysNobleVipTypeEnum vipEnum) {
|
||||||
ContactMode finalMode;
|
ContactMode finalMode;
|
||||||
|
|||||||
@ -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.dto.clientobject.user.vip.UserVipAbilityCO;
|
||||||
import com.red.circle.other.app.convertor.user.UserVipAbilityAppConvertor;
|
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.domain.gateway.user.UserProfileGateway;
|
||||||
import com.red.circle.other.infra.database.mongo.entity.user.profile.UserVipAbilitySetting;
|
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.infra.database.mongo.service.user.profile.UserVipAbilitySettingService;
|
||||||
@ -9,7 +10,6 @@ import com.red.circle.other.domain.enums.VipAbilityType;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户 VIP 设置
|
* 查询用户 VIP 设置
|
||||||
@ -27,7 +27,7 @@ public class UserVipAbilityQryExe {
|
|||||||
if (setting == null) {
|
if (setting == null) {
|
||||||
setting = new UserVipAbilitySetting();
|
setting = new UserVipAbilitySetting();
|
||||||
setting.setUserId(userId);
|
setting.setUserId(userId);
|
||||||
setting.setContactMode("EVERYONE");
|
setting.setContactMode(ContactMode.EVERYONE.name());
|
||||||
setting.setKickPrevention(true);
|
setting.setKickPrevention(true);
|
||||||
setting.setMysteriousInvisibility(true);
|
setting.setMysteriousInvisibility(true);
|
||||||
setting.setAntiBlock(true);
|
setting.setAntiBlock(true);
|
||||||
|
|||||||
@ -13,15 +13,18 @@ public class UserVipAbilitySetting {
|
|||||||
@Id
|
@Id
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/**
|
/** 联系权限模式: EVERYONE / VIP2_ABOVE / VIP5_ABOVE / DO_NOT_DISTURB */
|
||||||
* 联系模式枚举: EVERYONE, VIP2_ABOVE, VIP5_ABOVE, DO_NOT_DISTURB
|
|
||||||
*/
|
|
||||||
private String contactMode;
|
private String contactMode;
|
||||||
|
|
||||||
/** 功能开关 */
|
/** 防踢开关 */
|
||||||
private Boolean kickPrevention;
|
private Boolean kickPrevention;
|
||||||
|
|
||||||
|
/** 排行榜隐身开关 */
|
||||||
private Boolean mysteriousInvisibility;
|
private Boolean mysteriousInvisibility;
|
||||||
|
|
||||||
|
/** 防拉黑开关 */
|
||||||
private Boolean antiBlock;
|
private Boolean antiBlock;
|
||||||
|
|
||||||
|
/** 最后更新时间 */
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
}
|
}
|
||||||
@ -506,10 +506,8 @@ public class UserProfileGatewayImpl implements UserProfileGateway {
|
|||||||
@Override
|
@Override
|
||||||
public boolean getUserVipAbility(Long userId, VipAbilityType abilityType) {
|
public boolean getUserVipAbility(Long userId, VipAbilityType abilityType) {
|
||||||
if (!inWhiteList(userId)) return false;
|
if (!inWhiteList(userId)) return false;
|
||||||
|
if (!abilityType.hasAbility(resolveUserVipName(userId))) return false;
|
||||||
boolean hasVipLevel = abilityType.hasAbility(resolveUserVipName(userId));
|
return userVipAbilitySettingService.isEnabled(userId, abilityType);
|
||||||
boolean switchOn = userVipAbilitySettingService.isEnabled(userId, abilityType);
|
|
||||||
return hasVipLevel && switchOn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user