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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations