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

import javax.annotation.Resource;
import com.trade.admin.trade.purchaseorder.service.BPurchaseOrderService;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderInvoiceSearchDto;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderLogisticsSearchDto;
import com.trade.service.trade.purchaseorder.vo.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.trade.purchaseorder.dto.PurchaseSearchDto;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

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

    @Resource
    private BPurchaseOrderService purchaseOrderService;

    /**
     * 获取采购订单
     *
     * @param purchaseSearch 采购订单条件
     * @return 采购订单
     */
    @ApiOperation(value = "获取采购订单", notes = "获取采购订单")
    @PostMapping("/get/page")
    @PreAuthorize("@ss.hasPermi('trade:purchaseOrder:pages')")
    public ResponseResult<GridPage<PurchaseOrderVo>> getPurchaseOrderPage(
            @RequestBody PurchaseSearchDto purchaseSearch) {
        return ResponseResult.success(purchaseOrderService.queryListByPage(purchaseSearch));
    }

    /**
     * 获取采购订单详情
     *
     * @param orderId 订单id
     * @return 采购订单详情
     */
    @ApiOperation(value = "获取采购订单详情", notes = "获取采购订单详情")
    @GetMapping("/get/{orderId}")
    @PreAuthorize("@ss.hasPermi('trade:purchaseOrder:details')")
    public ResponseResult<PurchaseOrderDetailsVo> getSalesContractDetails(@PathVariable Long orderId) {
        return ResponseResult.success(purchaseOrderService.getDetailsById(orderId));
    }

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

    /**
     * 获取采购订单详情
     *
     * @param orderIds 订单id集合
     * @return 采购订单详情
     */
    @ApiOperation(value = "拉取采购订单发票", notes = "拉取采购订单发票")
    @PostMapping("/pull/purchaseInvoice")
    @PreAuthorize("@ss.hasPermi('trade:purchaseOrder:pullInvoice')")
    public ResponseResult<Boolean> pullPurchaseInvoice(@RequestBody List<Long> orderIds) {
        return ResponseResult.success(purchaseOrderService.pullPurchaseInvoice(orderIds));
    }

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

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

    /**
     * 重定向小图进采购发票下载
     */
    @GetMapping("/download/invoice")
    @PreAuthorize("@ss.hasRole('EXPORT_TAX_REFUNDER')")
    public ResponseResult<String> getDownloadPurchaseInvoiceUrl(String xtUserId, String xtEid) {
        String taxRebateUrl = purchaseOrderService.getDownloadPurchaseInvoiceUrl(xtUserId, xtEid);
        return ResponseResult.success(taxRebateUrl);
    }
}
