/
log.go
218 lines (209 loc) · 5.76 KB
/
log.go
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package service
import (
"context"
"encoding/json"
"strconv"
"strings"
"time"
"go-common/app/admin/main/videoup/model/archive"
"go-common/app/admin/main/videoup/model/music"
"go-common/app/admin/main/videoup/model/oversea"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/queue/databus/report"
)
// send to log service
func (s *Service) sendVideoLog(c context.Context, vp *archive.VideoParam, others string) (err error) {
var (
v *archive.Video
a *archive.Archive
)
if vp.Cid != 0 {
v, err = s.arc.VideoByCID(c, vp.Cid)
} else if vp.ID != 0 {
v, err = s.arc.NewVideoByID(c, vp.ID)
}
if err != nil || v == nil {
v = &archive.Video{} // ignore err
}
a, err = s.arc.Archive(c, vp.Aid)
if err != nil || a == nil {
a = &archive.Archive{} // ignore err
}
// send
logData := &report.ManagerInfo{
Uname: vp.Oname,
UID: vp.UID,
Business: archive.LogClientVideo,
Type: archive.LogClientTypeVideo,
Oid: vp.Cid,
Action: strconv.Itoa(int(vp.Status)),
Ctime: time.Now(),
Index: []interface{}{int64(vp.Attribute), v.CTime.Time().Unix(), vp.TagID, a.Title, vp.Note},
Content: map[string]interface{}{
"content": vp,
"others": others,
},
}
report.Manager(logData)
return
}
// send to log service
func (s *Service) sendArchiveLog(c context.Context, ap *archive.ArcParam, diff []string, a *archive.Archive) (err error) {
// fmt
ap.CTime = a.CTime
if ap.Title == "" {
ap.Title = a.Title
}
if ap.Attrs == nil {
ap.Attrs = &archive.AttrParam{}
}
diffStr := strings.Join(diff, "\n")
// log
logData := &report.ManagerInfo{
Uname: ap.UName,
UID: ap.UID,
Business: archive.LogClientArchive,
Type: archive.LogClientTypeArchive,
Oid: ap.Aid,
Action: strconv.Itoa(int(ap.State) + int(ap.Access)),
Ctime: time.Now(),
Index: []interface{}{a.Attribute, ap.CTime.Time().Unix(), ap.ReasonID, ap.Title, ap.Note},
Content: map[string]interface{}{
"content": ap,
"diff": diffStr,
},
}
report.Manager(logData)
extra, _ := json.Marshal(logData.Content)
log.Info("sendArchiveLog json.Marshal(%s) logData(%+v) ap(%+v)", extra, logData, ap)
return
}
//SendMusicLog send to log archive music
func (s *Service) SendMusicLog(c *bm.Context, clientType int, ap *music.LogParam) (err error) {
if s.c.Env == "dev" {
return
}
logData := &report.ManagerInfo{
Uname: ap.UName,
UID: ap.UID,
Business: archive.LogClientArchiveMusic,
Type: clientType,
Oid: ap.ID,
Action: ap.Action,
Ctime: time.Now(),
Index: []interface{}{ap.ID},
Content: map[string]interface{}{
"object": ap,
},
}
log.Info("sendMusicLog logData(%+v) ap(%+v)", logData, ap)
report.Manager(logData)
return
}
// sendPorderLog send porder modify log
func (s *Service) sendPorderLog(c context.Context, ap *archive.ArcParam, diff []string, porder *archive.Porder, a *archive.Archive) (err error) {
if a.AttrVal(archive.AttrBitIsPorder) != 1 && ap.Attrs.IsPorder != 1 {
log.Info("sendPorderLog ignore archive.is_porder(%d) ap.is_porder(%d) aid(%d)", a.AttrVal(archive.AttrBitIsPorder), ap.Attrs.IsPorder, a.Aid)
return
}
// fmt
var (
oldP = map[string]interface{}{
"is_porder": a.AttrVal(archive.AttrBitIsPorder),
"brand_id": porder.BrandID,
"brand_name": porder.BrandName,
"show_type": porder.ShowType,
"industry_id": porder.IndustryID,
"official": porder.Official,
"allow_tag": a.AttrVal(archive.AttrBitAllowTag),
}
newP = map[string]interface{}{
"is_porder": ap.Attrs.IsPorder,
"brand_id": ap.BrandID,
"brand_name": ap.BrandName,
"show_type": ap.ShowType,
"industry_id": ap.IndustryID,
"official": ap.Official,
"allow_tag": ap.Attrs.AllowTag,
}
)
ap.CTime = a.CTime
if ap.Title == "" {
ap.Title = a.Title
}
if ap.Attrs == nil {
ap.Attrs = &archive.AttrParam{}
}
diffStr := strings.Join(diff, "\n")
// log
logData := &report.ManagerInfo{
Uname: ap.UName,
UID: ap.UID,
Business: archive.LogClientPorder,
Type: archive.LogClientTypePorderLog,
Oid: ap.Aid,
Action: strconv.Itoa(int(ap.State) + int(ap.Access)),
Ctime: time.Now(),
Index: []interface{}{a.Attribute, ap.CTime.Time().Unix(), ap.ReasonID, ap.Title, ap.Note, ap.Porder.IndustryID, ap.Porder.Official, ap.Porder.GroupID},
Content: map[string]interface{}{
"content": ap,
"diff": diffStr,
"old": oldP,
"new": newP,
},
}
report.Manager(logData)
log.Info("sendPorderLog logData(%+v)", logData.Content)
return
}
// sendConsumerLog send consumer log
func (s *Service) sendConsumerLog(c context.Context, cl *archive.ConsumerLog) (err error) {
logData := &report.ManagerInfo{
Uname: cl.Uname,
UID: cl.UID,
Business: archive.LogClientConsumer,
Type: archive.LogClientTypeConsumer,
Oid: cl.UID,
Action: strconv.Itoa(int(cl.Action)),
Ctime: time.Now(),
Index: []interface{}{cl.UID, cl.Action, cl.Ctime},
Content: map[string]interface{}{
"content": cl,
},
}
report.Manager(logData)
log.Info("sendConsumerLog logData(%+v)", cl)
return
}
// sendPolicyLog send policy modify log
func (s *Service) sendPolicyLog(c context.Context, old, new *oversea.PolicyGroup) (err error) {
var (
action string
)
if new.ID == 0 {
action = "add"
} else if new.State == oversea.StateDeleted {
action = "del"
} else {
action = "update"
}
// log
logData := &report.ManagerInfo{
Uname: new.UserName,
UID: new.UID,
Business: archive.LogClientPolicy,
Type: archive.LogClientTypePolicy,
Oid: new.ID,
Action: action,
Ctime: time.Now(),
Index: []interface{}{new.Type},
Content: map[string]interface{}{
"old": old,
"new": new,
},
}
report.Manager(logData)
log.Info("sendPolicyLog logData(%+v)", logData)
return
}