print_data_api_controller.go 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. 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. for _, item := range schedules {
  33. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  34. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
  35. item.Count = list.Count
  36. }
  37. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
  38. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  39. fmt.Println("dialysis_count322333223322323", dialysis_count)
  40. item.Patient.TotalDialysis = dialysis_count
  41. item.Count = dialysis_count
  42. }
  43. }
  44. if getScheduleErr != nil {
  45. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  46. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  47. return
  48. }
  49. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  50. if getMedicalStaffErr != nil {
  51. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  52. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  53. return
  54. }
  55. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  56. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  57. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  58. this.ServeSuccessJSON(map[string]interface{}{
  59. "schedules": schedules,
  60. "medical_staffs": medicalStaffs,
  61. "users": adminUser,
  62. "templateInfo": templateInfo,
  63. "name": name,
  64. })
  65. }
  66. func (this *PrintDataAPIController) StockRecordPrintData() {
  67. types, _ := this.GetInt("type", 0)
  68. start_time := this.GetString("start_time")
  69. end_time := this.GetString("end_time")
  70. adminUserInfo := this.GetAdminUserInfo()
  71. timeLayout := "2006-01-02"
  72. loc, _ := time.LoadLocation("Local")
  73. var startTime int64
  74. if len(start_time) > 0 {
  75. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  76. if err != nil {
  77. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  78. return
  79. }
  80. startTime = theTime.Unix()
  81. }
  82. var endTime int64
  83. if len(end_time) > 0 {
  84. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  85. if err != nil {
  86. utils.ErrorLog(err.Error())
  87. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  88. return
  89. }
  90. endTime = theTime.Unix()
  91. }
  92. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  93. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  94. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  95. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  96. if err != nil {
  97. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  98. } else {
  99. this.ServeSuccessJSON(map[string]interface{}{
  100. "list": list,
  101. "type": types,
  102. "stockTotal": stockTotal,
  103. "info": info,
  104. "orgid": adminUserInfo.CurrentOrgId,
  105. "infomationList": infomationList,
  106. })
  107. }
  108. }
  109. func (this *PrintDataAPIController) CourseRecordPrintData() {
  110. ids_str := this.GetString("ids")
  111. ids_arr := strings.Split(ids_str, ",")
  112. adminUserInfo := this.GetAdminUserInfo()
  113. patient_id, _ := this.GetInt64("patient_id")
  114. //timeLayout := "2006-01-02 15:04:05"
  115. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, ids_arr)
  116. //dataTimeStr := time.Unix(record.RecordTime, 0).Format(timeLayout) //设置时间戳 使用模板格式化为日期字符串
  117. //tempTime := strings.Split(dataTimeStr, " ")
  118. //
  119. //recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", tempTime[0])
  120. //if parseDateErr != nil {
  121. // this.ErrorLog("日期(%v)解析错误:%v", tempTime[0], parseDateErr)
  122. // //this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  123. // //return
  124. //}
  125. //patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, patient_id)
  126. patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
  127. if err != nil {
  128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  129. return
  130. } else {
  131. this.ServeSuccessJSON(map[string]interface{}{
  132. "record": record,
  133. "patient": patient,
  134. })
  135. }
  136. }
  137. func (this *PrintDataAPIController) GetLastAfterWeight() {
  138. id, _ := this.GetInt64("id")
  139. fmt.Print("id", id)
  140. assmentdate, _ := this.GetInt64("assmentdate")
  141. adminUserInfo := this.GetAdminUserInfo()
  142. org_id := adminUserInfo.CurrentOrgId
  143. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  144. //fmt.Print("errr-------------",err)
  145. if err != nil {
  146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  147. return
  148. }
  149. this.ServeSuccessJSON(map[string]interface{}{
  150. "weight": weight,
  151. })
  152. }
  153. func (this *PrintDataAPIController) GetGoodDetailPrintList() {
  154. types, _ := this.GetInt("type", 0)
  155. start_time := this.GetString("start_time")
  156. end_time := this.GetString("end_time")
  157. adminUserInfo := this.GetAdminUserInfo()
  158. timeLayout := "2006-01-02"
  159. loc, _ := time.LoadLocation("Local")
  160. var startTime int64
  161. if len(start_time) > 0 {
  162. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  163. if err != nil {
  164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  165. return
  166. }
  167. startTime = theTime.Unix()
  168. }
  169. var endTime int64
  170. if len(end_time) > 0 {
  171. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  172. if err != nil {
  173. utils.ErrorLog(err.Error())
  174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  175. return
  176. }
  177. endTime = theTime.Unix()
  178. }
  179. limit, _ := this.GetInt64("limit")
  180. page, _ := this.GetInt64("page")
  181. //入库详情
  182. if types == 1 {
  183. list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  184. if err != nil {
  185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  186. return
  187. }
  188. this.ServeSuccessJSON(map[string]interface{}{
  189. "list": list,
  190. })
  191. }
  192. //出库详情
  193. if types == 2 {
  194. //list, err := service.GetWarehouseOutInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  195. list, _ := service.GetWarehouseOutInfoPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  196. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  197. if err != nil {
  198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  199. return
  200. }
  201. this.ServeSuccessJSON(map[string]interface{}{
  202. "list": list,
  203. "stockTotal": stockTotal,
  204. })
  205. }
  206. //退库详情
  207. if types == 4 {
  208. list, _ := service.GetWarehouseCancelPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  209. this.ServeSuccessJSON(map[string]interface{}{
  210. "list": list,
  211. })
  212. }
  213. }