use of com.zyd.blog.business.annotation.RedisCache 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);
}
use of com.zyd.blog.business.annotation.RedisCache in project OneBlog by zhangyd-c.
the class BizTagsServiceImpl method updateSelective.
@Override
@Transactional(rollbackFor = Exception.class)
@RedisCache(flush = true)
public boolean updateSelective(Tags entity) {
Assert.notNull(entity, "Tags不可为空!");
Tags old = this.getByName(entity.getName());
if (old != null && !old.getId().equals(entity.getId())) {
throw new ZhydException("标签修改失败,标签已存在![" + entity.getName() + "]");
}
entity.setUpdateTime(new Date());
return bizTagsMapper.updateByPrimaryKeySelective(entity.getBizTags()) > 0;
}
use of com.zyd.blog.business.annotation.RedisCache in project OneBlog by zhangyd-c.
the class BizCommentServiceImpl method commentForAdmin.
/**
* admin发表评论
*
* @param comment
* @return
*/
@Override
@RedisCache(flush = true)
public void commentForAdmin(Comment comment) throws ZhydCommentException {
Map config = configService.getConfigs();
User user = SessionUtil.getUser();
comment.setQq(user.getQq());
comment.setEmail(user.getEmail());
comment.setNickname(user.getNickname());
comment.setAvatar(user.getAvatar());
comment.setUrl((String) config.get(ConfigKeyEnum.SITE_URL.getKey()));
comment.setUserId(user.getId());
comment.setStatus(CommentStatusEnum.APPROVED.toString());
comment.setPid(comment.getId());
comment.setId(null);
this.comment(comment);
}
use of com.zyd.blog.business.annotation.RedisCache in project OneBlog by zhangyd-c.
the class SysConfigServiceImpl method saveConfig.
@Override
@RedisCache(flush = true, enable = false)
public void saveConfig(String key, String value) {
if (!StringUtils.isEmpty(key)) {
SysConfig config = null;
if (null == (config = this.getByKey(key))) {
config = new SysConfig();
config.setConfigKey(key);
config.setConfigValue(value);
config.setCreateTime(new Date());
config.setUpdateTime(new Date());
this.sysConfigMapper.insert(config);
} else {
config.setConfigKey(key);
config.setConfigValue(value);
config.setUpdateTime(new Date());
this.sysConfigMapper.updateByPrimaryKeySelective(config);
}
}
}
use of com.zyd.blog.business.annotation.RedisCache in project OneBlog by zhangyd-c.
the class SysLinkServiceImpl method autoLink.
/**
* 自动添加友链
*
* @param link
* @return
*/
@Override
@RedisCache(flush = true)
public boolean autoLink(Link link) throws ZhydLinkException {
String url = link.getUrl();
if (StringUtils.isEmpty(url)) {
throw new ZhydLinkException("链接地址为空!");
}
if (!RegexUtils.isUrl(url)) {
throw new ZhydLinkException("链接地址无效!");
}
Link bo = getOneByUrl(url);
if (bo != null) {
throw new ZhydLinkException("本站已经添加过贵站的链接!");
}
Map config = configService.getConfigs();
String domain = (String) config.get(ConfigKeyEnum.DOMAIN.getKey());
if (!(LinksUtil.hasLinkByHtml(url, domain)) && !LinksUtil.hasLinkByChinaz(url, domain)) {
throw new ZhydLinkException("贵站暂未添加本站友情链接!请先添加本站友链后重新提交申请!");
}
link.setSource(LinkSourceEnum.AUTOMATIC);
link.setStatus(true);
if (!StringUtils.isEmpty(link.getEmail())) {
link.setEmail(HtmlUtil.html2Text(link.getEmail()));
}
if (!StringUtils.isEmpty(link.getFavicon())) {
link.setFavicon(HtmlUtil.html2Text(link.getFavicon()));
}
if (!StringUtils.isEmpty(link.getName())) {
link.setName(HtmlUtil.html2Text(link.getName()));
}
if (!StringUtils.isEmpty(link.getUrl())) {
link.setUrl(HtmlUtil.html2Text(link.getUrl()));
}
if (!StringUtils.isEmpty(link.getDescription())) {
link.setDescription(HtmlUtil.html2Text(link.getDescription()));
}
this.insert(link);
log.info("友联自动申请成功,开始发送邮件通知...");
mailService.send(link, TemplateKeyEnum.TM_LINKS);
return true;
}
Aggregations