task.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package task
  2. import (
  3. "errors"
  4. "context"
  5. "go-common/app/admin/main/aegis/model/common"
  6. libtime "go-common/library/time"
  7. )
  8. //...
  9. const (
  10. ActionConsumerOff = int8(0)
  11. ActionConsumerOn = int8(1)
  12. TaskStateInit = int8(0)
  13. TaskStateDispatch = int8(1)
  14. TaskStateDelay = int8(2)
  15. TaskStateSubmit = int8(3)
  16. TaskStateRscSb = int8(4)
  17. TaskStateClosed = int8(5)
  18. TaskConfigAssign = int8(1)
  19. TaskConfigRangeWeight = int8(2)
  20. TaskConfigEqualWeight = int8(3)
  21. TaskRoleMember = int8(1) //组员
  22. TaskRoleLeader = int8(2) //组长
  23. TaskNoRole = int8(0) //无身份
  24. )
  25. // ErrEmpty empty pool
  26. var (
  27. ErrEmpty = errors.New("empty pool")
  28. ErrRole = errors.New("不在用户组内")
  29. )
  30. // Task ..
  31. type Task struct {
  32. ID int64 `form:"id" json:"id" gorm:"AUTO_INCREMENT;primary_key;"`
  33. BusinessID int64 `form:"business_id" json:"business_id" gorm:"column:business_id"`
  34. FlowID int64 `form:"flow_id" json:"flow_id" gorm:"column:flow_id"`
  35. RID int64 `form:"rid" json:"rid" gorm:"column:rid"`
  36. AdminID int64 `form:"admin_id" json:"admin_id" gorm:"column:admin_id"`
  37. UID int64 `form:"uid" json:"uid" gorm:"column:uid"`
  38. MID int64 `form:"mid" json:"mid" gorm:"column:mid"`
  39. State int8 `form:"state" json:"state" gorm:"column:state"`
  40. Weight int64 `form:"weight" json:"weight" gorm:"column:weight"`
  41. Utime int64 `form:"utime" json:"utime" gorm:"column:utime"`
  42. Gtime common.IntTime `form:"gtime" json:"gtime" gorm:"column:gtime"`
  43. Fans int64 `form:"fans" json:"fans" gorm:"column:fans"`
  44. Group string `form:"group" json:"group" gorm:"column:group"`
  45. Reason string `form:"reason" json:"reason" grom:"column:reason"`
  46. Ctime common.IntTime `form:"ctime" json:"ctime" gorm:"column:ctime"`
  47. Mtime common.IntTime `form:"mtime" json:"mtime" gorm:"column:mtime"`
  48. }
  49. // TableName ...
  50. func (t Task) TableName() string {
  51. return "task"
  52. }
  53. // TempOptions 中间参数
  54. type TempOptions struct {
  55. BisLeader bool // 是否组长
  56. NoCache bool // 不使用缓存
  57. Action string
  58. }
  59. // NextOptions options for Next
  60. type NextOptions struct {
  61. common.BaseOptions
  62. TempOptions
  63. SeizeCount int64 `form:"seize_count" default:"10"` // 抢占多少个
  64. DispatchCount int64 `form:"dispatch_count" default:"1"` // 领取多少个
  65. }
  66. // ListOptions options for List
  67. type ListOptions struct {
  68. common.BaseOptions
  69. common.Pager
  70. TempOptions
  71. BisShow bool // 用于列表展示还是直接派发
  72. State int8 `form:"state"`
  73. }
  74. // SubmitOptions options for Submit
  75. type SubmitOptions struct {
  76. common.BaseOptions
  77. TempOptions
  78. TaskID int64 `form:"task_id"`
  79. Utime uint64
  80. OldUID int64
  81. OldState int8
  82. }
  83. // DelayOptions options for Delay
  84. type DelayOptions struct {
  85. common.BaseOptions
  86. TaskID int64 `form:"task_id"`
  87. Reason string `form:"reason"`
  88. }
  89. // ConfigOption .
  90. type ConfigOption struct {
  91. common.BaseOptions
  92. ID int64 `form:"id"`
  93. Btime string `form:"btime"`
  94. Etime string `form:"etime"`
  95. Description string `form:"description"`
  96. ConfType int8 `form:"conf_type" validate:"required"`
  97. ConfJSON string `form:"conf_json" validate:"required"`
  98. }
  99. // Config .
  100. type Config struct {
  101. ID int64 `form:"id" json:"id" gorm:"AUTO_INCREMENT;primary_key;"`
  102. ConfJSON string `json:"conf_json" gorm:"column:conf_json"`
  103. ConfType int8 `form:"conf_type" json:"conf_type" gorm:"column:conf_type"`
  104. BusinessID int64 `form:"business_id" json:"business_id" gorm:"column:business_id"`
  105. FlowID int64 `form:"flow_id" json:"flow_id" gorm:"column:flow_id"`
  106. Btime libtime.Time `form:"btime" json:"btime" gorm:"column:btime"`
  107. Etime libtime.Time `form:"etime" json:"etime" gorm:"column:etime"`
  108. State int8 `form:"state" json:"state" gorm:"column:state"`
  109. UID int64 `form:"uid" json:"uid" gorm:"column:uid"`
  110. Uname string `form:"uname" json:"uname" gorm:"column:uname"`
  111. Description string `form:"description" json:"description" gorm:"column:description"`
  112. Ctime libtime.Time `form:"ctime" json:"ctime" gorm:"column:ctime"`
  113. Mtime libtime.Time `form:"mtime" json:"mtime" gorm:"column:mtime"`
  114. }
  115. // TableName for orm
  116. func (c Config) TableName() string {
  117. return "task_config"
  118. }
  119. // EqualWeightConfig 等值权重
  120. type EqualWeightConfig struct {
  121. Name string `json:"name"` // taskid 或者 mid
  122. IDs string `json:"ids"`
  123. Weight int64 `json:"weight"`
  124. Type int8 `json:"type"` // 周期或者定值
  125. }
  126. // RangeWeightConfig 权重
  127. type RangeWeightConfig struct {
  128. Name string `json:"name"`
  129. Range []*RangeConfig `json:"range"`
  130. }
  131. // RangeConfig 范围配置
  132. type RangeConfig struct {
  133. Threshold int64 `json:"threshold"`
  134. Weight int64 `json:"weight"`
  135. }
  136. // AssignConfig 指派
  137. type AssignConfig struct {
  138. MIDs []int64 `json:"mids"`
  139. UIDs []int64 `json:"uids"`
  140. }
  141. // QueryParams 配置筛选参数
  142. type QueryParams struct {
  143. common.Pager
  144. ConfType int8 `form:"conf_type"`
  145. State int8 `form:"state"`
  146. BusinessID int64 `form:"business_id"`
  147. FlowID int64 `form:"flow_id"`
  148. Btime string `form:"mtime_from"`
  149. Etime string `form:"mtime_to"`
  150. ConfName string `form:"conf_name"` // 筛选配置具体类型,fans,group,waittime,mid,taskid
  151. IDFilter string `form:"id_filter"` // 筛选具体的ID
  152. TypeFilter string `form:"type_filter"` // 筛选动态或静态权重
  153. }
  154. // History 任务日志
  155. type History struct {
  156. TaskID int64 `json:"task_id"`
  157. AdminID int64
  158. UID int64
  159. Reason string
  160. Uname string
  161. Action int8
  162. }
  163. // UnDOStat undo stat
  164. type UnDOStat struct {
  165. Assign int64 `json:"assign_count" gorm:"column:assign"`
  166. Delay int64 `json:"delay_count" gorm:"column:delay"`
  167. Normal int64 `json:"normal_count" gorm:"column:normal"`
  168. }
  169. // Stat 列表页最上方
  170. type Stat struct {
  171. Normal int64 `json:"normal_count" gorm:"column:normal"`
  172. Assign int64 `json:"assign_count" gorm:"column:assign"`
  173. DelayTotal int64 `json:"delay_total" gorm:"column:delayTotal"`
  174. DelayPersonal int64 `json:"delay_personal" gorm:"column:delayPersonal"`
  175. ReviewTotal int64 `json:"review_total"`
  176. ReviewPersonal int64 `json:"review_personal"`
  177. }
  178. // RangeFunc .
  179. type RangeFunc func(context.Context, *ListOptions) (map[int64]*Task, int64, []int64, []int64, error)
  180. // RemoveFunc .
  181. type RemoveFunc func(context.Context, *common.BaseOptions, ...interface{}) error
  182. // ListFuncDB .
  183. type ListFuncDB func(context.Context, map[int64]*Task, []int64, ...interface{}) (map[int64]struct{}, error)