Search in sources :

Example 1 with SysConfig

use of com.zyd.blog.persistence.beans.SysConfig in project OneBlog by zhangyd-c.

the class FriendlyLinkTask method check.

/**
 * 每晚凌晨12点,检查友情链接
 */
@Scheduled(cron = "0 0 0 * * ?")
public void check() {
    // 未开启自动检查友联的功能
    if (!enableAutoCheckLink) {
        return;
    }
    List<Link> linkList = sysLinkService.listAll();
    if (CollectionUtils.isEmpty(linkList)) {
        return;
    }
    SysConfig sysConfig = sysConfigService.getByKey(ConfigKeyEnum.DOMAIN.getKey());
    if (StringUtils.isEmpty(sysConfig)) {
        return;
    }
    String domain = sysConfig.getConfigValue();
    for (Link link : linkList) {
        if (!link.isStatus()) {
            // 因此自动恢复其友联
            if (LinksUtil.hasLinkByHtml(link.getUrl(), domain) || LinksUtil.hasLinkByChinaz(link.getUrl(), domain)) {
                link.setStatus(true);
                link.setDescription("");
                sysLinkService.updateSelective(link);
            }
            continue;
        }
        // 已经不存在本站链接,自动下架该网站的友联
        if (!(LinksUtil.hasLinkByHtml(link.getUrl(), domain)) && !LinksUtil.hasLinkByChinaz(link.getUrl(), domain)) {
            link.setStatus(false);
            link.setDescription("系统检测到该网站已经取消本站的链接,因此自动封禁其友链");
            sysLinkService.updateSelective(link);
            log.info("系统监测到该网站([{}])已经私自取消本站链接,因此自动下架的友联", link.getName());
        }
    }
}
Also used : SysConfig(com.zyd.blog.persistence.beans.SysConfig) Link(com.zyd.blog.business.entity.Link) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 2 with SysConfig

use of com.zyd.blog.persistence.beans.SysConfig 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 3 with SysConfig

use of com.zyd.blog.persistence.beans.SysConfig in project OneBlog by zhangyd-c.

the class SysConfigServiceImpl method getSiteInfo.

/**
 * 获取网站详情
 */
@Override
public Map<String, Object> getSiteInfo() {
    Map<String, Object> siteInfo = sysConfigMapper.getSiteInfo();
    if (!CollectionUtils.isEmpty(siteInfo)) {
        Date installdate = null;
        SysConfig config = this.getByKey(ConfigKeyEnum.INSTALLDATE.getKey());
        if (null == config || StringUtils.isEmpty(config.getConfigValue())) {
            // 默认建站日期为2019-01-01
            installdate = Date.from(LocalDate.of(2019, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant());
        } else {
            installdate = DateUtil.parse(config.getConfigValue(), DatePattern.NORM_DATETIME_PATTERN);
        }
        long between = 1;
        if (!installdate.after(new Date())) {
            between = DateUtil.between(installdate, new Date(), DateUnit.DAY);
        }
        siteInfo.put("installdate", between < 1 ? 1 : between);
    }
    return siteInfo;
}
Also used : SysConfig(com.zyd.blog.persistence.beans.SysConfig) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 4 with SysConfig

use of com.zyd.blog.persistence.beans.SysConfig in project OneBlog by zhangyd-c.

the class SysConfigServiceImpl method getByKey.

@Override
@RedisCache(enable = false)
public SysConfig getByKey(String key) {
    if (StringUtils.isEmpty(key)) {
        return null;
    }
    SysConfig sysConfig = new SysConfig();
    sysConfig.setConfigKey(key);
    return this.sysConfigMapper.selectOne(sysConfig);
}
Also used : SysConfig(com.zyd.blog.persistence.beans.SysConfig) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Example 5 with SysConfig

use of com.zyd.blog.persistence.beans.SysConfig in project OneBlog by zhangyd-c.

the class BizCommentServiceImpl method comment.

/**
 * 发表评论
 *
 * @param comment
 * @return
 */
@Override
@RedisCache(flush = true)
public Comment comment(Comment comment) throws ZhydCommentException {
    SysConfig sysConfig = configService.getByKey(ConfigKeyEnum.ANONYMOUS.getKey());
    boolean anonymous = true;
    if (null != sysConfig) {
        anonymous = "1".equals(sysConfig.getConfigValue());
    }
    // 非匿名且未登录
    if (!anonymous && !SessionUtil.isLogin()) {
        throw new ZhydCommentException("站长已关闭匿名评论,请先登录!");
    }
    // 过滤文本内容,防止xss
    this.filterContent(comment);
    // 已登录且非匿名,使用当前登录用户的信息评论
    if (SessionUtil.isLogin()) {
        this.setCurrentLoginUserInfo(comment);
    } else {
        this.setCurrentAnonymousUserInfo(comment);
    }
    // 用户没有头像时, 使用随机默认的头像
    if (StringUtils.isEmpty(comment.getAvatar())) {
        List<String> avatars = configService.getRandomUserAvatar();
        if (!CollectionUtils.isEmpty(avatars)) {
            Collections.shuffle(avatars);
            int randomIndex = new Random().nextInt(avatars.size());
            comment.setAvatar(avatars.get(randomIndex));
        }
    }
    if (StringUtils.isEmpty(comment.getStatus())) {
        comment.setStatus(CommentStatusEnum.VERIFYING.toString());
    }
    // set当前评论者的设备信息
    this.setCurrentDeviceInfo(comment);
    // set当前评论者的位置信息
    this.setCurrentLocation(comment);
    // 保存
    this.insert(comment);
    // 发送邮件通知
    this.sendEmail(comment);
    return comment;
}
Also used : SysConfig(com.zyd.blog.persistence.beans.SysConfig) ZhydCommentException(com.zyd.blog.framework.exception.ZhydCommentException) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Aggregations

SysConfig (com.zyd.blog.persistence.beans.SysConfig)6 RedisCache (com.zyd.blog.business.annotation.RedisCache)3 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 Link (com.zyd.blog.business.entity.Link)1 ZhydCommentException (com.zyd.blog.framework.exception.ZhydCommentException)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1