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

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.project.business.account.domain.BizAccount;
import cn.ezhizao.project.business.account.service.IBizAccountService;
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.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-11-01
 */
@RestController
@RequestMapping("/business/account")
public class BizAccountController extends BaseController
{
    @Resource
    private IBizAccountService bizAccountService;

    /**
     * 查询银行账户列表
     */
    @PreAuthorize("@ss.hasPermi('business:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizAccount bizAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAccount);
        startPage();
        startOrderBy();
        List<BizAccount> list = bizAccountService.getList(bizAccount);
        return getDataTable(list);
    }

    /**
     * 导出银行账户列表
     */
    @PreAuthorize("@ss.hasPermi('business:account:export')")
    @Log(title = "银行账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizAccount bizAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAccount);
        List<BizAccount> list = bizAccountService.getList(bizAccount);
        ExcelUtil<BizAccount> util = new ExcelUtil<BizAccount>(BizAccount.class);
        util.exportExcel(response, list, "银行账户数据");
    }

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

    /**
     * 新增银行账户
     */
    @PreAuthorize("@ss.hasPermi('business:account:save')")
    @Log(title = "银行账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAccount bizAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAccount);
        return toAjax(bizAccountService.save(bizAccount));
    }

    /**
     * 修改银行账户
     */
    @PreAuthorize("@ss.hasPermi('business:account:save')")
    @Log(title = "银行账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizAccount bizAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAccount);
        return toAjax(bizAccountService.updateById(bizAccount));
    }

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