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.PlayletItemType;
import com.playlet.system.service.IPlayletItemTypeService;
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;

/**
 * 剧场列Controller
 *
 * @author ruoyi
 * @date 2024-03-18
 */
@Controller
@RequestMapping("/system/playletType")
public class PlayletItemTypeController extends BaseController {
    private String prefix = "system/playlet/type";

    @Autowired
    private IPlayletItemTypeService playletItemTypeService;

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

    /**
     * 查询剧场列列表
     */
    @RequiresPermissions("playlet:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletItemType playletItemType)
    {
        startPage();
        List<PlayletItemType> list = playletItemTypeService.selectPlayletItemTypeList(playletItemType);
        return getDataTable(list);
    }

    /**
     * 导出剧场列列表
     */
    @RequiresPermissions("playlet:type:export")
    @Log(title = "剧场列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletItemType playletItemType)
    {
        List<PlayletItemType> list = playletItemTypeService.selectPlayletItemTypeList(playletItemType);
        ExcelUtil<PlayletItemType> util = new ExcelUtil<PlayletItemType>(PlayletItemType.class);
        return util.exportExcel(list, "剧场列数据");
    }

    /**
     * 新增剧场列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存剧场列
     */
    @RequiresPermissions("playlet:type:add")
    @Log(title = "剧场列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletItemType playletItemType)
    {
        return toAjax(playletItemTypeService.insertPlayletItemType(playletItemType));
    }

    /**
     * 修改剧场列
     */
    @RequiresPermissions("playlet:type:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletItemType playletItemType = playletItemTypeService.selectPlayletItemTypeById(id);
        mmap.put("playletItemType", playletItemType);
        return prefix + "/edit";
    }

    /**
     * 修改保存剧场列
     */
    @RequiresPermissions("playlet:type:edit")
    @Log(title = "剧场列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletItemType playletItemType)
    {
        return toAjax(playletItemTypeService.updatePlayletItemType(playletItemType));
    }

    /**
     * 删除剧场列
     */
    @RequiresPermissions("playlet:type:remove")
    @Log(title = "剧场列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletItemTypeService.deletePlayletItemTypeByIds(ids));
    }
}
