report.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/melloi/model"
  4. )
  5. // QueryReportSummarys query reportSummarys
  6. func (d *Dao) QueryReportSummarys(reportSummary *model.ReportSummary, searchAll bool, pn, ps int32, treeNodes []string) (qrsr *model.QueryReportSuResponse, err error) {
  7. qrsr = &model.QueryReportSuResponse{}
  8. reportSummary.Active = 1
  9. reportSummary.Debug = -1
  10. gDB := d.DB.Table(model.ReportSummary{}.TableName()) //.Where("app in (?)", treeNodes)
  11. if reportSummary.TestName != "" && reportSummary.ScriptID != 0 {
  12. gDB = gDB.Where("test_name LIKE ? and active = ? and debug = ? and script_id = ?", "%"+reportSummary.TestName+"%", 1, -1, reportSummary.ScriptID)
  13. }
  14. if reportSummary.UserName != "" && reportSummary.ScriptID != 0 {
  15. gDB = gDB.Where("user_name LIKE ? and active = ? and debug = ? and script_id = ?", "%"+reportSummary.UserName+"%", 1, -1, reportSummary.ScriptID)
  16. }
  17. if reportSummary.TestName != "" {
  18. gDB = gDB.Where("test_name LIKE ? and active = ? and debug = ?", "%"+reportSummary.TestName+"%", 1, -1)
  19. }
  20. if reportSummary.UserName != "" {
  21. gDB = gDB.Where("user_name LIKE ? and active = ? and debug = ?", "%"+reportSummary.UserName+"%", 1, -1)
  22. }
  23. if searchAll {
  24. gDB = gDB.Where("type in (0, 1, 2)")
  25. } else {
  26. if reportSummary.ID == 0 {
  27. gDB = gDB.Where("type = ?", reportSummary.Type)
  28. }
  29. }
  30. if reportSummary.TestName == "" && reportSummary.UserName == "" {
  31. gDB = gDB.Where(reportSummary)
  32. }
  33. err = gDB.Count(&qrsr.TotalSize).
  34. Order("ctime desc").Offset((pn - 1) * ps).Limit(ps).Find(&qrsr.ReportSummarys).Error
  35. qrsr.PageSize = ps /**/
  36. qrsr.PageNum = pn
  37. return
  38. }
  39. // QueryReportSummarysWhiteName query reportSummarys by whiteName
  40. func (d *Dao) QueryReportSummarysWhiteName(reportSummary *model.ReportSummary, searchAll bool, pn, ps int32) (qrsr *model.QueryReportSuResponse, err error) {
  41. qrsr = &model.QueryReportSuResponse{}
  42. reportSummary.Active = 1
  43. reportSummary.Debug = -1
  44. gDB := d.DB.Table(model.ReportSummary{}.TableName())
  45. if reportSummary.TestName != "" && reportSummary.ScriptID != 0 {
  46. gDB = gDB.Where("test_name LIKE ? and active = ? and debug = ? and script_id = ?", "%"+reportSummary.TestName+"%", 1, -1, reportSummary.ScriptID)
  47. }
  48. if reportSummary.UserName != "" && reportSummary.ScriptID != 0 {
  49. gDB = gDB.Where("user_name LIKE ? and active = ? and debug = ? and script_id = ?", "%"+reportSummary.UserName+"%", 1, -1, reportSummary.ScriptID)
  50. }
  51. if reportSummary.TestName != "" {
  52. gDB = gDB.Where("test_name LIKE ? and active = ? and debug = ?", "%"+reportSummary.TestName+"%", 1, -1)
  53. }
  54. if reportSummary.UserName != "" {
  55. gDB = gDB.Where("user_name LIKE ? and active = ? and debug = ?", "%"+reportSummary.UserName+"%", 1, -1)
  56. }
  57. if searchAll {
  58. gDB = gDB.Where("type in (0, 1, 2)")
  59. } else {
  60. if reportSummary.ID == 0 {
  61. gDB = gDB.Where("type = ?", reportSummary.Type)
  62. }
  63. }
  64. if reportSummary.TestName == "" && reportSummary.UserName == "" {
  65. gDB = gDB.Where(reportSummary)
  66. }
  67. err = gDB.Count(&qrsr.TotalSize).
  68. Order("ctime desc").Offset((pn - 1) * ps).Limit(ps).Find(&qrsr.ReportSummarys).Error
  69. qrsr.PageSize = ps /**/
  70. qrsr.PageNum = pn
  71. return
  72. }
  73. // QueryReportSurys query reportSummarys
  74. func (d *Dao) QueryReportSurys(reportSummary *model.ReportSummary) (res []*model.ReportSummary, err error) {
  75. err = d.DB.Table(model.ReportSummary{}.TableName()).Where(reportSummary).Find(&res).Error
  76. return
  77. }
  78. // QueryReportSuryByID query reportSummary by id
  79. func (d *Dao) QueryReportSuryByID(id int) (res *model.ReportSummary, err error) {
  80. reportSummary := model.ReportSummary{ID: id}
  81. res = &model.ReportSummary{}
  82. err = d.DB.Table(model.ReportSummary{}.TableName()).Where(reportSummary).First(&res).Error
  83. return
  84. }
  85. //CountQueryReportSummarys count queryReportSummarys
  86. func (d *Dao) CountQueryReportSummarys(reportSummary *model.ReportSummary) (total int, err error) {
  87. err = d.DB.Table(model.ReportSummary{}.TableName()).Where(reportSummary).Count(&total).Error
  88. return
  89. }
  90. //AddReportSummary add reportSummary
  91. func (d *Dao) AddReportSummary(reportSummary *model.ReportSummary) (reportSuID int, err error) {
  92. err = d.DB.Create(reportSummary).Error
  93. reportSuID = reportSummary.ID
  94. return
  95. }
  96. //UpdateReportSummary update Report
  97. func (d *Dao) UpdateReportSummary(reportSummary *model.ReportSummary) error {
  98. return d.DB.Model(&model.ReportSummary{}).Where("id = ?", reportSummary.ID).Updates(reportSummary).Error
  99. }
  100. //UpdateReportStatusByID update report status
  101. func (d *Dao) UpdateReportStatusByID(ID, testStatus int) error {
  102. return d.DB.Exec("update report_summary set test_status = ? where id = ? ", testStatus, ID).Error
  103. }
  104. //UpdateReportStatus update Report
  105. func (d *Dao) UpdateReportStatus(status int) error {
  106. return d.DB.Model(&model.ReportSummary{}).Where("test_status = 2").Update("test_status", 1).Error
  107. }
  108. //UpdateReportDockByID update Report
  109. func (d *Dao) UpdateReportDockByID(ID, dockerSum int) error {
  110. return d.DB.Model(&model.ReportSummary{}).Where("id =?", ID).Updates(model.ReportSummary{DockerSum: dockerSum}).Error
  111. }
  112. //DelReportSummary delete reportSummary
  113. func (d *Dao) DelReportSummary(id int) error {
  114. return d.DB.Model(&model.ReportSummary{}).Where("ID=?", id).Update("active", 0).Error
  115. }
  116. //QueryReTimely query rueryReTimely
  117. func (d *Dao) QueryReTimely(testName, beginTime, afterTime string, podNames []string) (reportTimelys []*model.ReportTimely, err error) {
  118. err = d.DB.Model(&model.ReportTimely{}).Where("test_name = ? and mtime >= ? and mtime <= ? and pod_name in (?)", testName, beginTime, afterTime, podNames).Find(&reportTimelys).Error
  119. return
  120. }