use of com.zyd.blog.framework.exception.ZhydArticleException in project OneBlog by zhangyd-c.
the class BizArticleServiceImpl method publish.
/**
* 发布文章
*
* @param article
* @param tags
* @param file
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean publish(Article article, Long[] tags, MultipartFile file) {
if (null == tags || tags.length <= 0) {
throw new ZhydArticleException("请至少选择一个标签");
}
if (null != file) {
FileUploader uploader = new GlobalFileUploader();
VirtualFile virtualFile = uploader.upload(file, FileUploadType.COVER_IMAGE.getPath(), true);
// 保存封面图片
article.setCoverImage(virtualFile.getFilePath());
}
Long articleId = null;
if ((articleId = article.getId()) != null) {
this.updateSelective(article);
} else {
article.setUserId(SessionUtil.getUser().getId());
articleId = this.insert(article).getId();
}
if (articleId != null) {
articleTagsService.removeByArticleId(articleId);
articleTagsService.insertList(tags, articleId);
}
return true;
}
use of com.zyd.blog.framework.exception.ZhydArticleException in project OneBlog by zhangyd-c.
the class BizArticleServiceImpl method doPraise.
/**
* 文章点赞
*
* @param id
*/
@Override
@RedisCache(flush = true)
public void doPraise(Long id) {
String ip = IpUtil.getRealIp(RequestHolder.getRequest());
String key = ip + "_doPraise_" + id;
ValueOperations<String, Object> operations = redisTemplate.opsForValue();
if (redisTemplate.hasKey(key)) {
throw new ZhydArticleException("一个小时只能点赞一次哈,感谢支持~~");
}
User user = SessionUtil.getUser();
BizArticleLove love = new BizArticleLove();
if (null != user) {
love.setUserId(user.getId());
}
love.setArticleId(id);
love.setUserIp(IpUtil.getRealIp(RequestHolder.getRequest()));
love.setLoveTime(new Date());
love.setCreateTime(new Date());
love.setUpdateTime(new Date());
bizArticleLoveMapper.insert(love);
operations.set(key, id, 1, TimeUnit.HOURS);
}
Aggregations