mysql_bugly_cookie.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/marthe/model"
  4. "go-common/library/ecode"
  5. pkgerr "github.com/pkg/errors"
  6. )
  7. // InsertCookie Insert Cookie.
  8. func (d *Dao) InsertCookie(buglyCookie *model.BuglyCookie) error {
  9. return pkgerr.WithStack(d.db.Create(buglyCookie).Error)
  10. }
  11. // UpdateCookie Update cookie.
  12. func (d *Dao) UpdateCookie(buglyCookie *model.BuglyCookie) error {
  13. return pkgerr.WithStack(d.db.Model(&model.BuglyCookie{}).Updates(buglyCookie).Error)
  14. }
  15. // UpdateCookieStatus Update Cookie Status.
  16. func (d *Dao) UpdateCookieStatus(id int64, status int) error {
  17. return pkgerr.WithStack(d.db.Model(&model.BuglyCookie{}).Where("id = ?", id).Update("status", status).Error)
  18. }
  19. // UpdateCookieUsageCount Update Cookie Usage Count.
  20. func (d *Dao) UpdateCookieUsageCount(id int64, usageCount int) error {
  21. return pkgerr.WithStack(d.db.Model(&model.BuglyCookie{}).Where("id = ?", id).Update("usage_count", usageCount).Error)
  22. }
  23. // QueryCookieByStatus Query Cookie By Status.
  24. func (d *Dao) QueryCookieByStatus(status int) (buglyCookies []*model.BuglyCookie, err error) {
  25. err = pkgerr.WithStack(d.db.Where("status=?", status).Order("ctime desc").Find(&buglyCookies).Error)
  26. return
  27. }
  28. // QueryCookieByQQAccount Query Cookie By QQ Account.
  29. func (d *Dao) QueryCookieByQQAccount(qqAccount int) (buglyCookie *model.BuglyCookie, err error) {
  30. buglyCookie = &model.BuglyCookie{}
  31. if err = d.db.Where("qq_account=?", qqAccount).First(buglyCookie).Error; err != nil {
  32. if err == ecode.NothingFound {
  33. err = nil
  34. } else {
  35. err = pkgerr.WithStack(err)
  36. }
  37. }
  38. return
  39. }
  40. // FindCookies Find Cookies.
  41. func (d *Dao) FindCookies(req *model.QueryBuglyCookiesRequest) (total int64, buglyCookies []*model.BuglyCookie, err error) {
  42. gDB := d.db.Model(&model.BuglyCookie{})
  43. if req.QQAccount != 0 {
  44. gDB = gDB.Where("qq_account=?", req.QQAccount)
  45. }
  46. if req.Status != 0 {
  47. gDB = gDB.Where("status=?", req.Status)
  48. }
  49. if err = pkgerr.WithStack(gDB.Count(&total).Error); err != nil {
  50. return
  51. }
  52. err = pkgerr.WithStack(gDB.Order("ctime desc").Offset((req.PageNum - 1) * req.PageSize).Limit(req.PageSize).Find(&buglyCookies).Error)
  53. return
  54. }