task_history.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "go-common/app/admin/main/videoup-task/model"
  7. "go-common/library/database/sql"
  8. "go-common/library/log"
  9. )
  10. const (
  11. _inTaskHisSQL = "INSERT INTO task_oper_history(pool,action,task_id,cid,uid,result,reason,utime) VALUE (?,?,?,?,?,?,?,?)"
  12. _mulinTaskHisSQL = "INSERT INTO task_oper_history(action,task_id,cid,uid) VALUES "
  13. )
  14. // TxAddTaskHis add task oper history
  15. func (d *Dao) TxAddTaskHis(tx *sql.Tx, pool, action int8, taskID, cid, uid, utime int64, result int16, reason string) (rows int64, err error) {
  16. res, err := tx.Exec(_inTaskHisSQL, pool, action, taskID, cid, uid, result, reason, utime)
  17. if err != nil {
  18. log.Error("tx.Exec(%s) error(%v)", _inTaskHisSQL, err)
  19. return
  20. }
  21. return res.RowsAffected()
  22. }
  23. // AddTaskHis 非事务
  24. func (d *Dao) AddTaskHis(c context.Context, pool, action int8, taskID, cid, uid, utime int64, result int16, reason string) (rows int64, err error) {
  25. res, err := d.arcDB.Exec(c, _inTaskHisSQL, pool, action, taskID, cid, uid, result, reason, utime)
  26. if err != nil {
  27. log.Error("d.arcDB.Exec(%s) error(%v)", _inTaskHisSQL, err)
  28. return
  29. }
  30. return res.RowsAffected()
  31. }
  32. // MulAddTaskHis 批量插入日志
  33. func (d *Dao) MulAddTaskHis(c context.Context, tls []*model.TaskForLog, action int8, uid int64) (rows int64, err error) {
  34. params := []string{}
  35. for _, item := range tls {
  36. var itemstr string
  37. itemstr += fmt.Sprintf("(%d,", action)
  38. itemstr += fmt.Sprintf("%d,", item.ID)
  39. itemstr += fmt.Sprintf("%d,", item.Cid)
  40. itemstr += fmt.Sprintf("%d)", uid)
  41. params = append(params, itemstr)
  42. }
  43. if len(params) == 0 {
  44. log.Warn("MulAddTaskHis empty params")
  45. return
  46. }
  47. sqlsring := strings.Join(params, ",")
  48. res, err := d.arcDB.Exec(c, _mulinTaskHisSQL+sqlsring)
  49. if err != nil {
  50. log.Error("d.arcDB.Exec(%s, %s) error(%v)", _mulinTaskHisSQL, sqlsring, err)
  51. return
  52. }
  53. return res.RowsAffected()
  54. }