print_data_api_controller.go 7.6KB

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