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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
gresp, body, errs := gorequest.New().Post(initNotifyRow.URL).Timeout(time.Second * 30).Send(initNotifyRow.Msg).End()
if errs != nil {
hcommon.Log.Errorf("err: [%T] %s", errs[0], errs[0].Error())
_, err = SQLUpdateTProductNotifyStatusByID(
context.Background(),
DbCon,
&model.DBTProductNotify{
ID: initNotifyRow.ID,
HandleStatus: 1,
HandleMsg: errs[0].Error(),
UpdateTime: time.Now().Unix(),
},
)
if err != nil {
hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
}
continue
}
if gresp.StatusCode != http.StatusOK {
// 状态错误
hcommon.Log.Errorf("req status error: %d", gresp.StatusCode)
_, err = SQLUpdateTProductNotifyStatusByID(
context.Background(),
DbCon,
&model.DBTProductNotify{
ID: initNotifyRow.ID,
HandleStatus: 1,
HandleMsg: fmt.Sprintf("http status: %d", gresp.StatusCode),
UpdateTime: time.Now().Unix(),
},
)
if err != nil {
hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
}
continue
}
resp := gin.H{}
err = json.Unmarshal([]byte(body), &resp)
if err != nil {
hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
_, err = SQLUpdateTProductNotifyStatusByID(
context.Background(),
DbCon,
&model.DBTProductNotify{
ID: initNotifyRow.ID,
HandleStatus: 1,
HandleMsg: body,
UpdateTime: time.Now().Unix(),
},
)
if err != nil {
hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
}
continue
}
_, ok := resp["error"]
if ok {
// 处理成功
_, err = SQLUpdateTProductNotifyStatusByID(
context.Background(),
DbCon,
&model.DBTProductNotify{
ID: initNotifyRow.ID,
HandleStatus: 2,
HandleMsg: body,
UpdateTime: time.Now().Unix(),
},
)
if err != nil {
hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
}
} else {
hcommon.Log.Errorf("no error in resp")
_, err = SQLUpdateTProductNotifyStatusByID(
context.Background(),
DbCon,
&model.DBTProductNotify{
ID: initNotifyRow.ID,
HandleStatus: 1,
HandleMsg: body,
UpdateTime: time.Now().Unix(),
},
)
if err != nil {
hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
}
continue
}
|