activity.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package service
  2. import (
  3. "context"
  4. "sort"
  5. "go-common/app/admin/main/workflow/model"
  6. "go-common/library/log"
  7. )
  8. // ActivityList will list activities by given conditions
  9. func (s *Service) ActivityList(c context.Context, business int8, cid int64) (acts *model.Activities, err error) {
  10. var (
  11. logs []*model.WLog
  12. events map[int64]*model.Event
  13. uids []int64
  14. uNames map[int64]string
  15. )
  16. if logs, err = s.AllAuditLog(c, cid, []int{model.WLogModuleChallenge}); err != nil {
  17. log.Error("s.AllAuditLog(%d) error(%v)", cid, err)
  18. }
  19. log.Info("audit log cid(%d) logs(%+v)", cid, logs)
  20. if events, err = s.dao.EventsByCid(c, cid); err != nil {
  21. log.Error("Failed to s.dao.EventsByCid(%d): %v", cid, err)
  22. return
  23. }
  24. acts = new(model.Activities)
  25. acts.Events = make([]*model.Event, 0, len(events))
  26. acts.Logs = logs
  27. for _, e := range events {
  28. acts.Events = append(acts.Events, e)
  29. uids = append(uids, e.AdminID)
  30. }
  31. if uNames, err = s.dao.BatchUNameByUID(c, uids); err != nil {
  32. log.Error("s.dao.SearchUNameByUid(%v) error(%v)", uids, err)
  33. err = nil
  34. } else {
  35. for i := range acts.Events {
  36. acts.Events[i].Admin = uNames[acts.Events[i].AdminID]
  37. }
  38. }
  39. //sort.Sort(model.LogSlice(acts.Logs))
  40. //sort.Sort(model.EventSlice(acts.Events))
  41. sort.Slice(acts.Logs, func(i, j int) bool {
  42. return acts.Logs[i].CTime < acts.Logs[j].CTime
  43. })
  44. sort.Slice(acts.Events, func(i, j int) bool {
  45. return acts.Events[i].CTime < acts.Events[j].CTime
  46. })
  47. return
  48. }