package com.ruoyi.web.controller.business;

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.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TbPayment;
import com.ruoyi.business.service.ITbPaymentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/payment")
public class TbPaymentController extends BaseController
{
    private String prefix = "business/payment";

    @Autowired
    private ITbPaymentService tbPaymentService;

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

    /**
     * 查询支付列表
     */
    @RequiresPermissions("business:payment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbPayment tbPayment)
    {
        startPage();
        List<TbPayment> list = tbPaymentService.selectTbPaymentList(tbPayment);
        return getDataTable(list);
    }

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

    /**
     * 新增支付
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存支付
     */
    @RequiresPermissions("business:payment:add")
    @Log(title = "支付", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPayment tbPayment)
    {
        return toAjax(tbPaymentService.insertTbPayment(tbPayment));
    }

    /**
     * 修改支付
     */
    @RequiresPermissions("business:payment:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbPayment tbPayment = tbPaymentService.selectTbPaymentById(id);
        mmap.put("tbPayment", tbPayment);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付
     */
    @RequiresPermissions("business:payment:edit")
    @Log(title = "支付", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPayment tbPayment)
    {
        return toAjax(tbPaymentService.updateTbPayment(tbPayment));
    }

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