mysql_bugly_issue.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // GetBuglyIssue Get Issue Record.
  8. func (d *Dao) GetBuglyIssue(issueNo, version string) (buglyIssue *model.BuglyIssue, err error) {
  9. buglyIssue = &model.BuglyIssue{}
  10. if err = d.db.Where("issue_no = ? and version = ?", issueNo, version).First(buglyIssue).Error; err != nil {
  11. if err == ecode.NothingFound {
  12. err = nil
  13. } else {
  14. err = pkgerr.WithStack(err)
  15. }
  16. }
  17. return
  18. }
  19. // UpdateBuglyIssue Update Issue Record.
  20. func (d *Dao) UpdateBuglyIssue(buglyIssue *model.BuglyIssue) error {
  21. return pkgerr.WithStack(d.db.Model(&model.BuglyIssue{}).Where("issue_no = ? and version = ?", buglyIssue.IssueNo, buglyIssue.Version).UpdateColumn(map[string]interface{}{
  22. "last_time": buglyIssue.LastTime,
  23. "happen_times": buglyIssue.HappenTimes,
  24. "user_times": buglyIssue.UserTimes,
  25. }).Error)
  26. }
  27. // InsertBuglyIssue Insert Issue Record.
  28. func (d *Dao) InsertBuglyIssue(buglyIssue *model.BuglyIssue) (err error) {
  29. return pkgerr.WithStack(d.db.Model(&model.BuglyIssue{}).Create(buglyIssue).Error)
  30. }
  31. // GetBuglyIssuesByFilterSQL Get Bugly Issues By Filter SQL.
  32. func (d *Dao) GetBuglyIssuesByFilterSQL(issueFilterSQL string) (buglyIssues []*model.BuglyIssue, err error) {
  33. if err = d.db.Raw(issueFilterSQL).Order("id asc").Find(&buglyIssues).Error; err != nil {
  34. if err == ecode.NothingFound {
  35. err = nil
  36. } else {
  37. err = pkgerr.WithStack(err)
  38. }
  39. }
  40. return
  41. }
  42. // UpdateBuglyIssueTapdBugID Update Issue Record Tapd Bug ID.
  43. func (d *Dao) UpdateBuglyIssueTapdBugID(id int64, tapdBugID string) error {
  44. return pkgerr.WithStack(d.db.Model(&model.BuglyIssue{}).Where("id=?", id).Update("tapd_bug_id", tapdBugID).Error)
  45. }
  46. // FindBuglyIssues Find Bugly Issues.
  47. func (d *Dao) FindBuglyIssues(req *model.QueryBuglyIssueRequest) (total int64, buglyIssues []*model.BuglyIssue, err error) {
  48. gDB := d.db.Model(&model.BuglyIssue{})
  49. if req.IssueNo != "" {
  50. gDB = gDB.Where("issue_no = ?", req.IssueNo)
  51. }
  52. if req.Title != "" {
  53. gDB = gDB.Where("title like ?", _wildcards+req.Title+_wildcards)
  54. }
  55. if req.ExceptionMsg != "" {
  56. gDB = gDB.Where("exception_msg like ?", _wildcards+req.ExceptionMsg+_wildcards)
  57. }
  58. if req.KeyStack != "" {
  59. gDB = gDB.Where("key_stack like ?", _wildcards+req.KeyStack+_wildcards)
  60. }
  61. if req.Detail != "" {
  62. gDB = gDB.Where("detail like ?", _wildcards+req.Detail+_wildcards)
  63. }
  64. if req.Tags != "" {
  65. gDB = gDB.Where("tags like ?", _wildcards+req.Tags+_wildcards)
  66. }
  67. if req.Version != "" {
  68. gDB = gDB.Where("version like ?", _wildcards+req.Version+_wildcards)
  69. }
  70. if req.ProjectID != "" {
  71. gDB = gDB.Where("project_id like ?", _wildcards+req.ProjectID+_wildcards)
  72. }
  73. if req.TapdBugID != "" {
  74. gDB = gDB.Where("tapd_bug_id = ?", req.TapdBugID)
  75. }
  76. if err = pkgerr.WithStack(gDB.Count(&total).Error); err != nil {
  77. return
  78. }
  79. err = pkgerr.WithStack(gDB.Order("mtime desc").Offset((req.PageNum - 1) * req.PageSize).Limit(req.PageSize).Find(&buglyIssues).Error)
  80. return
  81. }
  82. // GetBuglyIssuesHasInTapd Get Bugly Issues Has In Tapd.
  83. func (d *Dao) GetBuglyIssuesHasInTapd() (buglyIssues []*model.BuglyIssue, err error) {
  84. if err = d.db.Where("tapd_bug_id<>''").Find(&buglyIssues).Error; err != nil {
  85. if err == ecode.NothingFound {
  86. err = nil
  87. } else {
  88. err = pkgerr.WithStack(err)
  89. }
  90. }
  91. return
  92. }