task_qa_video.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "time"
  7. xsql "database/sql"
  8. "go-common/app/admin/main/videoup-task/model"
  9. "go-common/library/database/sql"
  10. "go-common/library/log"
  11. "go-common/library/xstr"
  12. )
  13. const (
  14. _inQAVideo = "INSERT INTO task_qa_video(cid,aid,task_id,task_utime,attribute,mid,fans,up_groups,arc_title,arc_typeid,audit_status,audit_tagid,audit_submit,audit_details,ctime,mtime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
  15. _QATaskVideo = `SELECT qa.id, qa.state, qa.type, qa.detail_id, qa.uid, qa.ftime, qa.ctime,
  16. qav.cid, qav.aid, coalesce(qav.task_id, 0) task_id, qav.task_utime, qav.attribute, qav.audit_tagid, qav.arc_title, qav.arc_typeid, qav.audit_status, qav.audit_submit, qav.audit_details, qav.mid, qav.fans, qav.up_groups
  17. FROM task_qa qa LEFT JOIN task_qa_video qav ON qa.detail_id = qav.id WHERE qa.id = ? LIMIT 1`
  18. _QATaskVideoSimple = `SELECT qa.id, qa.state, qa.type, qa.detail_id, qa.uid, qa.ftime, qa.ctime,
  19. qav.cid, qav.aid, coalesce(qav.task_id, 0) task_id,qav.task_utime, qav.attribute, qav.audit_tagid, qav.arc_title, qav.arc_typeid, qav.audit_status, qav.audit_submit, qav.mid, qav.fans, qav.up_groups
  20. FROM task_qa qa LEFT JOIN task_qa_video qav ON qa.detail_id = qav.id WHERE qa.id = ? LIMIT 1`
  21. _QAVideoDetail = "SELECT qa.id, qav.id, qav.mid, qav.task_utime FROM task_qa qa LEFT JOIN task_qa_video qav ON qa.detail_id = qav.id WHERE qa.id IN (%s)"
  22. _QAVideoByTASKID = `SELECT id FROM task_qa_video WHERE aid=? AND cid=? AND task_id=?`
  23. _upQAVideoUTime = "UPDATE task_qa_video SET task_utime=? WHERE aid=? AND cid=? AND task_id=?"
  24. _delQAVideo = "DELETE FROM task_qa_video WHERE mtime<? LIMIT ?"
  25. _delQATask = "DELETE FROM task_qa WHERE mtime<? LIMIT ?"
  26. )
  27. //InsertQAVideo insert qa video detail
  28. func (d *Dao) InsertQAVideo(tx *sql.Tx, dt *model.VideoDetail) (id int64, err error) {
  29. var (
  30. groups string
  31. )
  32. if len(dt.UPGroups) > 0 {
  33. var b []byte
  34. b, err = json.Marshal(dt.UPGroups)
  35. if err != nil {
  36. log.Error("InsertQAVideo json.Marshal(%v) error(%v) aid(%d) cid(%d)", dt.UPGroups, err, dt.AID, dt.CID)
  37. return
  38. }
  39. groups = string(b)
  40. }
  41. now := time.Now()
  42. res, err := tx.Exec(_inQAVideo, dt.CID, dt.AID, dt.TaskID, dt.TaskUTime, dt.Attribute, dt.MID, dt.Fans, groups,
  43. dt.ArcTitle, dt.ArcTypeID, dt.AuditStatus, dt.TagID, dt.AuditSubmit, dt.AuditDetails, now, now)
  44. if err != nil {
  45. PromeErr("arcdb: exec", "InsertQAVideo tx.Exec error(%v) aid(%d) cid(%d)", err, dt.AID, dt.CID)
  46. return
  47. }
  48. id, err = res.LastInsertId()
  49. return
  50. }
  51. //QATaskVideoByID get by id
  52. func (d *Dao) QATaskVideoByID(ctx context.Context, id int64) (q *model.QATaskVideo, err error) {
  53. var (
  54. groups string
  55. )
  56. q = new(model.QATaskVideo)
  57. if err = d.arcReadDB.QueryRow(ctx, _QATaskVideo, id).Scan(&q.ID, &q.State, &q.Type, &q.DetailID, &q.UID, &q.FTime, &q.CTime,
  58. &q.CID, &q.AID, &q.TaskID, &q.TaskUTime, &q.Attribute, &q.TagID, &q.ArcTitle, &q.ArcTypeID, &q.AuditStatus, &q.AuditSubmit, &q.AuditDetails,
  59. &q.MID, &q.Fans, &groups); err != nil {
  60. if err == sql.ErrNoRows {
  61. err = nil
  62. q = nil
  63. } else {
  64. PromeErr("arcReaddb: scan", "QATaskVideoByID row.Scan error(%v) id(%d)", err, id)
  65. }
  66. return
  67. }
  68. q.UPGroups = []int64{}
  69. if groups != "" {
  70. if err = json.Unmarshal([]byte(groups), &q.UPGroups); err != nil {
  71. log.Error("QATaskVideoByID json.Unmarshal(%s) error(%v) id(%d)", groups, err, id)
  72. return
  73. }
  74. }
  75. return
  76. }
  77. // QATaskVideoSimpleByID get without audit_details by id
  78. func (d *Dao) QATaskVideoSimpleByID(ctx context.Context, id int64) (q *model.QATaskVideo, err error) {
  79. var (
  80. groups string
  81. )
  82. q = new(model.QATaskVideo)
  83. if err = d.arcReadDB.QueryRow(ctx, _QATaskVideoSimple, id).Scan(&q.ID, &q.State, &q.Type, &q.DetailID, &q.UID, &q.FTime, &q.CTime,
  84. &q.CID, &q.AID, &q.TaskID, &q.TaskUTime, &q.Attribute, &q.TagID, &q.ArcTitle, &q.ArcTypeID, &q.AuditStatus, &q.AuditSubmit,
  85. &q.MID, &q.Fans, &groups); err != nil {
  86. if err == sql.ErrNoRows {
  87. err = nil
  88. q = nil
  89. } else {
  90. PromeErr("arcReaddb: scan", "QATaskVideoSimpleByID row.Scan error(%v) id(%d)", err, id)
  91. }
  92. return
  93. }
  94. q.UPGroups = []int64{}
  95. if groups != "" {
  96. if err = json.Unmarshal([]byte(groups), &q.UPGroups); err != nil {
  97. log.Error("QATaskVideoByID json.Unmarshal(%s) error(%v) id(%d)", groups, err, id)
  98. return
  99. }
  100. }
  101. return
  102. }
  103. //QAVideoDetail get detail id & task_utime
  104. func (d *Dao) QAVideoDetail(ctx context.Context, ids []int64) (list map[int64]map[string]int64, arr []int64, err error) {
  105. var (
  106. idStr string
  107. rows *sql.Rows
  108. )
  109. list = map[int64]map[string]int64{}
  110. arr = make([]int64, 0)
  111. idStr = xstr.JoinInts(ids)
  112. if rows, err = d.arcReadDB.Query(ctx, fmt.Sprintf(_QAVideoDetail, idStr)); err != nil {
  113. PromeErr("arcReaddb: query", "QAVideoDetail d.arcReadDB.Query error(%v) ids(%s)", err, idStr)
  114. return
  115. }
  116. defer rows.Close()
  117. for rows.Next() {
  118. var (
  119. id, detailID, mid, taskUTime int64
  120. )
  121. if err = rows.Scan(&id, &detailID, &mid, &taskUTime); err != nil {
  122. PromeErr("arcReaddb: scan", "QAVideoDetail rows.Scan error(%v) ids(%s)", err, idStr)
  123. return
  124. }
  125. list[id] = map[string]int64{
  126. "detail_id": detailID,
  127. "mid": mid,
  128. "task_utime": taskUTime,
  129. }
  130. arr = append(arr, mid)
  131. }
  132. return
  133. }
  134. //GetQAVideoID get id by aid & cid & taskid
  135. func (d *Dao) GetQAVideoID(ctx context.Context, aid int64, cid int64, taskID int64) (id int64, err error) {
  136. if err = d.arcDB.QueryRow(ctx, _QAVideoByTASKID, aid, cid, taskID).Scan(&id); err != nil {
  137. if err == sql.ErrNoRows {
  138. id = 0
  139. err = nil
  140. } else {
  141. log.Error("GetQAVideoID scan error(%v) aid(%d) cid(%d) taskid(%d)", err, aid, cid, taskID)
  142. }
  143. }
  144. return
  145. }
  146. //UpdateQAVideoUTime update task_utime
  147. func (d *Dao) UpdateQAVideoUTime(ctx context.Context, aid int64, cid int64, taskID, utime int64) (err error) {
  148. if _, err = d.arcDB.Exec(ctx, _upQAVideoUTime, utime, aid, cid, taskID); err != nil {
  149. PromeErr("arcdb: exec", "UpdateQAVideoUTime error(%v) aid(%d) cid(%d) taskid(%d)", err, aid, cid, taskID)
  150. }
  151. return
  152. }
  153. //DelQAVideo 删除数据
  154. func (d *Dao) DelQAVideo(ctx context.Context, mtime time.Time, limit int) (rows int64, err error) {
  155. var (
  156. result xsql.Result
  157. )
  158. if result, err = d.arcDB.Exec(ctx, _delQAVideo, mtime, limit); err != nil {
  159. PromeErr("arcdb: exec", "DelQAVideo error(%v) mtime(%v)", err, mtime)
  160. return
  161. }
  162. rows, err = result.RowsAffected()
  163. return
  164. }
  165. //DelQATask 删除数据
  166. func (d *Dao) DelQATask(ctx context.Context, mtime time.Time, limit int) (rows int64, err error) {
  167. var (
  168. result xsql.Result
  169. )
  170. if result, err = d.arcDB.Exec(ctx, _delQATask, mtime, limit); err != nil {
  171. PromeErr("arcdb: exec", "DelQATask error(%v) mtime(%v)", err, mtime)
  172. return
  173. }
  174. rows, err = result.RowsAffected()
  175. return
  176. }