package com.jy.business.payment.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.business.payment.model.dto.PaymentRequestsDto;
import com.jy.business.payment.model.dto.PaymentRequestsSelectDto;
import com.jy.business.payment.model.entity.PaymentRemit;
import com.jy.business.payment.model.vo.PaymentRemitExportVo;
import com.jy.business.payment.model.vo.PaymentRequestsExportVo;
import com.jy.business.payment.model.vo.PaymentRequestsVo;
import com.jy.business.payment.service.PaymentRequestsService;
import com.jy.flow.model.dto.RetrieveDto;
import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.utils.excel.ExcelUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 请款 前端控制器
 * </p>
 *
 * @author
 * @since 2024-10-18
 */
@RestController
@RequestMapping("/paymentRequests")
public class PaymentRequestsController {

    @Resource
    private PaymentRequestsService paymentRequestsService;

    @Resource
    private HttpServletResponse response;

    /**
     * 请款分页
     */
    @GetMapping("/getPage")
    public Page<PaymentRequestsVo> getPage(PaymentRequestsSelectDto dto) {
        return paymentRequestsService.getPage(dto);
    }

    /**
     * 导出
     */
    @GetMapping("/excelExport")
    public void excelExport(PaymentRequestsSelectDto dto) {
        dto.setSearchAll(true);
        Page<PaymentRequestsVo> page = getPage(dto);
        List<PaymentRequestsVo> records = page.getRecords();
        List<PaymentRequestsExportVo> list = BeanUtil.copyToList(records, PaymentRequestsExportVo.class);
        ExcelUtil.exportExcel(list, "请款", PaymentRequestsExportVo.class, response);
    }

    /**
     * 请款明细
     */
    @GetMapping("/getDetail")
    public PaymentRequestsVo getDetail(BaseSelectDto dto) {
        return paymentRequestsService.getDetail(dto.getId());
    }

    /**
     * 请款新增
     */
    @PostMapping("/add")
    public void add(@RequestBody PaymentRequestsDto dto) {
        paymentRequestsService.add(dto);
    }

    /**
     * 请款编辑
     */
    @PostMapping("/edit")
    public void edit(@RequestBody PaymentRequestsDto dto) {
        paymentRequestsService.edit(dto);
    }

    /**
     * 请款删除
     */
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        paymentRequestsService.delete(dto.getIdList());
    }

    /**
     * 打款分页
     */
    @GetMapping("/getRemitPage")
    public Page<PaymentRequestsVo> getRemitPage(PaymentRequestsSelectDto dto) {
        return paymentRequestsService.getRemitPage(dto);
    }

    /**
     * 打款导出
     */
    @GetMapping("/remitExcelExport")
    public void remitExcelExport(PaymentRequestsSelectDto dto) {
        dto.setSearchAll(true);
        Page<PaymentRequestsVo> page = getRemitPage(dto);
        List<PaymentRequestsVo> records = page.getRecords();
        List<PaymentRemitExportVo> list = BeanUtil.copyToList(records, PaymentRemitExportVo.class);
        ExcelUtil.exportExcel(list, "打款", PaymentRemitExportVo.class, response);
    }

    /**
     * 打款
     */
    @PostMapping("/remit")
    public void remit(@RequestBody PaymentRemit dto) {
        paymentRequestsService.remit(dto);
    }

    /**
     * 撤回流程
     */
    @PostMapping("/retrieve")
    public void retrieve(@RequestBody RetrieveDto dto) {
        paymentRequestsService.retrieve(dto);
    }

}
