From 37e1f35c00ce2cb5a16312697d45eb8a8fc5b135 Mon Sep 17 00:00:00 2001 From: lanyulei Date: Sat, 5 Jun 2021 00:40:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E9=82=AE=E4=BB=B6=E6=8A=84=E9=80=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82fix:=20#148?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- pkg/notify/email/email.go | 7 ++++--- pkg/notify/send.go | 3 ++- pkg/service/createWorkOrder.go | 20 ++++++++++++++++++++ pkg/service/handle.go | 13 +++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8eee456..c4b8c0c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ config/settings.dev.yml logs mysql/data redis/data -data/ \ No newline at end of file +data/ +needinit \ No newline at end of file diff --git a/pkg/notify/email/email.go b/pkg/notify/email/email.go index 1b26190..0dd56eb 100644 --- a/pkg/notify/email/email.go +++ b/pkg/notify/email/email.go @@ -14,7 +14,7 @@ import ( "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邮箱填授权码 mailConn := map[string]string{ "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("To", mailTo...) //发送给多个用户 + m.SetHeader("Cc", ccTo...) //发送给多个用户 m.SetHeader("Subject", subject) //设置邮件主题 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) { - err := server(mailTo, subject, body) +func SendMail(mailTo []string, ccTo []string, subject, body string) { + err := server(mailTo, ccTo, subject, body) if err != nil { logger.Info(err) return diff --git a/pkg/notify/send.go b/pkg/notify/send.go index d54b075..a3b1872 100644 --- a/pkg/notify/send.go +++ b/pkg/notify/send.go @@ -17,6 +17,7 @@ import ( type BodyData struct { SendTo interface{} // 接受人 + EmailCcTo []string // 抄送人邮箱列表 Subject string // 标题 Classify []int // 通知类型 Id int // 工单ID @@ -80,7 +81,7 @@ func (b *BodyData) SendNotify() (err error) { logger.Errorf("模版内容解析失败,%v", err.Error()) return } - go email.SendMail(emailList, b.Subject, b.Content) + go email.SendMail(emailList, b.EmailCcTo, b.Subject, b.Content) } } } diff --git a/pkg/service/createWorkOrder.go b/pkg/service/createWorkOrder.go index 8c9b5ba..a923a90 100644 --- a/pkg/service/createWorkOrder.go +++ b/pkg/service/createWorkOrder.go @@ -33,6 +33,7 @@ func CreateWorkOrder(c *gin.Context) (err error) { tpl []byte sourceEdges []map[string]interface{} targetEdges []map[string]interface{} + currentNode map[string]interface{} workOrderValue struct { process.WorkOrderInfo Tpls map[string][]interface{} `json:"tpls"` @@ -79,6 +80,13 @@ func CreateWorkOrder(c *gin.Context) (err error) { } 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)) if err != nil { return @@ -304,12 +312,24 @@ func CreateWorkOrder(c *gin.Context) (err error) { 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() { bodyData := notify.BodyData{ SendTo: map[string]interface{}{ "userList": sendToUserList, }, + EmailCcTo: emailCCList, Subject: "您有一条待办工单,请及时处理", Description: "您有一条待办工单请及时处理,工单描述如下", Classify: noticeList, diff --git a/pkg/service/handle.go b/pkg/service/handle.go index f9de51d..b775a88 100644 --- a/pkg/service/handle.go +++ b/pkg/service/handle.go @@ -806,10 +806,23 @@ func (h *Handle) HandleWorkOrder( 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{ SendTo: map[string]interface{}{ "userList": sendToUserList, }, + EmailCcTo: emailCCList, Subject: sendSubject, Description: sendDescription, Classify: noticeList,