Search in sources :

Example 1 with ArticleConditionVO

use of com.zyd.blog.business.vo.ArticleConditionVO in project OneBlog by zhangyd-c.

the class BizArticleServiceImpl method listRecommended.

/**
 * 站长推荐
 *
 * @param pageSize
 * @return
 */
@Override
public List<Article> listRecommended(int pageSize) {
    ArticleConditionVO vo = new ArticleConditionVO();
    vo.setRecommended(true);
    vo.setStatus(ArticleStatusEnum.PUBLISHED.getCode());
    vo.setPageSize(pageSize);
    PageInfo pageInfo = this.findPageBreakByCondition(vo);
    return null == pageInfo ? null : pageInfo.getList();
}
Also used : PageInfo(com.github.pagehelper.PageInfo) ArticleConditionVO(com.zyd.blog.business.vo.ArticleConditionVO)

Example 2 with ArticleConditionVO

use of com.zyd.blog.business.vo.ArticleConditionVO in project OneBlog by zhangyd-c.

the class BizArticleServiceImpl method findPageBreakByCondition.

/**
 * 分页查询
 *
 * @param vo
 * @return
 */
@Override
public PageInfo<Article> findPageBreakByCondition(ArticleConditionVO vo) {
    PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
    List<BizArticle> list = bizArticleMapper.findPageBreakByCondition(vo);
    if (CollectionUtils.isEmpty(list)) {
        return null;
    }
    List<Long> ids = list.stream().map(BizArticle::getId).collect(Collectors.toList());
    List<BizArticle> listTag = bizArticleMapper.listTagsByArticleId(ids);
    Map<Long, BizArticle> tagMap = listTag.stream().collect(Collectors.toMap(BizArticle::getId, a -> a, (k1, k2) -> k1));
    List<Article> boList = new LinkedList<>();
    Article article = null;
    for (BizArticle bizArticle : list) {
        BizArticle tagArticle = tagMap.get(bizArticle.getId());
        if (null == tagArticle) {
            log.warn("文章[{}] 未绑定标签信息,或者已绑定的标签不存在!", bizArticle.getTitle());
        } else {
            bizArticle.setTags(tagArticle.getTags());
        }
        this.subquery(bizArticle);
        article = new Article(bizArticle);
        article.setPassword(null);
        boList.add(article);
    }
    PageInfo bean = new PageInfo<BizArticle>(list);
    bean.setList(boList);
    return bean;
}
Also used : ArticleStatusEnum(com.zyd.blog.business.enums.ArticleStatusEnum) RequestHolder(com.zyd.blog.framework.holder.RequestHolder) Example(tk.mybatis.mapper.entity.Example) java.util(java.util) CommentStatusEnum(com.zyd.blog.business.enums.CommentStatusEnum) User(com.zyd.blog.business.entity.User) Autowired(org.springframework.beans.factory.annotation.Autowired) FileUploadType(com.zyd.blog.business.enums.FileUploadType) ResponseStatus(com.zyd.blog.business.enums.ResponseStatus) ZhydException(com.zyd.blog.framework.exception.ZhydException) ArticleConditionVO(com.zyd.blog.business.vo.ArticleConditionVO) Service(org.springframework.stereotype.Service) IpUtil(com.zyd.blog.util.IpUtil) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) BizArticleService(com.zyd.blog.business.service.BizArticleService) SessionUtil(com.zyd.blog.util.SessionUtil) ZhydArticleException(com.zyd.blog.framework.exception.ZhydArticleException) RedisCache(com.zyd.blog.business.annotation.RedisCache) PageHelper(com.github.pagehelper.PageHelper) PageInfo(com.github.pagehelper.PageInfo) VirtualFile(com.zyd.blog.file.entity.VirtualFile) Article(com.zyd.blog.business.entity.Article) Collectors(java.util.stream.Collectors) BizArticleTagsService(com.zyd.blog.business.service.BizArticleTagsService) com.zyd.blog.persistence.beans(com.zyd.blog.persistence.beans) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) ValueOperations(org.springframework.data.redis.core.ValueOperations) CollectionUtils(org.springframework.util.CollectionUtils) MultipartFile(org.springframework.web.multipart.MultipartFile) com.zyd.blog.persistence.mapper(com.zyd.blog.persistence.mapper) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) PageInfo(com.github.pagehelper.PageInfo) Article(com.zyd.blog.business.entity.Article)

Example 3 with ArticleConditionVO

use of com.zyd.blog.business.vo.ArticleConditionVO in project OneBlog by zhangyd-c.

the class BizArticleServiceImpl method listRelatedArticle.

/**
 * 根据某篇文章获取与该文章相关的文章<br>
 * 搜索同类型、同标签下的文章
 *
 * @param pageSize
 * @param article
 * @return
 */
@Override
public List<Article> listRelatedArticle(int pageSize, Article article) {
    if (null == article) {
        return listRandom(pageSize);
    }
    ArticleConditionVO vo = new ArticleConditionVO();
    vo.setStatus(ArticleStatusEnum.PUBLISHED.getCode());
    List<BizTags> tags = article.getTags();
    if (!CollectionUtils.isEmpty(tags)) {
        List<Long> tagIds = new ArrayList<>();
        for (BizTags tag : tags) {
            tagIds.add(tag.getId());
        }
        vo.setTagIds(tagIds);
    }
    vo.setTypeId(article.getTypeId());
    vo.setPageSize(pageSize);
    PageInfo pageInfo = this.findPageBreakByCondition(vo);
    return null == pageInfo ? null : pageInfo.getList();
}
Also used : PageInfo(com.github.pagehelper.PageInfo) ArticleConditionVO(com.zyd.blog.business.vo.ArticleConditionVO)

Example 4 with ArticleConditionVO

use of com.zyd.blog.business.vo.ArticleConditionVO in project OneBlog by zhangyd-c.

the class RenderController method type.

/**
 * 分类列表
 *
 * @param typeId
 * @param model
 * @return
 */
@GetMapping("/type/{typeId}")
@BussinessLog(value = "进入文章分类[{1}]列表页", platform = PlatformEnum.WEB)
public ModelAndView type(@PathVariable("typeId") Long typeId, Model model) {
    ArticleConditionVO vo = new ArticleConditionVO();
    vo.setTypeId(typeId);
    model.addAttribute("url", "type/" + typeId);
    loadIndexPage(vo, model);
    return ResultUtil.view(INDEX_URL);
}
Also used : ArticleConditionVO(com.zyd.blog.business.vo.ArticleConditionVO) GetMapping(org.springframework.web.bind.annotation.GetMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 5 with ArticleConditionVO

use of com.zyd.blog.business.vo.ArticleConditionVO in project OneBlog by zhangyd-c.

the class ArticleTags method typeList.

public Object typeList(Map params) {
    int pageSize = this.getPageSize(params);
    long typeId = -1;
    String typeStr = getParam(params, "typeId");
    if (!StringUtils.isEmpty(typeStr)) {
        typeId = Long.parseLong(typeStr);
    }
    // 按文章分类查询
    ArticleConditionVO vo = new ArticleConditionVO();
    vo.setTypeId(typeId);
    // 已发布状态
    vo.setStatus(ArticleStatusEnum.PUBLISHED.getCode());
    vo.setPageSize(pageSize);
    PageInfo<Article> pageInfo = articleService.findPageBreakByCondition(vo);
    return null == pageInfo ? null : pageInfo.getList();
}
Also used : Article(com.zyd.blog.business.entity.Article) ArticleConditionVO(com.zyd.blog.business.vo.ArticleConditionVO)

Aggregations

ArticleConditionVO (com.zyd.blog.business.vo.ArticleConditionVO)10 PageInfo (com.github.pagehelper.PageInfo)5 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Article (com.zyd.blog.business.entity.Article)2 PageHelper (com.github.pagehelper.PageHelper)1 RedisCache (com.zyd.blog.business.annotation.RedisCache)1 User (com.zyd.blog.business.entity.User)1 ArticleStatusEnum (com.zyd.blog.business.enums.ArticleStatusEnum)1 CommentStatusEnum (com.zyd.blog.business.enums.CommentStatusEnum)1 FileUploadType (com.zyd.blog.business.enums.FileUploadType)1 ResponseStatus (com.zyd.blog.business.enums.ResponseStatus)1 BizArticleService (com.zyd.blog.business.service.BizArticleService)1 BizArticleTagsService (com.zyd.blog.business.service.BizArticleTagsService)1 FileUploader (com.zyd.blog.file.FileUploader)1 VirtualFile (com.zyd.blog.file.entity.VirtualFile)1 ZhydArticleException (com.zyd.blog.framework.exception.ZhydArticleException)1 ZhydException (com.zyd.blog.framework.exception.ZhydException)1 RequestHolder (com.zyd.blog.framework.holder.RequestHolder)1 com.zyd.blog.persistence.beans (com.zyd.blog.persistence.beans)1