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.PublicStarRecord;
import com.playlet.system.service.IPublicStarRecordService;
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-24
 */
@Controller
@RequestMapping("/system/public/star")
public class PublicStarRecordController extends BaseController
{
    private String prefix = "system/public/star";

    @Autowired
    private IPublicStarRecordService publicStarRecordService;

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

    /**
     * 查询文章点赞记录列表
     */
    @RequiresPermissions("public:star:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PublicStarRecord publicStarRecord)
    {
        startPage();
        List<PublicStarRecord> list = publicStarRecordService.selectPublicStarRecordList(publicStarRecord);
        return getDataTable(list);
    }

    /**
     * 导出文章点赞记录列表
     */
    @RequiresPermissions("public:star:export")
    @Log(title = "文章点赞记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PublicStarRecord publicStarRecord)
    {
        List<PublicStarRecord> list = publicStarRecordService.selectPublicStarRecordList(publicStarRecord);
        ExcelUtil<PublicStarRecord> util = new ExcelUtil<PublicStarRecord>(PublicStarRecord.class);
        return util.exportExcel(list, "文章点赞记录数据");
    }

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

    /**
     * 新增保存文章点赞记录
     */
    @RequiresPermissions("public:star:add")
    @Log(title = "文章点赞记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PublicStarRecord publicStarRecord)
    {
        return toAjax(publicStarRecordService.insertPublicStarRecord(publicStarRecord));
    }

    /**
     * 修改文章点赞记录
     */
    @RequiresPermissions("public:star:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PublicStarRecord publicStarRecord = publicStarRecordService.selectPublicStarRecordById(id);
        mmap.put("publicStarRecord", publicStarRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存文章点赞记录
     */
    @RequiresPermissions("public:star:edit")
    @Log(title = "文章点赞记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PublicStarRecord publicStarRecord)
    {
        return toAjax(publicStarRecordService.updatePublicStarRecord(publicStarRecord));
    }

    /**
     * 删除文章点赞记录
     */
    @RequiresPermissions("public:star:remove")
    @Log(title = "文章点赞记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(publicStarRecordService.deletePublicStarRecordByIds(ids));
    }
}
