weian.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package controller
  2. import (
  3. "cold-delivery/app/admin/model"
  4. "cold-delivery/app/admin/service"
  5. "cold-delivery/app/admin/service/dto"
  6. "cold-delivery/common/nats/nats_server"
  7. "cold-delivery/conf"
  8. "encoding/json"
  9. "github.com/gin-gonic/gin"
  10. "github.com/gin-gonic/gin/binding"
  11. "github.com/go-resty/resty/v2"
  12. "gogs.baozhida.cn/zoie/OAuth-core/api"
  13. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  14. )
  15. type WeianController struct {
  16. api.Api
  17. }
  18. // GetOrderInfo 获取维安智配送订单详情
  19. // @Summary 获取维安智配送订单详情
  20. // @Description 获取维安智配送订单详情
  21. // @Tags 维安智配送
  22. // @Param no query string false "订单号"
  23. // @Success 200 {object} response.Response{data=response.Page{list=[]model.Waybill}} "{"code": 200, "data": [...]}"
  24. // @Router /api/weian/orderInfo [get]
  25. // @Security Bearer
  26. func (e WeianController) GetOrderInfo(c *gin.Context) {
  27. s := service.Waybill{}
  28. req := dto.WeianGetOrderInfoReq{}
  29. err := e.MakeContext(c).
  30. MakeOrm().
  31. Bind(&req, binding.Query).
  32. MakeService(&s.Service).
  33. Errors
  34. if err != nil {
  35. e.Logger.Error(err)
  36. e.Error(500, err, err.Error())
  37. return
  38. }
  39. client := resty.New()
  40. resp, err := client.R().
  41. SetQueryParams(map[string]string{
  42. "orderId": req.OrderId,
  43. }).
  44. Get(conf.ExtConfig.Weian.OrderInfoUrl)
  45. if err != nil {
  46. e.Logger.Error(err)
  47. e.Error(500, err, "获取维安智配送订单信息失败")
  48. return
  49. }
  50. var info model.WeianOrderResponse
  51. if err = json.Unmarshal(resp.Body(), &info); err != nil {
  52. e.Error(500, err, "获取药品扫码信息失败")
  53. return
  54. }
  55. if info.Code != 200 {
  56. e.Error(500, err, info.Msg)
  57. return
  58. }
  59. e.OK(info.Data, "查询成功")
  60. }
  61. // 测试opeapi鉴权
  62. func (e WeianController) GetWaybillNo(c *gin.Context) {
  63. s := service.Waybill{}
  64. req := dto.WeianGetWaybillNoReq{}
  65. err := e.MakeContext(c).
  66. MakeOrm().
  67. Bind(&req, binding.Query).
  68. MakeService(&s.Service).
  69. Errors
  70. if err != nil {
  71. e.Logger.Error(err)
  72. e.Error(500, err, err.Error())
  73. return
  74. }
  75. err = s.InsertByOrderId(&req)
  76. if err != nil {
  77. e.Error(500, err, err.Error())
  78. return
  79. }
  80. e.OK(req.WaybillNo, "查询成功")
  81. }
  82. func (e WeianController) GetWaybillData(c *gin.Context) {
  83. s := service.WaybillTask{}
  84. req := dto.WeianGetWaybillDataReq{}
  85. err := e.MakeContext(c).
  86. MakeOrm().
  87. Bind(&req, binding.Query).
  88. MakeService(&s.Service).
  89. Errors
  90. if err != nil {
  91. e.Logger.Error(err)
  92. e.Error(500, err, err.Error())
  93. return
  94. }
  95. var task model.WaybillTask
  96. err = s.Get(&req, &task)
  97. if err != nil {
  98. e.Error(500, err, err.Error())
  99. return
  100. }
  101. var ids []int
  102. for _, r := range task.DeviceSensorList {
  103. ids = append(ids, r.T_id)
  104. }
  105. dataReq := dto.WaybillTaskGetDataPageReq{
  106. Pagination: req.Pagination,
  107. WaybillNo: task.WaybillNo,
  108. TaskId: task.Id,
  109. T_ids: ids,
  110. StartTime: task.StartTime.String(),
  111. EndTime: task.EndTime.String(),
  112. }
  113. list, count, err := s.GetDataPage(&dataReq)
  114. if err != nil {
  115. e.Error(500, err, err.Error())
  116. return
  117. }
  118. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  119. }
  120. // GetLocus 获取轨迹信息
  121. // @Summary 获取轨迹信息
  122. // @Description 获取轨迹信息
  123. // @Tags 运单任务
  124. // @Accept application/json
  125. // @Product application/json
  126. // @Param data body dto.WaybillTaskGetNewestDataPageReq true "body"
  127. // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
  128. // @Router /api/waybill-task/locus [post]
  129. // @Security Bearer
  130. func (e WeianController) GetLocus(c *gin.Context) {
  131. s := service.WaybillTask{}
  132. req := dto.WaybillGetLocusReq{}
  133. err := e.MakeContext(c).
  134. MakeOrm().
  135. Bind(&req, binding.Query).
  136. MakeService(&s.Service).
  137. Errors
  138. if err != nil {
  139. e.Logger.Error(err)
  140. e.Error(500, err, err.Error())
  141. return
  142. }
  143. list := make([]nats_server.DeviceData_R2, 0)
  144. list, err = s.GetLocus(&req)
  145. if err != nil {
  146. e.Error(500, err, err.Error())
  147. return
  148. }
  149. e.OK(list, "获取轨迹信息成功")
  150. }