Search in sources :

Example 1 with Template

use of com.zyd.blog.business.entity.Template in project OneBlog by zhangyd-c.

the class MailServiceImpl method sendToAdmin.

/**
 * 发送到管理员的评论通知
 *
 * @param comment
 */
@Override
@Async
public void sendToAdmin(Comment comment) {
    Map config = configService.getConfigs();
    Template template = templateService.getTemplate(TemplateKeyEnum.TM_NEW_COMMENT);
    String temXml = template.getRefValue();
    Map<String, Object> map = new HashMap<>(2);
    map.put("comment", comment);
    map.put("config", config);
    String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
    String adminEmail = (String) config.get("authorEmail");
    if (StringUtils.isEmpty(adminEmail)) {
        log.warn("[sendToAdmin]邮件发送失败!未指定系统管理员的邮箱地址");
        return;
    }
    adminEmail = (adminEmail.contains("#") ? adminEmail.replace("#", "@") : adminEmail);
    MailDetail mailDetail = new MailDetail("有新的评论消息", adminEmail, (String) config.get("authorName"), mailContext);
    send(mailDetail);
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Example 2 with Template

use of com.zyd.blog.business.entity.Template in project OneBlog by zhangyd-c.

the class MailServiceImpl method send.

/**
 * 发送友情链接邮件通知
 *
 * @param link
 * @param keyEnum
 * @return
 */
@Override
@Async
public void send(Link link, TemplateKeyEnum keyEnum) {
    if (!StringUtils.isEmpty(link.getEmail())) {
        Map config = configService.getConfigs();
        Template template = templateService.getTemplate(keyEnum);
        String temXml = template.getRefValue();
        Map<String, Object> map = new HashMap<>(2);
        map.put("link", link);
        map.put("config", config);
        String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
        MailDetail mailDetail = new MailDetail("友情链接操作通知", link.getEmail(), link.getName(), mailContext);
        send(mailDetail);
    }
    this.sendToAdmin(link);
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Example 3 with Template

use of com.zyd.blog.business.entity.Template in project OneBlog by zhangyd-c.

the class MailServiceImpl method sendToAdmin.

/**
 * 发送到管理员的友链操作通知
 *
 * @param link
 */
@Override
@Async
public void sendToAdmin(Link link) {
    Map config = configService.getConfigs();
    Template template = templateService.getTemplate(TemplateKeyEnum.TM_LINKS_TO_ADMIN);
    String temXml = template.getRefValue();
    Map<String, Object> map = new HashMap<>(1);
    map.put("link", link);
    String mailContext = FreeMarkerUtil.template2String(temXml, map, true);
    String adminEmail = (String) config.get(ConfigKeyEnum.AUTHOR_EMAIL.getKey());
    if (StringUtils.isEmpty(adminEmail)) {
        log.warn("[sendToAdmin]邮件发送失败!未指定系统管理员的邮箱地址");
        return;
    }
    adminEmail = (adminEmail.contains("#") ? adminEmail.replace("#", "@") : adminEmail);
    MailDetail mailDetail = new MailDetail("有新的友链消息", adminEmail, (String) config.get(ConfigKeyEnum.AUTHOR_NAME.getKey()), mailContext);
    send(mailDetail);
}
Also used : HashMap(java.util.HashMap) MailDetail(com.zyd.blog.business.entity.MailDetail) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.zyd.blog.business.entity.Template) Async(org.springframework.scheduling.annotation.Async)

Example 4 with Template

use of com.zyd.blog.business.entity.Template in project OneBlog by zhangyd-c.

the class SysTemplateServiceImpl method listAll.

@Override
public List<Template> listAll() {
    List<SysTemplate> entityList = sysTemplateMapper.selectAll();
    if (CollectionUtils.isEmpty(entityList)) {
        return null;
    }
    List<Template> list = new ArrayList<>();
    for (SysTemplate entity : entityList) {
        list.add(new Template(entity));
    }
    return list;
}
Also used : SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) ArrayList(java.util.ArrayList) SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) Template(com.zyd.blog.business.entity.Template)

Example 5 with Template

use of com.zyd.blog.business.entity.Template in project OneBlog by zhangyd-c.

the class SysTemplateServiceImpl method findPageBreakByCondition.

/**
 * 分页查询
 *
 * @param vo
 * @return
 */
@Override
public PageInfo<Template> findPageBreakByCondition(TemplateConditionVO vo) {
    PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
    List<SysTemplate> list = sysTemplateMapper.findPageBreakByCondition(vo);
    if (CollectionUtils.isEmpty(list)) {
        return null;
    }
    List<Template> boList = new ArrayList<>();
    for (SysTemplate sysTemplate : list) {
        boList.add(new Template(sysTemplate));
    }
    PageInfo bean = new PageInfo<SysTemplate>(list);
    bean.setList(boList);
    return bean;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) ArrayList(java.util.ArrayList) SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) Template(com.zyd.blog.business.entity.Template)

Aggregations

Template (com.zyd.blog.business.entity.Template)10 HashMap (java.util.HashMap)6 MailDetail (com.zyd.blog.business.entity.MailDetail)4 SysTemplate (com.zyd.blog.persistence.beans.SysTemplate)4 Map (java.util.Map)4 Async (org.springframework.scheduling.annotation.Async)4 ArrayList (java.util.ArrayList)2 PageInfo (com.github.pagehelper.PageInfo)1 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1