package cn.ezhizao.project.business.statementAccount.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.statementAccount.domain.BizStatementAccount;
import cn.ezhizao.project.business.statementAccount.service.IBizStatementAccountService;
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 2023-12-05
 */
@RestController
@RequestMapping("/business/statementAccount")
public class BizStatementAccountController extends BaseController
{
    @Resource
    private IBizStatementAccountService bizStatementAccountService;

    /**
     * 查询对账单列表
     */
    @PreAuthorize("@ss.hasPermi('business:statementAccount:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizStatementAccount bizStatementAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStatementAccount);
        startPage();
        List<BizStatementAccount> list = bizStatementAccountService.getList(bizStatementAccount);
        return getDataTable(list);
    }

    /**
     * 导出对账单列表
     */
    @PreAuthorize("@ss.hasPermi('business:statementAccount:export')")
    @Log(title = "对账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizStatementAccount bizStatementAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStatementAccount);
        List<BizStatementAccount> list = bizStatementAccountService.getList(bizStatementAccount);
        ExcelUtil<BizStatementAccount> util = new ExcelUtil<BizStatementAccount>(BizStatementAccount.class);
        util.exportExcel(response, list, "对账单数据");
    }

    /**
     * 获取对账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:statementAccount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizStatementAccountService.getById(id));
    }

    /**
     * 新增对账单
     */
    @PreAuthorize("@ss.hasPermi('business:statementAccount:add')")
    @Log(title = "对账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizStatementAccount bizStatementAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStatementAccount);
        return toAjax(bizStatementAccountService.save(bizStatementAccount));
    }

    /**
     * 修改对账单
     */
    @PreAuthorize("@ss.hasPermi('business:statementAccount:edit')")
    @Log(title = "对账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizStatementAccount bizStatementAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStatementAccount);
        return toAjax(bizStatementAccountService.updateById(bizStatementAccount));
    }

    /**
     * 删除对账单
     */
    @PreAuthorize("@ss.hasPermi('business:statementAccount:remove')")
    @Log(title = "对账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizStatementAccountService.removeBatchByIds(ids));
    }
}
