123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package controller
- import (
- "cold-delivery/app/admin/model"
- "cold-delivery/app/admin/service"
- "cold-delivery/app/admin/service/dto"
- cDto "cold-delivery/common/dto"
- "cold-delivery/common/nats/nats_server"
- "cold-delivery/conf"
- "encoding/json"
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "github.com/go-resty/resty/v2"
- "gogs.baozhida.cn/zoie/OAuth-core/api"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- "time"
- )
- type WeianController struct {
- api.Api
- }
- // GetOrderInfo 获取维安智配送订单详情
- // @Summary 获取维安智配送订单详情
- // @Description 获取维安智配送订单详情
- // @Tags 维安智配送
- // @Param no query string false "订单号"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.Waybill}} "{"code": 200, "data": [...]}"
- // @Router /api/weian/orderInfo [get]
- // @Security Bearer
- func (e WeianController) GetOrderInfo(c *gin.Context) {
- s := service.Waybill{}
- req := dto.WeianGetOrderInfoReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- client := resty.New()
- resp, err := client.R().
- SetQueryParams(map[string]string{
- "orderId": req.OrderId,
- }).
- Get(conf.ExtConfig.Weian.OrderInfoUrl)
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, "获取维安智配送订单信息失败")
- return
- }
- var info model.WeianOrderResponse
- if err = json.Unmarshal(resp.Body(), &info); err != nil {
- e.Error(500, err, "获取药品扫码信息失败")
- return
- }
- if info.Code != 200 {
- e.Error(500, err, info.Msg)
- return
- }
- e.OK(info.Data, "查询成功")
- }
- // 测试opeapi鉴权
- func (e WeianController) GetWaybillNo(c *gin.Context) {
- s := service.Waybill{}
- req := dto.WeianGetWaybillNoReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- err = s.InsertByOrderId(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.WaybillNo, "查询成功")
- }
- func (e WeianController) GetWaybillData(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WeianGetWaybillDataReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var task model.WaybillTask
- err = s.Get(&req, &task)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- var ids []int
- for _, ds := range task.DeviceSensorList {
- ids = append(ids, ds.T_id)
- }
- startTime := task.StartTime.String()
- endTime := task.EndTime.String()
- if len(req.StartTime) > 0 {
- _, err = time.Parse("2006-01-02 15:04:05", req.StartTime)
- if err != nil {
- e.Error(500, err, "开始时间格式不正确")
- return
- }
- startTime = req.StartTime
- }
- if len(req.EndTime) > 0 {
- _, err = time.Parse("2006-01-02 15:04:05", req.EndTime)
- if err != nil {
- e.Error(500, err, "结束时间格式不正确")
- return
- }
- endTime = req.EndTime
- }
- dataReq := dto.WaybillTaskGetDataPageReq{
- Pagination: cDto.Pagination{
- Page: req.GetPageIndex(),
- PageSize: req.GetPageSize(),
- },
- WaybillNo: task.WaybillNo,
- TaskId: task.Id,
- T_ids: ids,
- StartTime: startTime,
- EndTime: endTime,
- }
- list, count, err := s.GetDataPage(&dataReq)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // GetLocus 获取轨迹信息
- // @Summary 获取轨迹信息
- // @Description 获取轨迹信息
- // @Tags 运单任务
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.WaybillTaskGetNewestDataPageReq true "body"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
- // @Router /api/waybill-task/locus [post]
- // @Security Bearer
- func (e WeianController) GetLocus(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WaybillGetLocusReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- list := make([]nats_server.DeviceData_R2, 0)
- list, err = s.GetLocus(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(list, "获取轨迹信息成功")
- }
|