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.PlayletUserItem;
import com.playlet.system.service.IPlayletUserItemService;
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-04-15
 */
@Controller
@RequestMapping("/system/playlet/userItem")
public class PlayletUserItemController extends BaseController
{
    private String prefix = "system/playlet/userItem";

    @Autowired
    private IPlayletUserItemService playletUserItemService;

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

    /**
     * 查询用户推广短剧列表
     */
    @RequiresPermissions("playlet:userItem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletUserItem playletUserItem)
    {
        startPage();
        List<PlayletUserItem> list = playletUserItemService.selectPlayletUserItemList(playletUserItem);
        return getDataTable(list);
    }

    /**
     * 导出用户推广短剧列表
     */
    @RequiresPermissions("playlet:userItem:export")
    @Log(title = "用户推广短剧", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletUserItem playletUserItem)
    {
        List<PlayletUserItem> list = playletUserItemService.selectPlayletUserItemList(playletUserItem);
        ExcelUtil<PlayletUserItem> util = new ExcelUtil<PlayletUserItem>(PlayletUserItem.class);
        return util.exportExcel(list, "用户推广短剧数据");
    }

    /**
     * 新增用户推广短剧
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户推广短剧
     */
    @RequiresPermissions("playlet:userItem:add")
    @Log(title = "用户推广短剧", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletUserItem playletUserItem)
    {
        return toAjax(playletUserItemService.insertPlayletUserItem(playletUserItem));
    }

    /**
     * 修改用户推广短剧
     */
    @RequiresPermissions("playlet:userItem:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletUserItem playletUserItem = playletUserItemService.selectPlayletUserItemById(id);
        mmap.put("playletUserItem", playletUserItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户推广短剧
     */
    @RequiresPermissions("playlet:userItem:edit")
    @Log(title = "用户推广短剧", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletUserItem playletUserItem)
    {
        return toAjax(playletUserItemService.updatePlayletUserItem(playletUserItem));
    }

    /**
     * 删除用户推广短剧
     */
    @RequiresPermissions("playlet:userItem:remove")
    @Log(title = "用户推广短剧", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletUserItemService.deletePlayletUserItemByIds(ids));
    }
}
