|
|
|
@ -0,0 +1,67 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* https://www.mall4j.com/
|
|
|
|
|
*
|
|
|
|
|
* 未经允许,不可做商业用途!
|
|
|
|
|
*
|
|
|
|
|
* 版权所有,侵权必究!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.yami.shop.api.controller; // 定义类所在的包
|
|
|
|
|
|
|
|
|
|
import com.yami.shop.service.OrderService; // 引入订单服务类
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 引入Spring的@Autowired注解
|
|
|
|
|
import com.yami.shop.common.response.ServerResponseEntity; // 引入服务器响应实体类
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; // 引入Spring的@GetMapping注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; // 引入Spring的@RequestMapping注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; // 引入Spring的@RestController注解
|
|
|
|
|
|
|
|
|
|
import com.yami.shop.bean.app.dto.DeliveryDto; // 引入物流DTO
|
|
|
|
|
import com.yami.shop.bean.model.Delivery; // 引入配送模型
|
|
|
|
|
import com.yami.shop.bean.model.Order; // 引入订单模型
|
|
|
|
|
import com.yami.shop.common.util.Json; // 引入JSON工具类
|
|
|
|
|
import com.yami.shop.service.DeliveryService; // 引入配送服务类
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil; // 引入Hutool工具类库中的HttpUtil工具类
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; // 引入Swagger的Tag注解
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter; // 引入Swagger的Parameter注解
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; // 引入Swagger的Operation注解
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DeliveryController类,负责查看物流信息。
|
|
|
|
|
* 该类包含一个查看物流信息的方法,根据订单号查看物流详情。
|
|
|
|
|
* @作者 lanhai
|
|
|
|
|
*/
|
|
|
|
|
@RestController // 标注这是一个控制器类,并且其返回结果直接写入HTTP响应体中,而不是视图名称
|
|
|
|
|
@RequestMapping("/delivery") // 定义请求路径的根地址为/delivery
|
|
|
|
|
@Tag(name = "查看物流接口") // 给API文档添加标签,描述这个控制器的功能
|
|
|
|
|
public class DeliveryController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeliveryService deliveryService; // 自动注入配送服务类
|
|
|
|
|
@Autowired
|
|
|
|
|
private OrderService orderService; // 自动注入订单服务类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查看物流接口
|
|
|
|
|
* @param orderNumber 订单号
|
|
|
|
|
* @return 服务器响应实体,包含物流信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/check")
|
|
|
|
|
@Operation(summary = "查看物流" , description = "根据订单号查看物流")
|
|
|
|
|
@Parameter(name = "orderNumber", description = "订单号" , required = true)
|
|
|
|
|
public ServerResponseEntity<DeliveryDto> checkDelivery(String orderNumber) {
|
|
|
|
|
|
|
|
|
|
Order order = orderService.getOrderByOrderNumber(orderNumber); // 根据订单号获取订单信息
|
|
|
|
|
Delivery delivery = deliveryService.getById(order.getDvyId()); // 根据配送ID获取配送信息
|
|
|
|
|
String url = delivery.getQueryUrl().replace("{dvyFlowId}", order.getDvyFlowId()); // 构建查询物流信息的URL
|
|
|
|
|
String deliveryJson = HttpUtil.get(url); // 发送HTTP GET请求获取物流信息
|
|
|
|
|
|
|
|
|
|
DeliveryDto deliveryDto = Json.parseObject(deliveryJson, DeliveryDto.class); // 将JSON格式的物流信息转换为DTO对象
|
|
|
|
|
deliveryDto.setDvyFlowId(order.getDvyFlowId()); // 设置物流流水号
|
|
|
|
|
deliveryDto.setCompanyHomeUrl(delivery.getCompanyHomeUrl()); // 设置物流公司主页URL
|
|
|
|
|
deliveryDto.setCompanyName(delivery.getDvyName()); // 设置物流公司名称
|
|
|
|
|
return ServerResponseEntity.success(deliveryDto); // 返回物流信息
|
|
|
|
|
}
|
|
|
|
|
}
|