xiangmi.go
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package handles
import (
"encoding/json"
"fmt"
"github.com/Shopify/sarama"
"github.com/astaxie/beego/logs"
syncOrderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/syncOrder/command"
syncOrderSrv "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/syncOrder/service"
)
func DataFromXiangMi(message *sarama.ConsumerMessage) error {
logs.Info("Done Message claimed: timestamp = %v, topic = %s offset = %v value = %v \n",
message.Timestamp, message.Topic, message.Offset, string(message.Value))
var (
msgData DataFromMessage
err error
)
err = json.Unmarshal(message.Value, &msgData)
if err != nil {
return fmt.Errorf("[Consumer][SyncBestshopOrder] 解析kafka数据失败;%s", err)
}
dataAction := msgData.Module + "/" + msgData.Action
switch dataAction {
case "xiangmi.order/ship":
err = syncBestshopOrder(msgData.Data)
if err != nil {
e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err)
return e
}
default:
logs.Error("未找到执行动作:Module=%s,Action=%s", msgData.Module, msgData.Action)
}
return nil
}
//SyncBestshopOrder 同步
func syncBestshopOrder(data []byte) error {
var (
cmd syncOrderCmd.CreateOrderFromBestshop
err error
)
err = json.Unmarshal(data, &cmd)
if err != nil {
return fmt.Errorf("[Consumer][syncBestshopOrder] 解析kafka数据失败;%s", err)
}
if cmd.PartnerId <= 0 {
logs.Info("[Consumer][syncBestshopOrder] PartnerId<=0 ,不处理消息")
return nil
}
srv := syncOrderSrv.NewOrderInfoService(nil)
err = srv.SyncOrderFromBestshop(cmd)
if err != nil {
e := fmt.Errorf("[Consumer][syncBestshopOrder] %s", err)
return e
}
return err
}