finclip-app-manager/infrastructure/kafka/notify.go

53 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package kafka
import (
"context"
"encoding/json"
"finclip-app-manager/infrastructure/client/httpcall"
"finclip-app-manager/infrastructure/config"
uuid "github.com/satori/go.uuid"
"strings"
)
//通知中心
type NotifyContent struct {
Msg string `json:"msg"`
Result string `json:"result"`
Reason string `json:"reason"`
Title string `json:"title"`
}
func GenNotifyData(ctx context.Context, organId string, t int, content NotifyContent) error {
data := make(map[string]interface{})
data["organTraceId"] = organId
data["tab"] = "work"
data["type"] = t //1000-1999:应用市场使用2000-2999:企业端使用3000-3999:运营端使用
data["content"] = content
data["id"] = uuid.NewV4().String()
jsonBytes, _ := json.Marshal(data)
if producer == nil {
req := &httpcall.AddNotifyReq{}
req.Id = uuid.NewV4().String()
req.Type = t
req.Content = content
req.OrganId = organId
req.Tab = "system"
err := hCaller.AddNotify(ctx, req)
return err
}
return sendMsg(ctx, config.GetConfig().KafkaNotifyTopic, string(jsonBytes))
}
func getAddrIp(address string) string {
ipArry := strings.Split(address, ",")
if len(ipArry) == 0 {
return ""
} else {
return ipArry[0]
}
}