analysis_api_controller.go 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package admin_api_controllers
  2. import (
  3. "XT_Admin_Api/models/admin_models"
  4. "XT_Admin_Api/service"
  5. "XT_Admin_Api/utils"
  6. "time"
  7. )
  8. type AnalysisAPIController struct {
  9. AdminBaseAPIAuthController
  10. }
  11. func (this *AnalysisAPIController) HomeStatistics() {
  12. range_data := this.GetString("range_data")
  13. range_type, _ := this.GetInt64("range_type")
  14. var rangeDate *time.Time
  15. var parseDateErr error
  16. var rangeTimeStamp int64
  17. if len(range_data) > 0 {
  18. rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
  19. if parseDateErr != nil {
  20. this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
  21. return
  22. }
  23. rangeTimeStamp = rangeDate.Unix()
  24. } else {
  25. rangeTimeStamp = 0
  26. }
  27. now := time.Now().Unix()
  28. newOrgCount, _ := service.GetRegistedOrgCount(rangeTimeStamp, now)
  29. totalOrg, _ := service.GetTotalOrgCount()
  30. activeOrgCount, _ := service.GetActiveOrgCount(rangeTimeStamp, now)
  31. totalActiveOrg, _ := service.GetActiveOrgTotalCount()
  32. activeAdminCount, _ := service.GetActiveAdminUserCount(rangeTimeStamp, now)
  33. adminTotalCount, _ := service.GetAdminUserTotalCount()
  34. patientCount, _ := service.GetNewPatientCount(rangeTimeStamp, now)
  35. patientTotalCount, _ := service.GetPatientTotalCount()
  36. var orgRegisterStatistics []*admin_models.Statistics
  37. var newPatientStatistics []*admin_models.Statistics
  38. var orgActiveAdminStatistics []*admin_models.Statistics
  39. var orgActiveStatistics []*admin_models.Statistics
  40. switch range_type {
  41. case 1:
  42. break
  43. case 2:
  44. orgRegisterStatistics, _ = service.GetYesterDayRegistedOrgCount()
  45. newPatientStatistics, _ = service.GetYesterDayNewPatientCount()
  46. orgActiveAdminStatistics, _ = service.GetYesterDayActiveAdminUserCount()
  47. orgActiveStatistics, _ = service.GetYesterDayActiveOrgCount()
  48. break
  49. case 3:
  50. orgRegisterStatistics, _ = service.GetWeekRegistedOrgCount()
  51. newPatientStatistics, _ = service.GetWeekNewPatientCount()
  52. orgActiveAdminStatistics, _ = service.GetWeekActiveAdminUserCount()
  53. orgActiveStatistics, _ = service.GetWeekActiveOrgCount()
  54. break
  55. case 4:
  56. orgRegisterStatistics, _ = service.GetMonthRegistedOrgCount()
  57. newPatientStatistics, _ = service.GetMonthNewPatientCount()
  58. orgActiveAdminStatistics, _ = service.GetMonthActiveAdminUserCount()
  59. orgActiveStatistics, _ = service.GetMonthActiveOrgCount()
  60. break
  61. case 5:
  62. orgRegisterStatistics, _ = service.GetThreeMonthRegistedOrgCount()
  63. newPatientStatistics, _ = service.GetThreeMonthNewPatientCount()
  64. orgActiveAdminStatistics, _ = service.GetThreeMonthActiveAdminUserCount()
  65. orgActiveStatistics, _ = service.GetThreeMonthActiveOrgCount()
  66. break
  67. case 6:
  68. orgRegisterStatistics, _ = service.GetSixMonthRegistedOrgCount()
  69. newPatientStatistics, _ = service.GetSixMonthNewPatientCount()
  70. orgActiveAdminStatistics, _ = service.GetSixMonthActiveAdminUserCount()
  71. orgActiveStatistics, _ = service.GetSixMonthActiveOrgCount()
  72. break
  73. case 7:
  74. orgRegisterStatistics, _ = service.GetYearRegistedOrgCount()
  75. newPatientStatistics, _ = service.GetYearNewPatientCount()
  76. orgActiveAdminStatistics, _ = service.GetYearActiveAdminUserCount()
  77. orgActiveStatistics, _ = service.GetYearActiveOrgCount()
  78. break
  79. }
  80. this.ServeSuccessJSON(map[string]interface{}{
  81. "org_count": newOrgCount,
  82. "org_total_count": totalOrg,
  83. "active_org_count": activeOrgCount,
  84. "active_org_total_count": totalActiveOrg,
  85. "active_admin_count": activeAdminCount,
  86. "active_admin_total_count": adminTotalCount,
  87. "patient_count": patientCount,
  88. "patient_total_count": patientTotalCount,
  89. "org_count_list": orgRegisterStatistics,
  90. "patient_count_list": newPatientStatistics,
  91. "active_count_list": orgActiveAdminStatistics,
  92. "active_org_list": orgActiveStatistics,
  93. })
  94. }