package com.playlet.web.controller.system;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.PublicDetailShare;
import com.playlet.system.service.IPublicDetailShareService;
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-20
 */
@Controller
@Api(tags = "管理系统*统计分享记录接口")
@RequestMapping("/system/public/share")
public class PublicDetailShareController extends BaseController
{
    private String prefix = "system/public/share";

    @Autowired
    private IPublicDetailShareService publicDetailShareService;

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

    /**
     * 查询文章分享记录列表
     */
    @RequiresPermissions("public:share:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "获取分享记录", httpMethod = "POST")
    public TableDataInfo list(PublicDetailShare publicDetailShare)
    {
        startPage();
        List<PublicDetailShare> list = publicDetailShareService.selectPublicDetailShareList(publicDetailShare);
        return getDataTable(list);
    }

    /**
     * 导出文章分享记录列表
     */
    @RequiresPermissions("public:share:export")
    @Log(title = "文章分享记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PublicDetailShare publicDetailShare)
    {
        List<PublicDetailShare> list = publicDetailShareService.selectPublicDetailShareList(publicDetailShare);
        ExcelUtil<PublicDetailShare> util = new ExcelUtil<PublicDetailShare>(PublicDetailShare.class);
        return util.exportExcel(list, "文章分享记录数据");
    }

    /**
     * 新增文章分享记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文章分享记录
     */
    @RequiresPermissions("public:share:add")
    @Log(title = "文章分享记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PublicDetailShare publicDetailShare)
    {
        return toAjax(publicDetailShareService.insertPublicDetailShare(publicDetailShare));
    }

    /**
     * 修改文章分享记录
     */
    @RequiresPermissions("public:share:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PublicDetailShare publicDetailShare = publicDetailShareService.selectPublicDetailShareById(id);
        mmap.put("publicDetailShare", publicDetailShare);
        return prefix + "/edit";
    }

    /**
     * 修改保存文章分享记录
     */
    @RequiresPermissions("public:share:edit")
    @Log(title = "文章分享记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PublicDetailShare publicDetailShare)
    {
        return toAjax(publicDetailShareService.updatePublicDetailShare(publicDetailShare));
    }

    /**
     * 删除文章分享记录
     */
    @RequiresPermissions("public:share:remove")
    @Log(title = "文章分享记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(publicDetailShareService.deletePublicDetailShareByIds(ids));
    }
}
