search.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package service
  2. import (
  3. "context"
  4. "go-common/library/ecode"
  5. "go-common/library/xstr"
  6. "net/url"
  7. "strconv"
  8. "go-common/app/admin/main/videoup-task/model"
  9. "go-common/library/database/elastic"
  10. "go-common/library/log"
  11. )
  12. const (
  13. _searchBusinessQAVideo = "task_qa"
  14. _searchBusinessQAVideoRandom = "task_qa_random"
  15. _searchIndexQAVideo = "task_qa"
  16. _searchLogURL = "/x/admin/search/log"
  17. )
  18. func (s *Service) searchQAVideo(c context.Context, pm *model.ListParams) (list *model.QAVideoList, err error) {
  19. needRandom := pm.Limit > 0 && pm.Seed != ""
  20. business := _searchBusinessQAVideo
  21. if needRandom {
  22. business = _searchBusinessQAVideoRandom
  23. }
  24. req := s.es.NewRequest(business).Index(_searchIndexQAVideo).Ps(pm.Ps).Pn(pm.Pn)
  25. if pm.CTimeFrom != "" || pm.CTimeTo != "" {
  26. req.WhereRange("ctime", pm.CTimeFrom, pm.CTimeTo, elastic.RangeScopeLcRc)
  27. }
  28. if pm.FTimeFrom != "" || pm.FTimeTo != "" {
  29. req.WhereRange("ftime", pm.FTimeFrom, pm.FTimeTo, elastic.RangeScopeLcRc)
  30. }
  31. if pm.FansFrom > 0 || pm.FansTo > 0 {
  32. req.WhereRange("fans", pm.FansFrom, pm.FansTo, elastic.RangeScopeLcRc)
  33. }
  34. if len(pm.UID) > 0 {
  35. req.WhereIn("uid", pm.UID)
  36. }
  37. if len(pm.TaskID) > 0 {
  38. req.WhereIn("task_id", pm.TaskID)
  39. }
  40. if len(pm.TagID) > 0 {
  41. req.WhereIn("audit_tagid", pm.TagID)
  42. }
  43. if len(pm.UPGroup) > 0 {
  44. req.WhereIn("up_groups", pm.UPGroup)
  45. }
  46. if len(pm.ArcTypeID) > 0 {
  47. req.WhereIn("arc_typeid", pm.ArcTypeID)
  48. }
  49. if len(pm.AuditStatus) > 0 {
  50. req.WhereIn("audit_status", pm.AuditStatus)
  51. }
  52. if len(pm.Keyword) > 0 {
  53. req.WhereLike([]string{"arc_title"}, pm.Keyword, true, elastic.LikeLevelLow)
  54. }
  55. if needRandom {
  56. req.WhereEq("seed", pm.Seed)
  57. } else {
  58. req.Order(pm.Order, pm.Sort)
  59. }
  60. if pm.State == model.QAStateWait || pm.State == model.QAStateFinish {
  61. req.WhereEq("state", pm.State)
  62. }
  63. if err = req.Scan(c, &list); err != nil {
  64. log.Error("searchQAVideo elastic scan error(%v) params(%+v)", err, pm)
  65. return
  66. }
  67. if needRandom && list != nil && list.Page.Total > pm.Limit {
  68. list.Page.Total = pm.Limit
  69. //移除多余部分
  70. addition := list.Page.Num*list.Page.Size - pm.Limit
  71. if addition > 0 {
  72. list.Result = list.Result[:(list.Page.Size - addition)]
  73. }
  74. }
  75. return
  76. }
  77. func (s *Service) lastInTime(c context.Context, ids []int64) (mcases map[int64][]interface{}, err error) {
  78. return s.lastTime(c, model.ActionHandsUP, ids)
  79. }
  80. func (s *Service) lastOutTime(c context.Context, ids []int64) (mcases map[int64][]interface{}, err error) {
  81. return s.lastTime(c, model.ActionHandsOFF, ids)
  82. }
  83. // lastInOutTime
  84. func (s *Service) lastTime(c context.Context, action int8, ids []int64) (mcases map[int64][]interface{}, err error) {
  85. mcases = make(map[int64][]interface{})
  86. params := url.Values{}
  87. uri := s.c.Host.Search + _searchLogURL
  88. params.Set("appid", "log_audit_group")
  89. params.Set("group", "uid")
  90. params.Set("uid", xstr.JoinInts(ids))
  91. params.Set("business", strconv.Itoa(model.LogClientConsumer))
  92. params.Set("action", strconv.Itoa(int(action)))
  93. params.Set("ps", strconv.Itoa(len(ids)))
  94. res := &model.SearchLogResult{}
  95. if err = s.httpClient.Get(c, uri, "", params, &res); err != nil {
  96. log.Error("log_audit_group d.httpClient.Get error(%v)", err)
  97. return
  98. }
  99. if res.Code != ecode.OK.Code() {
  100. log.Error("log_audit_group ecode:%v", res.Code)
  101. return
  102. }
  103. for _, item := range res.Data.Result {
  104. mcases[item.UID] = []interface{}{item.Ctime}
  105. }
  106. log.Info("log_audit_group get: %s params:%s ret:%v", uri, params.Encode(), res)
  107. return
  108. }