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.PlayletUser;
import com.playlet.system.service.IPlayletUserService;
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/user")
public class PlayletUserController extends BaseController
{
    private String prefix = "system/playlet/user";

    @Autowired
    private IPlayletUserService playletUserService;

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

    /**
     * 查询短剧用户列表
     */
    @RequiresPermissions("playlet:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletUser playletUser)
    {
        startPage();
        List<PlayletUser> list = playletUserService.selectPlayletUserList(playletUser);
        return getDataTable(list);
    }

    /**
     * 导出短剧用户列表
     */
    @RequiresPermissions("playlet:user:export")
    @Log(title = "短剧用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletUser playletUser)
    {
        List<PlayletUser> list = playletUserService.selectPlayletUserList(playletUser);
        ExcelUtil<PlayletUser> util = new ExcelUtil<PlayletUser>(PlayletUser.class);
        return util.exportExcel(list, "短剧用户数据");
    }

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

    /**
     * 新增保存短剧用户
     */
    @RequiresPermissions("playlet:user:add")
    @Log(title = "短剧用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletUser playletUser)
    {
        return toAjax(playletUserService.insertPlayletUser(playletUser));
    }

    /**
     * 修改短剧用户
     */
    @RequiresPermissions("playlet:user:edit")
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        PlayletUser playletUser = playletUserService.selectPlayletUserByID(ID);
        mmap.put("playletUser", playletUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存短剧用户
     */
    @RequiresPermissions("playlet:user:edit")
    @Log(title = "短剧用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletUser playletUser)
    {
        return toAjax(playletUserService.updatePlayletUser(playletUser));
    }

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