use of com.zyd.blog.business.entity.Link 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());
}
}
}
use of com.zyd.blog.business.entity.Link 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;
}
use of com.zyd.blog.business.entity.Link in project OneBlog by zhangyd-c.
the class SysLinkServiceImpl method listOfIndex.
/**
* 查询可在首页显示的友情链接列表
*
* @return
*/
@Override
@RedisCache
public List<Link> listOfIndex() {
LinkConditionVO vo = new LinkConditionVO(1, 1);
vo.setPageSize(100);
PageInfo<Link> pageInfo = this.findPageBreakByCondition(vo);
return pageInfo == null ? null : pageInfo.getList();
}
use of com.zyd.blog.business.entity.Link in project OneBlog by zhangyd-c.
the class SysLinkServiceImpl method listOfDisable.
/**
* 查询已禁用的友情链接列表
*
* @return
*/
@Override
@RedisCache
public List<Link> listOfDisable() {
LinkConditionVO vo = new LinkConditionVO(0, null);
vo.setPageSize(100);
PageInfo<Link> pageInfo = this.findPageBreakByCondition(vo);
return pageInfo == null ? null : pageInfo.getList();
}
use of com.zyd.blog.business.entity.Link in project OneBlog by zhangyd-c.
the class SysLinkServiceImpl method getByPrimaryKey.
@Override
public Link getByPrimaryKey(Long primaryKey) {
Assert.notNull(primaryKey, "PrimaryKey不可为空!");
SysLink entity = sysLinkMapper.selectByPrimaryKey(primaryKey);
return null == entity ? null : new Link(entity);
}
Aggregations