Search in sources :

Example 6 with Article

use of com.zyd.blog.business.entity.Article in project OneBlog by zhangyd-c.

the class BizArticleServiceImpl method getPrevAndNextArticles.

/**
 * 获取上一篇和下一篇
 *
 * @return
 */
@Override
public Map<String, Article> getPrevAndNextArticles(Date insertTime) {
    insertTime = null == insertTime ? new Date() : insertTime;
    List<BizArticle> entityList = bizArticleMapper.getPrevAndNextArticles(insertTime);
    if (CollectionUtils.isEmpty(entityList)) {
        return null;
    }
    Map<String, Article> resultMap = new HashMap<>();
    for (BizArticle entity : entityList) {
        if (entity.getCreateTime().getTime() < insertTime.getTime()) {
            resultMap.put("prev", new Article(entity));
        } else {
            resultMap.put("next", new Article(entity));
        }
    }
    return resultMap;
}
Also used : Article(com.zyd.blog.business.entity.Article)

Example 7 with Article

use of com.zyd.blog.business.entity.Article in project OneBlog by zhangyd-c.

the class BizArticleServiceImpl method listAll.

@Override
public List<Article> listAll() {
    List<BizArticle> entityList = bizArticleMapper.selectAll();
    if (CollectionUtils.isEmpty(entityList)) {
        return null;
    }
    List<Article> list = new ArrayList<>();
    for (BizArticle entity : entityList) {
        list.add(new Article(entity));
    }
    return list;
}
Also used : Article(com.zyd.blog.business.entity.Article)

Example 8 with Article

use of com.zyd.blog.business.entity.Article in project OneBlog by zhangyd-c.

the class RenderController method edit.

@RequiresPermissions("article:publish")
@BussinessLog(value = "进入修改文章页[id={1}]")
@GetMapping("/article/update/{id}")
public ModelAndView edit(@PathVariable("id") Long id, Model model) {
    model.addAttribute("id", id);
    Article article = articleService.getByPrimaryKey(id);
    if (!Arrays.asList("we", "md", "tiny").contains(article.getEditorType())) {
        throw new ZhydException("文章异常,未知的编辑器类型");
    }
    return ResultUtil.view("article/publish-" + article.getEditorType());
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) Article(com.zyd.blog.business.entity.Article) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 9 with Article

use of com.zyd.blog.business.entity.Article in project OneBlog by zhangyd-c.

the class RenderController method article.

/**
 * 文章详情
 *
 * @param model
 * @param articleId
 * @return
 */
@GetMapping("/article/{articleId}")
@BussinessLog(value = "进入文章[{2}]详情页", platform = PlatformEnum.WEB)
public ModelAndView article(Model model, @PathVariable("articleId") Long articleId) {
    Article article = bizArticleService.getByPrimaryKey(articleId);
    if (article == null || ArticleStatusEnum.UNPUBLISHED.getCode() == article.getStatusEnum().getCode()) {
        return ResultUtil.forward("/error/404");
    }
    if (article.getPrivate()) {
        article.setPassword(null);
        article.setContent(null);
        article.setContentMd(null);
    }
    if (article.getRequiredAuth()) {
        User sessionUser = SessionUtil.getUser();
        if (null != sessionUser) {
            article.setRequiredAuth(false);
        }
    }
    model.addAttribute("article", article);
    // 上一篇下一篇
    model.addAttribute("other", bizArticleService.getPrevAndNextArticles(article.getCreateTime()));
    // 相关文章
    model.addAttribute("relatedList", bizArticleService.listRelatedArticle(SIDEBAR_ARTICLE_SIZE, article));
    model.addAttribute("articleDetail", true);
    return ResultUtil.view("article");
}
Also used : User(com.zyd.blog.business.entity.User) Article(com.zyd.blog.business.entity.Article) GetMapping(org.springframework.web.bind.annotation.GetMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Aggregations

Article (com.zyd.blog.business.entity.Article)9 User (com.zyd.blog.business.entity.User)3 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)2 ArticleStatusEnum (com.zyd.blog.business.enums.ArticleStatusEnum)2 BizArticleService (com.zyd.blog.business.service.BizArticleService)2 BizArticleTagsService (com.zyd.blog.business.service.BizArticleTagsService)2 ArticleConditionVO (com.zyd.blog.business.vo.ArticleConditionVO)2 ZhydException (com.zyd.blog.framework.exception.ZhydException)2 SessionUtil (com.zyd.blog.util.SessionUtil)2 java.util (java.util)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Collectors (java.util.stream.Collectors)2 VirtualArticle (me.zhyd.hunter.entity.VirtualArticle)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CollectionUtils (org.springframework.util.CollectionUtils)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 PageHelper (com.github.pagehelper.PageHelper)1 PageInfo (com.github.pagehelper.PageInfo)1