package com.playlet.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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.PlayletItem;
import com.playlet.system.service.IPlayletItemService;
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-14-22:57
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 短剧基础Controller
 */
@Controller
@RequestMapping("/system/playlet/item")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletItemController extends BaseController {
    private String prefix = "system/playlet/item";


    private final IPlayletItemService playletItemService;

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

    /**
     * 查询短剧基础列表
     */
    @RequiresPermissions("system:item:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletItem playletItem)
    {
        startPage();
        List<PlayletItem> list = playletItemService.selectPlayletItemList(playletItem);
        return getDataTable(list);
    }

    /**
     * 导出短剧基础列表
     */
    @RequiresPermissions("system:item:export")
    @Log(title = "短剧基础", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletItem playletItem)
    {
        List<PlayletItem> list = playletItemService.selectPlayletItemList(playletItem);
        ExcelUtil<PlayletItem> util = new ExcelUtil<PlayletItem>(PlayletItem.class);
        return util.exportExcel(list, "短剧基础数据");
    }

    /**
     * 新增短剧基础
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短剧基础
     */
    @RequiresPermissions("system:item:add")
    @Log(title = "短剧基础", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletItem playletItem)
    {
        return toAjax(playletItemService.insertPlayletItem(playletItem));
    }

    /**
     * 修改短剧基础
     */
    @RequiresPermissions("system:item:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletItem playletItem = playletItemService.selectPlayletItemById(id);
        mmap.put("playletItem", playletItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存短剧基础
     */
    @RequiresPermissions("system:item:edit")
    @Log(title = "短剧基础", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletItem playletItem)
    {
        return toAjax(playletItemService.updatePlayletItem(playletItem));
    }

    /**
     * 删除短剧基础
     */
    @RequiresPermissions("system:item:remove")
    @Log(title = "短剧基础", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletItemService.deletePlayletItemByIds(ids));
    }
}
