codeapp展示

76 阅读2分钟
 文章列表展示

### app端文章列表-需求分析

文章布局展示
1,在默认频道展示10条文章信息

2,可以切换频道查看不同种类文章

3,当用户下拉可以加载最新的文章信息(按照发布时间)

本页文章列表中发布时间最大的时间为依据

4,当用户上拉可以加载更多的文章(分页)

本页文章列表中发布时间为最小的时间为依据

5,如果是当前频道的首页,前端传递默认参数:

-   maxTime:0(毫秒)
-   minTime:20000000000000(毫秒)--->2063年
 controller 在ApAricleController中添加方法 
    @PostMapping("/api/v1/article/load")
返回的不是pageresults是泛型
    public ResponseResult<List<ArticleDto>> load(@RequestBody ArticleHomeDto dto) {
        List<ArticleDto> articleDtoList = apArticleService.load(dto,1);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载更多
     * @return
     */
    @PostMapping("/api/v1/article/loadmore")
    public ResponseResult<List<ArticleDto>> loadMore(@RequestBody ArticleHomeDto dto) {
        List<ArticleDto> articleDtoList =  apArticleService.load(dto,1);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载最新
     * @return
     */
    @PostMapping("/api/v1/article/loadnew")
    public ResponseResult<List<ArticleDto>> loadNew(@RequestBody ArticleHomeDto dto) {
        List<ArticleDto> articleDtoList =   apArticleService.load(dto,2);
        return ResponseResult.ok(articleDtoList);
    }
    service 在ApArticleService中新增一个方法
/ /获取首页内容 dto  type  1- load  2- load new 
    List<ArticleDto> load(ArticleHomeDto dto,Integer type);
    ```
   /**
     * 文章列表首页
     * 分页
     * @param dto
     * @return
     */
    @Override
    public List<ArticleDto> loadArticle(ArticleHomeDto dto,int type) {
      Integer size = articleHomeDto.getSize();
        if (size == null || size == 0) {
            size = 10;
        }
        size = Math.min(size, MAX_PAGE_SIZE);
        IPage<ApArticle> ipage = new Page<>(1,dto.getSize());
          IPage<ApArticle> ipage = new Page<>(1, size);
//        设置条件
        LambdaQueryWrapper<ApArticle> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.
                eq(ApArticle::getIsDown,false).
                eq(ApArticle::getIsDelete,false);
        if(dto.getChannelId() !=0){
//            根据频道id查询文章
            queryWrapper.eq(ApArticle::getChannelId,dto.getChannelId());
        }
        if(dto.getMaxTime() != null && type==1){
//            查询更新,比当前列表的最大发布时间还要晚的文章
            queryWrapper.gt(ApArticle::getPublishTime,dto.getMaxTime());
        }
        if(dto.getMinTime() != null && type==2){
//            查询更多,比当前列表的最小发布时间还要早的文章
            queryWrapper.lt(ApArticle::getPublishTime,dto.getMinTime());
        }
//        排序
        queryWrapper.orderByDesc(ApArticle::getPublishTime);
//        分页查询
        IPage<ApArticle> articleIPage = page(ipage, queryWrapper);
        if(CollectionUtils.isEmpty(articleIPage.getRecords())){
            log.error("文章数据不存在");
            throw new LeadException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return BeanHelper.copyWithCollection(articleIPage.getRecords(),ArticleDto.class);
    }  
/**
 * 文章列表首页
 * @param dto
 * @return
 */  2表示load,1表示loadnew
@PostMapping("/api/v1/article/load")
public ResponseResult<List<ArticleDto>> load(@RequestBody ArticleHomeDto dto){
    return ResponseResult.ok(apArticleService.loadArticle(dto,2));
}

@PostMapping("/api/v1/article/loadnew")
public ResponseResult<List<ArticleDto>> loadNew(@RequestBody ArticleHomeDto dto){
    return ResponseResult.ok(apArticleService.loadArticle(dto,1));
}

@PostMapping("/api/v1/article/loadmore")
public ResponseResult<List<ArticleDto>> loadMore(@RequestBody ArticleHomeDto dto){
    return ResponseResult.ok(apArticleService.loadArticle(dto,2));
}