package com.trade.admin.trade.exportrebate.controller;

import com.trade.admin.system.controller.BaseController;
import com.trade.admin.trade.exportrebate.dto.ExportTaxRefundBatchRequest;
import com.trade.admin.trade.exportrebate.dto.ExportTaxRefundDetailsRequest;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.trade.exportrebate.dto.*;
import com.trade.service.trade.exportrebate.dto.search.TaxRebateExportAbstractInfoSearchDto;
import com.trade.service.trade.exportrebate.dto.search.TaxRebatePurchaseAbstractInfoSearchDto;
import com.trade.service.trade.exportrebate.dto.search.TaxRebateSummarySearchDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.trade.admin.trade.exportrebate.service.ExportTaxRebateService;

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

/**
 * 出口退税-出口明细接口
 *
 * @author hlb
 * @since 2024-10-22 15:46:46
 */
@RestController
@RequestMapping("/exportTaxRebate")
public class ExportTaxRebateController extends BaseController {

    /**
     * 服务对象
     */
    @Resource
    private ExportTaxRebateService exportTaxRebateService;

    /**
     * 分页查询出口退税明细汇总数据
     *
     * @param search 查询实体
     * @return 出口退税明细汇总数据
     */
    @GetMapping("/summaryData")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.pages')")
    public ResponseResult<GridPage<TaxRebateSummaryDataDto>> getSummaryDataByPage(TaxRebateSummarySearchDto search) {
        return success(exportTaxRebateService.getTaxRebateSummaryDataPagesBySearch(search));
    }

    /**
     * 出口退税明细合计数据查询
     *
     * @param search 查询条件
     * @return 出口退税明细合计数据
     */
    @GetMapping("/totalData")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.pages')")
    public ResponseResult<TaxRebateTotalDataDto> queryTotalData(TaxRebateSummarySearchDto search) {
        return success(exportTaxRebateService.getTaxRebateTotalDataBySearch(search));
    }

    /**
     * 分页查询出口退税出口明细摘要信息
     *
     * @param search 查询实体
     * @return 口退税出口明细摘要信息
     */
    @GetMapping("/exportPages")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.detail')")
    public ResponseResult<GridPage<TaxRebateExportAbstractInfo>> getTaxRebateExportPages(
            TaxRebateExportAbstractInfoSearchDto search) {
        return success(exportTaxRebateService.getTaxRebateExportAbstractInfoPagesBySearch(search));
    }

    /**
     * 分页查询出口退税进货明细摘要信息
     *
     * @param search 查询实体
     * @return 出口退税进货明细摘要信息
     */
    @GetMapping("/puchasePages")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.detail')")
    public ResponseResult<GridPage<TaxRebatePurchaseAbstractInfo>> getTaxRebatePurchasePages(
            TaxRebatePurchaseAbstractInfoSearchDto search) {
        return success(exportTaxRebateService.getTaxRebatePurchaseAbstractInfoPagesBySearch(search));
    }

    /**
     * 重定向小图进行退税
     */
    @GetMapping("/doTaxRebate")
    @PreAuthorize("@ss.hasRole('EXPORT_TAX_REFUNDER')")
    public ResponseResult<String> doTaxRebate(String xtUserId, String xtEid) {
        String taxRebateUrl = exportTaxRebateService.getTaxRebateUrl(xtUserId, xtEid);
        return ResponseResult.success(taxRebateUrl);
    }

    /**
     * 获取退税到账金额（批量选择申报批次）
     *
     * @param request 查询实体
     * @return
     */
    @PostMapping("/declarationBatch/refundAmount")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.exportTaxRefund')")
    public ResponseResult<BigDecimal> getRefundAmountForDeclarationBatch(ExportTaxRefundBatchRequest request) {
        return success(exportTaxRebateService.getRefundAmountForDeclarationBatch(request));
    }

    /**
     * 出口退税款确认（批量选择申报批次）
     *
     * @param request 查询实体
     * @return
     */
    @PostMapping("/declarationBatch/exportTaxRefund")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.exportTaxRefund')")
    public ResponseResult<Boolean> refundExportTaxForDeclarationBatch(ExportTaxRefundBatchRequest request) {
        return success(exportTaxRebateService.refundExportTaxForDeclarationBatch(request));
    }

    /**
     * 获取退税到账金额（批量选择商品）
     *
     * @param request 查询实体
     * @return
     */
    @PostMapping("/exportDetails/refundAmount")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.exportTaxRefund')")
    public ResponseResult<BigDecimal> getRefundAmountForExportDetails(List<TaxRebateExportAbstractInfo> request) {
        return success(exportTaxRebateService.getRefundAmountForExportDetails(request));
    }

    /**
     * 出口退税款确认（批量选择商品）
     *
     * @param request 查询实体
     * @return
     */
    @PostMapping("/exportDetails/exportTaxRefund")
    @PreAuthorize("@ss.hasPermi('trade:exportTaxRebate.exportTaxRefund')")
    public ResponseResult<Boolean> refundExportTaxForExportDetails(ExportTaxRefundDetailsRequest request) {
        return success(exportTaxRebateService.refundExportTaxForExportDetails(request));
    }
}
