Search in sources :

Example 1 with Article

use of com.zyd.blog.business.entity.Article 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 2 with Article

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

the class BizArticleServiceImpl method listHotArticle.

/**
 * 获取热门文章
 *
 * @return
 */
@Override
public List<Article> listHotArticle(int pageSize) {
    PageHelper.startPage(1, pageSize);
    List<BizArticle> entityList = bizArticleMapper.listHotArticle();
    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 3 with Article

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

the class RemoverServiceImpl method saveArticle.

private Article saveArticle(Long typeId, boolean isConvertImg, HunterPrintWriter writerUtil, User user, VirtualArticle virtualArticle) {
    Article article = new Article();
    article.setContent(isConvertImg ? parseImgForHtml(virtualArticle, writerUtil) : virtualArticle.getContent());
    article.setTitle(virtualArticle.getTitle());
    article.setCoverImage(CollectionUtils.isEmpty(virtualArticle.getImageLinks()) ? null : new ArrayList<>(virtualArticle.getImageLinks()).get(0).getSrcLink());
    article.setTypeId(typeId);
    article.setUserId(user.getId());
    article.setComment(true);
    article.setOriginal(true);
    // 默认是草稿
    article.setStatus(ArticleStatusEnum.UNPUBLISHED.getCode());
    article.setIsMarkdown(false);
    article.setDescription(virtualArticle.getDescription());
    article.setKeywords(virtualArticle.getKeywords());
    article.setEditorType("we");
    article = articleService.insert(article);
    writerUtil.print(String.format("[ save ] Succeed! <a href=\"%s\" target=\"_blank\">%s</a>", virtualArticle.getSource(), article.getTitle()));
    return article;
}
Also used : Article(com.zyd.blog.business.entity.Article) VirtualArticle(me.zhyd.hunter.entity.VirtualArticle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with Article

use of com.zyd.blog.business.entity.Article 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)

Example 5 with Article

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

the class RemoverServiceImpl method saveArticles.

private void saveArticles(Long typeId, HunterConfig config, HunterPrintWriter writerUtil, CopyOnWriteArrayList<VirtualArticle> list) {
    // 获取数据库中的标签列表
    List<Tags> tags = tagsService.listAll();
    Map<String, Long> originalTags = tags.stream().collect(Collectors.toMap(tag -> tag.getName().toUpperCase(), Tags::getId));
    User user = SessionUtil.getUser();
    // 添加文章到数据库
    Article article = null;
    for (VirtualArticle spiderVirtualArticle : list) {
        article = this.saveArticle(typeId, config.isConvertImg(), writerUtil, user, spiderVirtualArticle);
        this.saveTags(writerUtil, originalTags, article, spiderVirtualArticle);
    }
}
Also used : ArticleStatusEnum(com.zyd.blog.business.enums.ArticleStatusEnum) java.util(java.util) User(com.zyd.blog.business.entity.User) Autowired(org.springframework.beans.factory.annotation.Autowired) Hunter(me.zhyd.hunter.Hunter) HunterConfig(me.zhyd.hunter.config.HunterConfig) Service(org.springframework.stereotype.Service) BizTagsService(com.zyd.blog.business.service.BizTagsService) BizArticleService(com.zyd.blog.business.service.BizArticleService) PrintWriter(java.io.PrintWriter) Validated(org.springframework.validation.annotation.Validated) SessionUtil(com.zyd.blog.util.SessionUtil) ImageLink(me.zhyd.hunter.entity.ImageLink) HunterPrintWriter(me.zhyd.hunter.util.HunterPrintWriter) BlogHunterProcessor(me.zhyd.hunter.processor.BlogHunterProcessor) Article(com.zyd.blog.business.entity.Article) Collectors(java.util.stream.Collectors) VirtualArticle(me.zhyd.hunter.entity.VirtualArticle) BizArticleTagsService(com.zyd.blog.business.service.BizArticleTagsService) RemoverService(com.zyd.blog.business.service.RemoverService) Tags(com.zyd.blog.business.entity.Tags) ImageDownloadUtil(com.zyd.blog.business.util.ImageDownloadUtil) CollectionUtils(org.springframework.util.CollectionUtils) HunterProcessor(me.zhyd.hunter.processor.HunterProcessor) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) VirtualArticle(me.zhyd.hunter.entity.VirtualArticle) User(com.zyd.blog.business.entity.User) Article(com.zyd.blog.business.entity.Article) VirtualArticle(me.zhyd.hunter.entity.VirtualArticle) Tags(com.zyd.blog.business.entity.Tags)

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