log.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "go-common/app/admin/main/videoup/model/archive"
  9. "go-common/app/admin/main/videoup/model/music"
  10. "go-common/app/admin/main/videoup/model/oversea"
  11. "go-common/library/log"
  12. bm "go-common/library/net/http/blademaster"
  13. "go-common/library/queue/databus/report"
  14. )
  15. // send to log service
  16. func (s *Service) sendVideoLog(c context.Context, vp *archive.VideoParam, others string) (err error) {
  17. var (
  18. v *archive.Video
  19. a *archive.Archive
  20. )
  21. if vp.Cid != 0 {
  22. v, err = s.arc.VideoByCID(c, vp.Cid)
  23. } else if vp.ID != 0 {
  24. v, err = s.arc.NewVideoByID(c, vp.ID)
  25. }
  26. if err != nil || v == nil {
  27. v = &archive.Video{} // ignore err
  28. }
  29. a, err = s.arc.Archive(c, vp.Aid)
  30. if err != nil || a == nil {
  31. a = &archive.Archive{} // ignore err
  32. }
  33. // send
  34. logData := &report.ManagerInfo{
  35. Uname: vp.Oname,
  36. UID: vp.UID,
  37. Business: archive.LogClientVideo,
  38. Type: archive.LogClientTypeVideo,
  39. Oid: vp.Cid,
  40. Action: strconv.Itoa(int(vp.Status)),
  41. Ctime: time.Now(),
  42. Index: []interface{}{int64(vp.Attribute), v.CTime.Time().Unix(), vp.TagID, a.Title, vp.Note},
  43. Content: map[string]interface{}{
  44. "content": vp,
  45. "others": others,
  46. },
  47. }
  48. report.Manager(logData)
  49. return
  50. }
  51. // send to log service
  52. func (s *Service) sendArchiveLog(c context.Context, ap *archive.ArcParam, diff []string, a *archive.Archive) (err error) {
  53. // fmt
  54. ap.CTime = a.CTime
  55. if ap.Title == "" {
  56. ap.Title = a.Title
  57. }
  58. if ap.Attrs == nil {
  59. ap.Attrs = &archive.AttrParam{}
  60. }
  61. diffStr := strings.Join(diff, "\n")
  62. // log
  63. logData := &report.ManagerInfo{
  64. Uname: ap.UName,
  65. UID: ap.UID,
  66. Business: archive.LogClientArchive,
  67. Type: archive.LogClientTypeArchive,
  68. Oid: ap.Aid,
  69. Action: strconv.Itoa(int(ap.State) + int(ap.Access)),
  70. Ctime: time.Now(),
  71. Index: []interface{}{a.Attribute, ap.CTime.Time().Unix(), ap.ReasonID, ap.Title, ap.Note},
  72. Content: map[string]interface{}{
  73. "content": ap,
  74. "diff": diffStr,
  75. },
  76. }
  77. report.Manager(logData)
  78. extra, _ := json.Marshal(logData.Content)
  79. log.Info("sendArchiveLog json.Marshal(%s) logData(%+v) ap(%+v)", extra, logData, ap)
  80. return
  81. }
  82. //SendMusicLog send to log archive music
  83. func (s *Service) SendMusicLog(c *bm.Context, clientType int, ap *music.LogParam) (err error) {
  84. if s.c.Env == "dev" {
  85. return
  86. }
  87. logData := &report.ManagerInfo{
  88. Uname: ap.UName,
  89. UID: ap.UID,
  90. Business: archive.LogClientArchiveMusic,
  91. Type: clientType,
  92. Oid: ap.ID,
  93. Action: ap.Action,
  94. Ctime: time.Now(),
  95. Index: []interface{}{ap.ID},
  96. Content: map[string]interface{}{
  97. "object": ap,
  98. },
  99. }
  100. log.Info("sendMusicLog logData(%+v) ap(%+v)", logData, ap)
  101. report.Manager(logData)
  102. return
  103. }
  104. // sendPorderLog send porder modify log
  105. func (s *Service) sendPorderLog(c context.Context, ap *archive.ArcParam, diff []string, porder *archive.Porder, a *archive.Archive) (err error) {
  106. if a.AttrVal(archive.AttrBitIsPorder) != 1 && ap.Attrs.IsPorder != 1 {
  107. log.Info("sendPorderLog ignore archive.is_porder(%d) ap.is_porder(%d) aid(%d)", a.AttrVal(archive.AttrBitIsPorder), ap.Attrs.IsPorder, a.Aid)
  108. return
  109. }
  110. // fmt
  111. var (
  112. oldP = map[string]interface{}{
  113. "is_porder": a.AttrVal(archive.AttrBitIsPorder),
  114. "brand_id": porder.BrandID,
  115. "brand_name": porder.BrandName,
  116. "show_type": porder.ShowType,
  117. "industry_id": porder.IndustryID,
  118. "official": porder.Official,
  119. "allow_tag": a.AttrVal(archive.AttrBitAllowTag),
  120. }
  121. newP = map[string]interface{}{
  122. "is_porder": ap.Attrs.IsPorder,
  123. "brand_id": ap.BrandID,
  124. "brand_name": ap.BrandName,
  125. "show_type": ap.ShowType,
  126. "industry_id": ap.IndustryID,
  127. "official": ap.Official,
  128. "allow_tag": ap.Attrs.AllowTag,
  129. }
  130. )
  131. ap.CTime = a.CTime
  132. if ap.Title == "" {
  133. ap.Title = a.Title
  134. }
  135. if ap.Attrs == nil {
  136. ap.Attrs = &archive.AttrParam{}
  137. }
  138. diffStr := strings.Join(diff, "\n")
  139. // log
  140. logData := &report.ManagerInfo{
  141. Uname: ap.UName,
  142. UID: ap.UID,
  143. Business: archive.LogClientPorder,
  144. Type: archive.LogClientTypePorderLog,
  145. Oid: ap.Aid,
  146. Action: strconv.Itoa(int(ap.State) + int(ap.Access)),
  147. Ctime: time.Now(),
  148. Index: []interface{}{a.Attribute, ap.CTime.Time().Unix(), ap.ReasonID, ap.Title, ap.Note, ap.Porder.IndustryID, ap.Porder.Official, ap.Porder.GroupID},
  149. Content: map[string]interface{}{
  150. "content": ap,
  151. "diff": diffStr,
  152. "old": oldP,
  153. "new": newP,
  154. },
  155. }
  156. report.Manager(logData)
  157. log.Info("sendPorderLog logData(%+v)", logData.Content)
  158. return
  159. }
  160. // sendConsumerLog send consumer log
  161. func (s *Service) sendConsumerLog(c context.Context, cl *archive.ConsumerLog) (err error) {
  162. logData := &report.ManagerInfo{
  163. Uname: cl.Uname,
  164. UID: cl.UID,
  165. Business: archive.LogClientConsumer,
  166. Type: archive.LogClientTypeConsumer,
  167. Oid: cl.UID,
  168. Action: strconv.Itoa(int(cl.Action)),
  169. Ctime: time.Now(),
  170. Index: []interface{}{cl.UID, cl.Action, cl.Ctime},
  171. Content: map[string]interface{}{
  172. "content": cl,
  173. },
  174. }
  175. report.Manager(logData)
  176. log.Info("sendConsumerLog logData(%+v)", cl)
  177. return
  178. }
  179. // sendPolicyLog send policy modify log
  180. func (s *Service) sendPolicyLog(c context.Context, old, new *oversea.PolicyGroup) (err error) {
  181. var (
  182. action string
  183. )
  184. if new.ID == 0 {
  185. action = "add"
  186. } else if new.State == oversea.StateDeleted {
  187. action = "del"
  188. } else {
  189. action = "update"
  190. }
  191. // log
  192. logData := &report.ManagerInfo{
  193. Uname: new.UserName,
  194. UID: new.UID,
  195. Business: archive.LogClientPolicy,
  196. Type: archive.LogClientTypePolicy,
  197. Oid: new.ID,
  198. Action: action,
  199. Ctime: time.Now(),
  200. Index: []interface{}{new.Type},
  201. Content: map[string]interface{}{
  202. "old": old,
  203. "new": new,
  204. },
  205. }
  206. report.Manager(logData)
  207. log.Info("sendPolicyLog logData(%+v)", logData)
  208. return
  209. }