chall.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package model
  2. import (
  3. "fmt"
  4. "net/url"
  5. "time"
  6. )
  7. const (
  8. _challSrhComID = "workflow_chall_common"
  9. // QueueState .
  10. QueueState = 18
  11. )
  12. // Chall .
  13. type Chall struct {
  14. ID int64 `json:"id"`
  15. Business int64 `json:"business"`
  16. DispatchState int `json:"dispatch_state"`
  17. DispatchTime time.Time `json:"dispatch_time"`
  18. }
  19. // ChallSearchRes .
  20. type ChallSearchRes struct {
  21. Code int `json:"code"`
  22. Message string `json:"message"`
  23. TTL int32 `json:"ttl"`
  24. Data struct {
  25. Order string `json:"order"`
  26. Sort string `json:"sort"`
  27. Page struct {
  28. Num int64 `json:"num"`
  29. Size int64 `json:"size"`
  30. Total int64 `json:"total"`
  31. } `json:"page"`
  32. Result []struct {
  33. ID int64 `json:"id"`
  34. } `json:"result"`
  35. } `json:"data"`
  36. }
  37. // ChallSearchParams .
  38. type ChallSearchParams struct {
  39. Business string
  40. States string
  41. BusinessStates string
  42. AssigneeAdminIDs string
  43. AssigneeAdminIDsNot string
  44. MtimeTo string
  45. PN int64
  46. PS int64
  47. Order string
  48. Sort string
  49. }
  50. // Serialize .
  51. func (cp *ChallSearchParams) Serialize() (val url.Values) {
  52. val = url.Values{}
  53. val.Set("appid", _challSrhComID)
  54. val.Set("business", cp.Business)
  55. if cp.States != "" {
  56. val.Set("states", cp.States)
  57. }
  58. if cp.BusinessStates != "" {
  59. val.Set("business_states", cp.BusinessStates)
  60. }
  61. if cp.AssigneeAdminIDs != "" {
  62. val.Set("assignee_adminids", cp.AssigneeAdminIDs)
  63. }
  64. if cp.AssigneeAdminIDsNot != "" {
  65. val.Set("assignee_adminids_not", cp.AssigneeAdminIDsNot)
  66. }
  67. if cp.PN == 0 {
  68. val.Set("pn", "1")
  69. } else {
  70. val.Set("pn", fmt.Sprintf("%d", cp.PN))
  71. }
  72. if cp.PS == 0 {
  73. val.Set("ps", "200")
  74. } else {
  75. val.Set("ps", fmt.Sprintf("%d", cp.PS))
  76. }
  77. if cp.Order == "" {
  78. val.Set("order", "ctime")
  79. } else {
  80. val.Set("order", cp.Order)
  81. }
  82. if cp.Sort == "" {
  83. val.Set("sort", "desc")
  84. } else {
  85. val.Set("sort", cp.Sort)
  86. }
  87. if cp.MtimeTo != "" {
  88. val.Set("mtime_to", cp.MtimeTo)
  89. }
  90. return
  91. }