
package com.tmerclub.cloud.delivery.controller.admin;

import com.tmerclub.cloud.api.delivery.dto.DeliveryOrderDTO;
import com.tmerclub.cloud.api.delivery.vo.DeliveryOrderFeignVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.delivery.service.DeliveryOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lhd on 2020/05/15.
 */
@Controller
@RestController("adminOrderDeliveryController")
@RequestMapping("/mp/orderDelivery")
@Tag(name = "物流包裹")
public class OrderDeliveryController {

    @Autowired
    private DeliveryOrderService deliveryOrderService;

    @GetMapping("/info")
    @Operation(summary = "查询订单物流包裹信息", description = "查询订单物流包裹信息")
    public ServerResponseEntity<List<DeliveryOrderFeignVO>> page(@RequestParam("orderId") Long orderId) {
        List<DeliveryOrderFeignVO> deliveryOrders = deliveryOrderService.getByDeliveryByOrderId(orderId);
        return ServerResponseEntity.success(deliveryOrders);
    }

    /**
     * 修改订单物流包裹信息
     */
    @PutMapping("/update")
    public ServerResponseEntity<Void> updateOrderDeliveries(@RequestBody List<DeliveryOrderDTO> list) {
        deliveryOrderService.updateOrderDeliveries(list);
        return ServerResponseEntity.success();
    }

    @GetMapping("/{deliveryOrderId}")
    @Operation(summary = "物流包裹查询接口", description = "根据orderDeliveryId查询订单包裹信息")
    @Parameter(name = "deliveryOrderId", description = "订单物流包裹id")
    public ServerResponseEntity<DeliveryOrderFeignVO> deliveryOrder(@PathVariable("deliveryOrderId") Long deliveryOrderId) {
        DeliveryOrderFeignVO deliveryOrder = deliveryOrderService.deliveryOrderItemInfo(deliveryOrderId);
        return ServerResponseEntity.success(deliveryOrder);
    }

}
