From b50c505336068e3c880a69883375d3e87d04c0c6 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 17 Jul 2019 09:22:30 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E9=97=A8=E5=BA=97=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E6=A0=BC=E5=BC=8F=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8markdown=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/cms.go | 4 +++- business/jxstore/cms/store.go | 29 +++++++++++++++++------------ business/jxutils/msg/msg.go | 8 ++++++-- business/jxutils/tasksch/task.go | 3 ++- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index 3101a9030..8a8ef88a1 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -6,6 +6,8 @@ import ( "strings" "time" + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" + "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile" "git.rosy.net.cn/jx-callback/business/jxutils/msg" @@ -185,7 +187,7 @@ func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, ms for _, v := range receiveMsgUsersMap[msgType] { user, err2 := dao.GetUserByID(db, "name", v) if err2 == nil { - msg.SendUserMessage(user.GetID(), msgType, msgContent) + msg.SendUserMessage(dingdingapi.MsgTyeText, user.GetID(), msgType, msgContent) } else if err == nil { err = err2 } diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 50318016d..64b95590e 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -11,6 +11,7 @@ import ( "git.rosy.net.cn/jx-callback/business/auth2" "git.rosy.net.cn/baseapi/platformapi/dadaapi" + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -1546,19 +1547,23 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p curSnapshot := curSnapshotMap[v.GenMapKey()] storeDetail := storeDetailMap[v.StoreID] curStoreStatus := "无店" + curOpTimeStr := "无店" if curSnapshot != nil { curStoreStatus = model.StoreStatusName[curSnapshot.Status] + curOpTimeStr = jxutils.OperationTimeStr4VendorStore(curSnapshot) } - txtAlarm = append(txtAlarm, fmt.Sprintf(` -城市: %s -门店: %s -京西ID: %d -平台: %s -平台ID: %s -之前状态: %s -当前状态: %s`, storeDetail.CityName, storeDetail.Store.Name, v.StoreID, model.VendorChineseNames[v.VendorID], v.VendorStoreID, model.StoreStatusName[v.Status], curStoreStatus)) + txtAlarm = append(txtAlarm, fmt.Sprintf(`## 门店: %s(%d) +- 城市: %s +- 平台: %s +- 平台ID: %s +- 之前状态: %s +- 当前状态: %s +- 之前营业时间: %s +- 当前营业时间: %s +`, storeDetail.Store.Name, v.StoreID, storeDetail.CityName, model.VendorChineseNames[v.VendorID], v.VendorStoreID, model.StoreStatusName[v.Status], curStoreStatus, jxutils.OperationTimeStr4VendorStore(v), curOpTimeStr)) } - sendStoreStatusInfo2Mobile(mobile, title, excelURL, strings.Join(txtAlarm, "\n")) + alarmTextStr := "# " + title + " \n \n" + strings.Join(txtAlarm, " \n") + fmt.Sprintf("[详情点我](%s/billshow/?normal=true&path=%s)\n", globals.BackstageHost, excelURL) + sendStoreStatusInfo2Mobile(mobile, title, alarmTextStr) return nil, nil }, mobileList) tasksch.HandleTask(task, parentTask, true).Run() @@ -1571,7 +1576,7 @@ func shouldSkipMobile4SendStoreStatusInfo(mobile string) bool { return userProvider.GetUser(mobile, auth2.AuthTypeMobile) == nil } -func sendStoreStatusInfo2Mobile(mobile, title, excelURL, txtAlarm string) { +func sendStoreStatusInfo2Mobile(mobile, title, txtAlarm string) { mobileList := []string{mobile} for mobile := range mobileGroupMap[mobile] { mobileList = append(mobileList, mobile) @@ -1579,8 +1584,8 @@ func sendStoreStatusInfo2Mobile(mobile, title, excelURL, txtAlarm string) { for _, mobile := range mobileList { if user := userProvider.GetUser(mobile, auth2.AuthTypeMobile); user != nil { - globals.SugarLogger.Debugf("sendStoreStatusInfo2Mobile %s:%s, txtAlarm:\n%s", mobile, excelURL, txtAlarm) - msg.SendUserMessage(user.GetID(), title, fmt.Sprintf("门店状态报警\n%s\n详情见: \n%s", txtAlarm, excelURL)) + globals.SugarLogger.Debugf("sendStoreStatusInfo2Mobile %s, txtAlarm:\n%s", mobile, txtAlarm) + msg.SendUserMessage(dingdingapi.MsgTypeMarkdown, user.GetID(), title, txtAlarm) } } } diff --git a/business/jxutils/msg/msg.go b/business/jxutils/msg/msg.go index 32b9358bd..364786a91 100644 --- a/business/jxutils/msg/msg.go +++ b/business/jxutils/msg/msg.go @@ -10,7 +10,7 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) -func SendUserMessage(userID, title, content string) (err error) { +func SendUserMessage(msgType, userID, title, content string) (err error) { globals.SugarLogger.Debugf("SendUserMessage userID:%s, title:%s, content:%s", userID, title, content) authList, err := auth2.GetUserBindAuthInfo(userID) findOneMethod := false @@ -25,7 +25,11 @@ func SendUserMessage(userID, title, content string) (err error) { content = content[:dingdingapi.MaxWorkContentLen-4] + "..." } if globals.IsProductEnv() { - err = api.DingDingAPI.CorpAsyncSendSimple(auth.AuthID, content) + if msgType == dingdingapi.MsgTyeText { + err = api.DingDingAPI.CorpAsyncSendSimple(auth.AuthID, content) + } else if msgType == dingdingapi.MsgTypeMarkdown { + err = api.DingDingAPI.CorpAsyncSendMarkdown([]string{auth.AuthID}, nil, false, title, content) + } } break } diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index b9a915dcd..d418d2df9 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/msg" @@ -352,7 +353,7 @@ func (t *BaseTask) run(taskHandler func()) { content = fmt.Sprintf("%s执行失败,%s", taskDesc, t.Err.Error()) } } - msg.SendUserMessage(authInfo.UserID, "异步任务完成", content) + msg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) } } })