print_data_api_controller.go 7.5KB

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