package com.ruoyi.web.controller.oa;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oa.domain.CmcContractInvoice;
import com.ruoyi.oa.service.ICmcContractInvoiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同开票Controller
 * 
 * @author cmc
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/oa/contractInvoice")
public class CmcContractInvoiceController extends BaseController
{
    @Autowired
    private ICmcContractInvoiceService cmcContractInvoiceService;

    /**
     * 查询合同开票列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcContractInvoice cmcContractInvoice)
    {
        startPage();
        List<CmcContractInvoice> list = cmcContractInvoiceService.selectCmcContractInvoiceList(cmcContractInvoice);
        return getDataTable(list);
    }

    /**
     * 导出合同开票列表
     */
    @Log(title = "合同开票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcContractInvoice cmcContractInvoice)
    {
        List<CmcContractInvoice> list = cmcContractInvoiceService.selectCmcContractInvoiceList(cmcContractInvoice);
        ExcelUtil<CmcContractInvoice> util = new ExcelUtil<CmcContractInvoice>(CmcContractInvoice.class);
        util.exportExcel(response, list, "合同开票数据");
    }

    /**
     * 获取合同开票详细信息
     */
    @GetMapping(value = "/{invoiceId}")
    public AjaxResult getInfo(@PathVariable("invoiceId") Integer invoiceId)
    {
        return success(cmcContractInvoiceService.selectCmcContractInvoiceByInvoiceId(invoiceId));
    }

    /**
     * 新增合同开票
     */
    @Log(title = "合同开票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcContractInvoice cmcContractInvoice)
    {
        return toAjax(cmcContractInvoiceService.insertCmcContractInvoice(cmcContractInvoice));
    }

    /**
     * 修改合同开票
     */
    @Log(title = "合同开票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcContractInvoice cmcContractInvoice)
    {
        return toAjax(cmcContractInvoiceService.updateCmcContractInvoice(cmcContractInvoice));
    }

    /**
     * 删除合同开票
     */
    @Log(title = "合同开票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable String[] contractIds)
    {
        return success(cmcContractInvoiceService.deleteCmcContractInvoiceByContractIds(contractIds));
    }
}
