package com.hzy.project.business.payment.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hzy.framework.aspectj.lang.annotation.Log;
import com.hzy.framework.aspectj.lang.enums.BusinessType;
import com.hzy.project.business.payment.domain.Payment;
import com.hzy.project.business.payment.service.IPaymentService;
import com.hzy.framework.web.controller.BaseController;
import com.hzy.framework.web.domain.AjaxResult;
import com.hzy.common.utils.poi.ExcelUtil;
import com.hzy.framework.web.page.TableDataInfo;

/**
 * 支出Controller
 * 
 * @author ruoyi
 * @date 2026-01-02
 */
@Controller
@RequestMapping("/business/payment")
public class PaymentController extends BaseController
{
    private String prefix = "business/payment";

    @Autowired
    private IPaymentService paymentService;

    @RequiresPermissions("business:payment:view")
    @GetMapping()
    public String payment()
    {
        return prefix + "/payment";
    }

    /**
     * 查询支出列表
     */
    @RequiresPermissions("business:payment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Payment payment)
    {
        startPage();
        List<Payment> list = paymentService.selectPaymentList(payment);
        return getDataTable(list);
    }

    /**
     * 导出支出列表
     */
    @RequiresPermissions("business:payment:export")
    @Log(title = "支出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Payment payment)
    {
        List<Payment> list = paymentService.selectPaymentList(payment);
        ExcelUtil<Payment> util = new ExcelUtil<Payment>(Payment.class);
        return util.exportExcel(list, "支出数据");
    }

    /**
     * 新增支出
     */
    @RequiresPermissions("business:payment:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存支出
     */
    @RequiresPermissions("business:payment:add")
    @Log(title = "支出", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Payment payment)
    {
        return toAjax(paymentService.insertPayment(payment));
    }

    /**
     * 修改支出
     */
    @RequiresPermissions("business:payment:edit")
    @GetMapping("/edit/{paymentId}")
    public String edit(@PathVariable("paymentId") Long paymentId, ModelMap mmap)
    {
        Payment payment = paymentService.selectPaymentByPaymentId(paymentId);
        mmap.put("payment", payment);
        return prefix + "/edit";
    }

    /**
     * 修改保存支出
     */
    @RequiresPermissions("business:payment:edit")
    @Log(title = "支出", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Payment payment)
    {
        return toAjax(paymentService.updatePayment(payment));
    }

    /**
     * 删除支出
     */
    @RequiresPermissions("business:payment:remove")
    @Log(title = "支出", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paymentService.deletePaymentByPaymentIds(ids));
    }
}
