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.PlayletUserExpandAccount;
import com.playlet.system.service.IPlayletUserExpandAccountService;
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-14
 */
@Controller
@RequestMapping("/system/playlet/expand")
public class PlayletUserExpandAccountController extends BaseController
{
    private String prefix = "system/playlet/expand";

    @Autowired
    private IPlayletUserExpandAccountService playletUserExpandAccountService;

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

    /**
     * 查询用户外部账号列表
     */
    @RequiresPermissions("playlet:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletUserExpandAccount playletUserExpandAccount)
    {
        startPage();
        List<PlayletUserExpandAccount> list = playletUserExpandAccountService.selectPlayletUserExpandAccountList(playletUserExpandAccount);
        return getDataTable(list);
    }

    /**
     * 导出用户外部账号列表
     */
    @RequiresPermissions("playlet:account:export")
    @Log(title = "用户外部账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletUserExpandAccount playletUserExpandAccount)
    {
        List<PlayletUserExpandAccount> list = playletUserExpandAccountService.selectPlayletUserExpandAccountList(playletUserExpandAccount);
        ExcelUtil<PlayletUserExpandAccount> util = new ExcelUtil<PlayletUserExpandAccount>(PlayletUserExpandAccount.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(PlayletUserExpandAccount playletUserExpandAccount)
    {
        return toAjax(playletUserExpandAccountService.insertPlayletUserExpandAccount(playletUserExpandAccount));
    }

    /**
     * 修改用户外部账号
     */
    @RequiresPermissions("playlet:account:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletUserExpandAccount playletUserExpandAccount = playletUserExpandAccountService.selectPlayletUserExpandAccountById(id);
        mmap.put("playletUserExpandAccount", playletUserExpandAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户外部账号
     */
    @RequiresPermissions("playlet:account:edit")
    @Log(title = "用户外部账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletUserExpandAccount playletUserExpandAccount)
    {
        return toAjax(playletUserExpandAccountService.updatePlayletUserExpandAccount(playletUserExpandAccount));
    }

    /**
     * 删除用户外部账号
     */
    @RequiresPermissions("playlet:account:remove")
    @Log(title = "用户外部账号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletUserExpandAccountService.deletePlayletUserExpandAccountByIds(ids));
    }
}
