search.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "time"
  7. "go-common/app/admin/main/videoup-task/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. "go-common/library/xstr"
  11. )
  12. const (
  13. _searchURL = "/x/admin/search/log"
  14. )
  15. // OutTime 退出时间,es的group by查询,最大1000条
  16. func (d *Dao) OutTime(c context.Context, ids []int64) (mcases map[int64][]interface{}, err error) {
  17. mcases = make(map[int64][]interface{})
  18. params := url.Values{}
  19. params.Set("appid", "log_audit_group")
  20. params.Set("group", "uid")
  21. params.Set("uid", xstr.JoinInts(ids))
  22. params.Set("business", strconv.Itoa(model.LogClientConsumer))
  23. params.Set("action", strconv.Itoa(int(model.ActionHandsOFF)))
  24. params.Set("ps", strconv.Itoa(len(ids)))
  25. res := &model.SearchLogResult{}
  26. if err = d.hclient.Get(c, d.c.Host.Search+_searchURL, "", params, &res); err != nil {
  27. log.Error("log_audit_group d.hclient.Get error(%v)", err)
  28. return
  29. }
  30. if res.Code != ecode.OK.Code() {
  31. log.Error("log_audit_group ecode:%v", res.Code)
  32. return
  33. }
  34. for _, item := range res.Data.Result {
  35. mcases[item.UID] = []interface{}{item.Ctime}
  36. }
  37. log.Info("log_audit_group get: %s params:%s ret:%v", _searchURL, params.Encode(), res)
  38. return
  39. }
  40. // InQuitList 登入登出日志
  41. func (d *Dao) InQuitList(c context.Context, uids []int64, bt, et string) (l []*model.InQuit, err error) {
  42. params := url.Values{}
  43. params.Set("appid", "log_audit")
  44. params.Set("business", strconv.Itoa(model.LogClientConsumer))
  45. if len(uids) > 0 {
  46. params.Set("uid", xstr.JoinInts(uids))
  47. }
  48. if len(bt) > 0 && len(et) > 0 {
  49. params.Set("ctime_from", bt)
  50. params.Set("ctime_to", et)
  51. }
  52. params.Set("order", "ctime")
  53. params.Set("sort", "desc")
  54. params.Set("ps", "10000")
  55. res := &model.SearchLogResult{}
  56. if err = d.hclient.Get(c, d.c.Host.Search+_searchURL, "", params, res); err != nil {
  57. log.Error("InQuitList d.hclient.Get error(%v)", err)
  58. return
  59. }
  60. if res.Code != ecode.OK.Code() {
  61. log.Error("InQuitList ecode:%v", res.Code)
  62. return
  63. }
  64. mapHelp := make(map[int64]*model.InQuit)
  65. for i := len(res.Data.Result) - 1; i >= 0; i-- {
  66. item := res.Data.Result[i]
  67. if item.Action == "0" {
  68. ctime, _ := time.Parse(model.TimeFormatSec, item.Ctime)
  69. iqlog := &model.InQuit{
  70. Date: ctime.Format("2006-01-02"),
  71. UID: item.UID,
  72. Uname: item.Uname,
  73. InTime: ctime.Format("15:04:05"),
  74. }
  75. mapHelp[item.UID] = iqlog
  76. l = append([]*model.InQuit{iqlog}, l[:]...)
  77. }
  78. if item.Action == "1" {
  79. if iqlog, ok := mapHelp[item.UID]; ok {
  80. ctime, _ := time.Parse(model.TimeFormatSec, item.Ctime)
  81. if date := ctime.Format("2006-01-02"); date == iqlog.Date {
  82. iqlog.OutTime = ctime.Format("15:04:05")
  83. } else {
  84. iqlog.OutTime = ctime.Format(model.TimeFormatSec)
  85. }
  86. }
  87. }
  88. }
  89. return
  90. }