print_data_api_controller.go 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. if this.GetAdminUserInfo().CurrentOrgId == 10016 {
  32. schedules, getScheduleErr := service.GetSchedulesSix(adminUserInfo.CurrentOrgId, idStrs)
  33. for _, item := range schedules {
  34. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  35. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
  36. item.Count = list.Count
  37. }
  38. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
  39. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  40. item.Patient.TotalDialysis = listOne.Count
  41. item.Count = listOne.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. if this.GetAdminUserInfo().CurrentOrgId != 10016 {
  67. schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
  68. for _, item := range schedules {
  69. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  70. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
  71. item.Count = list.Count
  72. }
  73. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
  74. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  75. item.Patient.TotalDialysis = listOne.Count
  76. item.Count = listOne.Count
  77. }
  78. }
  79. if getScheduleErr != nil {
  80. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  81. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  82. return
  83. }
  84. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  85. if getMedicalStaffErr != nil {
  86. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  87. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  88. return
  89. }
  90. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  91. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  92. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  93. this.ServeSuccessJSON(map[string]interface{}{
  94. "schedules": schedules,
  95. "medical_staffs": medicalStaffs,
  96. "users": adminUser,
  97. "templateInfo": templateInfo,
  98. "name": name,
  99. })
  100. }
  101. }
  102. func (this *PrintDataAPIController) StockRecordPrintData() {
  103. types, _ := this.GetInt("type", 0)
  104. start_time := this.GetString("start_time")
  105. end_time := this.GetString("end_time")
  106. adminUserInfo := this.GetAdminUserInfo()
  107. timeLayout := "2006-01-02"
  108. loc, _ := time.LoadLocation("Local")
  109. var startTime int64
  110. if len(start_time) > 0 {
  111. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  112. if err != nil {
  113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  114. return
  115. }
  116. startTime = theTime.Unix()
  117. }
  118. var endTime int64
  119. if len(end_time) > 0 {
  120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  121. if err != nil {
  122. utils.ErrorLog(err.Error())
  123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. endTime = theTime.Unix()
  127. }
  128. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  129. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  130. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  131. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  132. if err != nil {
  133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  134. } else {
  135. this.ServeSuccessJSON(map[string]interface{}{
  136. "list": list,
  137. "type": types,
  138. "stockTotal": stockTotal,
  139. "info": info,
  140. "orgid": adminUserInfo.CurrentOrgId,
  141. "infomationList": infomationList,
  142. })
  143. }
  144. }
  145. func (this *PrintDataAPIController) CourseRecordPrintData() {
  146. ids_str := this.GetString("ids")
  147. ids_arr := strings.Split(ids_str, ",")
  148. adminUserInfo := this.GetAdminUserInfo()
  149. patient_id, _ := this.GetInt64("patient_id")
  150. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, ids_arr)
  151. //patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, patient_id)
  152. patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
  153. if err != nil {
  154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  155. return
  156. } else {
  157. this.ServeSuccessJSON(map[string]interface{}{
  158. "record": record,
  159. "patient": patient,
  160. })
  161. }
  162. }
  163. func (this *PrintDataAPIController) GetLastAfterWeight() {
  164. id, _ := this.GetInt64("id")
  165. fmt.Print("id", id)
  166. assmentdate, _ := this.GetInt64("assmentdate")
  167. adminUserInfo := this.GetAdminUserInfo()
  168. org_id := adminUserInfo.CurrentOrgId
  169. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  170. //fmt.Print("errr-------------",err)
  171. if err != nil {
  172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  173. return
  174. }
  175. this.ServeSuccessJSON(map[string]interface{}{
  176. "weight": weight,
  177. })
  178. }
  179. func (this *PrintDataAPIController) GetGoodDetailPrintList() {
  180. types, _ := this.GetInt("type", 0)
  181. start_time := this.GetString("start_time")
  182. end_time := this.GetString("end_time")
  183. adminUserInfo := this.GetAdminUserInfo()
  184. timeLayout := "2006-01-02"
  185. loc, _ := time.LoadLocation("Local")
  186. var startTime int64
  187. if len(start_time) > 0 {
  188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  189. if err != nil {
  190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. startTime = theTime.Unix()
  194. }
  195. var endTime int64
  196. if len(end_time) > 0 {
  197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  198. if err != nil {
  199. utils.ErrorLog(err.Error())
  200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  201. return
  202. }
  203. endTime = theTime.Unix()
  204. }
  205. limit, _ := this.GetInt64("limit")
  206. page, _ := this.GetInt64("page")
  207. //入库详情
  208. if types == 1 {
  209. list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  210. if err != nil {
  211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  212. return
  213. }
  214. this.ServeSuccessJSON(map[string]interface{}{
  215. "list": list,
  216. })
  217. }
  218. //出库详情
  219. if types == 2 {
  220. //list, err := service.GetWarehouseOutInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  221. list, _ := service.GetWarehouseOutInfoPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  222. fmt.Println("list23323232233232", list)
  223. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  224. if err != nil {
  225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  226. return
  227. }
  228. this.ServeSuccessJSON(map[string]interface{}{
  229. "list": list,
  230. "stockTotal": stockTotal,
  231. })
  232. }
  233. //退库详情
  234. if types == 4 {
  235. list, _ := service.GetWarehouseCancelPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  236. this.ServeSuccessJSON(map[string]interface{}{
  237. "list": list,
  238. })
  239. }
  240. }