package com.trade.admin.trade.filingdoc.controller;

import com.github.pagehelper.PageInfo;
import com.trade.admin.trade.exportrebate.service.ExportTaxRebateService;
import com.trade.admin.trade.purchasecontract.service.PurchaseContractService;
import com.trade.admin.trade.purchaseorder.service.BPurchaseOrderService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.trade.exportrebate.dto.TaxRebateSummaryDataDto;
import com.trade.service.trade.exportrebate.dto.search.TaxRebateSummarySearchDto;
import com.trade.service.trade.filingdoc.vo.*;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderInvoiceDocumentSearchDto;
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderLogisticsDocumentSearchDto;
import com.trade.service.trade.purchaseorder.vo.PurchaseOrderInvoiceDocumentVo;
import com.trade.service.trade.purchaseorder.vo.PurchaseOrderLogisticsDocumentVo;
import com.trade.service.trade.salescontract.service.SalesContractService;
import com.trade.service.trade.filingdoc.vo.SalesContract4FilingDocVO;
import com.trade.service.trade.salesorder.service.ICustomsDeclarationService;
import com.trade.service.trade.salesorder.service.ISalesOrderInvoiceService;
import com.trade.service.trade.salesorder.service.ISalesOrderLogisticsService;
import com.trade.service.trade.salesorder.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 备案单证 Controller
 * </p>
 *
 * @author zhangchenm
 * @since 2024-10-23
 */
@RestController
@RequestMapping("/filingDoc")
@Api(tags = "备案单证", value = "备案单证")
public class FilingDocController {

    @Resource
    private SalesContractService salesContractService;
    @Resource
    private PurchaseContractService purchasingContractService;
    @Resource
    private ISalesOrderInvoiceService salesOrderInvoiceService;
    @Resource
    private ISalesOrderLogisticsService salesOrderLogisticsService;
    @Resource
    private ICustomsDeclarationService customsDeclarationService;
    @Resource
    private ExportTaxRebateService exportTaxRebateService;
    @Resource
    private BPurchaseOrderService bPurchaseOrderService;

    /**
     * 备案单证汇总列表
     * 
     * @param search 查询条件
     * @return 备案单证列表
     */
    @RequestMapping("/list")
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:list')")
    public ResponseResult<GridPage<TaxRebateSummaryDataDto>> getSummaryDataByPage(TaxRebateSummarySearchDto search) {
        // 直接复用退税汇总页面，数据一致
        return ResponseResult.success(exportTaxRebateService.getTaxRebateSummaryDataPagesBySearch(search));
    }

    /**
     * 出口单证列表
     */
    @RequestMapping("/exportDocList")
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:exportDoc:list')")
    public ResponseResult<PageInfo<SalesContract4FilingDocVO>> salesContracts(Contract4FilingDocSearch search) {
        return ResponseResult.success(salesContractService.queryList4FilingDocBySearch(search));
    }

    /**
     * 进货单证列表
     */
    @RequestMapping("/purchaseDocList")
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:purchaseDoc:list')")
    public ResponseResult<PageInfo<PurchaseContract4FilingDocVO>> purchaseContracts(Contract4FilingDocSearch search) {
        return ResponseResult.success(purchasingContractService.queryList4FilingDocBySearch(search));
    }

    /**
     * 销售发票列表
     */
    @RequestMapping("/saleInvoiceList")
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:salesInvoice:list')")
    public ResponseResult<PageInfo<SalesOrderInvoiceVO>> saleInvoices(SalesOrderInvoiceSearch search) {
        return ResponseResult.success(salesOrderInvoiceService.queryListBySearch(search));
    }

    /**
     * 物流单证列表
     */
    @RequestMapping("/logisticsDocList")
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:logisticsDoc:list')")
    public ResponseResult<PageInfo<Logistics4FilingDocVO>> logisticsDocs(SalesOrderLogisticsSearch search) {
        return ResponseResult.success(salesOrderLogisticsService.queryList4FilingDocBySearch(search));
    }

    /**
     * 查询物流公司名称列表
     */
    @RequestMapping("/queryLogisticsCompanyDict")
    public ResponseResult<List<String>> queryLogisticsCompany4Dict() {
        return ResponseResult.success(salesOrderLogisticsService.queryAllLogisticsCompany4Dict());
    }

    /**
     * 报关单证列表
     */
    @RequestMapping("/customsDeclarationList")
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:customsDeclaration:list')")
    public ResponseResult<PageInfo<CustomsDeclaration4FilingDocVO>> customsDeclarations(
            CustomsDeclaration4FilingDocSearch search) {
        return ResponseResult.success(customsDeclarationService.queryList4FilingDocBySearch(search));
    }

    /**
     * 查询报关公司名称列表
     */
    @RequestMapping("/queryDeclareCompanyDict")
    public ResponseResult<List<String>> queryDeclareCompany4Dict() {
        return ResponseResult.success(customsDeclarationService.queryAllDeclareCompany4Dict());
    }

    /**
     * 采购发票单证列表
     * 
     * @param documentSearchDto
     * @return <GridPage<PurchaseOrderInvoiceDocumentVo>
     */
    @PostMapping(value = "/orderInvoiceDocList", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:orderInvoiceDoc:list')")
    @ApiOperation(value = "采购发票单证列表", notes = "采购发票单证列表")
    public ResponseResult<GridPage<PurchaseOrderInvoiceDocumentVo>> queryInvoiceDocumentListByPage(
            @RequestBody PurchaseOrderInvoiceDocumentSearchDto documentSearchDto) {
        return ResponseResult.success(bPurchaseOrderService.queryInvoiceDocumentListByPage(documentSearchDto));
    }

    /**
     * 采购订单物流单证列表
     *
     * @param documentSearchDto
     * @return GridPage<PurchaseOrderLogisticsDocumentVo>
     */
    @PostMapping(value = "/orderLogisticsDocList", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PreAuthorize("@ss.hasPermi('trade:filingDoc:orderLogisticsDoc:list')")
    @ApiOperation(value = "采购订单物流单证列表", notes = "采购订单物流单证列表")
    public ResponseResult<GridPage<PurchaseOrderLogisticsDocumentVo>> queryPurchaseOrderLogisticsDocument(
            @RequestBody PurchaseOrderLogisticsDocumentSearchDto documentSearchDto) {
        return ResponseResult.success(bPurchaseOrderService.queryPurchaseOrderLogisticsDocument(documentSearchDto));
    }

    /**
     * 查询物流公司名称
     *
     * @param purchaseContractNo 采购合同编号
     * @return 物流公司名称列表
     */
    @GetMapping("/logisticsCompanyName")
    @ApiOperation(value = "物流公司名称", notes = "物流公司名称")
    public ResponseResult<List<String>> queryLogisticsCompanyName(String purchaseContractNo) {
        return ResponseResult.success(bPurchaseOrderService.queryLogisticsCompanyName(purchaseContractNo));
    }
}
