动态相关列表 简化userProfile字段,点赞列表新增年龄字段

This commit is contained in:
tianfeng 2026-01-30 16:09:31 +08:00
parent 3dd2d99c22
commit cbab245b54
9 changed files with 244 additions and 20 deletions

View File

@ -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<SimplePropsDTO> useProps;
/**
* 佩戴的勋章.
*/
private List<SimpleBadgeDTO> 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;
}
}

View File

@ -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<Long, DynamicContent> contentMap = mapDynamicContent(contentList);
Map<Long, Long> likeQuantityMap = dynamicLikeService.mapLikeQuantity(contentIds);
Map<Long, DynamicTag> tagMap = dynamicTagService.mapByIds(getTagIds(contentList));
Map<Long, UserProfile> userProfileMap = userProfileGateway.mapByUserIds(userIds);
Map<Long, UserSimpleProfileDTO> userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds));
Map<Long, Integer> commentQuantityMap = dynamicCommentService.mapCommentQuantity(contentIds);
Map<Long, List<DynamicPicture>> 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);
}

View File

@ -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<Long, Boolean> subscriptionMap = getSubscriptionMap(cmd, userIds);
Map<Long, Long> likeQuantityMap = dynamicLikeService.mapLikeQuantity(ids);
Map<Long, DynamicTag> tagMap = dynamicTagService.mapByIds(getTagIds(dynamics));
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
userProfileGateway.mapByUserIds(userIds));
Map<Long, UserSimpleProfileDTO> userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds));
Map<Long, Integer> commentQuantityMap = dynamicCommentService.mapCommentQuantity(ids);
Map<Long, List<DynamicPicture>> 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());
}

View File

@ -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());

View File

@ -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<Long, Boolean> subscriptionMap = getSubscriptionMap(cmd, userIds);
Map<Long, Long> likeQuantityMap = dynamicLikeService.mapLikeQuantity(ids);
Map<Long, DynamicTag> tagMap = dynamicTagService.mapByIds(getTagIds(dynamics));
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
userProfileGateway.mapByUserIds(userIds)
);
Map<Long, UserSimpleProfileDTO> userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds));
Map<Long, Integer> commentQuantityMap = dynamicCommentService.mapCommentQuantity(ids);
Map<Long, List<DynamicPicture>> 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());

View File

@ -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<Long, Boolean> subscriptionMap = getSubscriptionMap(cmd, userIds);
Map<Long, Long> likeQuantityMap = dynamicLikeService.mapLikeQuantity(tmpContentIds);
Map<Long, DynamicTag> tagMap = dynamicTagService.mapByIds(getTagIds(resultList));
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
userProfileGateway.mapByUserIds(userIds));
Map<Long, UserSimpleProfileDTO> userProfileMap = userProfileAppConvertor.convertToSimpleProfiles(userProfileGateway.mapByUserIds(userIds));
Map<Long, Integer> commentQuantityMap = dynamicCommentService.mapCommentQuantity(tmpContentIds);
Map<Long, List<DynamicPicture>> 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;
}

View File

@ -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())
);
}
// 简化勋章idname三个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<Long, UserSimpleProfileDTO> convertToSimpleProfiles(
Map<Long, UserProfile> userProfileMap) {
if (userProfileMap == null || userProfileMap.isEmpty()) {
return java.util.Collections.emptyMap();
}
Map<Long, UserProfileDTO> fullProfiles = toMapUserProfileDTO(userProfileMap);
return fullProfiles.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> convertToSimpleProfile(entry.getValue())
));
}
}

View File

@ -50,6 +50,8 @@ public class DynamicLikeListCO extends ClientObject {
*/
private Integer userSex;
private Integer age;
/**
* 用户id
*/

View File

@ -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:未置顶)