Search in sources :

Example 1 with Tag

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

the class TagServiceImpl method stickTag.

@Override
public String stickTag(TagVO tagVO) {
    Tag tag = tagService.getById(tagVO.getUid());
    // 查找出最大的那一个
    QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
    queryWrapper.orderByDesc(SQLConf.SORT);
    Page<Tag> page = new Page<>();
    page.setCurrent(0);
    page.setSize(1);
    IPage<Tag> pageList = tagService.page(page, queryWrapper);
    List<Tag> list = pageList.getRecords();
    Tag maxTag = list.get(0);
    if (StringUtils.isEmpty(maxTag.getUid())) {
        return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
    }
    if (maxTag.getUid().equals(tag.getUid())) {
        return ResultUtil.errorWithMessage(MessageConf.THIS_TAG_IS_TOP);
    }
    Integer sortCount = maxTag.getSort() + 1;
    tag.setSort(sortCount);
    tag.setUpdateTime(new Date());
    tag.updateById();
    // 删除Redis中的BLOG_TAG
    deleteRedisBlogTagList();
    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) Tag(com.moxi.mogublog.commons.entity.Tag)

Example 2 with Tag

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

the class TagServiceImpl method editTag.

@Override
public String editTag(TagVO tagVO) {
    Tag tag = tagService.getById(tagVO.getUid());
    if (tag != null && !tag.getContent().equals(tagVO.getContent())) {
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SQLConf.CONTENT, tagVO.getContent());
        queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        Tag tempTag = tagService.getOne(queryWrapper);
        if (tempTag != null) {
            return ResultUtil.errorWithMessage(MessageConf.ENTITY_EXIST);
        }
    }
    tag.setContent(tagVO.getContent());
    tag.setStatus(EStatus.ENABLE);
    tag.setSort(tagVO.getSort());
    tag.setUpdateTime(new Date());
    tag.updateById();
    // 删除和标签相关的博客缓存
    blogService.deleteRedisByBlogTag();
    // 删除Redis中的BLOG_TAG
    deleteRedisBlogTagList();
    return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Tag(com.moxi.mogublog.commons.entity.Tag)

Example 3 with Tag

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

the class TagServiceImpl method getTopTag.

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

Example 4 with Tag

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

the class TagServiceImpl method tagSortByClickCount.

@Override
public String tagSortByClickCount() {
    QueryWrapper<Tag> queryWrapper = new QueryWrapper();
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    // 按点击从高到低排序
    queryWrapper.orderByDesc(SQLConf.CLICK_COUNT);
    List<Tag> tagList = tagService.list(queryWrapper);
    // 设置初始化最大的sort值
    Integer maxSort = tagList.size();
    for (Tag item : tagList) {
        item.setSort(item.getClickCount());
        item.setCreateTime(new Date());
    }
    tagService.updateBatchById(tagList);
    // 删除Redis中的BLOG_TAG
    deleteRedisBlogTagList();
    return ResultUtil.successWithMessage(MessageConf.OPERATION_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Tag(com.moxi.mogublog.commons.entity.Tag)

Example 5 with Tag

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

the class IndexRestApi method getHotTag.

@ApiOperation(value = "获取最热标签", notes = "获取最热标签")
@GetMapping("/getHotTag")
public String getHotTag() {
    String hotTagCount = sysParamsService.getSysParamsValueByKey(SysConf.HOT_TAG_COUNT);
    // 从Redis中获取友情链接
    String jsonResult = redisUtil.get(RedisConf.BLOG_TAG + Constants.SYMBOL_COLON + hotTagCount);
    if (StringUtils.isNotEmpty(jsonResult)) {
        List jsonResult2List = JsonUtils.jsonArrayToArrayList(jsonResult);
        return ResultUtil.result(SysConf.SUCCESS, jsonResult2List);
    }
    List<Tag> tagList = tagService.getHotTag(Integer.valueOf(hotTagCount));
    if (tagList.size() > 0) {
        redisUtil.setEx(RedisConf.BLOG_TAG + Constants.SYMBOL_COLON + hotTagCount, JsonUtils.objectToJson(tagList), 1, TimeUnit.HOURS);
    }
    return ResultUtil.result(SysConf.SUCCESS, tagList);
}
Also used : List(java.util.List) Tag(com.moxi.mogublog.commons.entity.Tag) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Tag (com.moxi.mogublog.commons.entity.Tag)8 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 BlogSort (com.moxi.mogublog.commons.entity.BlogSort)1 ESBlogIndex (com.moxi.mogublog.search.pojo.ESBlogIndex)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1