print_data_api_controller.go 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. service "Xcx_New/service/print_data_service/schedule_dialysis"
  5. "Xcx_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. beego.Router("/api/stock/getgooddetailprintlist", &PrintDataAPIController{}, "get:GetGoodDetailPrintList")
  17. }
  18. type PrintDataAPIController struct {
  19. BaseAuthAPIController
  20. }
  21. // /api/print/schedule/dialysis [get]
  22. // @param ids:string 排班 id,以逗号隔开 ("1,2,3")
  23. func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
  24. schIDStr := this.GetString("ids")
  25. if len(schIDStr) == 0 {
  26. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  27. return
  28. }
  29. idStrs := strings.Split(schIDStr, ",")
  30. adminUserInfo := this.GetAdminUserInfo()
  31. schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
  32. if getScheduleErr != nil {
  33. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  34. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  38. if getMedicalStaffErr != nil {
  39. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  40. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. return
  42. }
  43. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  44. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  45. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  46. this.ServeSuccessJSON(map[string]interface{}{
  47. "schedules": schedules,
  48. "medical_staffs": medicalStaffs,
  49. "users": adminUser,
  50. "templateInfo": templateInfo,
  51. "name": name,
  52. })
  53. }
  54. func (this *PrintDataAPIController) StockRecordPrintData() {
  55. types, _ := this.GetInt("type", 0)
  56. start_time := this.GetString("start_time")
  57. end_time := this.GetString("end_time")
  58. adminUserInfo := this.GetAdminUserInfo()
  59. timeLayout := "2006-01-02"
  60. loc, _ := time.LoadLocation("Local")
  61. var startTime int64
  62. if len(start_time) > 0 {
  63. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  64. if err != nil {
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. startTime = theTime.Unix()
  69. }
  70. var endTime int64
  71. if len(end_time) > 0 {
  72. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  73. if err != nil {
  74. utils.ErrorLog(err.Error())
  75. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  76. return
  77. }
  78. endTime = theTime.Unix()
  79. }
  80. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  81. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  82. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  83. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  84. if err != nil {
  85. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  86. } else {
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "list": list,
  89. "type": types,
  90. "stockTotal": stockTotal,
  91. "info": info,
  92. "orgid": adminUserInfo.CurrentOrgId,
  93. "infomationList": infomationList,
  94. })
  95. }
  96. }
  97. func (this *PrintDataAPIController) CourseRecordPrintData() {
  98. id, _ := this.GetInt64("id", 0)
  99. adminUserInfo := this.GetAdminUserInfo()
  100. if id == 0 {
  101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. timeLayout := "2006-01-02 15:04:05"
  105. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, id)
  106. dataTimeStr := time.Unix(record.RecordTime, 0).Format(timeLayout) //设置时间戳 使用模板格式化为日期字符串
  107. tempTime := strings.Split(dataTimeStr, " ")
  108. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", tempTime[0])
  109. if parseDateErr != nil {
  110. this.ErrorLog("日期(%v)解析错误:%v", tempTime[0], parseDateErr)
  111. //this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. //return
  113. }
  114. patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, record.PatientID, recordDate.Unix())
  115. if err != nil {
  116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  117. return
  118. } else {
  119. this.ServeSuccessJSON(map[string]interface{}{
  120. "record": record,
  121. "patient": patient,
  122. })
  123. }
  124. }
  125. func (this *PrintDataAPIController) GetLastAfterWeight() {
  126. id, _ := this.GetInt64("id")
  127. fmt.Print("id", id)
  128. assmentdate, _ := this.GetInt64("assmentdate")
  129. adminUserInfo := this.GetAdminUserInfo()
  130. org_id := adminUserInfo.CurrentOrgId
  131. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  132. //fmt.Print("errr-------------",err)
  133. if err != nil {
  134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  135. return
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "weight": weight,
  139. })
  140. }
  141. func (this *PrintDataAPIController) GetGoodDetailPrintList() {
  142. types, _ := this.GetInt("type", 0)
  143. start_time := this.GetString("start_time")
  144. end_time := this.GetString("end_time")
  145. adminUserInfo := this.GetAdminUserInfo()
  146. timeLayout := "2006-01-02"
  147. loc, _ := time.LoadLocation("Local")
  148. var startTime int64
  149. if len(start_time) > 0 {
  150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  151. if err != nil {
  152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. startTime = theTime.Unix()
  156. }
  157. var endTime int64
  158. if len(end_time) > 0 {
  159. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  160. if err != nil {
  161. utils.ErrorLog(err.Error())
  162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  163. return
  164. }
  165. endTime = theTime.Unix()
  166. }
  167. limit, _ := this.GetInt64("limit")
  168. page, _ := this.GetInt64("page")
  169. //入库详情
  170. if types == 1 {
  171. list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  172. if err != nil {
  173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  174. return
  175. }
  176. this.ServeSuccessJSON(map[string]interface{}{
  177. "list": list,
  178. })
  179. }
  180. //出库详情
  181. if types == 2 {
  182. list, err := service.GetWarehouseOutInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  183. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  184. if err != nil {
  185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  186. return
  187. }
  188. this.ServeSuccessJSON(map[string]interface{}{
  189. "list": list,
  190. "stockTotal": stockTotal,
  191. })
  192. }
  193. }