整理邮件模版。

This commit is contained in:
Mr. Lan 2020-07-25 16:11:47 +08:00
parent 7e80400479
commit 9f3e66e50f
3 changed files with 121 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import (
"ferry/tools/app"
"fmt"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
@ -206,9 +207,22 @@ func CreateWorkOrder(c *gin.Context) {
return
}
go notify.SendNotify(noticeList, map[string]interface{}{
"userList": sendToUserList,
}, "您有一条待办工单,请及时处理。", "测试")
// 发送通知
go func() {
bodyData := notify.BodyData{
SendTo: map[string]interface{}{
"userList": sendToUserList,
},
Subject: "您有一条待办工单,请及时处理。",
Classify: noticeList,
Id: workOrderValue.Id,
Title: workOrderValue.Title,
Creator: userInfo.NickName,
Priority: workOrderValue.Priority,
CreatedAt: time.Now().Format("2006-01-02 15:04:05"),
}
bodyData.SendNotify()
}()
}
// 执行任务

View File

@ -1,8 +1,13 @@
package notify
import (
"bytes"
"ferry/models/system"
"ferry/pkg/notify/email"
"os"
"text/template"
log "github.com/sirupsen/logrus"
)
/*
@ -10,17 +15,68 @@ import (
@同时发送多种通知方式
*/
func SendNotify(classify []int, sendTo interface{}, subject, body string) {
type BodyData struct {
SendTo interface{} // 接受人
Subject string // 标题
Classify []int // 通知类型
Id int // 工单ID
Title string // 工单标题
Creator string // 工单创建人
Priority int // 工单优先级
PriorityValue string // 工单优先级
CreatedAt string // 工单创建时间
Content string // 通知的内容
}
func (b *BodyData) ParsingTemplate() (err error) {
// 读取模版数据
var (
buf bytes.Buffer
)
log.Info(os.Getwd())
tmpl, err := template.ParseFiles("./pkg/notify/template/email.html")
if err != nil {
return
}
err = tmpl.Execute(&buf, b)
if err != nil {
return
}
b.Content = buf.String()
return
}
func (b *BodyData) SendNotify() {
var (
emailList []string
err error
)
for _, c := range classify {
switch b.Priority {
case 1:
b.PriorityValue = "正常"
case 2:
b.PriorityValue = "紧急"
case 3:
b.PriorityValue = "非常紧急"
}
for _, c := range b.Classify {
switch c {
case 1: // 邮件
for _, user := range sendTo.(map[string]interface{})["userList"].([]system.SysUser) {
for _, user := range b.SendTo.(map[string]interface{})["userList"].([]system.SysUser) {
emailList = append(emailList, user.Email)
}
go email.SendMail(emailList, subject, body)
err = b.ParsingTemplate()
if err != nil {
log.Errorf("模版内容解析失败,%v", err.Error())
return
}
go email.SendMail(emailList, b.Subject, b.Content)
}
}
}

View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ferry</title>
</head>
<body>
<br>
您有一条待办工单请及时处理,以下为工单详情:
<br>
<br>
<table>
<tr>
<td style="text-align: right">标题:</td>
<td>{{ .Title }}</td>
</tr>
<tr>
<td style="text-align: right">申请人:</td>
<td>{{ .Creator }}</td>
</tr>
<tr>
<td style="text-align: right">优先级:</td>
<td>{{ .PriorityValue }}</td>
</tr>
<tr>
<td style="text-align: right">申请时间:</td>
<td>{{ .CreatedAt }}</td>
</tr>
</table>
<br>
<a href="" target="_blank">点击此处跳转工单详情</a>
</body>
<style>
table {
border: 1px solid #ccc;
border-collapse:collapse;
}
td {
padding: 10px 15px 10px 15px;
border: 1px solid #ccc;
}
</style>
</html>