new_stock_api_controller.go 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "time"
  9. )
  10. type NewStockApiController struct {
  11. BaseAuthAPIController
  12. }
  13. func NewStockApiRegistRouters() {
  14. beego.Router("/api/drug/stock", &NewStockApiController{}, "Get:GetDrugStock")
  15. beego.Router("/api/drug/change", &NewStockApiController{}, "Get:GetDrugChange")
  16. //beego.Router("/api/drug/query", &NewStockApiController{}, "Get:GetDrugQuery")
  17. }
  18. func (c *NewStockApiController) GetDrugStock() {
  19. start_time := c.GetString("start_time")
  20. end_time := c.GetString("end_time")
  21. timeLayout := "2006-01-02"
  22. loc, _ := time.LoadLocation("Local")
  23. var startTime int64
  24. if len(start_time) > 0 {
  25. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  26. if err != nil {
  27. fmt.Println(err)
  28. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  29. return
  30. }
  31. startTime = theTime.Unix()
  32. }
  33. var endTime int64
  34. if len(end_time) > 0 {
  35. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  36. if err != nil {
  37. utils.ErrorLog(err.Error())
  38. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  39. return
  40. }
  41. endTime = theTime.Unix()
  42. }
  43. admin := c.GetAdminUserInfo()
  44. is_pc, _ := c.GetInt64("is_pc", 0)
  45. is_bg, _ := c.GetInt64("is_bg", 0)
  46. //manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  47. //dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
  48. fmt.Println(startTime)
  49. fmt.Println(endTime)
  50. warehousingInfo, err := service.FindAllDrugWarehousingInfo(admin.CurrentOrgId, is_pc, is_bg, startTime, endTime)
  51. //list, _ := service.GetAll/**/StoreHouseListThree(admin.CurrentOrgId)
  52. if err == nil {
  53. c.ServeSuccessJSON(map[string]interface{}{
  54. "info": warehousingInfo,
  55. //"manufacturerList": manufacturerList,
  56. //"dealerList": dealerList,
  57. //"list": list,
  58. })
  59. } else {
  60. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  61. }
  62. }
  63. func (c *NewStockApiController) GetDrugChange() {
  64. start_time := c.GetString("start_time")
  65. end_time := c.GetString("end_time")
  66. timeLayout := "2006-01-02"
  67. loc, _ := time.LoadLocation("Local")
  68. var startTime int64
  69. if len(start_time) > 0 {
  70. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  71. if err != nil {
  72. fmt.Println(err)
  73. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  74. return
  75. }
  76. startTime = theTime.Unix()
  77. }
  78. var endTime int64
  79. if len(end_time) > 0 {
  80. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  81. if err != nil {
  82. utils.ErrorLog(err.Error())
  83. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  84. return
  85. }
  86. endTime = theTime.Unix()
  87. }
  88. orgId := c.GetAdminUserInfo().CurrentOrgId
  89. page, _ := c.GetInt64("page")
  90. limit, _ := c.GetInt64("limit")
  91. list, total, _ := service.GetNewDrugFlow(orgId, limit, page, startTime, endTime)
  92. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  93. dealerList, _ := service.GetAllDealerList(orgId)
  94. houseList, _ := service.GetAllStoreHouseList(orgId)
  95. //patientList, _ := service.GetAllPatientListSix(orgId)
  96. c.ServeSuccessJSON(map[string]interface{}{
  97. "info": list,
  98. "total": total,
  99. "manufacturerList": manufacturerList,
  100. "dealerList": dealerList,
  101. "houseList": houseList,
  102. //"patientList": patientList,
  103. })
  104. }
  105. func (c *NewStockApiController) GetDrugQuery() {
  106. id, _ := c.GetInt64("id", 0)
  107. if id <= 0 {
  108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  109. return
  110. }
  111. admin := c.GetAdminUserInfo()
  112. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  113. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  114. dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
  115. if err != nil {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  117. return
  118. }
  119. if warehousing.ID <= 0 {
  120. return
  121. }
  122. warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
  123. list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
  124. if err == nil {
  125. c.ServeSuccessJSON(map[string]interface{}{
  126. "info": warehousingInfo,
  127. "warehousing": warehousing,
  128. "manufacturerList": manufacturerList,
  129. "dealerList": dealerList,
  130. "list": list,
  131. })
  132. } else {
  133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  134. }
  135. }