diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java index 02b262e1..23ce609e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java @@ -50,10 +50,7 @@ import com.red.circle.tool.core.sequence.IdWorkerUtils; import com.red.circle.tool.core.text.StringUtils; import java.sql.Timestamp; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; @@ -319,23 +316,57 @@ public class RoomEnterCmdExe { manager.getSetting().setTakeMicRole(RoomTakeMicRoleEnum.ALL.name()); } - NobleAbilityCO userNobleAbility = userProfileGateway.getUserNobleAbility(manager.getUserId()); - String mikeType = ""; + List nobleAbilityCOList = userProfileGateway.getUserNobleAbility(manager.getUserId()); String oldMikeType = manager.getSetting().getRoomSpecialMikeType(); - if (Objects.nonNull(userNobleAbility)) { + if (StringUtils.isNotBlank(oldMikeType)) { RoomSetting setting = manager.getSetting(); - mikeType = "TYPE_VIP" + userNobleAbility.getVipLevel(); - setting.setRoomSpecialMikeType(mikeType); - manager.setSetting(setting); + Integer maxVipLevel = getMaxVipLevel(nobleAbilityCOList); + Integer oldVipLevel = extractVipLevel(oldMikeType); + + // 不一样则更新 + if (oldVipLevel > maxVipLevel) { + String mikeType = "TYPE_VIP" + maxVipLevel; + setting.setRoomSpecialMikeType(mikeType); + manager.setSetting(setting); + + roomProfileManagerService.updateSelectiveSetting(manager.getId(), + roomProfileAppConvertor.toRoomSetting(new UpdateRoomSettingCmd().setRoomId(manager.getId()).setRoomSpecialMikeType(mikeType))); + } } - // 不一样则更新 - if (!mikeType.equals(oldMikeType)) { - roomProfileManagerService.updateSelectiveSetting(manager.getId(), - roomProfileAppConvertor.toRoomSetting(new UpdateRoomSettingCmd().setRoomId(manager.getId()).setRoomSpecialMikeType(mikeType))); + } + + private Integer getMaxVipLevel(List nobleAbilityCOList) { + if (CollectionUtils.isEmpty(nobleAbilityCOList)) { + return 0; } + return nobleAbilityCOList.stream() + .filter(Objects::nonNull) + .filter(co -> co.getVipLevel() != null) + .max(Comparator.comparing(NobleAbilityCO::getVipLevel)) + .map(NobleAbilityCO::getVipLevel) + .orElse(0); } + private Integer extractVipLevel(String mikeType) { + if (StringUtils.isBlank(mikeType)) { + return 0; + } + + String numberStr = mikeType.replaceAll(".*?(\\d+)$", "$1"); + + if (StringUtils.isBlank(numberStr) || numberStr.equals(mikeType)) { + return 0; + } + + try { + return Integer.parseInt(numberStr); + } catch (NumberFormatException e) { + return 0; + } + } + + public void checkSysOrigin(Long userId, String sysOrigin) { SysOriginPlatformEnum reqUserOrigin = SysOriginPlatformEnum.valueOf( userProfileGateway.getSysOrigin(userId)); diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/user/UserProfileGateway.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/user/UserProfileGateway.java index db03e1cf..55c454ac 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/user/UserProfileGateway.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/user/UserProfileGateway.java @@ -178,7 +178,7 @@ public interface UserProfileGateway { * @param userId 用户ID * @return 贵族能力信息 */ - NobleAbilityCO getUserNobleAbility(Long userId); + List getUserNobleAbility(Long userId); /** * 修改用户签名为空. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/UserCacheService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/UserCacheService.java index 3a8667c2..4a3435b6 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/UserCacheService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/UserCacheService.java @@ -82,7 +82,7 @@ public interface UserCacheService { /** * 获取用户贵族能力. */ - NobleAbilityCO getUserNobleAbility(Long userId, Function orElseGet); + List getUserNobleAbility(Long userId, Function> orElseGet); /** * 移除权益缓存. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/impl/UserCacheServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/impl/UserCacheServiceImpl.java index 031cabf2..51f8fac2 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/impl/UserCacheServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/user/impl/UserCacheServiceImpl.java @@ -1,6 +1,7 @@ package com.red.circle.other.infra.database.cache.service.user.impl; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.google.common.collect.Lists; import com.red.circle.component.redis.service.RedisService; import com.red.circle.other.domain.model.user.NobleAbilityCO; @@ -174,8 +175,8 @@ public class UserCacheServiceImpl implements UserCacheService { } @Override - public NobleAbilityCO getUserNobleAbility(Long userId, - Function orElseGet) { + public List getUserNobleAbility(Long userId, + Function> orElseGet) { String key = UserKey.NOBLE_ABILITY.getKey(userId); @@ -183,13 +184,17 @@ public class UserCacheServiceImpl implements UserCacheService { if (StringUtils.isNotBlank(cacheValue)) { try { - return JSON.parseObject(cacheValue, NobleAbilityCO.class); + JSONArray jsonArray = JSONArray.parseArray(cacheValue); + return jsonArray.stream().map(e -> { + NobleAbilityCO nobleAbilityCO = JSON.parseObject(JSON.toJSONString(e), NobleAbilityCO.class); + return nobleAbilityCO; + }).toList(); } catch (Exception ignored) { } return null; } - NobleAbilityCO ability = orElseGet.apply(userId); + List ability = orElseGet.apply(userId); if (Objects.nonNull(ability)) { redisService.setIfAbsent(key, JSON.toJSONString(ability), 10, TimeUnit.MINUTES); 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 3b02ca65..5e602e91 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 @@ -47,14 +47,7 @@ import com.red.circle.tool.core.text.StringUtils; import com.red.circle.tool.core.thread.ThreadPoolManager; import com.red.circle.tool.core.tuple.ImmutableKeyValuePair; import java.math.BigDecimal; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -521,11 +514,11 @@ public class UserProfileGatewayImpl implements UserProfileGateway { } @Override - public NobleAbilityCO getUserNobleAbility(Long userId) { + public List getUserNobleAbility(Long userId) { return userCacheService.getUserNobleAbility(userId, this::getNobleAbility); } - private NobleAbilityCO getNobleAbility(Long userId) { + private List getNobleAbility(Long userId) { UserProfile userProfile = getByUserId(userId); if (Objects.isNull(userProfile)) { return null; @@ -542,12 +535,13 @@ public class UserProfileGatewayImpl implements UserProfileGateway { return null; } - PropsNobleVipAbility ability = vipAbilities.get(0); - NobleAbilityCO result = new NobleAbilityCO(); - result.setVipType(ability.getVipType()); - result.setVipLevel(ability.getVipLevel()); - result.setRoomMaxMember(ability.getRoomMaxMember()); - return result; + return vipAbilities.stream().map(e -> { + NobleAbilityCO result = new NobleAbilityCO(); + result.setVipType(e.getVipType()); + result.setVipLevel(e.getVipLevel()); + result.setRoomMaxMember(e.getRoomMaxMember()); + return result; + }).toList(); } /**