Search in sources :

Example 6 with Template

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

the class MailServiceImpl method send.

/**
 * 发送评论邮件通知
 *
 * @param comment
 * @param keyEnum
 * @param audit
 * @return
 */
@Override
@Async
public void send(Comment comment, TemplateKeyEnum keyEnum, boolean audit) {
    if (comment == null || StringUtils.isEmpty(comment.getEmail())) {
        this.sendToAdmin(comment);
        return;
    }
    Map config = configService.getConfigs();
    Template template = templateService.getTemplate(keyEnum);
    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 subject = "评论回复通知";
    if (audit) {
        subject = "评论审核结果通知";
    }
    MailDetail mailDetail = new MailDetail(subject, comment.getEmail(), comment.getNickname(), mailContext);
    send(mailDetail);
    if (!audit) {
        this.sendToAdmin(comment);
    }
}
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 7 with Template

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

the class SysTemplateServiceImpl method getTemplate.

@Override
public Template getTemplate(String key) {
    if (StringUtils.isEmpty(key)) {
        return null;
    }
    SysTemplate entity = new SysTemplate();
    entity.setRefKey(key);
    entity = this.sysTemplateMapper.selectOne(entity);
    return null == entity ? null : new Template(entity);
}
Also used : SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) Template(com.zyd.blog.business.entity.Template)

Example 8 with Template

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

the class SysTemplateServiceImpl method getByPrimaryKey.

@Override
public Template getByPrimaryKey(Long primaryKey) {
    Assert.notNull(primaryKey, "PrimaryKey不可为空!");
    SysTemplate entity = sysTemplateMapper.selectByPrimaryKey(primaryKey);
    return null == entity ? null : new Template(entity);
}
Also used : SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) SysTemplate(com.zyd.blog.persistence.beans.SysTemplate) Template(com.zyd.blog.business.entity.Template)

Example 9 with Template

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

the class RestWebSiteController method robots.

@GetMapping(value = "/robots.txt", produces = { "text/plain" })
@BussinessLog(value = "查看robots", platform = PlatformEnum.WEB)
public String robots() {
    Template template = templateService.getTemplate(TemplateKeyEnum.TM_ROBOTS);
    Map<String, Object> map = new HashMap<>();
    map.put("config", configService.getConfigs());
    return FreeMarkerUtil.template2String(template.getRefValue(), map, true);
}
Also used : HashMap(java.util.HashMap) Template(com.zyd.blog.business.entity.Template) GetMapping(org.springframework.web.bind.annotation.GetMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 10 with Template

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

the class RestWebSiteController method getSitemap.

private String getSitemap(TemplateKeyEnum key) {
    Template template = templateService.getTemplate(key);
    Map<String, Object> map = new HashMap<>();
    map.put("articleTypeList", typeService.listAll());
    map.put("articleTagsList", tagsService.listAll());
    map.put("articleList", articleService.listAll());
    map.put("config", configService.getConfigs());
    return FreeMarkerUtil.template2String(template.getRefValue(), map, true);
}
Also used : HashMap(java.util.HashMap) 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