weian.go 4.4 KB

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