Search in sources :

Example 1 with RedisCache

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);
}
Also used : ZhydArticleException(com.zyd.blog.framework.exception.ZhydArticleException) User(com.zyd.blog.business.entity.User) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Example 2 with RedisCache

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) BizArticleTags(com.zyd.blog.persistence.beans.BizArticleTags) BizTags(com.zyd.blog.persistence.beans.BizTags) Tags(com.zyd.blog.business.entity.Tags) Date(java.util.Date) RedisCache(com.zyd.blog.business.annotation.RedisCache) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RedisCache

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);
}
Also used : User(com.zyd.blog.business.entity.User) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Example 4 with RedisCache

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);
        }
    }
}
Also used : SysConfig(com.zyd.blog.persistence.beans.SysConfig) Date(java.util.Date) LocalDate(java.time.LocalDate) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Example 5 with RedisCache

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;
}
Also used : ZhydLinkException(com.zyd.blog.framework.exception.ZhydLinkException) Link(com.zyd.blog.business.entity.Link) SysLink(com.zyd.blog.persistence.beans.SysLink) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Aggregations

RedisCache (com.zyd.blog.business.annotation.RedisCache)15 Link (com.zyd.blog.business.entity.Link)4 SysLink (com.zyd.blog.persistence.beans.SysLink)4 LinkConditionVO (com.zyd.blog.business.vo.LinkConditionVO)3 ZhydException (com.zyd.blog.framework.exception.ZhydException)3 SysConfig (com.zyd.blog.persistence.beans.SysConfig)3 Date (java.util.Date)3 Transactional (org.springframework.transaction.annotation.Transactional)3 User (com.zyd.blog.business.entity.User)2 BizArticleTags (com.zyd.blog.persistence.beans.BizArticleTags)2 Tags (com.zyd.blog.business.entity.Tags)1 CommentConditionVO (com.zyd.blog.business.vo.CommentConditionVO)1 FileUploader (com.zyd.blog.file.FileUploader)1 VirtualFile (com.zyd.blog.file.entity.VirtualFile)1 ZhydArticleException (com.zyd.blog.framework.exception.ZhydArticleException)1 ZhydCommentException (com.zyd.blog.framework.exception.ZhydCommentException)1 ZhydLinkException (com.zyd.blog.framework.exception.ZhydLinkException)1 BizComment (com.zyd.blog.persistence.beans.BizComment)1 BizTags (com.zyd.blog.persistence.beans.BizTags)1 GlobalFileUploader (com.zyd.blog.plugin.file.GlobalFileUploader)1