package cn.ezhizao.project.business.paymentEntry.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.paymentEntry.domain.BizPaymentType;
import cn.ezhizao.project.business.paymentEntry.service.IBizPaymentTypeService;
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-28
 */
@RestController
@RequestMapping("/paymentEntry/type")
public class BizPaymentTypeController extends BaseController
{
    @Resource
    private IBizPaymentTypeService bizPaymentTypeService;

    /**
     * 查询支出类目列表
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPaymentType bizPaymentType) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentType);
        List<BizPaymentType> list = bizPaymentTypeService.getList(bizPaymentType);
        return getDataTable(list);
    }

    /**
     * 导出支出类目列表
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:export')")
    @Log(title = "支出类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPaymentType bizPaymentType) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentType);
        List<BizPaymentType> list = bizPaymentTypeService.getList(bizPaymentType);
        ExcelUtil<BizPaymentType> util = new ExcelUtil<BizPaymentType>(BizPaymentType.class);
        util.exportExcel(response, list, "支出类目数据");
    }

    /**
     * 获取支出类目详细信息
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizPaymentTypeService.getById(id));
    }

    /**
     * 新增支出类目
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:add')")
    @Log(title = "支出类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPaymentType bizPaymentType) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentType);
        return toAjax(bizPaymentTypeService.save(bizPaymentType));
    }

    /**
     * 修改支出类目
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:edit')")
    @Log(title = "支出类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPaymentType bizPaymentType) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentType);
        return toAjax(bizPaymentTypeService.updateById(bizPaymentType));
    }

    /**
     * 删除支出类目
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:remove')")
    @Log(title = "支出类目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizPaymentTypeService.removeBatchByIds(ids));
    }
}
