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.PlayletPublicDetail;
import com.playlet.system.service.IPlayletPublicDetailService;
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/detail")
public class PlayletPublicDetailController extends BaseController
{
    private String prefix = "system/playlet/detail";

    @Autowired
    private IPlayletPublicDetailService playletPublicDetailService;

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

    /**
     * 查询公众号文章详情列表
     */
    @RequiresPermissions("playlet:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletPublicDetail playletPublicDetail)
    {
        startPage();
        List<PlayletPublicDetail> list = playletPublicDetailService.selectPlayletPublicDetailList(playletPublicDetail);
        return getDataTable(list);
    }

    /**
     * 导出公众号文章详情列表
     */
    @RequiresPermissions("playlet:detail:export")
    @Log(title = "公众号文章详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletPublicDetail playletPublicDetail)
    {
        List<PlayletPublicDetail> list = playletPublicDetailService.selectPlayletPublicDetailList(playletPublicDetail);
        ExcelUtil<PlayletPublicDetail> util = new ExcelUtil<PlayletPublicDetail>(PlayletPublicDetail.class);
        return util.exportExcel(list, "公众号文章详情数据");
    }

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

    /**
     * 新增保存公众号文章详情
     */
    @RequiresPermissions("playlet:detail:add")
    @Log(title = "公众号文章详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletPublicDetail playletPublicDetail)
    {
        return toAjax(playletPublicDetailService.insertPlayletPublicDetail(playletPublicDetail));
    }

    /**
     * 修改公众号文章详情
     */
    @RequiresPermissions("playlet:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletPublicDetail playletPublicDetail = playletPublicDetailService.selectPlayletPublicDetailById(id);
        mmap.put("playletPublicDetail", playletPublicDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存公众号文章详情
     */
    @RequiresPermissions("playlet:detail:edit")
    @Log(title = "公众号文章详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletPublicDetail playletPublicDetail)
    {
        return toAjax(playletPublicDetailService.updatePlayletPublicDetail(playletPublicDetail));
    }

    /**
     * 删除公众号文章详情
     */
    @RequiresPermissions("playlet:detail:remove")
    @Log(title = "公众号文章详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletPublicDetailService.deletePlayletPublicDetailByIds(ids));
    }
}
