package com.yc.ship.module.trade.controller.admin.report;

import com.yc.ship.framework.apilog.core.annotation.ApiAccessLog;
import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.module.trade.controller.admin.report.vo.*;
import com.yc.ship.module.trade.service.report.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

import static com.yc.ship.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.yc.ship.framework.common.pojo.CommonResult.success;

/**
 * 银行对账报表 Controller
 *
 * @author auto-generated
 */
@Tag(name = "管理后台 - 银行对账报表")
@RestController
@RequestMapping("/trade/report/bank-statement")
@Validated
@Slf4j
public class BankStatementReportController {

    @Resource
    private BankStatementReportService bankStatementReportService;

    @Resource
    private IncomeOrderLedgerService incomeOrderLedgerService;

    @Resource
    private BankTransactionDetailsService bankTransactionDetailsService;

    @Resource
    private IncomeAuditService incomeAuditService;

    @Resource
    private PrepaidRechargeLedgerService prepaidRechargeLedgerService;

    @Resource
    private DistributorBalanceService distributorBalanceService;

    /**
     * 查询银行对账报表分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/page")
    @Operation(summary = "查询银行对账报表分页")
    /*@PreAuthorize("@ss.hasPermission('trade:report:bank-statement:query')")*/
    public CommonResult<PageResult<BankStatementReportRespVO>> getBankStatementReportPage(@Valid BankStatementReportPageReqVO pageReqVO) {
        PageResult<BankStatementReportRespVO> pageResult = bankStatementReportService.getBankStatementReportPage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出银行对账报表 Excel
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/export-excel")
    @Operation(summary = "导出银行对账报表 Excel")
    /*@PreAuthorize("@ss.hasPermission('trade:report:bank-statement:export')")*/
    @ApiAccessLog(operateType = EXPORT)
    public void exportBankStatementReportExcel(@Valid BankStatementReportPageReqVO pageReqVO,
                                                HttpServletResponse response) throws IOException {
        bankStatementReportService.exportBankStatementReportExcel(pageReqVO, response);
    }

    // ==================== 订单收入台账接口 ====================

    /**
     * 查询订单收入台账分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/income-order-ledger/page")
    @Operation(summary = "查询订单收入台账分页")
/*
    @PreAuthorize("@ss.hasPermission('trade:report:bank-statement:query')")
*/
    public CommonResult<PageResult<IncomeOrderLedgerRespVO>> getIncomeOrderLedgerPage(@Valid IncomeOrderLedgerPageReqVO pageReqVO) {
        PageResult<IncomeOrderLedgerRespVO> pageResult = incomeOrderLedgerService.getIncomeOrderLedgerPage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出订单收入台账 Excel（数字字段导出为数字格式）
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/income-order-ledger/export-excel")
    @Operation(summary = "导出订单收入台账 Excel")
/*
    @PreAuthorize("@ss.hasPermission('trade:report:bank-statement:export')")
*/
    @ApiAccessLog(operateType = EXPORT)
    public void exportIncomeOrderLedgerExcel(@Valid IncomeOrderLedgerPageReqVO pageReqVO,
                                              HttpServletResponse response) throws IOException {
        incomeOrderLedgerService.exportIncomeOrderLedgerExcel(pageReqVO, response);
    }

    // ==================== 银行流水交易明细接口 ====================

    /**
     * 查询银行流水交易明细分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/bank-transaction-details/page")
    @Operation(summary = "查询银行流水交易明细分页")
    public CommonResult<PageResult<BankTransactionDetailsRespVO>> getBankTransactionDetailsPage(@Valid BankTransactionDetailsPageReqVO pageReqVO) {
        PageResult<BankTransactionDetailsRespVO> pageResult = bankTransactionDetailsService.getBankTransactionDetailsPage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出银行流水交易明细 Excel（数字字段导出为数字格式）
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/bank-transaction-details/export-excel")
    @Operation(summary = "导出银行流水交易明细 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBankTransactionDetailsExcel(@Valid BankTransactionDetailsPageReqVO pageReqVO,
                                                    HttpServletResponse response) throws IOException {
        bankTransactionDetailsService.exportBankTransactionDetailsExcel(pageReqVO, response);
    }

    // ==================== 收入稽核表接口 ====================

    /**
     * 查询收入稽核表分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/income-audit/page")
    @Operation(summary = "查询收入稽核表分页")
    public CommonResult<PageResult<IncomeAuditRespVO>> getIncomeAuditPage(@Valid IncomeAuditPageReqVO pageReqVO) {
        PageResult<IncomeAuditRespVO> pageResult = incomeAuditService.getIncomeAuditPage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出收入稽核表 Excel（数字字段导出为数字格式）
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/income-audit/export-excel")
    @Operation(summary = "导出收入稽核表 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportIncomeAuditExcel(@Valid IncomeAuditPageReqVO pageReqVO,
                                       HttpServletResponse response) throws IOException {
        incomeAuditService.exportIncomeAuditExcel(pageReqVO, response);
    }



    // ==================== 预存款充值流水接口 ====================

    /**
     * 查询预存款充值流水分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/prepaid-recharge-ledger/page")
    @Operation(summary = "查询预存款充值流水分页")
/*
    @PreAuthorize("@ss.hasPermission('trade:report:bank-statement:query')")
*/
    public CommonResult<PageResult<PrepaidRechargeLedgerRespVO>> getPrepaidRechargeLedgerPage(@Valid PrepaidRechargeLedgerPageReqVO pageReqVO) {
        PageResult<PrepaidRechargeLedgerRespVO> pageResult = prepaidRechargeLedgerService.getPrepaidRechargeLedgerPage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出预存款充值流水 Excel（数字字段导出为数字格式）
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/prepaid-recharge-ledger/export-excel")
    @Operation(summary = "导出预存款充值流水 Excel")
/*
    @PreAuthorize("@ss.hasPermission('trade:report:bank-statement:export')")
*/
    @ApiAccessLog(operateType = EXPORT)
    public void exportPrepaidRechargeLedgerExcel(@Valid PrepaidRechargeLedgerPageReqVO pageReqVO,
                                                 HttpServletResponse response) throws IOException {
        prepaidRechargeLedgerService.exportPrepaidRechargeLedgerExcel(pageReqVO, response);
    }

    // ==================== 预存款余额表接口 ====================

    /**
     * 查询预存款余额表分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/distributor-balance/page")
    @Operation(summary = "查询预存款余额表分页")
/*
    @PreAuthorize("@ss.hasPermission('trade:report:bank-statement:query')")
*/
    public CommonResult<PageResult<DistributorBalanceRespVO>> getDistributorBalancePage(@Valid DistributorBalancePageReqVO pageReqVO) {
        PageResult<DistributorBalanceRespVO> pageResult = distributorBalanceService.getDistributorBalancePage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出预存款余额表 Excel（数字字段导出为数字格式）
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/distributor-balance/export-excel")
    @Operation(summary = "导出预存款余额表 Excel")
/*
    @PreAuthorize("@ss.hasPermission('trade:report:bank-statement:export')")
*/
    @ApiAccessLog(operateType = EXPORT)
    public void exportDistributorBalanceExcel(@Valid DistributorBalancePageReqVO pageReqVO,
                                               HttpServletResponse response) throws IOException {
        distributorBalanceService.exportDistributorBalanceExcel(pageReqVO, response);
    }


}
