new_stock_api_controller.go 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. is_sale, _ := c.GetInt64("is_sale")
  67. is_bg, _ := c.GetInt64("is_bg")
  68. timeLayout := "2006-01-02"
  69. loc, _ := time.LoadLocation("Local")
  70. var startTime int64
  71. if len(start_time) > 0 {
  72. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  73. if err != nil {
  74. fmt.Println(err)
  75. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  76. return
  77. }
  78. startTime = theTime.Unix()
  79. }
  80. var endTime int64
  81. if len(end_time) > 0 {
  82. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  83. if err != nil {
  84. utils.ErrorLog(err.Error())
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. endTime = theTime.Unix()
  89. }
  90. orgId := c.GetAdminUserInfo().CurrentOrgId
  91. page, _ := c.GetInt64("page")
  92. limit, _ := c.GetInt64("limit")
  93. list, total, _ := service.GetNewDrugFlow(orgId, limit, page, startTime, endTime, is_sale, is_bg)
  94. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  95. dealerList, _ := service.GetAllDealerList(orgId)
  96. houseList, _ := service.GetAllStoreHouseList(orgId)
  97. //patientList, _ := service.GetAllPatientListSix(orgId)
  98. c.ServeSuccessJSON(map[string]interface{}{
  99. "info": list,
  100. "total": total,
  101. "manufacturerList": manufacturerList,
  102. "dealerList": dealerList,
  103. "houseList": houseList,
  104. //"patientList": patientList,
  105. })
  106. }
  107. func (c *NewStockApiController) GetDrugQuery() {
  108. id, _ := c.GetInt64("id", 0)
  109. if id <= 0 {
  110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. admin := c.GetAdminUserInfo()
  114. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  115. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  116. dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
  117. if err != nil {
  118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  119. return
  120. }
  121. if warehousing.ID <= 0 {
  122. return
  123. }
  124. warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
  125. list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
  126. if err == nil {
  127. c.ServeSuccessJSON(map[string]interface{}{
  128. "info": warehousingInfo,
  129. "warehousing": warehousing,
  130. "manufacturerList": manufacturerList,
  131. "dealerList": dealerList,
  132. "list": list,
  133. })
  134. } else {
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  136. }
  137. }