Stats.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package apis
  2. import (
  3. "go-admin/app/observe/service"
  4. "go-admin/app/observe/service/dto"
  5. "go-admin/utils"
  6. "net/http"
  7. "github.com/gin-gonic/gin"
  8. )
  9. type Stats struct {
  10. utils.OtApi
  11. }
  12. func (s Stats) SetPlatformStats(c *gin.Context) {
  13. svc := new(service.Stats)
  14. err := s.MakeContext(c).MakeDB().MakeService(&svc.OtService).Errors
  15. if err != nil {
  16. s.Error(http.StatusInternalServerError, err, err.Error())
  17. return
  18. }
  19. result := make(map[string]interface{})
  20. if err := svc.SetTotalStats(&result); err != nil {
  21. s.Error(http.StatusInternalServerError, err, err.Error())
  22. return
  23. }
  24. s.OK(result, "ok")
  25. }
  26. func (s Stats) GetPlatformStats(c *gin.Context) {
  27. svc := new(service.Stats)
  28. err := s.MakeContext(c).MakeDB().MakeService(&svc.OtService).Errors
  29. if err != nil {
  30. s.Error(http.StatusInternalServerError, err, err.Error())
  31. return
  32. }
  33. result := make(map[string]interface{})
  34. if err := svc.GetTotalStats(&result); err != nil {
  35. s.Error(http.StatusInternalServerError, err, err.Error())
  36. return
  37. }
  38. s.OK(result, "ok")
  39. }
  40. func (s Stats) GetApdexModelByAlias(c *gin.Context) {
  41. req := new(dto.ApdexHandlerReq)
  42. svc := new(service.Stats)
  43. err := s.MakeContext(c).MakeDB().Bind(req).MakeService(&svc.OtService).Errors
  44. if err != nil {
  45. s.Error(http.StatusInternalServerError, err, err.Error())
  46. return
  47. }
  48. result := make(map[string]interface{})
  49. if err := svc.GetApdexModelByAppAlias(req, &result); err != nil {
  50. s.Error(http.StatusInternalServerError, err, err.Error())
  51. return
  52. }
  53. s.OK(result, "ok")
  54. }
  55. func (s Stats) SetApdexModelArgsByAlias(c *gin.Context) {
  56. req := new(dto.ApdexUpdateReq)
  57. svc := new(service.Stats)
  58. err := s.MakeContext(c).MakeDB().Bind(req).MakeService(&svc.OtService).Errors
  59. if err != nil {
  60. s.Error(http.StatusInternalServerError, err, err.Error())
  61. return
  62. }
  63. result := make(map[string]interface{})
  64. if err := svc.SetApdexModelByAppAlias(req, &result); err != nil {
  65. s.Error(http.StatusInternalServerError, err, err.Error())
  66. return
  67. }
  68. s.OK(result, "模型更新成功")
  69. }