diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/dynamic/DynamicRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/dynamic/DynamicRestController.java index 5bbb397d..659cbce7 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/dynamic/DynamicRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/dynamic/DynamicRestController.java @@ -8,11 +8,7 @@ import com.red.circle.common.business.dto.cmd.IdLongCmd; import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.web.controller.BaseController; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicCommentListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicMessageListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicSendRestrictCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicTagCO; +import com.red.circle.other.app.dto.clientobject.dynamic.*; import com.red.circle.other.app.dto.cmd.dynamic.*; import com.red.circle.other.app.service.dynamic.DynamicService; import java.util.List; @@ -91,6 +87,19 @@ public class DynamicRestController extends BaseController { return dynamicService.listDynamicChildComment(cmd); } + /** + * 动态点赞列表. + * + * @eo.name 动态点赞列表. + * @eo.url /list/like + * @eo.method get + * @eo.request-type formdata + */ + @GetMapping("/list/like") + public PageResult listDynamicLike(@Validated DynamicLikeLimitCmd cmd) { + return dynamicService.listDynamicLike(cmd); + } + /** * 动态内容详情. * 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 new file mode 100644 index 00000000..c19ee0bd --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicLikeQryExe.java @@ -0,0 +1,81 @@ +package com.red.circle.other.app.command.dynamic.query; + +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.dto.PageResult; +import com.red.circle.other.app.dto.clientobject.dynamic.DynamicLikeListCO; +import com.red.circle.other.app.dto.cmd.dynamic.DynamicLikeLimitCmd; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +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.DynamicLike; +import com.red.circle.other.infra.database.rds.service.dynamic.DynamicContentService; +import com.red.circle.other.infra.database.rds.service.dynamic.DynamicLikeService; +import com.red.circle.other.inner.asserts.DynamicErrorCode; +import com.red.circle.tool.core.collection.CollectionUtils; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +/** + * 动态点赞列表查询. + * + * @author pengshigang + * @since 2025-01-29 + */ +@Component +@RequiredArgsConstructor +public class DynamicLikeQryExe { + + private final UserProfileGateway userProfileGateway; + private final DynamicContentService dynamicContentService; + private final DynamicLikeService dynamicLikeService; + + public PageResult execute(DynamicLikeLimitCmd cmd) { + + DynamicContent dynamicContent = dynamicContentService.getById(cmd.getDynamicId()); + ResponseAssert.notNull(DynamicErrorCode.CONTENT_IS_NULL, dynamicContent); + ResponseAssert.isFalse(DynamicErrorCode.CONTENT_DELETE, dynamicContent.getDel()); + + PageResult likes = pageData(cmd); + if (CollectionUtils.isEmpty(likes.getRecords())) { + return PageResult.newPageResult(0); + } + + Map userMap = userProfileGateway.mapByUserIds(getUserIds(likes)); + + return likes.convert(like -> { + + DynamicLikeListCO listCO = new DynamicLikeListCO(); + UserProfile createUser = userMap.get(like.getCreateUser()); + if (Objects.isNull(createUser)) { + return null; + } + listCO.setUserAvatar(createUser.getUserAvatar()); + listCO.setUserNickname(createUser.getUserNickname()); + listCO.setUserSex(createUser.getUserSex()); + listCO.setUserId(createUser.getId()); + + listCO.setId(like.getId()); + listCO.setDynamicId(like.getDynamicContentId()); + listCO.setCreateTime(like.getCreateTime()); + + return listCO; + + }); + } + + private Set getUserIds(PageResult likes) { + return likes.getRecords().stream() + .map(DynamicLike::getCreateUser) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + } + + private PageResult pageData(DynamicLikeLimitCmd cmd) { + return dynamicLikeService.pageByTimeDesc(cmd.getPageReq(), cmd.getDynamicId()); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/dynamic/DynamicServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/dynamic/DynamicServiceImpl.java index fcffc861..ac5ace25 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/dynamic/DynamicServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/dynamic/DynamicServiceImpl.java @@ -20,6 +20,7 @@ import com.red.circle.other.app.command.dynamic.delete.DynamicMessageAllDelCmdEx import com.red.circle.other.app.command.dynamic.delete.DynamicMessageDelCmdExe; import com.red.circle.other.app.command.dynamic.query.DynamicChildCommentQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicCommentQryExe; +import com.red.circle.other.app.command.dynamic.query.DynamicLikeQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicDetailsQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicFollowQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicLatestQryExe; @@ -28,11 +29,7 @@ import com.red.circle.other.app.command.dynamic.query.DynamicMessageQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicMyQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicPopularQryExe; import com.red.circle.other.app.command.dynamic.query.DynamicTagQryExe; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicCommentListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicMessageListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicSendRestrictCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicTagCO; +import com.red.circle.other.app.dto.clientobject.dynamic.*; import com.red.circle.other.app.dto.cmd.dynamic.*; import java.util.List; @@ -64,6 +61,7 @@ public class DynamicServiceImpl implements DynamicService { private final DynamicDetailsQryExe dynamicDetailsQryExe; private final DynamicCommentQryExe dynamicCommentQryExe; private final DynamicChildCommentQryExe dynamicChildCommentQryExe; + private final DynamicLikeQryExe dynamicLikeQryExe; private final DynamicCommentDelCmdExe dynamicCommentDelExe; private final DynamicCommentLikeCmdExe dynamicCommentLikeExe; private final DynamicContentDelCmdExe dynamicContentDelExe; @@ -96,6 +94,11 @@ public class DynamicServiceImpl implements DynamicService { return dynamicChildCommentQryExe.execute(cmd); } + @Override + public PageResult listDynamicLike(DynamicLikeLimitCmd cmd) { + return dynamicLikeQryExe.execute(cmd); + } + @Override public DynamicListCO getDynamicDetails(IdLongCmd cmd) { return dynamicDetailsQryExe.execute(cmd); 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 new file mode 100644 index 00000000..21738ad0 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/dynamic/DynamicLikeListCO.java @@ -0,0 +1,64 @@ +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 java.io.Serial; +import java.sql.Timestamp; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 动态点赞列表. + * + * @author pengshigang + * @since 2025-01-29 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +public class DynamicLikeListCO extends ClientObject { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 点赞id. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 动态内容id. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long dynamicId; + + /** + * 用户头像. + */ + private String userAvatar; + + /** + * 用户昵称. + */ + private String userNickname; + + /** + * 用户性别:0 女,1 男. + */ + private Integer userSex; + + /** + * 用户id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long userId; + + /** + * 创建时间. + */ + private Timestamp createTime; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicLikeLimitCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicLikeLimitCmd.java new file mode 100644 index 00000000..7ca99146 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicLikeLimitCmd.java @@ -0,0 +1,35 @@ +package com.red.circle.other.app.dto.cmd.dynamic; + +import com.red.circle.common.business.dto.PageReq; +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 动态-点赞列表. + * + * @author pengshigang + * @since 2025-01-29 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class DynamicLikeLimitCmd extends AppExtCommand { + + /** + * 页码. + * + * @eo.required + */ + @NotNull + private PageReq pageReq; + + /** + * 动态内容id. + * + * @eo.required + */ + @NotNull + private Long dynamicId; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/dynamic/DynamicService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/dynamic/DynamicService.java index 639d3d8a..79567454 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/dynamic/DynamicService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/dynamic/DynamicService.java @@ -5,11 +5,7 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.common.business.dto.cmd.IdLongCmd; import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; import com.red.circle.framework.dto.PageResult; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicCommentListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicMessageListCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicSendRestrictCO; -import com.red.circle.other.app.dto.clientobject.dynamic.DynamicTagCO; +import com.red.circle.other.app.dto.clientobject.dynamic.*; import com.red.circle.other.app.dto.cmd.dynamic.*; import java.util.List; @@ -45,6 +41,11 @@ public interface DynamicService { */ PageResult listDynamicChildComment(DynamicChildCommentLimitCmd cmd); + /** + * 动态点赞列表. + */ + PageResult listDynamicLike(DynamicLikeLimitCmd cmd); + /** * 动态内容详情. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicLikeService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicLikeService.java index 68e25ba7..9fa83783 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicLikeService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicLikeService.java @@ -1,5 +1,7 @@ package com.red.circle.other.infra.database.rds.service.dynamic; +import com.red.circle.framework.dto.PageQuery; +import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.mybatis.service.BaseService; import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicLike; import java.util.Collection; @@ -48,4 +50,12 @@ public interface DynamicLikeService extends BaseService { * @param contentIds 动态内容ID */ Map mapLikeQuantity(Collection contentIds); + + /** + * 分页查询动态点赞列表(按时间倒序) + * + * @param pageQuery 分页参数 + * @param contentId 动态内容ID + */ + PageResult pageByTimeDesc(PageQuery pageQuery, Long contentId); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicLikeServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicLikeServiceImpl.java index e16b7b5c..ecdfb67e 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicLikeServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicLikeServiceImpl.java @@ -2,6 +2,8 @@ package com.red.circle.other.infra.database.rds.service.dynamic.impl; import com.google.common.collect.Maps; +import com.red.circle.framework.dto.PageQuery; +import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.mybatis.constant.PageConstant; import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; import com.red.circle.other.infra.database.cache.service.other.DynamicCacheService; @@ -111,4 +113,12 @@ public class DynamicLikeServiceImpl extends BaseServiceImpl pageByTimeDesc(PageQuery pageQuery, Long contentId) { + return query() + .eq(DynamicLike::getDynamicContentId, contentId) + .orderByDesc(DynamicLike::getCreateTime) + .page(pageQuery); + } }