search.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/workflow/model"
  5. "go-common/library/database/elastic"
  6. "go-common/library/log"
  7. )
  8. const (
  9. challBusiness = "workflow_chall_common"
  10. challIndex = "workflow_chall_common"
  11. appealBusiness = "workflow_appeal"
  12. appealIndex = "workflow_appeal"
  13. )
  14. // SearchChall .
  15. func (d *Dao) SearchChall(c context.Context, params *model.SearchParams) (res *model.ChallSearchCommonRes, err error) {
  16. r := d.es.NewRequest(challBusiness).Fields("id").
  17. Index(challIndex).
  18. WhereEq("business", params.Business).
  19. WhereEq("state", params.States).
  20. WhereEq("business_state", params.BusinessStates)
  21. if params.AssigneeAdminIDs != "" {
  22. r = r.WhereEq("assignee_adminid", params.AssigneeAdminIDs)
  23. }
  24. if params.AssigneeAdminIDsNot != "" {
  25. r = r.WhereNot("assignee_adminid", params.AssigneeAdminIDsNot)
  26. }
  27. if params.MtimeTo != "" {
  28. r = r.WhereRange("mtime", "", params.MtimeTo, elastic.RangeScopeLcRo)
  29. }
  30. log.Info("search condition %v", r.Params())
  31. err = r.Scan(c, &res)
  32. return
  33. }
  34. // SearchAppeal .
  35. func (d *Dao) SearchAppeal(c context.Context, cond model.AppealSearchCond) (res *model.AppealSearchRes, err error) {
  36. r := d.es.NewRequest(appealBusiness).Index(appealIndex).Fields(cond.Fields...).WhereIn("bid", cond.Bid).
  37. WhereIn("id", cond.IDs).WhereIn("assign_state", cond.AssignState).WhereIn("audit_state", cond.AuditState).
  38. WhereIn("transfer_state", cond.TransferState).WhereIn("audit_adminid", cond.AuditAdmin).
  39. WhereIn("transfer_adminid", cond.TransferAdmin).WhereRange("ctime", cond.CTimeFrom, cond.CTimeTo, elastic.RangeScopeLcRo).
  40. WhereRange("dtime", cond.DTimeFrom, cond.DTimeTo, elastic.RangeScopeLcRo).WhereRange("ttime", cond.TTimeFrom, cond.TTimeTo, elastic.RangeScopeLcRo).
  41. WhereRange("mtime", cond.MTimeFrom, cond.MTimeTo, elastic.RangeScopeLcRo).Order(cond.Order, cond.Sort).Pn(cond.PN).Ps(cond.PS)
  42. log.Info("search condition (%v)", r.Params())
  43. if err = r.Scan(c, &res); err != nil {
  44. log.Error("r.Scan(%+v) error(%v)", &res, err)
  45. }
  46. if res == nil {
  47. res = new(model.AppealSearchRes)
  48. }
  49. return
  50. }