blocked.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "sort"
  6. creditMDL "go-common/app/admin/main/credit/model"
  7. "go-common/app/admin/main/credit/model/blocked"
  8. account "go-common/app/service/main/account/model"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. "go-common/library/sync/errgroup"
  12. "go-common/library/xstr"
  13. )
  14. // Infos deal info data.
  15. func (s *Service) Infos(c context.Context, arg *blocked.ArgBlockedSearch) (list []*blocked.Info, pager *blocked.Pager, err error) {
  16. var ids []int64
  17. ids, pager, err = s.searchDao.Blocked(c, arg)
  18. if err != nil {
  19. log.Error("s.searchDao.Blocked error (%v)", err)
  20. return
  21. }
  22. if len(ids) == 0 {
  23. return
  24. }
  25. var (
  26. infoMap map[int64]*account.Info
  27. uids = make([]int64, len(ids))
  28. )
  29. ids = creditMDL.ArrayUnique(ids)
  30. if err = s.blockedDao.ReadDB.Where("id IN (?)", ids).Order(fmt.Sprintf("%s %s", arg.Order, arg.Sort)).Find(&list).Error; err != nil {
  31. if err != ecode.NothingFound {
  32. log.Error("s.blockedDao(%s) error(%v)", xstr.JoinInts(ids), err)
  33. return
  34. }
  35. log.Warn("search ids(%s) not in db", xstr.JoinInts(ids))
  36. err = nil
  37. return
  38. }
  39. for _, v := range list {
  40. uids = append(uids, v.UID)
  41. }
  42. if infoMap, err = s.accDao.RPCInfos(c, uids); err != nil {
  43. log.Error("s.accDao.RPCInfos(%s) error(%v)", xstr.JoinInts(uids), err)
  44. err = nil
  45. }
  46. for _, v := range list {
  47. v.OPName = s.Managers[v.OperID]
  48. if v.OPName == "" {
  49. v.OPName = v.OOPName
  50. }
  51. if in, ok := infoMap[v.UID]; ok {
  52. v.UName = in.Name
  53. }
  54. v.ReasonTypeDesc = blocked.ReasonTypeDesc(v.ReasonType)
  55. v.PublishStatusDesc = blocked.PStatusDesc[v.PublishStatus]
  56. v.OriginTypeDesc = blocked.OriginTypeDesc[v.OriginType]
  57. v.BlockedTypeDesc = blocked.BTypeDesc[v.BlockedType]
  58. v.BlockedDaysDesc = blocked.BDaysDesc(v.BlockedDays, v.MoralNum, v.PunishType, v.BlockedForever)
  59. }
  60. return
  61. }
  62. // InfosEx export info list
  63. func (s *Service) InfosEx(c context.Context, arg *blocked.ArgBlockedSearch) (list []*blocked.Info, err error) {
  64. var (
  65. count int
  66. pager *blocked.Pager
  67. g errgroup.Group
  68. ps = 500
  69. )
  70. if list, pager, err = s.Infos(c, arg); err != nil {
  71. log.Error("s.Infos(%+v) error(%v)", arg, err)
  72. return
  73. }
  74. if pager == nil {
  75. log.Warn("arg(%+v) info search data empty!", arg)
  76. return
  77. }
  78. count = pager.Total / ps
  79. if pager.Total%ps != 0 {
  80. count++
  81. }
  82. lCh := make(chan []*blocked.Info, count)
  83. for pn := 1; pn <= count; pn++ {
  84. tmpPn := pn
  85. g.Go(func() (err error) {
  86. var gInfo []*blocked.Info
  87. gArg := &blocked.ArgBlockedSearch{
  88. Keyword: arg.Keyword,
  89. UID: arg.UID,
  90. OPID: arg.OPID,
  91. OriginType: arg.OriginType,
  92. BlockedType: arg.BlockedType,
  93. PublishStatus: arg.PublishStatus,
  94. Start: arg.Start,
  95. End: arg.End,
  96. PN: tmpPn,
  97. PS: ps,
  98. Order: arg.Order,
  99. Sort: arg.Sort,
  100. }
  101. gInfo, _, err = s.Infos(c, gArg)
  102. if err != nil {
  103. log.Error("s.Infos(%+v) error(%v)", gArg, err)
  104. err = nil
  105. return
  106. }
  107. lCh <- gInfo
  108. return
  109. })
  110. }
  111. g.Wait()
  112. close(lCh)
  113. for bInfo := range lCh {
  114. list = append(list, bInfo...)
  115. }
  116. sort.Slice(list, func(i int, j int) bool {
  117. return list[i].ID < list[j].ID
  118. })
  119. return
  120. }
  121. // Publishs get publishs data
  122. func (s *Service) Publishs(c context.Context, arg *blocked.ArgPublishSearch) (list []*blocked.Publish, pager *blocked.Pager, err error) {
  123. var ids []int64
  124. ids, pager, err = s.searchDao.Publish(c, arg)
  125. if err != nil {
  126. log.Error("s.searchDao.Publish error (%v)", err)
  127. return
  128. }
  129. if len(ids) == 0 {
  130. return
  131. }
  132. ids = creditMDL.ArrayUnique(ids)
  133. if err = s.blockedDao.ReadDB.Where("id IN (?)", ids).Order(fmt.Sprintf("%s %s", arg.Order, arg.Sort)).Find(&list).Error; err != nil {
  134. if err != ecode.NothingFound {
  135. log.Error("s.blockedDao(%s) error(%v)", xstr.JoinInts(ids), err)
  136. return
  137. }
  138. log.Warn("search ids(%s) not in db", xstr.JoinInts(ids))
  139. err = nil
  140. }
  141. for _, v := range list {
  142. v.OPName = s.Managers[v.OPID]
  143. v.PublishTypeDesc = blocked.PTypeDesc[v.Type]
  144. v.PublishStatusDesc = blocked.PStatusDesc[v.PublishStatus]
  145. v.StickStatusDesc = blocked.SStatusDesc[v.StickStatus]
  146. }
  147. return
  148. }