uparchiveinfo.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package data
  2. import (
  3. "context"
  4. "go-common/app/admin/main/up/dao/data"
  5. "go-common/app/admin/main/up/model/datamodel"
  6. "go-common/app/admin/main/up/util"
  7. "go-common/library/log"
  8. "sort"
  9. "strconv"
  10. )
  11. //GetUpArchiveInfo get up archive info
  12. func (s *Service) GetUpArchiveInfo(c context.Context, arg *datamodel.GetUpArchiveInfoArg) (result *datamodel.GetUpArchiveInfoResult, err error) {
  13. if arg.DataType == 0 {
  14. arg.DataType = datamodel.DataType30Day
  15. }
  16. result = &datamodel.GetUpArchiveInfoResult{}
  17. var mids = util.ExplodeInt64(arg.Mids, ",")
  18. var length = len(mids)
  19. if length == 0 {
  20. log.Info("no mids specified")
  21. return
  22. } else if length > 100 {
  23. // 每次最多100个
  24. mids = mids[0:100]
  25. }
  26. dataMap, err := s.data.UpArchiveInfo(c, mids, data.UpArchiveDataType(arg.DataType))
  27. if err != nil {
  28. log.Error("get up archive info fail, err=%v, arg=%+v", err, arg)
  29. return
  30. }
  31. for mid, v := range dataMap {
  32. (*result)[mid] = v
  33. }
  34. log.Info("get up archive info ok, type=%d", arg.DataType)
  35. return
  36. }
  37. //GetUpArchiveTagInfo get up archive tag info
  38. func (s *Service) GetUpArchiveTagInfo(c context.Context, arg *datamodel.GetUpArchiveTagInfoArg) (result []*datamodel.ViewerTagData, err error) {
  39. tagData, err := s.data.UpArchiveTagInfo(c, arg.Mid)
  40. if err != nil {
  41. log.Error("get up archive tag fail, err=%v", err)
  42. return
  43. }
  44. var tagResultMap = make(map[int64]*datamodel.ViewerTagData)
  45. var tagIds []int64
  46. for idxstr, tid := range tagData.TagMap {
  47. tagIds = append(tagIds, tid)
  48. var idx, _ = strconv.Atoi(idxstr)
  49. var tag = &datamodel.ViewerTagData{
  50. Idx: idx,
  51. TagID: int(tid),
  52. }
  53. tagResultMap[tid] = tag
  54. }
  55. var tagMeta = s.GetTags(c, tagIds...)
  56. for tid, meta := range tagMeta {
  57. tag, ok := tagResultMap[tid]
  58. if !ok {
  59. continue
  60. }
  61. tag.Name = meta.TagName
  62. }
  63. for _, tag := range tagResultMap {
  64. result = append(result, tag)
  65. }
  66. if len(result) > 1 {
  67. sort.Slice(result, func(i, j int) bool {
  68. return result[i].Idx < result[j].Idx
  69. })
  70. }
  71. log.Info("get up archive tag info ok, mid=%d", arg.Mid)
  72. return
  73. }
  74. //GetUpArchiveTypeInfo get type info
  75. func (s *Service) GetUpArchiveTypeInfo(c context.Context, arg *datamodel.GetUpArchiveTypeInfoArg) (result *datamodel.UpArchiveTypeData, err error) {
  76. res, err := s.data.UpArchiveTypeInfo(c, arg.Mid)
  77. result = &res
  78. if err != nil {
  79. log.Error("fail to get up type, err=%v", err)
  80. return
  81. }
  82. log.Info("get up archive type info ok, mid=%d", arg.Mid)
  83. return
  84. }