task.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. package model
  2. import (
  3. "time"
  4. "go-common/library/log"
  5. "go-common/library/xstr"
  6. )
  7. var (
  8. // TookTypeMinute video task took time in 1 minute
  9. TookTypeMinute = int8(1)
  10. // TookTypeHalfHour video task took time in 10 minutes
  11. TookTypeHalfHour = int8(2)
  12. // TaskStateUnclaimed video task belongs to nobody
  13. TaskStateUnclaimed = int8(0)
  14. // TaskStateUntreated video task not submit
  15. TaskStateUntreated = int8(1)
  16. // TaskStateCompleted video task completed
  17. TaskStateCompleted = int8(2)
  18. // TaskStateDelayed video task delayed
  19. TaskStateDelayed = int8(3)
  20. // TaskStateClosed video task closed
  21. TaskStateClosed = int8(4)
  22. // PoolForFirst 一审任务池
  23. PoolForFirst = int8(0)
  24. // PoolForSecond 二审任务池
  25. PoolForSecond = int8(1)
  26. // TypeRealTime 实时任务
  27. TypeRealTime = int8(0)
  28. // TypeDispatched 已分发任务
  29. TypeDispatched = int8(1)
  30. // TypeFinished 结束任务
  31. TypeFinished = int8(2)
  32. // TypeDelay 延时任务
  33. TypeDelay = int8(3)
  34. // TypeReview 复审任务
  35. TypeReview = int8(5)
  36. // TypeUpDelete 已删除任务
  37. TypeUpDelete = int8(6)
  38. // TypeSpecialWait 特殊停滞任务
  39. TypeSpecialWait = int8(7)
  40. // SubjectForNormal 普通任务
  41. SubjectForNormal = int8(0) //normal task subject
  42. // SubjectForTask 指派任务
  43. SubjectForTask = int8(1) //specified task subject
  44. _taskdispatchstate = map[int8]struct{}{
  45. TypeRealTime: {},
  46. TypeDispatched: {},
  47. TypeFinished: {},
  48. TypeDelay: {},
  49. TypeReview: {},
  50. TypeUpDelete: {},
  51. TypeSpecialWait: {},
  52. }
  53. // WLVConf 默认值
  54. WLVConf = &WeightVC{
  55. MaxWeight: int64(200000), //最大权重值
  56. SubRelease: int64(18), //指派再释放的任务
  57. //特殊任务参数
  58. Slv1: int64(8), // 普通用户>=1W粉
  59. Slv2: int64(10), // 普通用户>=10W粉
  60. Slv3: int64(12), // 优质用户<1W粉
  61. Slv4: int64(15), // 优质用户>=1W粉
  62. Slv5: int64(18), // 优质用户>=10W粉
  63. Slv6: int64(6), // 高危用户>=10W粉
  64. Slv7: int64(0), // 其他高危
  65. //普通任务参数
  66. Nlv1: int64(3), // 等待时长 9-15
  67. Nlv2: int64(6), // 等待时长 15-27
  68. Nlv3: int64(9), // 等待时长 27-45
  69. Nlv4: int64(12), // 等待时长 >45
  70. Nlv5: int64(0), // 等待时长 <=9
  71. //定时任务参数
  72. Tlv1: int64(3), // 距离发布2h-4h
  73. Tlv2: int64(9), // 距离发布1-2h
  74. Tlv3: int64(21), // 距离发布 <1h
  75. Tlv4: int64(0), // 距离发布 > 4h
  76. }
  77. )
  78. const (
  79. // ActionHandsUP 0签入
  80. ActionHandsUP = int8(0)
  81. // ActionHandsOFF 1签出
  82. ActionHandsOFF = int8(1)
  83. // ActionSubmit 2提交
  84. ActionSubmit = int8(2)
  85. // ActionDelay 3延迟
  86. ActionDelay = int8(3)
  87. // ActionClose 4关闭
  88. ActionClose = int8(4)
  89. //ActionOldSubmit 5旧一审提交
  90. ActionOldSubmit = int8(5)
  91. //ActionTaskDelete 10任务删除
  92. ActionTaskDelete = int8(10)
  93. //ActionDispatch 分配
  94. ActionDispatch = int8(6)
  95. //ActionRelease 释放(拒审)
  96. ActionRelease = int8(7)
  97. // WConfMid 按照mid配置权重
  98. WConfMid = int8(0)
  99. // WConfTaskID 按照taskid配置权重
  100. WConfTaskID = int8(1)
  101. // WConfType 按照分区配置权重
  102. WConfType = int8(2)
  103. // WConfUpFrom 按照投稿来源配置权重
  104. WConfUpFrom = int8(3)
  105. // WConfRelease 指派任务释放
  106. WConfRelease = int8(4)
  107. // TimeFormatSec 时间格式化
  108. TimeFormatSec = "2006-01-02 15:04:05"
  109. // TaskLeader 组长
  110. TaskLeader int8 = 1
  111. // TaskMember 组员
  112. TaskMember int8 = 2
  113. )
  114. // MemberStat .
  115. type MemberStat struct {
  116. UID int64 `json:"uid"`
  117. DispatchCount int64 `json:"dispatch"`
  118. ReleaseCount int64 `json:"release"`
  119. SubmitCount int64 `json:"submit"` // 总提交数
  120. OSubmitCount int64 `json:"oldsubmit"` // action=5
  121. NSubmitCount int64 `json:"newsubmit"` // action=2
  122. BelongCount int64 `json:"belong"` // 总推送数 分配到的-释法的
  123. PassCount int64 `json:"pass"` // 提交并且通过的数量
  124. NormalCount int64 `json:"normalCount"` // 普通任务数量
  125. SubjectCount int64 `json:"specialCount"` // 指派任务数量
  126. InTime string `json:"inTime"` // 最近开始时间
  127. QuitTime string `json:"quitTime"` // 最近退出时间
  128. CompleteRate string `json:"completeRate"` // 处理率
  129. PassRate string `json:"passRate"` // 通过率
  130. SumDu int64 `json:"-"`
  131. SumDuration string `json:"videoDuration"` // 累积处理视频总时长
  132. AvgUt float64 `json:"-"`
  133. AvgUtime string `json:"avgTime"` // 单任务平均耗时
  134. }
  135. // CfWeightDesc 权重配置文字描述
  136. func CfWeightDesc(radio int8) (desc string) {
  137. switch radio {
  138. case WConfMid:
  139. desc = "mid配置"
  140. case WConfTaskID:
  141. desc = "taskid配置"
  142. case WConfType:
  143. desc = "分区配置"
  144. case WConfUpFrom:
  145. desc = "投稿来源"
  146. case WConfRelease:
  147. desc = "指派释放"
  148. default:
  149. desc = "其他配置"
  150. }
  151. return
  152. }
  153. // IsDispatch 判断任务状态
  154. func IsDispatch(st int8) bool {
  155. if _, ok := _taskdispatchstate[st]; ok {
  156. return true
  157. }
  158. return false
  159. }
  160. // ParseWeightConf 解析权重配置
  161. func ParseWeightConf(twc *WeightConf, uid int64, uname string) (mcases map[int64]*WCItem, IsTaskID bool, err error) {
  162. var (
  163. ids []int64
  164. )
  165. mcases = make(map[int64]*WCItem)
  166. if ids, err = xstr.SplitInts(twc.Ids); err != nil {
  167. log.Error("ParseWeightConfig Config(%v) parse error(%v) Idlist(%s)", twc, err)
  168. return nil, false, err
  169. }
  170. for _, id := range ids {
  171. wci := &WCItem{
  172. CID: id,
  173. Radio: twc.Radio,
  174. Rule: twc.Rule,
  175. Weight: twc.Weight,
  176. Uname: uname,
  177. Desc: twc.Desc,
  178. Bt: twc.Bt,
  179. Et: twc.Et,
  180. Mtime: NewFormatTime(time.Now()),
  181. }
  182. if twc.Radio == WConfTaskID {
  183. IsTaskID = true
  184. }
  185. mcases[id] = wci
  186. }
  187. return
  188. }
  189. // WeightVC Weight Value Config 权重分值配置
  190. type WeightVC struct {
  191. MaxWeight int64 `json:"maxweight" form:"maxweight" default:"20000"`
  192. SubRelease int64 `json:"subrelease" form:"subrelease" default:"18"`
  193. Slv1 int64 `json:"slv1" form:"slv1" default:"8"`
  194. Slv2 int64 `json:"slv2" form:"slv2" default:"10"`
  195. Slv3 int64 `json:"slv3" form:"slv3" default:"12"`
  196. Slv4 int64 `json:"slv4" form:"slv4" default:"15"`
  197. Slv5 int64 `json:"slv5" form:"slv5" default:"18"`
  198. Slv6 int64 `json:"slv6" form:"slv6" default:"6"`
  199. Slv7 int64 `json:"slv7" form:"slv7" default:"0"`
  200. Nlv1 int64 `json:"nlv1" form:"nlv1" default:"3"`
  201. Nlv2 int64 `json:"nlv2" form:"nlv2" default:"6"`
  202. Nlv3 int64 `json:"nlv3" form:"nlv3" default:"9"`
  203. Nlv4 int64 `json:"nlv4" form:"nlv4" default:"12"`
  204. Nlv5 int64 `json:"nlv5" form:"nlv5" default:"0"`
  205. Tlv1 int64 `json:"tlv1" form:"tlv1" default:"3"`
  206. Tlv2 int64 `json:"tlv2" form:"tlv2" default:"9"`
  207. Tlv3 int64 `json:"tlv3" form:"tlv3" default:"21"`
  208. Tlv4 int64 `json:"tlv4" form:"tlv4" default:"0"`
  209. }
  210. // Task 审核任务
  211. type Task struct {
  212. ID int64 `json:"id"`
  213. Pool int8 `json:"pool"`
  214. Subject int8 `json:"subject"`
  215. AdminID int64 `json:"adminid"`
  216. Aid int64 `json:"aid"`
  217. Cid int64 `json:"cid"`
  218. UID int64 `json:"uid"`
  219. State int8 `json:"state"`
  220. UTime int64 `json:"utime"`
  221. CTime FormatTime `json:"ctime"`
  222. MTime FormatTime `json:"mtime"`
  223. DTime FormatTime `json:"dtime"`
  224. GTime FormatTime `json:"gtime"`
  225. PTime FormatTime `json:"ptime"`
  226. Weight int64 `json:"weight"`
  227. Mid int64 `json:"mid"`
  228. }
  229. // TaskWeightLog 权重变更日志
  230. type TaskWeightLog struct {
  231. TaskID int64 `json:"taskid"`
  232. Mid int64 `json:"mid"`
  233. Weight int64 `json:"weight"`
  234. CWeight int64 `json:"cweight"`
  235. NWeight int64 `json:"nweight"`
  236. SWeight int64 `json:"sweight"`
  237. TWeight int64 `json:"tweight"`
  238. Uptime FormatTime `json:"uptime"`
  239. Creator string `json:"creator"` //创作者
  240. UpSpecial []int8 `json:"upspecial"` //标记是否优质,劣质用户
  241. Fans int64 `json:"fans"` //粉丝数
  242. Wait float64 `json:"wait"` //等待时长
  243. Ptime string `json:"ptime,omitempty"`
  244. CfItems []*WCItem `json:"cfitems,omitempty"`
  245. Desc string `json:"desc,omitempty"` // 配置描述
  246. }
  247. // TaskPriority 任务参数
  248. type TaskPriority struct {
  249. TaskID int64 `json:"taskid"`
  250. Weight int64 `json:"weight"` //权重总值
  251. State int8 `json:"state"` //任务状态
  252. Mid int64 `json:"mid"`
  253. Special int8 `json:"special"` //特殊任务
  254. Ctime FormatTime `json:"ctime"` //任务生成时间
  255. Ptime FormatTime `json:"ptime"` //定时发布时间
  256. CfItems []*WCItem `json:"cfitems,omitempty"`
  257. Fans int64 `json:"fans"` //粉丝数
  258. AccFailed bool `json:"accfaild"` //账号查询是否失败
  259. UpGroups []int8 `json:"ugs"` //分组
  260. UpFrom int8 `json:"upfrom"` //来源
  261. TypeID int16 `json:"typeid"` //分区
  262. }
  263. // WeightConf 任务权重配置
  264. type WeightConf struct {
  265. Radio int8 `form:"radio"` // 0,mid,1,taskid,2,分区, 3, 投稿来源
  266. Ids string `form:"ids" validate:"required"` // id列表,逗号分隔
  267. Rule int8 `form:"rule"` // 0,动态权重,1,静态权重
  268. Weight int64 `form:"weight" validate:"required"` // 配置的权重
  269. Desc string `form:"desc" validate:"required"` // 描述信息
  270. Bt FormatTime `form:"bt"` //配置生效开始时间
  271. Et FormatTime `form:"et"` //配置生效结束时间
  272. }
  273. // WCItem task weight config item
  274. type WCItem struct {
  275. Radio int8 `json:"radio"`
  276. ID int64 `json:"id,omitempty"`
  277. CID int64 `json:"cid"` // config id 四种配置通用
  278. UID int64 `json:"uid,omitempty"`
  279. Uname string `json:"user,omitempty"`
  280. TypeName string `json:"typename,omitempty"`
  281. UpFrom string `json:"upfrom,omitempty"`
  282. Rule int8 `json:"rule"`
  283. State int8 `json:"state"`
  284. Weight int64 `json:"weight,omitempty"`
  285. Mtime FormatTime `json:"mtime,omitempty"`
  286. Desc string `json:"desc,omitempty"`
  287. FileName string `json:"filename,omitempty"`
  288. Title string `json:"title,omitempty"`
  289. Vid int64 `json:"vid,omitempty"`
  290. Creator string `json:"creator,omitempty"`
  291. Fans int64 `json:"fans,omitempty"`
  292. Bt FormatTime `json:"bt,omitempty"`
  293. Et FormatTime `json:"et,omitempty"`
  294. }
  295. // Confs 权重配置筛选参数
  296. type Confs struct {
  297. Radio int8 `form:"radio" default:"1"`
  298. Cid int64 `form:"cid" default:"-1"`
  299. Operator string `form:"operator"`
  300. Bt FormatTime `form:"bt"`
  301. Et FormatTime `form:"et"`
  302. Rule int8 `form:"rule" default:"-1"`
  303. State int `form:"state"`
  304. Pn int `form:"page" default:"1"`
  305. Ps int `form:"ps" default:"20"`
  306. }
  307. // TaskTook 一审耗时
  308. type TaskTook struct {
  309. ID int64 `json:"id"`
  310. M90 int `json:"m90"`
  311. M80 int `json:"m80"`
  312. M60 int `json:"m60"`
  313. M50 int `json:"m50"`
  314. TypeID int8 `json:"type"`
  315. Ctime time.Time `json:"ctime"`
  316. Mtime time.Time `json:"-"`
  317. }
  318. // AuthRole 一审任务角色
  319. type AuthRole struct {
  320. ID int64 `json:"id"`
  321. UID int64 `json:"uid"`
  322. Role int8 `json:"role"`
  323. UserName string `json:"username"`
  324. NickName string `json:"nickname"`
  325. Ctime time.Time `json:"ctime"`
  326. Mtime time.Time `json:"mtime"`
  327. }
  328. // Consumers 组员信息
  329. type Consumers struct {
  330. ID int64 `json:"id"`
  331. UID int64 `json:"uid"`
  332. UserName string `json:"username"`
  333. State int8 `json:"state"`
  334. Ctime FormatTime `json:"ctime"`
  335. Mtime FormatTime `json:"mtime"`
  336. LastOut string `json:"lastout,omitempty"`
  337. }
  338. // ConsumerLog 组员日志
  339. type ConsumerLog struct {
  340. UID int64 `json:"uid"`
  341. Uname string `json:"uname"`
  342. Action int8 `json:"action"`
  343. Ctime string `json:"ctime"`
  344. Desc string `json:"desc"`
  345. }
  346. // InQuit 组员日志
  347. type InQuit struct {
  348. Date string `json:"date"`
  349. UID int64 `json:"uid"`
  350. Uname string `json:"uname"`
  351. InTime string `json:"inTime"`
  352. OutTime string `json:"quitTime"`
  353. }
  354. // TaskForLog 释放任务
  355. type TaskForLog struct {
  356. ID int64
  357. Cid int64
  358. Subject int8
  359. Mtime time.Time
  360. }