audit_log.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package block
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. model "go-common/app/job/main/member/model/block"
  7. "go-common/library/log"
  8. manager "go-common/library/queue/databus/report"
  9. )
  10. // AddAuditLog .
  11. func (s *Service) AddAuditLog(c context.Context, tp model.BlockAction, uid int64, uname string, oids []int64, duration time.Duration, source model.BlockSource, area model.BlockArea, reason, comment string, notify bool, stime time.Time) error {
  12. var (
  13. err error
  14. dur = int64(duration / time.Second)
  15. notifyStr = strconv.FormatBool(notify)
  16. )
  17. for _, oid := range oids {
  18. managerInfo := &manager.ManagerInfo{
  19. UID: uid,
  20. Uname: uname,
  21. Business: model.BlockLogBizID,
  22. Type: int(tp),
  23. Action: tp.String(),
  24. Oid: oid,
  25. Ctime: time.Now(),
  26. Index: []interface{}{dur, uint8(source), uint8(area), reason, comment, notifyStr},
  27. Content: map[string]interface{}{
  28. "duration": dur,
  29. "source": source,
  30. "area": area,
  31. "reason": reason,
  32. "comment": comment,
  33. "notify": notifyStr,
  34. "action_time": stime.Unix(),
  35. "remove_time": stime.Add(time.Second * time.Duration(dur)).Unix(),
  36. },
  37. }
  38. if err = manager.Manager(managerInfo); err != nil {
  39. log.Error("manager.Manager(%+v) error(%+v)", managerInfo, err)
  40. continue
  41. }
  42. log.Info("s.managerSendLog(%+v)", managerInfo)
  43. }
  44. return err
  45. }