package com.playlet.web.controller.system;

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.playlet.common.annotation.Log;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletUserInvoice;
import com.playlet.system.service.IPlayletUserInvoiceService;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.utils.poi.ExcelUtil;
import com.playlet.common.core.page.TableDataInfo;

/**
 * @Date: 2024-03-25 15:48
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 用户开票信息Controller
 */
@Controller
@RequestMapping("/system/invoice")
public class PlayletUserInvoiceController extends BaseController {
    private String prefix = "system/invoice";

    @Autowired
    private IPlayletUserInvoiceService playletUserInvoiceService;

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

    /**
     * 查询用户开票信息列表
     */
    @RequiresPermissions("system:invoice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletUserInvoice playletUserInvoice) {
        startPage();
        List<PlayletUserInvoice> list = playletUserInvoiceService.selectPlayletUserInvoiceList(playletUserInvoice);
        return getDataTable(list);
    }

    /**
     * 导出用户开票信息列表
     */
    @RequiresPermissions("system:invoice:export")
    @Log(title = "用户开票信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletUserInvoice playletUserInvoice) {
        List<PlayletUserInvoice> list = playletUserInvoiceService.selectPlayletUserInvoiceList(playletUserInvoice);
        ExcelUtil<PlayletUserInvoice> util = new ExcelUtil<PlayletUserInvoice>(PlayletUserInvoice.class);
        return util.exportExcel(list, "用户开票信息数据");
    }

    /**
     * 新增用户开票信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存用户开票信息
     */
    @RequiresPermissions("system:invoice:add")
    @Log(title = "用户开票信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletUserInvoice playletUserInvoice) {
        return toAjax(playletUserInvoiceService.insertPlayletUserInvoice(playletUserInvoice));
    }

    /**
     * 修改用户开票信息
     */
    @RequiresPermissions("system:invoice:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PlayletUserInvoice playletUserInvoice = playletUserInvoiceService.selectPlayletUserInvoiceById(id);
        mmap.put("playletUserInvoice", playletUserInvoice);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户开票信息
     */
    @RequiresPermissions("system:invoice:edit")
    @Log(title = "用户开票信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletUserInvoice playletUserInvoice) {
        return toAjax(playletUserInvoiceService.updatePlayletUserInvoice(playletUserInvoice));
    }

    /**
     * 删除用户开票信息
     */
    @RequiresPermissions("system:invoice:remove")
    @Log(title = "用户开票信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(playletUserInvoiceService.deletePlayletUserInvoiceByIds(ids));
    }
}
