cmsvideo.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/bbq/video/model"
  5. xsql "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _updatevideostatus = "update video set state = ? where svid = ?"
  10. _updateCmsvideoStatus = "insert into cms_video (svid,cms_status,sv_status,`from`,title,pubtime,mid) values (?,?,?,?,?,?,?) on duplicate key update cms_status = values(cms_status),sv_status=values(sv_status),cms_uname = '',`from` = values(`from`),title=values(title),pubtime=values(pubtime),mid = values(mid)"
  11. _selectVideoRows = "select id,svid,title,mid,`from`,pubtime from video where state = ? and id > ? limit 1000"
  12. _updateVR = "update video_repository set state = ? where svid=?"
  13. )
  14. //UpdateCms ..
  15. func (d *Dao) UpdateCms(c context.Context, v *model.VideoRaw) (err error) {
  16. if _, err = d.dbCms.Exec(c,
  17. _updateCmsvideoStatus,
  18. v.SVID,
  19. v.State,
  20. v.State,
  21. v.From,
  22. v.Title,
  23. v.Pubtime,
  24. v.MID,
  25. ); err != nil {
  26. log.Error("DeliveryNewVdieoToCms insert cms_video err,svid : %v,err :%v", v.SVID, err)
  27. return
  28. }
  29. return
  30. }
  31. //TransToCheckBack ..
  32. func (d *Dao) TransToCheckBack() (err error) {
  33. var (
  34. rows *xsql.Rows
  35. count int64
  36. id int64
  37. c = context.Background()
  38. )
  39. for {
  40. if rows, err = d.db.Query(c, _selectVideoRows, model.VideoStPassReview, count); err != nil {
  41. log.Error("DeliveryNewVdieoToCms select video failed ,err:%v", err)
  42. return
  43. }
  44. flag := false
  45. for rows.Next() {
  46. videoinfo := model.VideoInfo{}
  47. if err = rows.Scan(
  48. &id,
  49. &videoinfo.SVID,
  50. &videoinfo.Title,
  51. &videoinfo.MID,
  52. &videoinfo.From,
  53. &videoinfo.Pubtime,
  54. ); err != nil {
  55. if err == xsql.ErrNoRows {
  56. return
  57. }
  58. continue
  59. }
  60. count = id
  61. //满足运营导入规则
  62. if d.CmsRule(videoinfo.SVID) {
  63. if _, err = d.dbCms.Exec(c,
  64. _updateCmsvideoStatus,
  65. videoinfo.SVID,
  66. model.VideoStCheckBack,
  67. model.VideoStCheckBack,
  68. videoinfo.From,
  69. videoinfo.Title,
  70. videoinfo.Pubtime,
  71. videoinfo.MID,
  72. ); err != nil {
  73. log.Error("DeliveryNewVdieoToCms insert cms_video err,svid : %v,err :%v", videoinfo.SVID, err)
  74. continue
  75. }
  76. if _, err = d.db.Exec(c,
  77. _updatevideostatus,
  78. model.VideoStCheckBack,
  79. videoinfo.SVID,
  80. ); err != nil {
  81. log.Error("DeliveryNewVdieoToCms update video status err : %v,svid : %v", err, videoinfo.SVID)
  82. continue
  83. }
  84. if _, err = d.dbCms.Exec(c, _updateVR, model.VideoStCheckBack, videoinfo.SVID); err != nil {
  85. log.Error("DeliveryNewVdieoToCms update vr err :%v,svid : %v", err, videoinfo.SVID)
  86. continue
  87. }
  88. }
  89. flag = true
  90. }
  91. rows.Close()
  92. if !flag {
  93. return
  94. }
  95. }
  96. }
  97. // CmsRule ...
  98. func (d *Dao) CmsRule(svid int64) (flag bool) {
  99. return true
  100. }
  101. //TransToReview ...
  102. func (d *Dao) TransToReview() (err error) {
  103. var (
  104. rows *xsql.Rows
  105. count int64
  106. id int64
  107. c = context.Background()
  108. )
  109. for {
  110. if rows, err = d.db.Query(c, _selectVideoRows, model.VideoStPendingPassReview, count); err != nil {
  111. log.Error("TransToReview select video failed ,err:%v", err)
  112. continue
  113. }
  114. flag := false
  115. for rows.Next() {
  116. videoinfo := model.VideoInfo{}
  117. if err = rows.Scan(
  118. &id,
  119. &videoinfo.SVID,
  120. &videoinfo.Title,
  121. &videoinfo.MID,
  122. &videoinfo.From,
  123. &videoinfo.Pubtime,
  124. ); err != nil {
  125. if err == xsql.ErrNoRows {
  126. return
  127. }
  128. continue
  129. }
  130. count = id
  131. //满足运营导入规则
  132. if d.CmsRule(videoinfo.SVID) {
  133. var st int
  134. if videoinfo.From == model.VideoFromBILI || videoinfo.From == model.VideoFromCMS {
  135. st = model.VideoStPassReview
  136. } else {
  137. st = model.VideoStPassReviewReject
  138. }
  139. if _, err = d.dbCms.Exec(c,
  140. _updateCmsvideoStatus,
  141. videoinfo.SVID,
  142. st,
  143. st,
  144. videoinfo.From,
  145. videoinfo.Title,
  146. videoinfo.Pubtime,
  147. videoinfo.MID,
  148. ); err != nil {
  149. log.Error("TransToReview insert cms_video err,svid : %v,err :%v", videoinfo.SVID, err)
  150. continue
  151. }
  152. if _, err = d.db.Exec(c,
  153. _updatevideostatus,
  154. st,
  155. videoinfo.SVID,
  156. ); err != nil {
  157. log.Error("TransToReview update video status err : %v,svid : %v", err, videoinfo.SVID)
  158. continue
  159. }
  160. }
  161. flag = true
  162. }
  163. rows.Close()
  164. if !flag {
  165. return
  166. }
  167. }
  168. }