package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.annotation.Log;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.core.domain.Result;
import com.playlet.common.core.page.TableDataInfo;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletUserInvoice;
import com.playlet.web.service.app.PlayletUserInvoiceAppService;
import io.swagger.annotations.ApiOperation;
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.*;

import java.util.List;

/**
 * @Date: 2024-03-25 15:50
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 用户开票信息app Controller
 */
@Controller
@RequestMapping("/app/invoice")
public class PlayletUserInvoiceAppController extends BaseController {

    private String prefix = "system/invoice";

    @Autowired
    private PlayletUserInvoiceAppService playletUserInvoiceAppService;

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

    /**
     * 查询用户开票信息基础列表
     */
    @ResponseBody
    @PostMapping("/getInvoiceList")
    @ApiOperation(value = "分页查询短剧基础列表")
    public Result<PageInfo<PlayletUserInvoice>> getInvoiceList(@RequestBody PlayletUserInvoice invoice,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return Result.success(playletUserInvoiceAppService.getInvoiceList(invoice, pageNum, pageSize));
    }

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

    /**
     * 修改用户开票信息
     */
    @RequiresPermissions("system:invoice:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PlayletUserInvoice playletUserInvoice = playletUserInvoiceAppService.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(playletUserInvoiceAppService.updatePlayletUserInvoice(playletUserInvoice));
    }

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

