package com.fdkankan.manage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.manage.service.IExcelService;
import com.fdkankan.manage.service.IInvoiceService;
import com.fdkankan.manage.service.IOrderService;
import com.fdkankan.manage.vo.InvoicePageParamVO;
import com.fdkankan.manage.vo.InvoiceVO;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 发票表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-05-31
 */
@RestController
@RequestMapping("/service/manage/invoice")
public class InvoiceController extends BaseController {

    @Autowired
    private IInvoiceService invoiceService;
    @Autowired
    private IExcelService excelService;

    /**
     * <p>
            发票管理列表
     * </p>
     * @author dengsixing
     * @date 2022/6/1
     * @param param
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.fdkankan.manage.vo.InvoiceVO>
     **/
    @PostMapping("/pageInvoice")
    public Page<InvoiceVO> pageInvoice(@RequestBody InvoicePageParamVO param){
        return invoiceService.pageInvoice(param);
    }

    /**
     * 开票登记
     * @param id 发票申请id
     * @param invoiceNum
     * @param shipNum
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/invoiceRegister")
    public ResultData invoiceRegister(
        @RequestParam("id") Long id, @RequestParam("invoiceNum") String invoiceNum, String shipNum,
        @RequestParam(value = "file", required = false) MultipartFile file) throws Exception{
        return invoiceService.invoiceRegister(this.getUserId(), id, invoiceNum, shipNum, file);
    }

    /**
     * 开票详情
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/getInvoiceRegisterDetail")
    public ResultData getInvoiceRegisterDetail(@RequestParam("id") Long id) throws Exception{
        return invoiceService.getInvoiceRegisterDetail(id);
    }

    /**
     * 导出发票申请
     * @param param
     * @throws IOException
     */
    @PostMapping("/export")
    public void export(@RequestBody InvoicePageParamVO param) throws IOException {
        excelService.exportInvoice(request, response, param);
    }
}

