package com.usky.iot.controller.web;


import com.usky.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.CrmInvoiceInfo;
import com.usky.iot.service.CrmInvoiceInfoService;
import com.usky.iot.service.vo.CrmCustomInfoExportVO;
import com.usky.iot.service.vo.CrmInvoiceInfoExportVO;
import com.usky.iot.service.vo.CrmInvoiceInfoRequest;
import com.usky.iot.service.vo.CrmInvoiceInfoStatisticVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 客户发票信息表 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-06-29
 */
@RestController
@RequestMapping("/crmInvoiceInfo")
public class CrmInvoiceInfoController {

    @Autowired
    private CrmInvoiceInfoService crmInvoiceInfoService;

    /**
     * 新增
     * @param invoiceInfo
     * @return
     */
    @PostMapping
    public ApiResult<Void> add(@RequestBody CrmInvoiceInfo invoiceInfo){
        crmInvoiceInfoService.add(invoiceInfo);
        return ApiResult.success();
    }

    /**
     * 开票状态变更
     * @param invoiceInfo
     * @return
     */
    @PutMapping
    public ApiResult<Void> update(@RequestBody CrmInvoiceInfo invoiceInfo){
        crmInvoiceInfoService.update(invoiceInfo);
        return ApiResult.success();
    }

    /**
     * 分页
     * @param crmInvoiceInfoRequest
     * @return
     */
    @PostMapping("/page")
    public ApiResult<CommonPage<CrmInvoiceInfo>> page(@RequestBody CrmInvoiceInfoRequest crmInvoiceInfoRequest){
        return ApiResult.success(crmInvoiceInfoService.page(crmInvoiceInfoRequest));
    }

    /**
     * 统计
     * @param crmInvoiceInfoRequest
     * @return
     */
    @PostMapping("statistic")
    public ApiResult<List<CrmInvoiceInfoStatisticVO>> statistic(@RequestBody CrmInvoiceInfoRequest crmInvoiceInfoRequest){
        return ApiResult.success(crmInvoiceInfoService.statistic(crmInvoiceInfoRequest));
    }

    /**
     * 导出
     * @param crmInvoiceInfoRequest
     * @param response
     * @throws IOException
     */
    @PostMapping("export")
    public void export(@RequestBody CrmInvoiceInfoRequest crmInvoiceInfoRequest, HttpServletResponse response) throws IOException{
        List<CrmInvoiceInfoExportVO> list = crmInvoiceInfoService.export(crmInvoiceInfoRequest);
        ExcelUtil<CrmInvoiceInfoExportVO> util = new ExcelUtil<CrmInvoiceInfoExportVO>(CrmInvoiceInfoExportVO.class);
        util.exportExcel(response,list,"开票信息","开票信息");
    }

}

