print_data_api_controller.go 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  81. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  82. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  83. if err != nil {
  84. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  85. } else {
  86. this.ServeSuccessJSON(map[string]interface{}{
  87. "list": list,
  88. "type": types,
  89. "stockTotal": stockTotal,
  90. "info": info,
  91. "orgid": adminUserInfo.CurrentOrgId,
  92. "infomationList": infomationList,
  93. })
  94. }
  95. }
  96. func (this *PrintDataAPIController) CourseRecordPrintData() {
  97. id, _ := this.GetInt64("id", 0)
  98. adminUserInfo := this.GetAdminUserInfo()
  99. if id == 0 {
  100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. timeLayout := "2006-01-02 15:04:05"
  104. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, id)
  105. dataTimeStr := time.Unix(record.RecordTime, 0).Format(timeLayout) //设置时间戳 使用模板格式化为日期字符串
  106. tempTime := strings.Split(dataTimeStr, " ")
  107. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", tempTime[0])
  108. if parseDateErr != nil {
  109. this.ErrorLog("日期(%v)解析错误:%v", tempTime[0], parseDateErr)
  110. //this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. //return
  112. }
  113. patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, record.PatientID, recordDate.Unix())
  114. if err != nil {
  115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  116. return
  117. } else {
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "record": record,
  120. "patient": patient,
  121. })
  122. }
  123. }
  124. func (this *PrintDataAPIController) GetLastAfterWeight() {
  125. id, _ := this.GetInt64("id")
  126. fmt.Print("id", id)
  127. assmentdate, _ := this.GetInt64("assmentdate")
  128. adminUserInfo := this.GetAdminUserInfo()
  129. org_id := adminUserInfo.CurrentOrgId
  130. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  131. //fmt.Print("errr-------------",err)
  132. if err != nil {
  133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  134. return
  135. }
  136. this.ServeSuccessJSON(map[string]interface{}{
  137. "weight": weight,
  138. })
  139. }