mysql_mask.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/dm/model"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _countMaskUp = "SELECT count(*) FROM dm_mask_up WHERE state=1"
  9. _getMaskUp = "SELECT id,mid,state,comment,ctime,mtime from dm_mask_up where state=1 ORDER BY mtime DESC limit ?,? "
  10. _maskUpOpen = "INSERT INTO dm_mask_up(mid,state,comment) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?,comment=?"
  11. )
  12. // MaskUps get mask up info from db.
  13. func (d *Dao) MaskUps(c context.Context, pn, ps int64) (maskUps []*model.MaskUp, total int64, err error) {
  14. maskUps = make([]*model.MaskUp, 0)
  15. countRow := d.biliDM.QueryRow(c, _countMaskUp)
  16. if err = countRow.Scan(&total); err != nil {
  17. log.Error("row.ScanCount error(%v)", err)
  18. return
  19. }
  20. rows, err := d.biliDM.Query(c, _getMaskUp, (pn-1)*ps, ps)
  21. if err != nil {
  22. log.Error("biliDM.Query(%s) error(%v)", _getMaskUp, err)
  23. return
  24. }
  25. defer rows.Close()
  26. for rows.Next() {
  27. maskUp := &model.MaskUp{}
  28. if err = rows.Scan(&maskUp.ID, &maskUp.Mid, &maskUp.State, &maskUp.Comment, &maskUp.CTime, &maskUp.MTime); err != nil {
  29. log.Error("biliDM.Scan(%s) error(%v)", _getMaskUp, err)
  30. return
  31. }
  32. maskUps = append(maskUps, maskUp)
  33. }
  34. if err = rows.Err(); err != nil {
  35. log.Error("biliDM.rows.Err() error(%v)", err)
  36. }
  37. return
  38. }
  39. // MaskUpOpen mask up open.
  40. func (d *Dao) MaskUpOpen(c context.Context, mid int64, state int32, comment string) (affect int64, err error) {
  41. res, err := d.biliDM.Exec(c, _maskUpOpen, mid, state, comment, state, comment)
  42. if err != nil {
  43. log.Error("d.biliDM.Exec(%s,%d,%v,%v) error(%v)", _maskUpOpen, mid, state, comment, err)
  44. return
  45. }
  46. return res.RowsAffected()
  47. }