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

import cn.ezhizao.common.utils.poi.ExcelUtil;
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.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.paymentEntry.domain.BizPaymentSubject;
import cn.ezhizao.project.business.paymentEntry.service.IBizPaymentSubjectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 支出科目Controller
 *
 * @author ruoyi
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/expenditure/subject")
public class BizPaymentSubjectController extends BaseController
{
    @Resource
    private IBizPaymentSubjectService bizPaymentSubjectService;

    /**
     * 查询支出科目列表
     */
    @PreAuthorize("@ss.hasPermi('paymentEntry:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPaymentSubject bizPaymentSubject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentSubject);
        startPage();
        bizPaymentSubject.setStatus(null);
        List<BizPaymentSubject> list = bizPaymentSubjectService.getList(bizPaymentSubject);
        return getDataTable(list);
    }

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

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

    /**
     * 新增支出科目
     */
    @PreAuthorize("@ss.hasPermi('expenditure:subject:add')")
    @Log(title = "支出科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPaymentSubject bizPaymentSubject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentSubject);
        return toAjax(bizPaymentSubjectService.save(bizPaymentSubject));
    }

    /**
     * 修改支出科目
     */
    @PreAuthorize("@ss.hasPermi('expenditure:subject:edit')")
    @Log(title = "支出科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPaymentSubject bizPaymentSubject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizPaymentSubject);
        return toAjax(bizPaymentSubjectService.updateById(bizPaymentSubject));
    }

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