management_analyse_api_controller.go 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package new_mobile_api_controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/service/management_service"
  5. service "Xcx_New/service/print_data_service/schedule_dialysis"
  6. "Xcx_New/utils"
  7. "time"
  8. )
  9. type ManagementAnalyseApiController struct {
  10. NewMobileBaseAPIAuthController
  11. }
  12. func (this *ManagementAnalyseApiController) StockRecordPrintData() {
  13. types, _ := this.GetInt("type", 0)
  14. start_time := this.GetString("start_time")
  15. end_time := this.GetString("end_time")
  16. adminUserInfo := this.GetMobileAdminUserInfo()
  17. timeLayout := "2006-01-02"
  18. loc, _ := time.LoadLocation("Local")
  19. var startTime int64
  20. if len(start_time) > 0 {
  21. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  22. if err != nil {
  23. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. startTime = theTime.Unix()
  27. }
  28. var endTime int64
  29. if len(end_time) > 0 {
  30. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  31. if err != nil {
  32. utils.ErrorLog(err.Error())
  33. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  34. return
  35. }
  36. endTime = theTime.Unix()
  37. }
  38. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.Org.Id)
  39. if err != nil {
  40. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. } else {
  42. this.ServeSuccessJSON(map[string]interface{}{
  43. "list": list,
  44. "type": types,
  45. })
  46. }
  47. }
  48. func (this *ManagementAnalyseApiController) StatisticsPatientChart() {
  49. start_time := this.GetString("start_time")
  50. end_time := this.GetString("end_time")
  51. statistics_type, _ := this.GetInt("type", 0)
  52. adminUserInfo := this.GetMobileAdminUserInfo()
  53. timeLayout := "2006-01-02"
  54. loc, _ := time.LoadLocation("Local")
  55. var startTime int64
  56. if len(start_time) > 0 {
  57. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  58. if err != nil {
  59. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  60. return
  61. }
  62. startTime = theTime.Unix()
  63. }
  64. var endTime int64
  65. if len(end_time) > 0 {
  66. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  67. if err != nil {
  68. utils.ErrorLog(err.Error())
  69. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  70. return
  71. }
  72. endTime = theTime.Unix()
  73. }
  74. data, total_one, _ := management_service.GetPatientChartData(adminUserInfo.Org.Id, startTime, endTime, statistics_type)
  75. total, _ := management_service.GetLapsetoPatientTotal(adminUserInfo.Org.Id, statistics_type)
  76. total_three, _ := management_service.GetLapsetoPatientTotal(adminUserInfo.Org.Id, 2)
  77. this.ServeSuccessJSON(map[string]interface{}{
  78. "chart_data": data,
  79. "total_one": total_one,
  80. "total": total,
  81. "total_three": total + total_three,
  82. })
  83. }
  84. func (this *ManagementAnalyseApiController) StatisticsPatientTable() {
  85. start_time := this.GetString("start_time")
  86. end_time := this.GetString("end_time")
  87. statistics_type, _ := this.GetInt("type", 0)
  88. page, _ := this.GetInt64("page", 0)
  89. limit, _ := this.GetInt64("limit", 0)
  90. if page == 0 {
  91. page = 1
  92. }
  93. if limit == 0 {
  94. limit = 20
  95. }
  96. adminUserInfo := this.GetMobileAdminUserInfo()
  97. timeLayout := "2006-01-02"
  98. loc, _ := time.LoadLocation("Local")
  99. var startTime int64
  100. if len(start_time) > 0 {
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  102. if err != nil {
  103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. startTime = theTime.Unix()
  107. }
  108. var endTime int64
  109. if len(end_time) > 0 {
  110. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  111. if err != nil {
  112. utils.ErrorLog(err.Error())
  113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  114. return
  115. }
  116. endTime = theTime.Unix()
  117. }
  118. data, total, _ := management_service.GetPatientTableData(adminUserInfo.Org.Id, page, limit, startTime, endTime, statistics_type)
  119. this.ServeSuccessJSON(map[string]interface{}{
  120. "data": data,
  121. "total": total,
  122. })
  123. }