use of com.zyd.blog.framework.exception.ZhydLinkException 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