From cbab245b549cb86b5de7ea1efb734a7606c1991a Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 30 Jan 2026 16:09:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=9B=B8=E5=85=B3=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E7=AE=80=E5=8C=96userProfile=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E7=82=B9=E8=B5=9E=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=B9=B4=E9=BE=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/dto/user/UserSimpleProfileDTO.java | 142 ++++++++++++++++++ .../dynamic/query/DynamicFollowQryExe.java | 6 +- .../dynamic/query/DynamicLatestQryExe.java | 11 +- .../dynamic/query/DynamicLikeQryExe.java | 1 + .../dynamic/query/DynamicListQryByTagExe.java | 11 +- .../dynamic/query/DynamicPopularQryExe.java | 6 +- .../user/UserProfileAppConvertor.java | 78 ++++++++++ .../dynamic/DynamicLikeListCO.java | 2 + .../clientobject/dynamic/DynamicListCO.java | 7 +- 9 files changed, 244 insertions(+), 20 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/UserSimpleProfileDTO.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserSimpleProfileDTO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserSimpleProfileDTO.java new file mode 100644 index 00000000..53140314 --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserSimpleProfileDTO.java @@ -0,0 +1,142 @@ +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 java.io.Serial; +import java.io.Serializable; +import java.util.List; +import lombok.Data; + +/** + * 用户简化资料(用于动态列表等场景,减少数据传输量). + * + * @author pengshigang + * @since 2025-01-29 + */ +@Data +public class UserSimpleProfileDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 用户id. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 账号. + */ + private String account; + + /** + * 头像. + */ + private String userAvatar; + + /** + * 用户昵称. + */ + private String userNickname; + + private Integer age; + + /** + * 用户性别:0 女,1 男. + */ + private Integer userSex; + + /** + * 靓号信息. + */ + private OwnSpecialIdDTO ownSpecialId; + + /** + * 使用的道具(仅包含贵族VIP类型). + */ + private List useProps; + + /** + * 佩戴的勋章. + */ + private List wearBadge; + + /** + * 简化的道具信息. + */ + @Data + public static class SimplePropsDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 道具类型. + */ + private String type; + + /** + * 道具名称. + */ + private String name; + + /** + * 封面图. + */ + private String cover; + + /** + * 资源链接. + */ + private String sourceUrl; + + /** + * 扩展内容. + */ + private String expand; + + /** + * 过期时间. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long expireTime; + } + + /** + * 简化的勋章信息. + */ + @Data + public static class SimpleBadgeDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 主键标识. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 徽章名称. + */ + private String name; + + /** + * 选中url. + */ + private String selectUrl; + + /** + * 没有选中的url. + */ + private String notSelectUrl; + + /** + * 动画链接. + */ + private String animationUrl; + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicFollowQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicFollowQryExe.java index 86ce77dd..17401a19 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicFollowQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicFollowQryExe.java @@ -23,6 +23,7 @@ import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTimelineService; import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptionService; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.inner.model.dto.user.UserSimpleProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.num.NumUtils; import java.util.List; @@ -93,7 +94,7 @@ public class DynamicFollowQryExe { Map contentMap = mapDynamicContent(contentList); Map likeQuantityMap = dynamicLikeService.mapLikeQuantity(contentIds); Map tagMap = dynamicTagService.mapByIds(getTagIds(contentList)); - Map userProfileMap = userProfileGateway.mapByUserIds(userIds); + Map userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds)); Map commentQuantityMap = dynamicCommentService.mapCommentQuantity(contentIds); Map> pictureMap = dynamicPictureService.mapPreviewGroup(contentIds); @@ -110,8 +111,7 @@ public class DynamicFollowQryExe { } DynamicListCO result = new DynamicListCO(); - UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO( - userProfileMap.get(dynamic.getCreateUser())); + UserSimpleProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); if (Objects.nonNull(userProfile)) { result.setUserProfile(userProfile); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLatestQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLatestQryExe.java index 657ccade..dfd394ce 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLatestQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLatestQryExe.java @@ -7,6 +7,7 @@ import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO; import com.red.circle.other.app.dto.cmd.dynamic.DynamicLimitCmd; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; +import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicContent; import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicPicture; import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicTag; @@ -17,6 +18,7 @@ import com.red.circle.other.infra.database.rds.service.dynamic.DynamicPictureSer import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService; import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptionService; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.inner.model.dto.user.UserSimpleProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.num.NumUtils; import java.util.List; @@ -73,15 +75,14 @@ public class DynamicLatestQryExe { Map subscriptionMap = getSubscriptionMap(cmd, userIds); Map likeQuantityMap = dynamicLikeService.mapLikeQuantity(ids); Map tagMap = dynamicTagService.mapByIds(getTagIds(dynamics)); - Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( - userProfileGateway.mapByUserIds(userIds)); + Map userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds)); Map commentQuantityMap = dynamicCommentService.mapCommentQuantity(ids); Map> pictureMap = dynamicPictureService.mapPreviewGroup(ids); return dynamics.convert(dynamic -> { DynamicListCO result = new DynamicListCO(); - UserProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); + UserSimpleProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); result.setUserProfile(userProfile); processUser(userProfile, result); processBase(dynamic, result, pictureMap); @@ -118,10 +119,10 @@ public class DynamicLatestQryExe { DynamicPopularQryExe.processBaseDetails(dynamic, result, pictureMap); } - private void processUser(UserProfileDTO userProfile, DynamicListCO result) { + private void processUser(UserSimpleProfileDTO userProfile, + DynamicListCO result) { result.setUserId(userProfile.getId()); result.setUserAvatar(userProfile.getUserAvatar()); - result.setUserSex(userProfile.getUserSex()); result.setUserNickname(userProfile.getUserNickname()); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLikeQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLikeQryExe.java index c19ee0bd..f59ef462 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLikeQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLikeQryExe.java @@ -56,6 +56,7 @@ public class DynamicLikeQryExe { listCO.setUserAvatar(createUser.getUserAvatar()); listCO.setUserNickname(createUser.getUserNickname()); listCO.setUserSex(createUser.getUserSex()); + listCO.setAge(createUser.getAge()); listCO.setUserId(createUser.getId()); listCO.setId(like.getId()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicListQryByTagExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicListQryByTagExe.java index 83c52a75..9f822c22 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicListQryByTagExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicListQryByTagExe.java @@ -15,6 +15,7 @@ import com.red.circle.other.infra.database.rds.service.dynamic.DynamicPictureSer import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService; import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptionService; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.inner.model.dto.user.UserSimpleProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.num.NumUtils; import java.util.List; @@ -67,20 +68,18 @@ public class DynamicListQryByTagExe { Map subscriptionMap = getSubscriptionMap(cmd, userIds); Map likeQuantityMap = dynamicLikeService.mapLikeQuantity(ids); Map tagMap = dynamicTagService.mapByIds(getTagIds(dynamics)); - Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( - userProfileGateway.mapByUserIds(userIds) - ); + Map userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds)); Map commentQuantityMap = dynamicCommentService.mapCommentQuantity(ids); Map> pictureMap = dynamicPictureService.mapPreviewGroup(ids); return dynamics.stream().map(dynamic -> { - UserProfileDTO baseInfo = userProfileMap.get(dynamic.getCreateUser()); + UserSimpleProfileDTO baseInfo = userProfileMap.get(dynamic.getCreateUser()); if (Objects.isNull(baseInfo)) { return null; } DynamicListCO result = new DynamicListCO(); - UserProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); + UserSimpleProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); if (Objects.nonNull(userProfile)) { result.setUserProfile(userProfile); } @@ -117,7 +116,7 @@ public class DynamicListQryByTagExe { DynamicPopularQryExe.processBaseDetails(dynamic, result, pictureMap); } - private void processUser(UserProfileDTO baseInfo, DynamicListCO result) { + private void processUser(UserSimpleProfileDTO baseInfo, DynamicListCO result) { result.setUserId(baseInfo.getId()); result.setUserAvatar(baseInfo.getUserAvatar()); result.setUserSex(baseInfo.getUserSex()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicPopularQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicPopularQryExe.java index 9b88c531..a04388f7 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicPopularQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicPopularQryExe.java @@ -26,6 +26,7 @@ import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService import com.red.circle.other.infra.database.rds.service.dynamic.TopDynamicService; import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptionService; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.inner.model.dto.user.UserSimpleProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.num.NumUtils; import java.util.List; @@ -118,8 +119,7 @@ public class DynamicPopularQryExe { Map subscriptionMap = getSubscriptionMap(cmd, userIds); Map likeQuantityMap = dynamicLikeService.mapLikeQuantity(tmpContentIds); Map tagMap = dynamicTagService.mapByIds(getTagIds(resultList)); - Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( - userProfileGateway.mapByUserIds(userIds)); + Map userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds)); Map commentQuantityMap = dynamicCommentService.mapCommentQuantity(tmpContentIds); Map> pictureMap = dynamicPictureService.mapPreviewGroup( tmpContentIds); @@ -131,7 +131,7 @@ public class DynamicPopularQryExe { return null; } DynamicListCO result = new DynamicListCO(); - UserProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); + UserSimpleProfileDTO userProfile = userProfileMap.get(dynamic.getCreateUser()); if (Objects.isNull(userProfile)) { return null; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/user/UserProfileAppConvertor.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/user/UserProfileAppConvertor.java index da387d2f..6d02717b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/user/UserProfileAppConvertor.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/user/UserProfileAppConvertor.java @@ -12,6 +12,7 @@ import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.domain.enums.PhotoAuditStatus; import com.red.circle.other.inner.model.dto.user.PhotoItem; +import com.red.circle.other.inner.model.dto.user.UserSimpleProfileDTO; import com.red.circle.other.inner.model.dto.user.props.UserUseBadgeDTO; import java.sql.Timestamp; import java.time.LocalDateTime; @@ -80,4 +81,81 @@ public interface UserProfileAppConvertor { .collect(Collectors.toList()); } + /** + * 自定义转换UserProfileDTO为UserSimpleProfileDTO + */ + default UserSimpleProfileDTO convertToSimpleProfile(UserProfileDTO dto) { + if (dto == null) { + return null; + } + + UserSimpleProfileDTO simple = + new UserSimpleProfileDTO(); + simple.setId(dto.getId()); + simple.setAccount(dto.getAccount()); + simple.setUserAvatar(dto.getUserAvatar()); + simple.setUserNickname(dto.getUserNickname()); + simple.setOwnSpecialId(dto.getOwnSpecialId()); + simple.setUserSex(dto.getUserSex()); + simple.setAge(dto.getAge()); + + // 过滤道具:只保留NOBLE_VIP类型 + if (dto.getUseProps() != null) { + simple.setUseProps( + dto.getUseProps().stream() + .filter(props -> props.getPropsResources() != null + && "NOBLE_VIP".equals(props.getPropsResources().getType())) + .map(props -> { + UserSimpleProfileDTO.SimplePropsDTO simpleProps = + new UserSimpleProfileDTO.SimplePropsDTO(); + simpleProps.setType(props.getPropsResources().getType()); + simpleProps.setName(props.getPropsResources().getName()); + simpleProps.setCover(props.getPropsResources().getCover()); + simpleProps.setSourceUrl(props.getPropsResources().getSourceUrl()); + simpleProps.setExpand(props.getPropsResources().getExpand()); + simpleProps.setExpireTime(props.getExpireTime()); + return simpleProps; + }) + .collect(Collectors.toList()) + ); + } + + // 简化勋章:id、name、三个url + if (dto.getWearBadge() != null) { + simple.setWearBadge( + dto.getWearBadge().stream() + .map(badge -> { + UserSimpleProfileDTO.SimpleBadgeDTO simpleBadge = + new UserSimpleProfileDTO.SimpleBadgeDTO(); + simpleBadge.setId(badge.getId()); + simpleBadge.setName(badge.getBadgeName()); + simpleBadge.setSelectUrl(badge.getSelectUrl()); + simpleBadge.setNotSelectUrl(badge.getNotSelectUrl()); + simpleBadge.setAnimationUrl(badge.getAnimationUrl()); + return simpleBadge; + }) + .collect(Collectors.toList()) + ); + } + + return simple; + } + + /** + * 批量转换为简化的用户信息 + */ + default Map convertToSimpleProfiles( + Map userProfileMap) { + if (userProfileMap == null || userProfileMap.isEmpty()) { + return java.util.Collections.emptyMap(); + } + + Map fullProfiles = toMapUserProfileDTO(userProfileMap); + return fullProfiles.entrySet().stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> convertToSimpleProfile(entry.getValue()) + )); + } + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicLikeListCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicLikeListCO.java index 21738ad0..ceaf400d 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicLikeListCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicLikeListCO.java @@ -50,6 +50,8 @@ public class DynamicLikeListCO extends ClientObject { */ private Integer userSex; + private Integer age; + /** * 用户id */ diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicListCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicListCO.java index d66148e6..75324852 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicListCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicListCO.java @@ -3,10 +3,11 @@ package com.red.circle.other.app.dto.clientobject.dynamic; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.red.circle.framework.dto.ClientObject; -import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import java.io.Serial; import java.sql.Timestamp; import java.util.List; + +import com.red.circle.other.inner.model.dto.user.UserSimpleProfileDTO; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -100,9 +101,9 @@ public class DynamicListCO extends ClientObject { private Timestamp createTime; /** - * 房主资料信息. + * 房主资料信息(简化版). */ - private UserProfileDTO userProfile; + private UserSimpleProfileDTO userProfile; /** * 是否为置顶动态(true:置顶, false:未置顶)