mysql_tapd_bug_version_template.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // InsertTapdBugVersionTemplate Insert TapdBug Version Template.
  8. func (d *Dao) InsertTapdBugVersionTemplate(tapdBugVersionTemplate *model.TapdBugVersionTemplate) error {
  9. return pkgerr.WithStack(d.db.Create(tapdBugVersionTemplate).Error)
  10. }
  11. // UpdateTapdBugVersionTemplate Update Tapd Bug Version Template.
  12. func (d *Dao) UpdateTapdBugVersionTemplate(tapdBugVersionTemplate *model.TapdBugVersionTemplate) error {
  13. return pkgerr.WithStack(d.db.Save(&tapdBugVersionTemplate).Error)
  14. }
  15. // QueryTapdBugVersionTemplate Query Tapd Bug Version Template.
  16. func (d *Dao) QueryTapdBugVersionTemplate(id int64) (tapdBugVersionTemplate *model.TapdBugVersionTemplate, err error) {
  17. tapdBugVersionTemplate = &model.TapdBugVersionTemplate{}
  18. if err = d.db.Where("id=?", id).First(&tapdBugVersionTemplate).Error; err != nil {
  19. if err == ecode.NothingFound {
  20. err = nil
  21. } else {
  22. err = pkgerr.WithStack(err)
  23. }
  24. }
  25. return
  26. }
  27. // QueryTapdBugVersionTemplateByVersion Query Tapd Bug Version Template.
  28. func (d *Dao) QueryTapdBugVersionTemplateByVersion(version string) (tapdBugVersionTemplate *model.TapdBugVersionTemplate, err error) {
  29. tapdBugVersionTemplate = &model.TapdBugVersionTemplate{}
  30. if err = d.db.Where("version=?", version).First(&tapdBugVersionTemplate).Error; err != nil {
  31. if err == ecode.NothingFound {
  32. err = nil
  33. } else {
  34. err = pkgerr.WithStack(err)
  35. }
  36. }
  37. return
  38. }
  39. // FindTapdBugVersionTemplates Find Tapd Bug Version Templates.
  40. func (d *Dao) FindTapdBugVersionTemplates(req *model.QueryTapdBugVersionTemplateRequest) (total int64, tapdBugVersionTemplate []*model.TapdBugVersionTemplate, err error) {
  41. gDB := d.db.Model(&model.TapdBugVersionTemplate{})
  42. if req.ProjectID > 0 {
  43. gDB = gDB.Where("project_template_id = ?", req.ProjectID)
  44. }
  45. if req.Version != "" {
  46. gDB = gDB.Where("version like ?", req.Version+_wildcards)
  47. }
  48. if req.UpdateBy != "" {
  49. gDB = gDB.Where("update_by = ?", req.UpdateBy)
  50. }
  51. if err = pkgerr.WithStack(gDB.Count(&total).Error); err != nil {
  52. return
  53. }
  54. err = pkgerr.WithStack(gDB.Order("ctime desc").Offset((req.PageNum - 1) * req.PageSize).Limit(req.PageSize).Find(&tapdBugVersionTemplate).Error)
  55. return
  56. }