app.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/bbq/app-bbq/api/http/v1"
  6. "go-common/app/interface/bbq/app-bbq/model"
  7. "go-common/library/database/sql"
  8. )
  9. const (
  10. _queryNewAppVersion = "select `id`, `platform`, `ver_name`, `ver_code`, `title`, `content`, `download`, `md5`, `size`, `force`, `status` from `app_package` where platform = ? and ver_code > ? and status = 1 order by ver_code desc;"
  11. _queryAppPackage = "select `id`, `platform`, `ver_name`, `ver_code`, `title`, `content`, `download`, `md5`, `size`, `force`, `status`, `ctime` from `app_package` where status>0;"
  12. _queryAppResource = "select `id`, `platform`, `name`, `version`, `md5`, `download`, `status`, `start_time`, `end_time` from `app_resource` where `platform` in (0, ?) and `version` = ? and `status` = ? and `end_time` > ?;"
  13. )
  14. // FetchNewAppVersion .
  15. func (d *Dao) FetchNewAppVersion(c context.Context, platform int, vCode int) (result *model.AppVersion, err error) {
  16. result = &model.AppVersion{}
  17. err = d.db.QueryRow(c, _queryNewAppVersion, platform, vCode).Scan(&result.ID, &result.Platform, &result.Name, &result.Code, &result.Title, &result.Content, &result.Download, &result.MD5, &result.Size, &result.Force, &result.Status)
  18. if err == sql.ErrNoRows {
  19. err = nil
  20. }
  21. return
  22. }
  23. // FetchAppPackage .
  24. func (d *Dao) FetchAppPackage(c context.Context) (result []*v1.AppPackage, err error) {
  25. rows, err := d.db.Query(c, _queryAppPackage)
  26. for rows.Next() {
  27. tmp := &v1.AppPackage{}
  28. err = rows.Scan(&tmp.ID, &tmp.Platform, &tmp.VersionName, &tmp.VersionCode, &tmp.Title, &tmp.Content, &tmp.Download, &tmp.MD5, &tmp.Size, &tmp.Force, &tmp.Status, &tmp.CTime)
  29. if err != nil {
  30. continue
  31. }
  32. result = append(result, tmp)
  33. }
  34. return
  35. }
  36. // FetchAppResource .
  37. func (d *Dao) FetchAppResource(c context.Context, plat int, ver int) (result []*model.AppResource, err error) {
  38. result = make([]*model.AppResource, 0)
  39. rows, err := d.db.Query(c, _queryAppResource, plat, ver, 1, time.Now().Format("2006-01-02 15:04:05"))
  40. if err != nil {
  41. return
  42. }
  43. for rows.Next() {
  44. tmp := new(model.AppResource)
  45. err = rows.Scan(&tmp.ID, &tmp.Platform, &tmp.Name, &tmp.Code, &tmp.MD5, &tmp.Download, &tmp.Status, &tmp.StartTime, &tmp.EndTime)
  46. if err != nil {
  47. continue
  48. }
  49. result = append(result, tmp)
  50. }
  51. return
  52. }