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.PlayletBanner;
import com.playlet.system.service.IPlayletBannerService;
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-10
 */
@Controller
@RequestMapping("/system/playlet/banner")
public class PlayletBannerController extends BaseController
{
    private String prefix = "system/playlet/banner";

    @Autowired
    private IPlayletBannerService playletBannerService;

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

    /**
     * 查询短剧广告管理列表
     */
    @RequiresPermissions("playlet:banner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletBanner playletBanner)
    {
        startPage();
        List<PlayletBanner> list = playletBannerService.selectPlayletBannerList(playletBanner);
        return getDataTable(list);
    }

    /**
     * 导出短剧广告管理列表
     */
    @RequiresPermissions("playlet:banner:export")
    @Log(title = "短剧广告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletBanner playletBanner)
    {
        List<PlayletBanner> list = playletBannerService.selectPlayletBannerList(playletBanner);
        ExcelUtil<PlayletBanner> util = new ExcelUtil<PlayletBanner>(PlayletBanner.class);
        return util.exportExcel(list, "短剧广告管理数据");
    }

    /**
     * 新增短剧广告管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短剧广告管理
     */
    @RequiresPermissions("playlet:banner:add")
    @Log(title = "短剧广告管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletBanner playletBanner)
    {
        return toAjax(playletBannerService.insertPlayletBanner(playletBanner));
    }

    /**
     * 修改短剧广告管理
     */
    @RequiresPermissions("playlet:banner:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletBanner playletBanner = playletBannerService.selectPlayletBannerById(id);
        mmap.put("playletBanner", playletBanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存短剧广告管理
     */
    @RequiresPermissions("playlet:banner:edit")
    @Log(title = "短剧广告管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletBanner playletBanner)
    {
        return toAjax(playletBannerService.updatePlayletBanner(playletBanner));
    }

    /**
     * 删除短剧广告管理
     */
    @RequiresPermissions("playlet:banner:remove")
    @Log(title = "短剧广告管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletBannerService.deletePlayletBannerByIds(ids));
    }
}
