1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package utils
- import (
- "adm-dws/apis"
- "adm-dws/common.in/clinit"
- "adm-dws/common.in/mq"
- "adm-dws/consts"
- "adm-dws/model"
- "encoding/json"
- "fmt"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- )
- func getKey(content string,keys []string) string{
- key := ""
- if keys == nil {
- return key
- }
- for _,v := range keys{
- key = key+gjson.Get(content, v).String()
- }
- return key
- }
- // 获取主键
- func GetPrimaryKey(content string,outputSource string ,keys []string ) (string,string) {
- key := getKey(content,keys)
- if key == ""{
- return "",""
- }
- lockKey := fmt.Sprintf("dws-lock-%s-%s",outputSource,key)
- taskKey := fmt.Sprintf("dws-task-%s-%s",outputSource,key)
- return lockKey,taskKey
- }
- func SendAdsMsg(adsMsg *apis.AdsMessage) error {
- mqMsg,_ := json.Marshal(adsMsg)
- err := mq.AdsMq.PublishMsg(mqMsg)
- if err != nil{
- // 发送消息失败记录消息到本地库
- failMsg := &model.FailMsg{}
- failMsg.Msg = string(mqMsg)
- failMsg.MsgType = consts.ADSMSGTYPE
- err = failMsg.Insert(clinit.DB())
- if err != nil {
- l.Error("mysql",
- zap.String("sql", "insert into t_adm-dws_fail_msg"),
- zap.String("fields", failMsg.Msg),
- zap.String("error", err.Error()))
- }
- return err
- }
- return err
- }
- func SendDwsMsg(dwsMsg *apis.DwsMessage) error{
- mqMsg,_ := json.Marshal(*dwsMsg)
- err := mq.DwsMq.PublishMsg(mqMsg)
- if err != nil{
- // 发送消息失败记录消息到本地库
- failMsg := &model.FailMsg{}
- failMsg.Msg = string(mqMsg)
- failMsg.MsgType = consts.DWSMSGTYPE
- err = failMsg.Insert(clinit.DB())
- if err != nil {
- l.Error("mysql",
- zap.String("sql", "insert into t_adm-dws_fail_msg"),
- zap.String("fields", failMsg.Msg),
- zap.String("error", err.Error()))
- }
- return err
- }
- return err
- }
- func SendMd5Msg(msg map[string]string) error{
- mqMsg,_ := json.Marshal(msg)
- err := mq.Md5Mq.PublishMsg(mqMsg)
- if err != nil{
- l.Error("send msg",
- zap.String("call", "Md5Mq.PublishMsg"),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
|