relation_log.go 814 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/admin/main/relation/model"
  6. )
  7. // RelationLog is.
  8. func (s *Service) RelationLog(ctx context.Context, mid, fid int64, from time.Time, to time.Time) (model.RelationLogList, error) {
  9. logs, err := s.dao.RelationLogs(ctx, mid, fid, from, to)
  10. if err != nil {
  11. return nil, err
  12. }
  13. // order log by mtime with desc
  14. logs.OrderByMTime(true)
  15. uids := make([]int64, 0, len(logs)*2)
  16. for _, l := range logs {
  17. uids = append(uids, l.Mid)
  18. uids = append(uids, l.Fid)
  19. }
  20. uinfos, err := s.dao.RPCInfos(ctx, uids)
  21. if err != nil {
  22. return nil, err
  23. }
  24. for _, l := range logs {
  25. if mi, ok := uinfos[l.Mid]; ok {
  26. l.MemberName = mi.Name
  27. }
  28. }
  29. for _, l := range logs {
  30. if fi, ok := uinfos[l.Fid]; ok {
  31. l.FollowingName = fi.Name
  32. }
  33. }
  34. return logs, nil
  35. }