From cff5c76200b104e69e03e87e863b73c66403c4f7 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Mon, 27 Apr 2026 14:13:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=BA=A6=E5=85=8B=E9=A3=8E?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=92=8C=E4=B8=8A=E9=BA=A6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?cp=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 44032e2fdf57ee96bdbee9468ae29470fd187d1c) --- .../user/user/api/UserCpClientApi.java | 4 +++ .../inner/model/dto/user/CpUserInfoDTO.java | 24 +++++++++++++++ .../app/dto/clientobject/LiveMicUserCO.java | 8 ++--- .../circle/live/domain/live/LiveMicUser.java | 8 ++--- .../live/domain/live/dto/LiveMicUserDTO.java | 8 ++--- .../service/impl/LiveMicCacheServiceImpl.java | 4 --- .../repository/LiveMicrophoneGatewayImpl.java | 11 ++++--- .../user/user/UserCpClientEndpoint.java | 6 ++++ .../user/user/UserCpClientService.java | 9 ++++++ .../user/impl/UserCpClientServiceImpl.java | 30 +++++++++++++++++++ 10 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpUserInfoDTO.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java index 85b66300..57bf9230 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java @@ -5,6 +5,7 @@ import com.red.circle.framework.dto.ResultResponse; import com.red.circle.other.inner.model.cmd.user.CpApplyQryCmd; import com.red.circle.other.inner.model.cmd.user.ListLatestCpCmd; import com.red.circle.other.inner.model.dto.user.CpRelationshipDTO; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.UserCpApplyDTO; import com.red.circle.other.inner.model.dto.user.WeekCpUserIdDTO; import com.red.circle.other.inner.model.dto.user.WeekCpValueCountDTO; @@ -133,4 +134,7 @@ public interface UserCpClientApi { @PostMapping("/cpIdList") ResultResponse> getCpUserIdByUserIds(@RequestBody List userIds); + + @PostMapping("/cpInfoList") + ResultResponse>> getCpInfoByUserIds(@RequestBody List userIds); } diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpUserInfoDTO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpUserInfoDTO.java new file mode 100644 index 00000000..9130e3d9 --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpUserInfoDTO.java @@ -0,0 +1,24 @@ +package com.red.circle.other.inner.model.dto.user; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * CP用户信息. + * + * @author tf + */ +@Data +@Accessors(chain = true) +public class CpUserInfoDTO { + + /** CP用户id. */ + @JsonSerialize(using = ToStringSerializer.class) + private Long cpUserId; + + /** CP等级. */ + private Integer cpLevel; + +} diff --git a/rc-service/rc-service-live/live-client/src/main/java/com/red/circle/live/app/dto/clientobject/LiveMicUserCO.java b/rc-service/rc-service-live/live-client/src/main/java/com/red/circle/live/app/dto/clientobject/LiveMicUserCO.java index 2091dadb..5fbafa20 100644 --- a/rc-service/rc-service-live/live-client/src/main/java/com/red/circle/live/app/dto/clientobject/LiveMicUserCO.java +++ b/rc-service/rc-service-live/live-client/src/main/java/com/red/circle/live/app/dto/clientobject/LiveMicUserCO.java @@ -2,6 +2,7 @@ package com.red.circle.live.app.dto.clientobject; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.OwnSpecialIdDTO; import com.red.circle.other.inner.model.dto.user.props.UserUsePropsDTO; import java.io.Serial; @@ -28,11 +29,8 @@ public class LiveMicUserCO implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long id; - /** - * CP用户id. - */ - @JsonSerialize(using = ToStringSerializer.class) - private Long cpUserId; + /** CP列表. */ + private List cpList; /** * 账号. diff --git a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicUser.java b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicUser.java index 39bc63c1..dd051c64 100644 --- a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicUser.java +++ b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicUser.java @@ -3,6 +3,7 @@ package com.red.circle.live.domain.live; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.OwnSpecialIdDTO; import com.red.circle.other.inner.model.dto.user.props.UserUsePropsDTO; import java.io.Serial; @@ -30,11 +31,8 @@ public class LiveMicUser implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long id; - /** - * CP用户id. - */ - @JsonSerialize(using = ToStringSerializer.class) - private Long cpUserId; + /** CP列表. */ + private List cpList; /** * 账号. diff --git a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/dto/LiveMicUserDTO.java b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/dto/LiveMicUserDTO.java index 5c303a84..267747e2 100644 --- a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/dto/LiveMicUserDTO.java +++ b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/dto/LiveMicUserDTO.java @@ -2,6 +2,7 @@ package com.red.circle.live.domain.live.dto; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import java.io.Serial; import java.io.Serializable; import java.util.List; @@ -26,11 +27,8 @@ public class LiveMicUserDTO implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long id; - /** - * CP用户id. - */ - @JsonSerialize(using = ToStringSerializer.class) - private Long cpUserId; + /** CP列表. */ + private List cpList; /** * 账号. diff --git a/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicCacheServiceImpl.java b/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicCacheServiceImpl.java index eb9470fc..0695130f 100644 --- a/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicCacheServiceImpl.java +++ b/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicCacheServiceImpl.java @@ -60,11 +60,7 @@ public class LiveMicCacheServiceImpl implements LiveMicCacheService { @Override public void goUp(Long roomId, Integer index, LiveMicrophone microphone) { -// if (Objects.isNull(microphone.getRefreshTime())) { -// microphone.updateLastActivityTime(); -// } microphone.updateLastActivityTime(); - log.info("用户上麦 index = {} microphone = {} ", index, JSON.toJSONString(microphone)); redisService.hashPut(LiveMicKey.SEAT.getKey(roomId), Objects.toString(index), microphone); diff --git a/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/repository/LiveMicrophoneGatewayImpl.java b/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/repository/LiveMicrophoneGatewayImpl.java index 8ec2d2f2..affbca5f 100644 --- a/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/repository/LiveMicrophoneGatewayImpl.java +++ b/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/repository/LiveMicrophoneGatewayImpl.java @@ -42,6 +42,7 @@ import com.red.circle.other.inner.model.cmd.live.LiveHeartbeatCmd; import com.red.circle.other.inner.model.cmd.live.MemberRolesQryCmd; import com.red.circle.other.inner.model.dto.live.RoomProfileDTO; import com.red.circle.other.inner.model.dto.live.RoomProfileManagerDTO; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.WealthAndCharmLevelDTO; import com.red.circle.tool.core.collection.CollectionUtils; @@ -196,6 +197,7 @@ public class LiveMicrophoneGatewayImpl implements LiveMicrophoneGateway { micUser.setCharmLevel(body.getCharmLevel()); micUser.setWealthLevel(body.getWealthLevel()); } + micUser.setCpList(userCpClient.getCpInfoByUserIds(List.of(userId)).getBody().get(userId)); LiveMicrophone liveMicrophone = new LiveMicrophone() .setMicIndex(micSeat.getMicIndex()) @@ -599,8 +601,6 @@ public class LiveMicrophoneGatewayImpl implements LiveMicrophoneGateway { private Map mapLiveMicrophone(Long roomId) { List liveMicrophones = liveMicCacheService.listLiveMicrophone(roomId); - log.info("在线取麦克风列表信息 -列表: {}", liveMicrophones); - //获取房间用户心动值 Map liveHeartbeatMap = getLiveHeartbeatMap(liveHeartbeatClient.listLiveHeartbeat(roomId).getBody()); if (CollectionUtils.isEmpty(liveMicrophones)) { return CollectionUtils.newHashMap(); @@ -609,13 +609,12 @@ public class LiveMicrophoneGatewayImpl implements LiveMicrophoneGateway { List liveMicUsers = liveMicrophones.stream().map(LiveMicrophone::getUser).toList(); List userIds = liveMicUsers.stream().map(LiveMicUser::getId).toList(); updateLiveMicrophoneUserInfo(liveMicrophones, roomId, userIds); - Map cpUserIdMap = userCpClient.getCpUserIdByUserIds(userIds).getBody(); - log.info("用户ID集合={}, 结果集cpUserIdMap = {}", userIds, cpUserIdMap); + Map> cpInfoMap = userCpClient.getCpInfoByUserIds(userIds).getBody(); return liveMicrophones.stream() .peek(liveMicrophone -> { LiveMicUser user = liveMicrophone.getUser(); - user.setHeartbeatVal(Objects.nonNull(liveHeartbeatMap.get(user.getId()))? liveHeartbeatMap.get(user.getId()):0L); - user.setCpUserId(Objects.nonNull(cpUserIdMap.get(user.getId()))? cpUserIdMap.get(user.getId()):0L); + user.setHeartbeatVal(Objects.nonNull(liveHeartbeatMap.get(user.getId())) ? liveHeartbeatMap.get(user.getId()) : 0L); + user.setCpList(cpInfoMap.get(user.getId())); liveMicrophone.setUser(user); }) .collect(Collectors.toMap(LiveMicrophone::getMicIndex, v -> v)); diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java index 9448aba4..6d16f35f 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java @@ -7,6 +7,7 @@ import com.red.circle.tool.core.text.StringUtils; import com.red.circle.other.inner.model.cmd.user.CpApplyQryCmd; import com.red.circle.other.inner.model.cmd.user.ListLatestCpCmd; import com.red.circle.other.inner.model.dto.user.CpRelationshipDTO; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.UserCpApplyDTO; import com.red.circle.other.inner.model.dto.user.WeekCpUserIdDTO; import com.red.circle.other.inner.model.dto.user.WeekCpValueCountDTO; @@ -155,4 +156,9 @@ public class UserCpClientEndpoint implements UserCpClientApi { public ResultResponse> getCpUserIdByUserIds(List userIds) { return ResultResponse.success(userCpClientService.getCpUserIdByUserIds(userIds)); } + + @Override + public ResultResponse>> getCpInfoByUserIds(List userIds) { + return ResultResponse.success(userCpClientService.getCpInfoByUserIds(userIds)); + } } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpClientService.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpClientService.java index ba49eda2..56269996 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpClientService.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpClientService.java @@ -4,6 +4,7 @@ package com.red.circle.other.app.inner.service.user.user; import com.red.circle.framework.dto.PageResult; import com.red.circle.other.inner.model.cmd.user.CpApplyQryCmd; import com.red.circle.other.inner.model.dto.user.CpRelationshipDTO; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.UserCpApplyDTO; import java.math.BigDecimal; import java.util.List; @@ -70,4 +71,12 @@ public interface UserCpClientService { * @return cp用户id */ Map getCpUserIdByUserIds(List userIds); + + /** + * 批量获取cp用户信息(含cpUserId和cpLevel). + * + * @param userIds 用户id列表 + * @return userId -> List + */ + Map> getCpInfoByUserIds(List userIds); } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java index 8462e8cc..dc0adbc6 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java @@ -2,6 +2,7 @@ package com.red.circle.other.app.inner.service.user.user.impl; import com.red.circle.framework.dto.PageResult; import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService; +import com.red.circle.other.infra.database.rds.entity.user.user.CpLevelConfig; import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; @@ -9,12 +10,15 @@ import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; import com.red.circle.other.app.inner.convertor.user.UserCpInnerConvertor; import com.red.circle.other.inner.model.cmd.user.CpApplyQryCmd; import com.red.circle.other.inner.model.dto.user.CpRelationshipDTO; +import com.red.circle.other.inner.model.dto.user.CpUserInfoDTO; import com.red.circle.other.inner.model.dto.user.UserCpApplyDTO; import com.red.circle.other.app.inner.service.user.user.UserCpClientService; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import com.red.circle.tool.core.collection.CollectionUtils; import lombok.RequiredArgsConstructor; @@ -89,4 +93,30 @@ public class UserCpClientServiceImpl implements UserCpClientService { HashMap::putAll); } + @Override + public Map> getCpInfoByUserIds(List userIds) { + if (CollectionUtils.isEmpty(userIds)) { + return new HashMap<>(); + } + List list = cpRelationshipService.query() + .select(CpRelationship::getUserId, CpRelationship::getCpUserId, CpRelationship::getCpValId) + .in(CpRelationship::getUserId, userIds) + .list(); + if (CollectionUtils.isEmpty(list)) { + return new HashMap<>(); + } + Set cpValIds = list.stream().map(CpRelationship::getCpValId).collect(Collectors.toSet()); + Map cpValueMap = cpValueService.mapCpVal(cpValIds); + return list.stream() + .collect(Collectors.groupingBy( + CpRelationship::getUserId, + Collectors.mapping(v -> { + BigDecimal cpVal = cpValueMap.getOrDefault(v.getCpValId(), BigDecimal.ZERO); + return new CpUserInfoDTO() + .setCpUserId(v.getCpUserId()) + .setCpLevel(CpLevelConfig.of(cpVal).getLevel()); + }, Collectors.toList()) + )); + } + }