log.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "time"
  7. "go-common/app/admin/main/spy/model"
  8. "go-common/library/log"
  9. )
  10. // AddLog add log.
  11. func (s *Service) AddLog(c context.Context, name string, m int8, v interface{}) (err error) {
  12. b, err := json.Marshal(v)
  13. if err != nil {
  14. log.Error("AddLog json.Marshal(%v) error(%v)", v, err)
  15. return
  16. }
  17. l := &model.Log{Name: name, Module: m, Context: string(b)}
  18. _, err = s.spyDao.AddLog(c, l)
  19. if err != nil {
  20. log.Error("userDao spyDao.AddLog(%v) error(%v)", l, err)
  21. return
  22. }
  23. return
  24. }
  25. // AddLog2 add log.
  26. func (s *Service) AddLog2(c context.Context, l *model.Log) (err error) {
  27. l.Ctime = time.Now()
  28. _, err = s.spyDao.AddLog(c, l)
  29. return
  30. }
  31. // LogList add log.
  32. func (s *Service) LogList(c context.Context, refID int64, module int8) (list []*model.Log, err error) {
  33. list, err = s.spyDao.LogList(c, refID, module)
  34. return
  35. }
  36. // UpdateStateLog get log.
  37. func (s *Service) UpdateStateLog(refID int64, state string) (log string) {
  38. log = fmt.Sprintf("%d : 状态修改为[%s]", refID, state)
  39. return
  40. }
  41. // AddRemarkLog add reamrk log.
  42. func (s *Service) AddRemarkLog(refID int64, remark string) (log string) {
  43. log = fmt.Sprintf("%d : [备注]%s", refID, remark)
  44. return
  45. }
  46. // DeleteStatLog delete log .
  47. func (s *Service) DeleteStatLog(refID int64) (log string) {
  48. log = fmt.Sprintf("%d 删除记录", refID)
  49. return
  50. }
  51. // UpdateStatCountLog update stat count log.
  52. func (s *Service) UpdateStatCountLog(refID int64, old int64, new int64) (log string) {
  53. log = fmt.Sprintf("%d [修正数值] %d -> %d", refID, old, new)
  54. return
  55. }