package cn.ezhizao.project.business.invoice.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.invoice.domain.BizInvoiceRecord;
import cn.ezhizao.project.business.invoice.service.IBizInvoiceRecordService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 发票操作记录Controller
 *
 * @author ruoyi
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/business/invoice/invoiceRecord")
public class BizInvoiceRecordController extends BaseController
{
    @Resource
    private IBizInvoiceRecordService bizInvoiceRecordService;

    /**
     * 查询发票操作记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizInvoiceRecord bizInvoiceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizInvoiceRecord);
        startPage();
        List<BizInvoiceRecord> list = bizInvoiceRecordService.getList(bizInvoiceRecord);
        return getDataTable(list);
    }

    /**
     * 导出发票操作记录列表
     */
    @Log(title = "发票操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizInvoiceRecord bizInvoiceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizInvoiceRecord);
        List<BizInvoiceRecord> list = bizInvoiceRecordService.getList(bizInvoiceRecord);
        ExcelUtil<BizInvoiceRecord> util = new ExcelUtil<BizInvoiceRecord>(BizInvoiceRecord.class);
        util.exportExcel(response, list, "发票操作记录数据");
    }

    /**
     * 获取发票操作记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizInvoiceRecordService.getById(id));
    }

    /**
     * 新增发票操作记录
     */
    @Log(title = "发票操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizInvoiceRecord bizInvoiceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizInvoiceRecord);
        return toAjax(bizInvoiceRecordService.save(bizInvoiceRecord));
    }

    /**
     * 修改发票操作记录
     */
    @PreAuthorize("@ss.hasPermi('business:invoice:invoiceRecord:edit')")
    @Log(title = "发票操作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizInvoiceRecord bizInvoiceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizInvoiceRecord);
        return toAjax(bizInvoiceRecordService.updateById(bizInvoiceRecord));
    }

    /**
     * 删除发票操作记录
     */
    @PreAuthorize("@ss.hasPermi('business:invoice:invoiceRecord:remove')")
    @Log(title = "发票操作记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizInvoiceRecordService.removeBatchByIds(ids));
    }
}
