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.PlayletPublicUser;
import com.playlet.system.service.IPlayletPublicUserService;
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-06-14
 */
@Controller
@RequestMapping("/system/public/user")
public class PlayletPublicUserController extends BaseController
{
    private String prefix = "system/public/user";

    @Autowired
    private IPlayletPublicUserService playletPublicUserService;

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

    /**
     * 查询公众号用户列表
     */
    @RequiresPermissions("public:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletPublicUser playletPublicUser)
    {
        startPage();
        List<PlayletPublicUser> list = playletPublicUserService.selectPlayletPublicUserList(playletPublicUser);
        return getDataTable(list);
    }

    /**
     * 导出公众号用户列表
     */
    @RequiresPermissions("public:user:export")
    @Log(title = "公众号用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletPublicUser playletPublicUser)
    {
        List<PlayletPublicUser> list = playletPublicUserService.selectPlayletPublicUserList(playletPublicUser);
        ExcelUtil<PlayletPublicUser> util = new ExcelUtil<PlayletPublicUser>(PlayletPublicUser.class);
        return util.exportExcel(list, "公众号用户数据");
    }

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

    /**
     * 新增保存公众号用户
     */
    @RequiresPermissions("public:user:add")
    @Log(title = "公众号用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletPublicUser playletPublicUser)
    {
        return toAjax(playletPublicUserService.insertPlayletPublicUser(playletPublicUser));
    }

    /**
     * 修改公众号用户
     */
    @RequiresPermissions("public:user:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletPublicUser playletPublicUser = playletPublicUserService.selectPlayletPublicUserById(id);
        mmap.put("playletPublicUser", playletPublicUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存公众号用户
     */
    @RequiresPermissions("public:user:edit")
    @Log(title = "公众号用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletPublicUser playletPublicUser)
    {
        return toAjax(playletPublicUserService.updatePlayletPublicUser(playletPublicUser));
    }

    /**
     * 删除公众号用户
     */
    @RequiresPermissions("public:user:remove")
    @Log(title = "公众号用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletPublicUserService.deletePlayletPublicUserByIds(ids));
    }
}
