first_pass.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. "time"
  9. )
  10. const (
  11. _slFirstPassByAID = "SELECT `id` FROM `archive_first_pass` WHERE `aid`=? LIMIT 1;"
  12. _firstPassCount = "SELECT COUNT(id) FROM archive_first_pass WHERE aid IN (%s)"
  13. _inFirstPass = "INSERT INTO `archive_first_pass`(`aid`, `ctime`, `mtime`) VALUES(?,?,?);"
  14. )
  15. //GetFirstPassByAID 根据aid获取第一次过审的记录
  16. func (d *Dao) GetFirstPassByAID(c context.Context, aid int64) (id int64, err error) {
  17. row := d.db.QueryRow(c, _slFirstPassByAID, aid)
  18. if err = row.Scan(&id); err != nil {
  19. if err == sql.ErrNoRows {
  20. err = nil
  21. } else {
  22. log.Error("GetFirstPassByAID error(%v) aid(%d)", err, aid)
  23. }
  24. return
  25. }
  26. return
  27. }
  28. // FirstPassCount 根据aid获取第一次过审的数量
  29. func (d *Dao) FirstPassCount(c context.Context, aids []int64) (count int, err error) {
  30. if len(aids) < 1 {
  31. return
  32. }
  33. row := d.rdb.QueryRow(c, fmt.Sprintf(_firstPassCount, xstr.JoinInts(aids)))
  34. if err = row.Scan(&count); err != nil {
  35. if err == sql.ErrNoRows {
  36. err = nil
  37. } else {
  38. log.Error("row.Scan() error(%v) aid(%v)", err, aids)
  39. }
  40. return
  41. }
  42. return
  43. }
  44. //AddFirstPass 添加一条 第一次过审的记录
  45. func (d *Dao) AddFirstPass(tx *sql.Tx, aid int64) (err error) {
  46. now := time.Now()
  47. if _, err = tx.Exec(_inFirstPass, aid, now, now); err != nil {
  48. log.Error("AddFirstPass error(%v) aid(%d)", aid, err)
  49. }
  50. return
  51. }