print_data_api_controller.go 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. service "XT_New/service/print_data_service/schedule_dialysis"
  5. "XT_New/utils"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "github.com/astaxie/beego"
  10. )
  11. func PrintDataAPIControllerRegistRouters() {
  12. beego.Router("/api/print/schedule/dialysis", &PrintDataAPIController{}, "get:ScheduleDialysisRecordPrintData")
  13. beego.Router("/api/print/stock", &PrintDataAPIController{}, "get:StockRecordPrintData")
  14. beego.Router("/api/print/course", &PrintDataAPIController{}, "get:CourseRecordPrintData")
  15. beego.Router("/api/print/getlastafterweight", &PrintDataAPIController{}, "get:GetLastAfterWeight")
  16. }
  17. type PrintDataAPIController struct {
  18. BaseAuthAPIController
  19. }
  20. // /api/print/schedule/dialysis [get]
  21. // @param ids:string 排班 id,以逗号隔开 ("1,2,3")
  22. func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
  23. schIDStr := this.GetString("ids")
  24. if len(schIDStr) == 0 {
  25. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  26. return
  27. }
  28. idStrs := strings.Split(schIDStr, ",")
  29. adminUserInfo := this.GetAdminUserInfo()
  30. schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
  31. if getScheduleErr != nil {
  32. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  33. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. return
  35. }
  36. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  37. if getMedicalStaffErr != nil {
  38. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  39. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  40. return
  41. }
  42. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  43. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  44. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  45. this.ServeSuccessJSON(map[string]interface{}{
  46. "schedules": schedules,
  47. "medical_staffs": medicalStaffs,
  48. "users": adminUser,
  49. "templateInfo": templateInfo,
  50. "name": name,
  51. })
  52. }
  53. func (this *PrintDataAPIController) StockRecordPrintData() {
  54. types, _ := this.GetInt("type", 0)
  55. start_time := this.GetString("start_time")
  56. end_time := this.GetString("end_time")
  57. adminUserInfo := this.GetAdminUserInfo()
  58. timeLayout := "2006-01-02"
  59. loc, _ := time.LoadLocation("Local")
  60. var startTime int64
  61. if len(start_time) > 0 {
  62. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  63. if err != nil {
  64. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  65. return
  66. }
  67. startTime = theTime.Unix()
  68. }
  69. var endTime int64
  70. if len(end_time) > 0 {
  71. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  72. if err != nil {
  73. utils.ErrorLog(err.Error())
  74. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  75. return
  76. }
  77. endTime = theTime.Unix()
  78. }
  79. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  80. if err != nil {
  81. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  82. } else {
  83. this.ServeSuccessJSON(map[string]interface{}{
  84. "list": list,
  85. "type": types,
  86. })
  87. }
  88. }
  89. func (this *PrintDataAPIController) CourseRecordPrintData() {
  90. id, _ := this.GetInt64("id", 0)
  91. adminUserInfo := this.GetAdminUserInfo()
  92. if id == 0 {
  93. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. timeLayout := "2006-01-02 15:04:05"
  97. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, id)
  98. dataTimeStr := time.Unix(record.RecordTime, 0).Format(timeLayout) //设置时间戳 使用模板格式化为日期字符串
  99. tempTime := strings.Split(dataTimeStr, " ")
  100. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", tempTime[0])
  101. if parseDateErr != nil {
  102. this.ErrorLog("日期(%v)解析错误:%v", tempTime[0], parseDateErr)
  103. //this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. //return
  105. }
  106. patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, record.PatientID, recordDate.Unix())
  107. if err != nil {
  108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  109. return
  110. } else {
  111. this.ServeSuccessJSON(map[string]interface{}{
  112. "record": record,
  113. "patient": patient,
  114. })
  115. }
  116. }
  117. func (this *PrintDataAPIController) GetLastAfterWeight() {
  118. id, _ := this.GetInt64("id")
  119. fmt.Print("id", id)
  120. assmentdate, _ := this.GetInt64("assmentdate")
  121. adminUserInfo := this.GetAdminUserInfo()
  122. org_id := adminUserInfo.CurrentOrgId
  123. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  124. //fmt.Print("errr-------------",err)
  125. if err != nil {
  126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  127. return
  128. }
  129. this.ServeSuccessJSON(map[string]interface{}{
  130. "weight": weight,
  131. })
  132. }