/**
 * @filename:0urchaseOrderController.java 2024-09-11
 * @project KJT v1.0.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.client.trade.purchaseorder.controller;

import com.trade.client.trade.exportrebate.service.ExportTaxRebateService;
import com.trade.client.trade.purchaseorder.service.CPurchaseOrderService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderInvoiceSearchDto;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderLogisticsDto;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderLogisticsSearchDto;
import com.trade.service.trade.purchaseorder.dto.PurchaseSearchDto;
import com.trade.service.trade.purchaseorder.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 说明： 合同文件信息API接口层
 * </P>
 * 
 * @version: v1.0.0
 * @author: wanglang
 * @time 2024-09-11
 */
@Api(tags = "采购订单信息", value = "采购订单信息")
@RestController
@RequestMapping("/purchaseOrder")
public class PurchaseOrderController {

    @Resource
    private CPurchaseOrderService cPurchaseOrderService;
    @Resource
    private ExportTaxRebateService exportTaxRebateService;

    /**
     * 保存物流信息
     *
     * @param purchaseOrderLogisticsDto 物流信息
     * @param request HttpServletRequest
     * @return ResponseResult<Boolean>
     */
    @ApiOperation(value = "保存物流信息", notes = "保存物流信息")
    @PostMapping("/save/logistics")
    public ResponseResult<Boolean> saveOrderLogistics(
            @Valid @RequestBody PurchaseOrderLogisticsDto purchaseOrderLogisticsDto, HttpServletRequest request) {
        return ResponseResult.success(cPurchaseOrderService.saveOrderLogistics(purchaseOrderLogisticsDto));
    }

    /**
     * 获取采购订单
     *
     * @param purchaseSearch 采购订单查询条件
     * @return 采购订单信息
     */
    @ApiOperation(value = "获取采购订单", notes = "获取采购订单")
    @PostMapping("/get/page")
    public ResponseResult<GridPage<PurchaseOrderVo>> getPurchaseOrderPage(
            @RequestBody PurchaseSearchDto purchaseSearch) {
        return ResponseResult.success(cPurchaseOrderService.queryListByPage(purchaseSearch));
    }

    /**
     * 获取采购订单详情
     *
     * @param orderId 订单id
     * @return 采购订单详情
     */
    @ApiOperation(value = "获取采购订单详情", notes = "获取采购订单详情")
    @GetMapping("/get/{orderId}")
    public ResponseResult<PurchaseOrderDetailsVo> getSalesContractDetails(@PathVariable Long orderId) {
        return ResponseResult.success(cPurchaseOrderService.getDetailsById(orderId));
    }

    /**
     * 获取采购订单物流信息
     *
     * @param orderLogisticsSearch 物流信息条件
     * @return 获取采购订单物流信息
     */
    @ApiOperation(value = "获取采购订单物流信息", notes = "获取采购订单物流信息")
    @PostMapping("/get/logisticsPage")
    public ResponseResult<GridPage<PurchaseOrderLogisticsPageVo>> getOrderLogisticsByPage(
            @RequestBody PurchaseOrderLogisticsSearchDto orderLogisticsSearch) {
        return ResponseResult.success(cPurchaseOrderService.queryOrderLogisticsByPage(orderLogisticsSearch));
    }

    /**
     * 获取采购订单发票
     *
     * @param invoiceSearchDto 采购订单发票条件
     * @return 采购订单发票
     */
    @ApiOperation(value = "获取采购订单发票", notes = "获取采购订单发票")
    @PostMapping("/get/invoicePage")
    public ResponseResult<GridPage<PurchaseOrderInvoiceVo>> getInvoicePage(
            @RequestBody PurchaseOrderInvoiceSearchDto invoiceSearchDto) {
        return ResponseResult.success(cPurchaseOrderService.queryInvoiceListByPage(invoiceSearchDto));
    }

    /**
     * 获取采购订单发票详情
     *
     * @param invoiceId 采购订单发票id
     * @return 采购订单发票
     */
    @ApiOperation(value = "获取采购订单发票详情", notes = "获取采购订单发票详情")
    @GetMapping("/get/invoiceDetail")
    public ResponseResult<PurchaseOrderInvoiceDetailsVo> getInvoiceDetails(Long invoiceId) {
        return ResponseResult.success(cPurchaseOrderService.getInvoiceDetails(invoiceId));
    }

    /**
     * 重定向小图进行发票下载
     */
    @GetMapping("/download/invoice")
    public ResponseResult<String> getDownloadPurchaseInvoiceUrl() {
        String url = exportTaxRebateService.getDownloadPurchaseInvoiceUrl();
        return ResponseResult.success(url);
    }
}
