Search in sources :

Example 1 with PostsVo

use of com.codingmore.vo.PostsVo in project codingmore-learning by itwanger.

the class PostsServiceImpl method getPostsById.

@Override
public PostsVo getPostsById(Long id) {
    Posts posts = this.getById(id);
    PostsVo postsVo = new PostsVo();
    BeanUtils.copyProperties(posts, postsVo);
    QueryWrapper<TermRelationships> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("object_id", posts.getId());
    List<TermRelationships> termRelationshipsList = iTermRelationshipsService.list(queryWrapper);
    if (termRelationshipsList.size() > 0) {
        postsVo.setTermTaxonomyId(termRelationshipsList.get(0).getTermTaxonomyId());
    }
    return postsVo;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) PostsVo(com.codingmore.vo.PostsVo)

Example 2 with PostsVo

use of com.codingmore.vo.PostsVo in project coding-more by itwanger.

the class ContentPageRequestStrategy method handleRequest.

@Override
public String handleRequest(WebRequestParam webRequestParam) {
    iPostsService.increasePageView(webRequestParam.getPostId(), webRequestParam.getRequest());
    Boolean hasClickedLike = iPostsService.hasClickedLike(webRequestParam.getPostId(), webRequestParam.getRequest());
    webRequestParam.getRequest().setAttribute(CLICKED_LIKE, hasClickedLike);
    PostsVo postsVo = iPostsService.getPostsById(webRequestParam.getPostId());
    webRequestParam.getRequest().setAttribute(POSTS_VO, postsVo);
    if (StringUtils.isNotBlank(postsVo.getTagsName())) {
        webRequestParam.getRequest().setAttribute(TAG_LIST, CollectionUtils.arrayToList(postsVo.getTagsName().split(",")));
    }
    List<Site> siteList = siteService.list();
    // 处理站点配置
    if (siteList.size() > 0) {
        Site site = siteList.get(0);
        SiteVo siteVo = new SiteVo();
        BeanUtils.copyProperties(site, siteVo);
        webRequestParam.getRequest().setAttribute(SITE_CONFIG, siteVo);
    }
    return CONTENT_PAGE;
}
Also used : Site(com.codingmore.model.Site) SiteVo(com.codingmore.vo.SiteVo) PostsVo(com.codingmore.vo.PostsVo)

Example 3 with PostsVo

use of com.codingmore.vo.PostsVo in project coding-more by itwanger.

the class PostsServiceImpl method getPostsById.

@Override
public PostsVo getPostsById(Long id) {
    Posts posts = this.getById(id);
    PostsVo postsVo = new PostsVo();
    if (posts == null) {
        return postsVo;
    }
    BeanUtils.copyProperties(posts, postsVo);
    QueryWrapper<TermRelationships> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("term_relationships_id", posts.getPostsId());
    List<TermRelationships> termRelationshipsList = iTermRelationshipsService.list(queryWrapper);
    if (termRelationshipsList.size() > 0) {
        postsVo.setTermTaxonomyId(termRelationshipsList.get(0).getTermTaxonomyId());
    }
    QueryWrapper<PostTagRelation> tagRelationWrapper = new QueryWrapper<>();
    tagRelationWrapper.eq("post_id", posts.getPostsId());
    tagRelationWrapper.orderBy(true, true, "term_order");
    List<PostTagRelation> postTagRelationList = iPostTagRelationService.list(tagRelationWrapper);
    if (postTagRelationList.size() > 0) {
        List<Long> tagIds = postTagRelationList.stream().map(PostTagRelation::getPostTagId).collect(Collectors.toList());
        QueryWrapper<PostTag> tagQuery = new QueryWrapper<>();
        tagQuery.in("post_tag_id", tagIds);
        List<PostTag> postTags = iPostTagService.list(tagQuery);
        Collections.sort(postTags, new Comparator<PostTag>() {

            @Override
            public int compare(PostTag o1, PostTag o2) {
                return tagIds.indexOf(o1.getPostTagId()) - tagIds.indexOf(o2.getPostTagId());
            }
        });
        postsVo.setTagsName(StringUtils.join(postTags.stream().map(PostTag::getDescription).collect(Collectors.toList()), ","));
        postsVo.setTags(postTags);
    }
    Users users = iUsersService.getById(posts.getPostAuthor());
    postsVo.setUserNiceName(users.getUserNicename());
    return postsVo;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) PostsVo(com.codingmore.vo.PostsVo)

Example 4 with PostsVo

use of com.codingmore.vo.PostsVo in project coding-more by itwanger.

the class IndexPageRequestStrategy method handleRequest.

@Override
public String handleRequest(WebRequestParam webRequestParam) {
    List<Site> siteList = siteService.list();
    // 处理站点配置
    if (siteList.size() > 0) {
        Site site = siteList.get(0);
        SiteVo siteVo = new SiteVo();
        BeanUtils.copyProperties(site, siteVo);
        webRequestParam.getRequest().setAttribute(SITE_CONFIG, siteVo);
    }
    PostsPageQueryParam pageQueryParam = new PostsPageQueryParam();
    pageQueryParam.setPage(webRequestParam.getPage());
    pageQueryParam.setAsc(webRequestParam.isAsc());
    pageQueryParam.setOrderBy(webRequestParam.getOrderBy());
    /* pageQueryParam.setOrderBy("post_date"); */
    pageQueryParam.setPageSize(webRequestParam.getPageSize());
    pageQueryParam.setPostStatus(PostStatus.PUBLISHED.toString());
    pageQueryParam.setTermTaxonomyId(webRequestParam.getChannelId());
    // IPage<PostsVo> pageVo = postsService.findByPageWithTag(pageQueryParam);
    List<PostsVo> pageVoList = postsService.findByPageWithTagPaged(pageQueryParam);
    // 设置浏览量
    pageVoList.forEach(postsVo -> {
        postsVo.setLikeCount(Long.parseLong(String.valueOf(postsService.getLikeCount(postsVo.getPostsId()))));
    });
    webRequestParam.getRequest().setAttribute(POSTS_ITEMS, pageVoList);
    // webRequestParam.getRequest().setAttribute(POSTS_TOTAL,pageVo.getTotal());
    return INDEX_PAGE;
}
Also used : Site(com.codingmore.model.Site) SiteVo(com.codingmore.vo.SiteVo) PostsPageQueryParam(com.codingmore.dto.PostsPageQueryParam) PostsVo(com.codingmore.vo.PostsVo)

Aggregations

PostsVo (com.codingmore.vo.PostsVo)4 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 Site (com.codingmore.model.Site)2 SiteVo (com.codingmore.vo.SiteVo)2 PostsPageQueryParam (com.codingmore.dto.PostsPageQueryParam)1