Search in sources :

Example 1 with BlogSort

use of com.moxi.mogublog.commons.entity.BlogSort in project mogu_blog_v2 by moxi624.

the class BlogSortServiceImpl method editBlogSort.

@Override
public String editBlogSort(BlogSortVO blogSortVO) {
    BlogSort blogSort = blogSortService.getById(blogSortVO.getUid());
    /**
     * 判断需要编辑的博客分类是否存在
     */
    if (!blogSort.getSortName().equals(blogSortVO.getSortName())) {
        QueryWrapper<BlogSort> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SQLConf.SORT_NAME, blogSortVO.getSortName());
        queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        BlogSort tempSort = blogSortService.getOne(queryWrapper);
        if (tempSort != null) {
            return ResultUtil.errorWithMessage(MessageConf.ENTITY_EXIST);
        }
    }
    blogSort.setContent(blogSortVO.getContent());
    blogSort.setSortName(blogSortVO.getSortName());
    blogSort.setSort(blogSortVO.getSort());
    blogSort.setStatus(EStatus.ENABLE);
    blogSort.setUpdateTime(new Date());
    blogSort.updateById();
    // 删除和博客相关的Redis缓存
    blogService.deleteRedisByBlogSort();
    return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BlogSort(com.moxi.mogublog.commons.entity.BlogSort)

Example 2 with BlogSort

use of com.moxi.mogublog.commons.entity.BlogSort in project mogu_blog_v2 by moxi624.

the class FreemarkerController method setBlog.

/**
 * 设置博客的分类标签和内容
 *
 * @param list
 * @return
 */
private List<Blog> setBlog(List<Blog> list) {
    final StringBuffer fileUids = new StringBuffer();
    List<String> sortUids = new ArrayList<>();
    List<String> tagUids = new ArrayList<>();
    list.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            fileUids.append(item.getFileUid() + SysConf.FILE_SEGMENTATION);
        }
        if (StringUtils.isNotEmpty(item.getBlogSortUid())) {
            sortUids.add(item.getBlogSortUid());
        }
        if (StringUtils.isNotEmpty(item.getTagUid())) {
            tagUids.add(item.getTagUid());
        }
    });
    String pictureList = null;
    if (fileUids != null) {
        pictureList = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    Collection<BlogSort> sortList = new ArrayList<>();
    Collection<Tag> tagList = new ArrayList<>();
    if (sortUids.size() > 0) {
        sortList = blogSortService.listByIds(sortUids);
    }
    if (tagUids.size() > 0) {
        tagList = tagService.listByIds(tagUids);
    }
    Map<String, BlogSort> sortMap = new HashMap<>();
    Map<String, Tag> tagMap = new HashMap<>();
    Map<String, String> pictureMap = new HashMap<>();
    sortList.forEach(item -> {
        sortMap.put(item.getUid(), item);
    });
    tagList.forEach(item -> {
        tagMap.put(item.getUid(), item);
    });
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    for (Blog item : list) {
        // 设置分类
        if (StringUtils.isNotEmpty(item.getBlogSortUid())) {
            item.setBlogSort(sortMap.get(item.getBlogSortUid()));
        }
        // 获取标签
        if (StringUtils.isNotEmpty(item.getTagUid())) {
            List<String> tagUidsTemp = StringUtils.changeStringToString(item.getTagUid(), SysConf.FILE_SEGMENTATION);
            List<Tag> tagListTemp = new ArrayList<Tag>();
            tagUidsTemp.forEach(tag -> {
                tagListTemp.add(tagMap.get(tag));
            });
            item.setTagList(tagListTemp);
        }
        // 获取图片
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            List<String> pictureUidsTemp = StringUtils.changeStringToString(item.getFileUid(), SysConf.FILE_SEGMENTATION);
            List<String> pictureListTemp = new ArrayList<>();
            pictureUidsTemp.forEach(picture -> {
                pictureListTemp.add(pictureMap.get(picture));
            });
            item.setPhotoList(pictureListTemp);
        }
    }
    return list;
}
Also used : BlogSort(com.moxi.mogublog.commons.entity.BlogSort) Tag(com.moxi.mogublog.commons.entity.Tag) Blog(com.moxi.mogublog.commons.entity.Blog)

Example 3 with BlogSort

use of com.moxi.mogublog.commons.entity.BlogSort in project mogu_blog_v2 by moxi624.

the class BlogSortServiceImpl method addBlogSort.

@Override
public String addBlogSort(BlogSortVO blogSortVO) {
    // 判断添加的分类是否存在
    QueryWrapper<BlogSort> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq(SQLConf.SORT_NAME, blogSortVO.getSortName());
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    BlogSort tempSort = blogSortService.getOne(queryWrapper);
    if (tempSort != null) {
        return ResultUtil.errorWithMessage(MessageConf.ENTITY_EXIST);
    }
    BlogSort blogSort = new BlogSort();
    blogSort.setContent(blogSortVO.getContent());
    blogSort.setSortName(blogSortVO.getSortName());
    blogSort.setSort(blogSortVO.getSort());
    blogSort.setStatus(EStatus.ENABLE);
    blogSort.insert();
    return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BlogSort(com.moxi.mogublog.commons.entity.BlogSort)

Example 4 with BlogSort

use of com.moxi.mogublog.commons.entity.BlogSort in project mogu_blog_v2 by moxi624.

the class BlogSortServiceImpl method getTopOne.

@Override
public BlogSort getTopOne() {
    QueryWrapper<BlogSort> blogSortQueryWrapper = new QueryWrapper<>();
    blogSortQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    blogSortQueryWrapper.last(SysConf.LIMIT_ONE);
    blogSortQueryWrapper.orderByDesc(SQLConf.SORT);
    BlogSort blogSort = blogSortService.getOne(blogSortQueryWrapper);
    return blogSort;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BlogSort(com.moxi.mogublog.commons.entity.BlogSort)

Example 5 with BlogSort

use of com.moxi.mogublog.commons.entity.BlogSort in project mogu_blog_v2 by moxi624.

the class BlogSortServiceImpl method stickBlogSort.

@Override
public String stickBlogSort(BlogSortVO blogSortVO) {
    BlogSort blogSort = blogSortService.getById(blogSortVO.getUid());
    // 查找出最大的那一个
    QueryWrapper<BlogSort> queryWrapper = new QueryWrapper<>();
    queryWrapper.orderByDesc(SQLConf.SORT);
    Page<BlogSort> page = new Page<>();
    page.setCurrent(0);
    page.setSize(1);
    IPage<BlogSort> pageList = blogSortService.page(page, queryWrapper);
    List<BlogSort> list = pageList.getRecords();
    BlogSort maxSort = list.get(0);
    if (StringUtils.isEmpty(maxSort.getUid())) {
        return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
    }
    if (maxSort.getUid().equals(blogSort.getUid())) {
        return ResultUtil.errorWithMessage(MessageConf.THIS_SORT_IS_TOP);
    }
    Integer sortCount = maxSort.getSort() + 1;
    blogSort.setSort(sortCount);
    blogSort.setUpdateTime(new Date());
    blogSort.updateById();
    return ResultUtil.successWithMessage(MessageConf.OPERATION_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) BlogSort(com.moxi.mogublog.commons.entity.BlogSort)

Aggregations

BlogSort (com.moxi.mogublog.commons.entity.BlogSort)6 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)5 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 Blog (com.moxi.mogublog.commons.entity.Blog)1 Tag (com.moxi.mogublog.commons.entity.Tag)1