feat: 添加流程节点邮件抄送功能。fix: #148
This commit is contained in:
parent
ce5c8adacf
commit
37e1f35c00
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,4 +9,5 @@ config/settings.dev.yml
|
|||||||
logs
|
logs
|
||||||
mysql/data
|
mysql/data
|
||||||
redis/data
|
redis/data
|
||||||
data/
|
data/
|
||||||
|
needinit
|
@ -14,7 +14,7 @@ import (
|
|||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func server(mailTo []string, subject, body string, args ...string) error {
|
func server(mailTo []string, ccTo []string, subject, body string, args ...string) error {
|
||||||
//定义邮箱服务器连接信息,如果是网易邮箱 pass填密码,qq邮箱填授权码
|
//定义邮箱服务器连接信息,如果是网易邮箱 pass填密码,qq邮箱填授权码
|
||||||
mailConn := map[string]string{
|
mailConn := map[string]string{
|
||||||
"user": viper.GetString("settings.email.user"),
|
"user": viper.GetString("settings.email.user"),
|
||||||
@ -29,6 +29,7 @@ func server(mailTo []string, subject, body string, args ...string) error {
|
|||||||
|
|
||||||
m.SetHeader("From", m.FormatAddress(mailConn["user"], viper.GetString("settings.email.alias"))) //这种方式可以添加别名,即“XX官方”
|
m.SetHeader("From", m.FormatAddress(mailConn["user"], viper.GetString("settings.email.alias"))) //这种方式可以添加别名,即“XX官方”
|
||||||
m.SetHeader("To", mailTo...) //发送给多个用户
|
m.SetHeader("To", mailTo...) //发送给多个用户
|
||||||
|
m.SetHeader("Cc", ccTo...) //发送给多个用户
|
||||||
m.SetHeader("Subject", subject) //设置邮件主题
|
m.SetHeader("Subject", subject) //设置邮件主题
|
||||||
m.SetBody("text/html", body) //设置邮件正文
|
m.SetBody("text/html", body) //设置邮件正文
|
||||||
|
|
||||||
@ -38,8 +39,8 @@ func server(mailTo []string, subject, body string, args ...string) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendMail(mailTo []string, subject, body string) {
|
func SendMail(mailTo []string, ccTo []string, subject, body string) {
|
||||||
err := server(mailTo, subject, body)
|
err := server(mailTo, ccTo, subject, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info(err)
|
logger.Info(err)
|
||||||
return
|
return
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
type BodyData struct {
|
type BodyData struct {
|
||||||
SendTo interface{} // 接受人
|
SendTo interface{} // 接受人
|
||||||
|
EmailCcTo []string // 抄送人邮箱列表
|
||||||
Subject string // 标题
|
Subject string // 标题
|
||||||
Classify []int // 通知类型
|
Classify []int // 通知类型
|
||||||
Id int // 工单ID
|
Id int // 工单ID
|
||||||
@ -80,7 +81,7 @@ func (b *BodyData) SendNotify() (err error) {
|
|||||||
logger.Errorf("模版内容解析失败,%v", err.Error())
|
logger.Errorf("模版内容解析失败,%v", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go email.SendMail(emailList, b.Subject, b.Content)
|
go email.SendMail(emailList, b.EmailCcTo, b.Subject, b.Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ func CreateWorkOrder(c *gin.Context) (err error) {
|
|||||||
tpl []byte
|
tpl []byte
|
||||||
sourceEdges []map[string]interface{}
|
sourceEdges []map[string]interface{}
|
||||||
targetEdges []map[string]interface{}
|
targetEdges []map[string]interface{}
|
||||||
|
currentNode map[string]interface{}
|
||||||
workOrderValue struct {
|
workOrderValue struct {
|
||||||
process.WorkOrderInfo
|
process.WorkOrderInfo
|
||||||
Tpls map[string][]interface{} `json:"tpls"`
|
Tpls map[string][]interface{} `json:"tpls"`
|
||||||
@ -79,6 +80,13 @@ func CreateWorkOrder(c *gin.Context) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(processValue.Structure, &processState.Structure)
|
err = json.Unmarshal(processValue.Structure, &processState.Structure)
|
||||||
|
|
||||||
|
for _, node := range processState.Structure["nodes"] {
|
||||||
|
if node["clazz"] == "start" {
|
||||||
|
currentNode = node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodeValue, err := processState.GetNode(variableValue[0].(map[string]interface{})["id"].(string))
|
nodeValue, err := processState.GetNode(variableValue[0].(map[string]interface{})["id"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -304,12 +312,24 @@ func CreateWorkOrder(c *gin.Context) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取需要抄送的邮件
|
||||||
|
emailCCList := make([]string, 0)
|
||||||
|
if len(currentNode["cc"].([]interface{})) > 0 {
|
||||||
|
err = orm.Eloquent.Model(&system.SysUser{}).
|
||||||
|
Where("user_id in (?)", currentNode["cc"]).
|
||||||
|
Pluck("email", &emailCCList).Error
|
||||||
|
if err != nil {
|
||||||
|
err = errors.New("查询邮件抄送人失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
// 发送通知
|
// 发送通知
|
||||||
go func() {
|
go func() {
|
||||||
bodyData := notify.BodyData{
|
bodyData := notify.BodyData{
|
||||||
SendTo: map[string]interface{}{
|
SendTo: map[string]interface{}{
|
||||||
"userList": sendToUserList,
|
"userList": sendToUserList,
|
||||||
},
|
},
|
||||||
|
EmailCcTo: emailCCList,
|
||||||
Subject: "您有一条待办工单,请及时处理",
|
Subject: "您有一条待办工单,请及时处理",
|
||||||
Description: "您有一条待办工单请及时处理,工单描述如下",
|
Description: "您有一条待办工单请及时处理,工单描述如下",
|
||||||
Classify: noticeList,
|
Classify: noticeList,
|
||||||
|
@ -806,10 +806,23 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取需要抄送的邮件
|
||||||
|
emailCCList := make([]string, 0)
|
||||||
|
if len(h.stateValue["cc"].([]interface{})) > 0 {
|
||||||
|
err = orm.Eloquent.Model(&system.SysUser{}).
|
||||||
|
Where("user_id in (?)", h.stateValue["cc"]).
|
||||||
|
Pluck("email", &emailCCList).Error
|
||||||
|
if err != nil {
|
||||||
|
err = errors.New("查询邮件抄送人失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bodyData := notify.BodyData{
|
bodyData := notify.BodyData{
|
||||||
SendTo: map[string]interface{}{
|
SendTo: map[string]interface{}{
|
||||||
"userList": sendToUserList,
|
"userList": sendToUserList,
|
||||||
},
|
},
|
||||||
|
EmailCcTo: emailCCList,
|
||||||
Subject: sendSubject,
|
Subject: sendSubject,
|
||||||
Description: sendDescription,
|
Description: sendDescription,
|
||||||
Classify: noticeList,
|
Classify: noticeList,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user