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.PlayletPublicAccount;
import com.playlet.system.service.IPlayletPublicAccountService;
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-07
 */
@Controller
@RequestMapping("/system/playlet/account")
public class PlayletPublicAccountController extends BaseController
{
    private String prefix = "system/playlet/account";

    @Autowired
    private IPlayletPublicAccountService playletPublicAccountService;

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

    /**
     * 查询公众号列列表
     */
    @RequiresPermissions("playlet:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletPublicAccount playletPublicAccount)
    {
        startPage();
        List<PlayletPublicAccount> list = playletPublicAccountService.selectPlayletPublicAccountList(playletPublicAccount);
        return getDataTable(list);
    }

    /**
     * 导出公众号列列表
     */
    @RequiresPermissions("playlet:account:export")
    @Log(title = "公众号列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletPublicAccount playletPublicAccount)
    {
        List<PlayletPublicAccount> list = playletPublicAccountService.selectPlayletPublicAccountList(playletPublicAccount);
        ExcelUtil<PlayletPublicAccount> util = new ExcelUtil<PlayletPublicAccount>(PlayletPublicAccount.class);
        return util.exportExcel(list, "公众号列数据");
    }

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

    /**
     * 新增保存公众号列
     */
    @RequiresPermissions("playlet:account:add")
    @Log(title = "公众号列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletPublicAccount playletPublicAccount)
    {
        return toAjax(playletPublicAccountService.insertPlayletPublicAccount(playletPublicAccount));
    }

    /**
     * 修改公众号列
     */
    @RequiresPermissions("playlet:account:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletPublicAccount playletPublicAccount = playletPublicAccountService.selectPlayletPublicAccountById(id);
        mmap.put("playletPublicAccount", playletPublicAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存公众号列
     */
    @RequiresPermissions("playlet:account:edit")
    @Log(title = "公众号列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletPublicAccount playletPublicAccount)
    {
        return toAjax(playletPublicAccountService.updatePlayletPublicAccount(playletPublicAccount));
    }

    /**
     * 删除公众号列
     */
    @RequiresPermissions("playlet:account:remove")
    @Log(title = "公众号列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletPublicAccountService.deletePlayletPublicAccountByIds(ids));
    }
}
