mysql_upper.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. // UpperPassed upper passed articles
  10. func (d *Dao) UpperPassed(c context.Context, mid int64) (aids [][2]int64, err error) {
  11. rows, err := d.upPassedStmt.Query(c, mid)
  12. if err != nil {
  13. PromError("db:up文章列表")
  14. log.Error("getUpPasStmt.Query(%d) error(%+v)", mid, err)
  15. return
  16. }
  17. defer rows.Close()
  18. for rows.Next() {
  19. var (
  20. aid, ptime int64
  21. attributes int32
  22. )
  23. if err = rows.Scan(&aid, &ptime, &attributes); err != nil {
  24. log.Error("rows.Scan error(%+v)", err)
  25. return
  26. }
  27. if !model.NoDistributeAttr(attributes) {
  28. aids = append(aids, [2]int64{aid, ptime})
  29. }
  30. }
  31. err = rows.Err()
  32. promErrorCheck(err)
  33. return
  34. }
  35. // UppersPassed uppers passed articles
  36. func (d *Dao) UppersPassed(c context.Context, mids []int64) (aidm map[int64][][2]int64, err error) {
  37. rows, err := d.articleDB.Query(c, fmt.Sprintf(_uppersPassedSQL, xstr.JoinInts(mids)))
  38. if err != nil {
  39. PromError("db:批量查询up文章列表")
  40. log.Error("UpsPassed error(%+v)", err)
  41. return
  42. }
  43. defer rows.Close()
  44. aidm = make(map[int64][][2]int64, len(mids))
  45. for rows.Next() {
  46. var (
  47. aid, mid, ptime int64
  48. attributes int32
  49. )
  50. if err = rows.Scan(&aid, &mid, &ptime, &attributes); err != nil {
  51. log.Error("rows.Scan error(%+v)", err)
  52. return
  53. }
  54. if !model.NoDistributeAttr(attributes) {
  55. aidm[mid] = append(aidm[mid], [2]int64{aid, ptime})
  56. }
  57. }
  58. for _, mid := range mids {
  59. if aidm[mid] == nil {
  60. aidm[mid] = [][2]int64{}
  61. }
  62. }
  63. err = rows.Err()
  64. promErrorCheck(err)
  65. return
  66. }