package com.trade.admin.finance.paymentcollection.controller;

import com.trade.admin.finance.disbursement.dto.ConfirmedDisbursementDto;
import com.trade.admin.finance.disbursement.service.BBillingDisbursementService;
import com.trade.admin.finance.disbursement.vo.BillingDisbursementDetail;
import com.trade.admin.finance.paymentcollection.dto.BillingIncomeDetailDto;
import com.trade.admin.finance.paymentcollection.dto.BillingIncomeInfoDto;
import com.trade.admin.finance.paymentcollection.service.BPaymentCollectionService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.finance.disbursement.dto.DisbursementSearchDto;
import com.trade.service.finance.disbursement.vo.BillingDisbursementPageVo;
import com.trade.service.finance.paymentcollection.dto.BillingIncomeSearchDto;
import com.trade.service.finance.paymentcollection.dto.EntryApplyDto;
import com.trade.service.finance.paymentcollection.dto.EntryReviewDto;
import com.trade.service.finance.paymentcollection.vo.BillingIncomePageVo;
import com.trade.service.finance.paymentcollection.vo.EntrySalesContractDetailVo;
import com.trade.service.finance.paymentcollection.vo.EntrySalesContractVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @description: 出入账管理
 * @Author: wanglang
 * @Date: 2024/10/22
 * @Version: 1.0
 */
@Api(tags = "出入账管理", value = "出入账管理")
@RestController
@RequestMapping("/paymentCollection")
public class BPaymentCollectionController {

    @Resource
    private BPaymentCollectionService paymentCollectionService;
    @Resource
    private BBillingDisbursementService billingDisbursementService;

    /**
     * 获取入账列表分页信息
     *
     * @param incomeSearchDto 入账列表分页信息条件
     * @return 入账列表分页信息
     */
    @ApiOperation(value = "获取入账分页", notes = "获取入账分页")
    @PostMapping("/get/entryPage")
    @PreAuthorize("@ss.hasPermi('paymentCollection:entry:pages')")
    public ResponseResult<GridPage<BillingIncomePageVo>> getEntryPage(
            @RequestBody BillingIncomeSearchDto incomeSearchDto) {
        return ResponseResult.success(paymentCollectionService.queryListByPage(incomeSearchDto));
    }

    /**
     * 获取销售合同列表
     *
     * @return 销售合同列表
     */
    @ApiOperation(value = "获取销售合同列表", notes = "获取销售合同列表")
    @GetMapping("/get/salesContract")
    @Deprecated
    public ResponseResult<List<EntrySalesContractVo>> getSalesContract() {
        return ResponseResult.success(paymentCollectionService.getEntrySalesContractList());
    }

    /**
     * 获取销售合同详情
     *
     * @return 销售合同详情
     */
    @ApiOperation(value = "获取销售合同详情", notes = "获取销售合同详情")
    @GetMapping("/get/salesContractDetail")
    @Deprecated
    public ResponseResult<EntrySalesContractDetailVo> getEntrySalesContractDetail(Long contractId) {
        return ResponseResult.success(paymentCollectionService.getEntrySalesContractDetail(contractId));
    }

    /**
     * 提交入账申请
     *
     * @param entryApplyDto 入账申请信息
     * @return true/false
     */
    @ApiOperation(value = "提交入账申请", notes = "提交入账申请")
    @PostMapping("/submit/entryApply")
    @PreAuthorize("@ss.hasPermi('paymentCollection:submit:entryApply')")
    @Deprecated
    public ResponseResult<Boolean> submitEntryApply(@RequestBody EntryApplyDto entryApplyDto) {
        return ResponseResult.success(paymentCollectionService.submitEntryApply(entryApplyDto));
    }

    /**
     * 提交入账审核
     *
     * @param entryReviewDto 入账审核信息
     * @return true/false
     */
    @ApiOperation(value = "提交入账申请审核", notes = "提交入账申请审核")
    @PostMapping("/submit/entryReview")
    @PreAuthorize("@ss.hasPermi('paymentCollection:submit:entryReview')")
    public ResponseResult<Boolean> submitEntryReview(@RequestBody @Validated EntryReviewDto entryReviewDto) {
        return ResponseResult.success(paymentCollectionService.submitEntryReview(entryReviewDto));
    }

    /**
     * 获取入账详情
     *
     * @return 入账详情
     */
    @ApiOperation(value = "获取入账详情", notes = "获取入账详情")
    @GetMapping("/get/billingIncomeDetail")
    @PreAuthorize("@ss.hasPermi('paymentCollection:entry:detail')")
    public ResponseResult<BillingIncomeDetailDto> getBillingIncomeDetail(Long id) {
        return ResponseResult.success(paymentCollectionService.getBillingIncomeDetail(id));
    }

    /**
     * 提交入账详情信息
     *
     * @param billingIncomeInfoDto 入账详情信息
     * @return true/false
     */
    @ApiOperation(value = "提交入账详情信息", notes = "提交入账详情信息")
    @PostMapping("/submit/entryDetail")
    @PreAuthorize("@ss.hasPermi('paymentCollection:submit:entryDetail')")
    public ResponseResult<Boolean> submitEntryDetail(
            @RequestBody @Validated BillingIncomeInfoDto billingIncomeInfoDto) {
        return ResponseResult.success(paymentCollectionService.submitEntryDetail(billingIncomeInfoDto));
    }

    /**
     * 获取出账列表分页信息
     *
     * @param searchDto 出账列表分页信息条件
     * @return 出账列表分页信息
     */
    @ApiOperation(value = "获取出账分页", notes = "获取出账分页")
    @PostMapping("/get/disbursementPage")
    @PreAuthorize("@ss.hasPermi('paymentCollection:disbursement:pages')")
    public ResponseResult<GridPage<BillingDisbursementPageVo>> getDisbursementPage(
            @RequestBody DisbursementSearchDto searchDto) {
        return ResponseResult.success(billingDisbursementService.queryListByPage(searchDto));
    }

    /**
     * 提交出账确认
     *
     * @param confirmedDisbursementDto 出账确认信息
     * @return true/false
     */
    @ApiOperation(value = "提交出账确认", notes = "提交出账确认")
    @PostMapping("/submit/disbursementConfirmed")
    @PreAuthorize("@ss.hasPermi('paymentCollection:submit:disbursementConfirmed')")
    public ResponseResult<Boolean> confirmedDisbursement(
            @RequestBody @Valid ConfirmedDisbursementDto confirmedDisbursementDto) {
        return ResponseResult.success(billingDisbursementService.confirmedDisbursement(confirmedDisbursementDto));
    }

    /**
     * 获取出账详情
     *
     * @return 出账详情
     */
    @ApiOperation(value = "获取出账详情", notes = "获取出账详情")
    @GetMapping("/get/disbursementDetail")
    @PreAuthorize("@ss.hasPermi('paymentCollection:disbursement:detail')")
    public ResponseResult<BillingDisbursementDetail> getDisbursementDetail(Long id) {
        return ResponseResult.success(billingDisbursementService.queryDetailV2(id));
    }
}
