mysql_bugly_project.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package dao
  2. import (
  3. "database/sql"
  4. "go-common/app/admin/ep/marthe/model"
  5. "go-common/library/ecode"
  6. pkgerr "github.com/pkg/errors"
  7. )
  8. // InsertBuglyProject Insert Bugly Project.
  9. func (d *Dao) InsertBuglyProject(buglyProject *model.BuglyProject) error {
  10. return pkgerr.WithStack(d.db.Create(buglyProject).Error)
  11. }
  12. // UpdateBuglyProject Update Bugly Project.
  13. func (d *Dao) UpdateBuglyProject(buglyProject *model.BuglyProject) error {
  14. return pkgerr.WithStack(d.db.Model(&model.BuglyProject{}).Updates(buglyProject).Error)
  15. }
  16. // QueryBuglyProject Query Bugly Project.
  17. func (d *Dao) QueryBuglyProject(id int64) (buglyProject *model.BuglyProject, err error) {
  18. buglyProject = &model.BuglyProject{}
  19. err = pkgerr.WithStack(d.db.Where("id = ?", id).First(buglyProject).Error)
  20. return
  21. }
  22. // QueryBuglyProjectByName Query Bugly Project.
  23. func (d *Dao) QueryBuglyProjectByName(projectName string) (buglyProject *model.BuglyProject, err error) {
  24. buglyProject = &model.BuglyProject{}
  25. if err = d.db.Where("project_name = ?", projectName).First(buglyProject).Error; err == ecode.NothingFound {
  26. err = nil
  27. }
  28. return
  29. }
  30. // QueryAllBuglyProjects Query All Bugly Project.
  31. func (d *Dao) QueryAllBuglyProjects() (buglyProjects []*model.BuglyProject, err error) {
  32. err = pkgerr.WithStack(d.db.Model(&model.BuglyProject{}).Find(&buglyProjects).Error)
  33. return
  34. }
  35. // FindBuglyProjects Find Bugly Project.
  36. func (d *Dao) FindBuglyProjects(req *model.QueryBuglyProjectRequest) (total int64, buglyProject []*model.BuglyProject, err error) {
  37. gDB := d.db.Model(&model.BuglyProject{})
  38. if req.ProjectID != "" {
  39. gDB = gDB.Where("project_id=?", req.ProjectID)
  40. }
  41. if req.ProjectName != "" {
  42. gDB = gDB.Where("project_name like ?", _wildcards+req.ProjectName+_wildcards)
  43. }
  44. if req.PlatformID != "" {
  45. gDB = gDB.Where("platform_id=?", req.PlatformID)
  46. }
  47. if req.UpdateBy != "" {
  48. gDB = gDB.Where("update_by=?", req.UpdateBy)
  49. }
  50. if err = pkgerr.WithStack(gDB.Count(&total).Error); err != nil {
  51. return
  52. }
  53. err = pkgerr.WithStack(gDB.Order("ctime desc").Offset((req.PageNum - 1) * req.PageSize).Limit(req.PageSize).Find(&buglyProject).Error)
  54. return
  55. }
  56. // QueryBuglyProjectList Query Bugly Project List.
  57. func (d *Dao) QueryBuglyProjectList() (projectList []string, err error) {
  58. var (
  59. rows *sql.Rows
  60. )
  61. sql := "select DISTINCT project_name from bugly_projects"
  62. if rows, err = d.db.Raw(sql).Rows(); err != nil {
  63. return
  64. }
  65. defer rows.Close()
  66. for rows.Next() {
  67. var ver string
  68. if err = rows.Scan(&ver); err != nil {
  69. return
  70. }
  71. projectList = append(projectList, ver)
  72. }
  73. return
  74. }