challenge.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package param
  2. import (
  3. "net/url"
  4. "strconv"
  5. "go-common/library/xstr"
  6. )
  7. // ChallengeListCommonParam .
  8. type ChallengeListCommonParam struct {
  9. Business int8 `form:"business" validate:"required"`
  10. IDs []int64 `form:"ids,split"`
  11. Oids []string `form:"oids,split"`
  12. ObjectMids []int64 `form:"object_mids,split"`
  13. Mids []int64 `form:"mids,split"`
  14. Gids []int64 `form:"gids,split"`
  15. States []int64 `form:"states,split"`
  16. TypeIDs []int64 `form:"typeids,split"`
  17. Tids []int64 `form:"tids,split" validate:"dive,gt=0"`
  18. Rounds []int64 `form:"rounds,split"`
  19. AssigneeAdminIDs []int64 `form:"assignee_adminids,split"`
  20. AssigneeAdminNames []string `form:"assignee_adminnames,split"`
  21. AdminIDs []int64 `form:"adminids,split"`
  22. BusinessStates []int64 `form:"business_states,split"`
  23. DispatchStates []int64 `form:"dispatch_states,split"`
  24. Title string `form:"title"`
  25. Content string `form:"content"`
  26. AdminReply string `form:"admin_reply"`
  27. UserReply string `form:"user_reply"`
  28. CTimeFrom string `form:"ctime_from"`
  29. CTimeTo string `form:"ctime_to"`
  30. Order string `form:"order" default:"ctime"`
  31. Sort string `form:"sort_order" default:"desc"`
  32. PS int `form:"ps" default:"50"`
  33. PN int `form:"pn" default:"1"`
  34. }
  35. // ChallengeListV3Param .
  36. type ChallengeListV3Param struct {
  37. Business int8 `form:"business" validate:"required"`
  38. IDs []int64 `form:"cid,split"`
  39. Oids []string `form:"oid,split"`
  40. Mids []int64 `form:"mid,split"`
  41. Gids []int64 `form:"gid,split"`
  42. States []int64 `form:"state,split"`
  43. TypeIDs []int64 `form:"typeid,split"`
  44. Tids []int64 `form:"tid,split"`
  45. Roles []int64 `form:"role,split"`
  46. AssigneeAdminIDs []int64 `form:"assignee_adminid,split"`
  47. AssigneeAdminNames []string `form:"assignee_admin_name,split"`
  48. AdminIDs []int64 `form:"adminid,split"`
  49. AdminNames []string `form:"admin_name,split"`
  50. BusinessStates []int64 `form:"business_state,split"`
  51. KW []string `form:"kw,split"`
  52. KWField []string `form:"kw_field,split"`
  53. CTimeFrom string `form:"ctime_from"`
  54. CTimeTo string `form:"ctime_to"`
  55. Order string `form:"order" default:"id"`
  56. Sort string `form:"sort" default:"desc"`
  57. PS int `form:"ps" default:"50"`
  58. PN int `form:"pn" default:"1"`
  59. }
  60. // ChallRstParam describe the reset request params to a challenge row
  61. type ChallRstParam struct {
  62. Cid int64 `form:"cid" json:"cid" validate:"required,min=1"`
  63. State int8 `form:"state" json:"state" validate:"min=0,max=14"`
  64. AdminID int64 `json:"adminid"`
  65. AdminName string `json:"admin_name"`
  66. Reason string `form:"reason" json:"reason"`
  67. Business int8 `form:"business" json:"business"`
  68. }
  69. // ChallUpParam describe the update request params to a challenge row
  70. type ChallUpParam struct {
  71. Cid int64 `form:"cid" json:"cid" validate:"required,min=1"`
  72. Tid int64 `form:"tid" json:"tid"`
  73. Note string `form:"note" json:"note"`
  74. AdminID int64 `form:"adminid" json:"adminid"`
  75. AdminName string `json:"admin_name"`
  76. Business int8 `form:"business" json:"business"`
  77. Role int8 `form:"role" json:"role"`
  78. }
  79. // ChallResParam describe the set result request params to a challenge row
  80. type ChallResParam struct {
  81. Cid int64 `json:"cid" form:"cid" validate:"required,min=1"`
  82. State int8 `json:"state" form:"state" validate:"min=0,max=14"`
  83. Reason string `json:"reason" form:"reason"`
  84. AdminID int64 `json:"adminid" form:"adminid"`
  85. AdminName string `json:"admin_name"`
  86. }
  87. // BatchChallResParam describe the set result request params to a set of challenges
  88. type BatchChallResParam struct {
  89. Cids []int64 `json:"cids" form:"cid,split" validate:"required,gt=0"`
  90. State int8 `json:"state" form:"state" validate:"min=0,max=14"`
  91. Business int8 `form:"business" json:"business"`
  92. Role int8 `form:"role" json:"role"`
  93. AdminID int64 `json:"adminid"`
  94. AdminName string `json:"admin_name"`
  95. Reason string `json:"reason" form:"reason"`
  96. }
  97. // ChallSetParamV3 .
  98. type ChallSetParamV3 struct {
  99. ID []int64 `json:"id" form:"id,split" validate:"required,gt=0"`
  100. State int8 `json:"state" form:"state" validate:"min=0,max=14"`
  101. AdminID int64 `json:"adminid"`
  102. Reason string `json:"reason" form:"reason"`
  103. }
  104. // BatchChallBusStateParam .
  105. type BatchChallBusStateParam struct {
  106. Cids []int64 `form:"cid,split" json:"cid" validate:"required,gt=0"`
  107. AssigneeAdminID int64 `json:"assignee_admin_id"`
  108. AssigneeAdminName string `json:"assignee_admin_name"`
  109. Business int8 `form:"business"`
  110. Role int8 `form:"role"`
  111. BusState int8 `form:"business_state" json:"business_state" validate:"min=0,max=14"`
  112. }
  113. // EventParam is used to parse user request
  114. type EventParam struct {
  115. Cid int64 `json:"cid" form:"cid" validate:"required,min=1"`
  116. AdminID int64 `json:"adminid" form:"adminid"`
  117. AdminName string `json:"admin_name"`
  118. Content string `json:"content" form:"content"`
  119. Attachments string `json:"attachments" form:"attachments"`
  120. Event int8 `json:"event" form:"event" validate:"required,min=1"`
  121. }
  122. // BatchEventParam is used to parse user request
  123. type BatchEventParam struct {
  124. Cids []int64 `json:"cids,split" form:"cids,split" validate:"required,dive,gt=0"`
  125. AdminID int64 `json:"adminid" form:"adminid"`
  126. AdminName string `json:"admin_name"`
  127. Content string `json:"content" form:"content"`
  128. Attachments string `json:"attachments" form:"attachments"`
  129. Event int8 `json:"event" form:"event" validate:"required,min=1"`
  130. }
  131. // ChallExtraParam describe the request params to update challenge extra data
  132. type ChallExtraParam struct {
  133. Cid int64 `json:"cid" validate:"required,min=1"`
  134. AdminID int64 `json:"adminid" validate:"required,min=1"`
  135. AdminName string `json:"admin_name"`
  136. Extra map[string]interface{} `json:"extra" validate:"required"`
  137. }
  138. // ChallExtraParamV3 .
  139. type ChallExtraParamV3 struct {
  140. Cids []int64 `json:"cid" form:"cid,split" validate:"required,dive,gt=0"`
  141. AdminID int64 `json:"adminid"`
  142. AdminName string `json:"admin_name"`
  143. Extra string `json:"extra" form:"extra" validate:"required"`
  144. }
  145. // BatchChallExtraParam describe the request params to batch update challenges extra data
  146. type BatchChallExtraParam struct {
  147. Cids []int64 `json:"cid" form:"cid" validate:"required,min=1"`
  148. Business int8 `json:"business" form:"business"`
  149. AdminID int64 `json:"adminid" validate:"required,min=1"`
  150. AdminName string `json:"admin_name"`
  151. Extra map[string]interface{} `json:"extra" form:"extra" validate:"required"`
  152. }
  153. // BusChallsBusStateParam describe the request params to update business state of challenges in business
  154. type BusChallsBusStateParam struct {
  155. Business int8 `json:"business" validate:"required,min=1"`
  156. Oid int64 `json:"oid" validate:"required,min=1"`
  157. AdminID int64 `json:"adminid" validate:"required,min=1"`
  158. BusState int8 `json:"business_state" validate:"min=0,max=14"`
  159. PreBusStates []int8 `json:"pre_business_states" validate:"dive,gt=-1"`
  160. Extra map[string]interface{} `json:"extra"`
  161. }
  162. // ValidComponent will verify the component field is valid
  163. func (e *EventParam) ValidComponent() bool {
  164. if e.Cid > 0 &&
  165. e.AdminID > 0 &&
  166. e.Content != "" &&
  167. e.Event > 0 {
  168. return true
  169. }
  170. return false
  171. }
  172. // ValidComponent will verify the component field is valid
  173. func (be *BatchEventParam) ValidComponent() bool {
  174. if len(be.Cids) > 0 &&
  175. be.AdminID > 0 &&
  176. be.Content != "" &&
  177. be.Event > 0 {
  178. return true
  179. }
  180. return false
  181. }
  182. // MessageParam is the model to send message to end user
  183. type MessageParam struct {
  184. Type string
  185. Source int8
  186. DataType int8
  187. MC string
  188. Title string
  189. Context string
  190. MidList []int64
  191. }
  192. // Query method will serialize all conditions into a url.Values struct
  193. func (mp *MessageParam) Query() (uv url.Values) {
  194. uv = url.Values{}
  195. uv.Set("type", mp.Type)
  196. uv.Set("source", strconv.Itoa(int(mp.Source)))
  197. uv.Set("data_type", strconv.Itoa(int(mp.DataType)))
  198. uv.Set("mc", mp.MC)
  199. uv.Set("title", mp.Title)
  200. uv.Set("context", mp.Context)
  201. uv.Set("mid_list", xstr.JoinInts(mp.MidList))
  202. return uv
  203. }