statistics_api_controller.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package controllers
  2. import (
  3. "XT_New/service"
  4. "github.com/astaxie/beego"
  5. "time"
  6. )
  7. type StatisticsApiController struct {
  8. BaseAuthAPIController
  9. }
  10. func StatisticsApiRegistRouters() {
  11. beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics")
  12. }
  13. func (c *StatisticsApiController) GetStatistics() {
  14. adminUserInfo := c.GetAdminUserInfo()
  15. // thisTime := time.Now()
  16. year, month, day := time.Now().Date()
  17. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  18. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  19. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  20. todayWeek := int(todayTime.Weekday())
  21. if todayWeek == 0 {
  22. todayWeek = 7
  23. }
  24. weekEnd := 7 - todayWeek
  25. weekStart := weekEnd - 6
  26. // endDay := todayTime.AddDate(0, 0, weekEnd)
  27. startDay := todayTime.AddDate(0, 0, weekStart)
  28. //患者总数
  29. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  30. //今日透析
  31. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  32. //本周透析
  33. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  34. //传染病
  35. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  36. //性别分布
  37. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  38. //年龄分布
  39. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  40. //透析模式
  41. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  42. c.ServeSuccessJSON(map[string]interface{}{
  43. "patient_count": patientCount,
  44. "today_dialysis_count": todayDialysisCount,
  45. "week_daylysis_count": weekDaylysisCount,
  46. "disease_counts": diseaseCounts,
  47. "gender_counts": genderCounts,
  48. "age_counts": ageCounts,
  49. "mode_counts": modeCounts,
  50. })
  51. }