platform.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/vip/model"
  5. xsql "go-common/library/database/sql"
  6. "github.com/pkg/errors"
  7. )
  8. const (
  9. _platformAll = "SELECT id,platform_name,platform,device,mobi_app,panel_type FROM vip_platform_config WHERE is_del=0 ORDER BY id"
  10. _platformByID = "SELECT id,platform_name,platform,device,mobi_app,panel_type FROM vip_platform_config WHERE id =?;"
  11. )
  12. // PlatformAll .
  13. func (d *Dao) PlatformAll(c context.Context) (res []*model.ConfPlatform, err error) {
  14. var rows *xsql.Rows
  15. if rows, err = d.db.Query(c, _platformAll); err != nil {
  16. err = errors.WithStack(err)
  17. return
  18. }
  19. defer rows.Close()
  20. res = make([]*model.ConfPlatform, 0)
  21. for rows.Next() {
  22. r := new(model.ConfPlatform)
  23. if err = rows.Scan(&r.ID, &r.PlatformName, &r.Platform, &r.Device, &r.MobiApp, &r.PanelType); err != nil {
  24. err = errors.WithStack(err)
  25. res = nil
  26. return
  27. }
  28. res = append(res, r)
  29. }
  30. err = rows.Err()
  31. return
  32. }
  33. //PlatformByID get info by open id.
  34. func (d *Dao) PlatformByID(c context.Context, id int64) (r *model.ConfPlatform, err error) {
  35. r = new(model.ConfPlatform)
  36. if err = d.db.QueryRow(c, _platformByID, id).
  37. Scan(&r.ID, &r.PlatformName, &r.Platform, &r.Device, &r.MobiApp, &r.PanelType); err != nil {
  38. if err == xsql.ErrNoRows {
  39. r = nil
  40. err = nil
  41. return
  42. }
  43. err = errors.Wrapf(err, "dao platform by id(%d)", id)
  44. }
  45. return
  46. }