rank.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/melloi/model"
  4. )
  5. //TreesQuery query department and performance test count of department
  6. func (d *Dao) TreesQuery() (res *model.TreeList, err error) {
  7. res = &model.TreeList{}
  8. //select department, count(department) as count from report_summary where department != '' GROUP BY department ORDER BY count desc
  9. err = d.DB.Table("report_summary").Select("department, project, app").Group("app").
  10. Having("department != ''").Order("department").Scan(&res.TreeList).Error
  11. return
  12. }
  13. //TreeNumQuery query department
  14. func (d *Dao) TreeNumQuery() (res *model.NumList, err error) { /**/
  15. res = &model.NumList{}
  16. //select count(DISTINCT department) as count from report_summary where department != ''
  17. if err = d.DB.Table("report_summary").Select("department, count(DISTINCT department) as dept_num").
  18. Where("department != ''").Scan(&res.NumList).Error; err != nil {
  19. return
  20. }
  21. if err = d.DB.Table("report_summary").Select("project, count(DISTINCT project) as pro_num").
  22. Where("project != ''").Scan(&res.NumList).Error; err != nil {
  23. return
  24. }
  25. if err = d.DB.Table("report_summary").Select("app, count(DISTINCT app) as app_num").
  26. Where("app != ''").Scan(&res.NumList).Error; err != nil {
  27. return
  28. }
  29. return
  30. }
  31. //TopHttpQuery query performance test top api
  32. func (d *Dao) TopHttpQuery() (res *model.TopAPIRes, err error) {
  33. res = &model.TopAPIRes{}
  34. //select s.url, count(r.script_id) as count from report_summary r INNER JOIN script s on r.script_id = s.id GROUP BY s.url having url != '' ORDER BY count desc
  35. err = d.DB.Limit(10).Table("report_summary").Select("script.url, count(report_summary.script_id) as count").
  36. Joins("inner join script on report_summary.script_id = script.id").
  37. Where("report_summary.active = 1 and report_summary.debug != 1 and script.test_type = 1 and report_summary.type = 0").
  38. Group("script.url").Having("script.url != ''").Order("count desc").Scan(&res.APIList).Error
  39. return
  40. }
  41. //TopGrpcQuery Top Grpc Query
  42. func (d *Dao) TopGrpcQuery() (res *model.GrpcRes, err error) {
  43. res = &model.GrpcRes{}
  44. //select g.service_name, g.request_method, count(r.script_id) as count from report_summary r INNER JOIN grpc g on r.script_id = g.id
  45. //where g.service_name != '' and r.active = 1 and r.debug != 1 and r.type = 1
  46. //GROUP BY g.service_name ORDER BY count desc
  47. err = d.DB.Limit(10).Table("report_summary").Select("grpc.service_name, grpc.request_method, count(report_summary.script_id) as count").
  48. Joins("inner join grpc on report_summary.script_id = grpc.id").
  49. Where("report_summary.active = 1 and report_summary.debug != 1 and grpc.service_name != '' and report_summary.type = 1").
  50. Group("grpc.service_name").Order("count desc").Scan(&res.GrpcList).Error
  51. return
  52. }
  53. //TopSceneQuery Top Scene Query
  54. func (d *Dao) TopSceneQuery() (res *model.SceneRes, err error) {
  55. res = &model.SceneRes{}
  56. //select s.scene_name, count(r.script_id) as count from report_summary r INNER JOIN scene s on r.scene_id = s.id
  57. //where s.scene_name != '' and s.is_active = 1 and s.is_draft = 0 and r.active = 1 and r.debug != 1 and r.scene_id != 0 and r.type = 2
  58. //GROUP BY s.scene_name ORDER BY count desc
  59. err = d.DB.Limit(10).Table("report_summary").Select("scene.department, scene.scene_name, count(report_summary.script_id) as count").
  60. Joins("inner join scene on report_summary.scene_id = scene.id").
  61. Where("report_summary.active = 1 and report_summary.debug != 1 and scene.scene_name != '' and scene.is_active = 1 and scene.is_draft = 0 and report_summary.scene_id != 0 and report_summary.type = 2").
  62. Group("scene.scene_name").Order("count desc").Scan(&res.SceneList).Error
  63. return
  64. }
  65. //TopDeptQuery query performance test top department
  66. func (d *Dao) TopDeptQuery() (res *model.TopDeptRes, err error) {
  67. res = &model.TopDeptRes{}
  68. //select department, count(department) as count from report_summary where department != '' GROUP BY department ORDER BY count desc
  69. err = d.DB.Limit(10).Table("report_summary").Select("department, count(department) as count").
  70. Where("report_summary.active = 1 and report_summary.debug != 1").
  71. Group("department").Having("department != ''").Order("count desc").Scan(&res.DeptList).Error
  72. return
  73. }
  74. //BuildLineQuery query performance test count by time
  75. func (d *Dao) BuildLineQuery(rank *model.Rank, summary *model.ReportSummary) (res *model.BuildLineRes, err error) {
  76. res = &model.BuildLineRes{}
  77. //select DATE_FORMAT(ctime, '%H') as count from report_summary where ctime >= date_sub(now(), interval 24 hour) AND ctime <= NOW()
  78. //switch rank.TimeDegree {
  79. //case "H":
  80. // err = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m-%d %H') as date").
  81. // Where(summary).Where("active = 1 and debug != 1").
  82. // Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime).Order("date").
  83. // Scan(&res.BuildList).Error
  84. //case "d":
  85. // err = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m-%d') as date").Where(summary).
  86. // Where("active = 1 and debug != 1").
  87. // Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime).Order("date").Scan(&res.BuildList).Error
  88. //case "m":
  89. // err = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m') as date").Where(summary).
  90. // Where("active = 1 and debug != 1").
  91. // Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime).Order("date").Scan(&res.BuildList).Error
  92. //case "Y":
  93. // err = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y') as date").Where(summary).
  94. // Where("active = 1 and debug != 1").
  95. // Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime).Order("date").Scan(&res.BuildList).Error
  96. //default:
  97. // err = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m-%d %H') as date").Where(summary).
  98. // Where("active = 1 and debug != 1").
  99. // Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime).Order("date").Scan(&res.BuildList).Error
  100. //}
  101. gDB := d.DB.Table(model.ReportSummary{}.TableName())
  102. switch rank.TimeDegree {
  103. case "H":
  104. gDB = gDB.Select("DATE_FORMAT(ctime, '%Y-%m-%d %H') as date").
  105. Where("active = 1 and debug != 1").
  106. Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime)
  107. case "d":
  108. gDB = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m-%d') as date").
  109. Where("active = 1 and debug != 1").
  110. Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime)
  111. case "m":
  112. gDB = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m') as date").
  113. Where("active = 1 and debug != 1").
  114. Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime)
  115. case "Y":
  116. gDB = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y') as date").
  117. Where("active = 1 and debug != 1").
  118. Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime)
  119. default:
  120. gDB = d.DB.Table("report_summary").Select("DATE_FORMAT(ctime, '%Y-%m-%d %H') as date").
  121. Where("active = 1 and debug != 1").
  122. Where("ctime >= ? AND ctime <= ?", rank.StartTime, rank.EndTime)
  123. }
  124. if rank.SearchAll {
  125. err = gDB.Where("type in (0, 1, 2)").Order("date").Scan(&res.BuildList).Error
  126. } else {
  127. err = gDB.Where("type = ?", summary.Type).Order("date").Scan(&res.BuildList).Error
  128. }
  129. return
  130. }
  131. //StateLineQuery query statistic of state
  132. func (d *Dao) StateLineQuery() (res *model.StateLineRes, err error) {
  133. res = &model.StateLineRes{}
  134. //select test_status, count(test_status) as count from report_summary GROUP BY test_status
  135. err = d.DB.Table("report_summary").Select("test_status, count(test_status) as count").Where("test_status != 0").
  136. Where("active = 1 and debug != 1").Group("test_status").Scan(&res.StateList).Error
  137. return
  138. }