diff --git a/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/dto/PageReq.java b/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/dto/PageReq.java new file mode 100644 index 00000000..92e2527b --- /dev/null +++ b/rc-common-business/common-business-dto/src/main/java/com/red/circle/common/business/dto/PageReq.java @@ -0,0 +1,17 @@ +package com.red.circle.common.business.dto; + +import com.red.circle.framework.dto.PageQuery; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class PageReq extends PageQuery { + + private Integer cursor = 1; + + private Integer limit = 20; + + private Boolean searchCount = true; + +} 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 ca06ea67..f6598fbd 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 @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 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.framework.web.controller.BaseController; import com.red.circle.other.app.dto.clientobject.dynamic.DynamicCommentListCO; import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO; @@ -125,8 +126,8 @@ public class DynamicRestController extends BaseController { * @eo.method get * @eo.request-type formdata */ - @GetMapping("/my/list") - public List listMyDynamic(@Validated DynamicMyLimitCmd cmd) { + @GetMapping("/my/page") + public PageResult listMyDynamic(@Validated DynamicMyLimitCmd cmd) { return dynamicService.listMyDynamic(cmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicMyQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicMyQryExe.java index 1d2d8b2d..8d947513 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicMyQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/query/DynamicMyQryExe.java @@ -3,6 +3,8 @@ package com.red.circle.other.app.command.dynamic.query; import com.google.common.collect.Lists; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; +import com.red.circle.framework.dto.PageQuery; +import com.red.circle.framework.dto.PageResult; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO; import com.red.circle.other.app.dto.cmd.dynamic.DynamicMyLimitCmd; @@ -19,11 +21,8 @@ import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptio import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.num.NumUtils; -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; @@ -51,18 +50,17 @@ public class DynamicMyQryExe { private final UserSubscriptionService userSubscriptionService; private final UserProfileAppConvertor userProfileAppConvertor; - public List execute(DynamicMyLimitCmd cmd) { + public PageResult execute(DynamicMyLimitCmd cmd) { + PageResult dynamics = dynamicContentService + .pageByTimeDesc(cmd.getUserId(), cmd.getPageReq()); - List dynamics = dynamicContentService - .pageByTimeDesc(cmd.getPageNumber(), cmd.getUserId()); - - if (CollectionUtils.isEmpty(dynamics)) { - return Lists.newArrayList(); + if (CollectionUtils.isEmpty(dynamics.getRecords())) { + return PageResult.newPageResult(0); } Set ids = getIds(dynamics); if (CollectionUtils.isEmpty(ids)) { - return Lists.newArrayList(); + return PageResult.newPageResult(0); } Boolean isMySubscription = isMySubscription(cmd); @@ -79,7 +77,7 @@ public class DynamicMyQryExe { Map commentQuantityMap = dynamicCommentService.mapCommentQuantity(ids); Map> pictureMap = dynamicPictureService.mapPreviewGroup(ids); - return dynamics.stream().map(dynamic -> { + return dynamics.convert(dynamic -> { DynamicListCO result = new DynamicListCO(); processUser(user, result); @@ -91,7 +89,7 @@ public class DynamicMyQryExe { result.setCommentStrQuantity(NumUtils.formatInt(commentQuantityMap.get(dynamic.getId()))); return result; - }).collect(Collectors.toList()); + }); } @@ -134,12 +132,12 @@ public class DynamicMyQryExe { } } - private Set getTagIds(List dynamics) { - return dynamics.stream().map(DynamicContent::getTagId).collect(Collectors.toSet()); + private Set getTagIds(PageResult dynamics) { + return dynamics.getRecords().stream().map(DynamicContent::getTagId).collect(Collectors.toSet()); } - private Set getIds(List dynamics) { - return dynamics.stream().map(DynamicContent::getId).collect(Collectors.toSet()); + private Set getIds(PageResult dynamics) { + return dynamics.getRecords().stream().map(DynamicContent::getId).collect(Collectors.toSet()); } } 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 4c53d4cf..07521338 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 @@ -3,6 +3,7 @@ package com.red.circle.other.app.service.dynamic; 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.command.dynamic.DynamicCheckSendPermissionCmdExe; import com.red.circle.other.app.command.dynamic.DynamicCommentCmdExe; import com.red.circle.other.app.command.dynamic.DynamicCommentLikeCmdExe; @@ -101,7 +102,7 @@ public class DynamicServiceImpl implements DynamicService { } @Override - public List listMyDynamic(DynamicMyLimitCmd cmd) { + public PageResult listMyDynamic(DynamicMyLimitCmd cmd) { return dynamicMyQryExe.execute(cmd); } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicMyLimitCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicMyLimitCmd.java index bd13181a..4ced4072 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicMyLimitCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicMyLimitCmd.java @@ -1,6 +1,9 @@ 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 com.red.circle.framework.core.dto.PageCommand; +import com.red.circle.framework.dto.PageQuery; import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; @@ -15,14 +18,6 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) public class DynamicMyLimitCmd extends AppExtCommand { - /** - * 页码. - * - * @eo.required - */ - @NotNull - private Integer pageNumber; - /** * 用户id. * @@ -31,4 +26,6 @@ public class DynamicMyLimitCmd extends AppExtCommand { @NotNull private Long userId; + private PageReq pageReq; + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicPageCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicPageCmd.java new file mode 100644 index 00000000..2b852a88 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/dynamic/DynamicPageCmd.java @@ -0,0 +1,28 @@ +package com.red.circle.other.app.dto.cmd.dynamic; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.framework.core.dto.PageCommand; +import com.red.circle.framework.dto.PageQuery; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 动态-内容分页. + * + * @author pengshigang + * @since 2022-4-11 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class DynamicPageCmd extends AppExtCommand { + + /** + * 用户id. + * + * @eo.required + */ + @NotNull + private Long userId; + +} 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 4b06579b..4fc6bd9e 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 @@ -4,6 +4,7 @@ package com.red.circle.other.app.service.dynamic; 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; @@ -58,7 +59,7 @@ public interface DynamicService { /** * 我的动态列表. */ - List listMyDynamic(DynamicMyLimitCmd cmd); + PageResult listMyDynamic(DynamicMyLimitCmd cmd); /** * 最新动态列表. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicContentService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicContentService.java index 0170b115..c8c4699c 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicContentService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/DynamicContentService.java @@ -1,6 +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.DynamicContent; @@ -43,7 +44,7 @@ public interface DynamicContentService extends BaseService { * @param pageNumber 第几页 * @param userId 创建人 */ - List pageByTimeDesc(Integer pageNumber, Long userId); + PageResult pageByTimeDesc(Long userId, PageQuery pageQuery); /** * 获得分页数据 diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicContentServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicContentServiceImpl.java index 28be2399..b9559693 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicContentServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/dynamic/impl/DynamicContentServiceImpl.java @@ -2,6 +2,7 @@ package com.red.circle.other.infra.database.rds.service.dynamic.impl; import com.google.common.collect.Lists; 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.convertor.MybatisConvertor; @@ -73,17 +74,13 @@ public class DynamicContentServiceImpl extends } @Override - public List pageByTimeDesc(Integer pageNumber, Long userId) { - if (Objects.isNull(pageNumber) || pageNumber < 1) { - pageNumber = 1; - } + public PageResult pageByTimeDesc(Long userId, PageQuery pageQuery) { return query() .eq(DynamicContent::getDel, Boolean.FALSE) .eq(DynamicContent::getCreateUser, userId) .orderByDesc(DynamicContent::getCreateTime) - .last(getPageSql(pageNumber)) - .list(); + .page(pageQuery); } @Override