package com.ruoyi.frequency.votecomment.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.votecomment.entity.VoteComment;
import com.ruoyi.frequency.votecomment.service.VoteCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 帖子评论Controller
 *
 * @author liwenlong
 * @date 2023-10-09
 */
@RestController
@RequestMapping("/frequency/votecomment")
public class VoteCommentController extends BaseController {
    @Autowired
    private VoteCommentService voteCommentService;

    /**
     * 查询投票评论列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:poscomment:list')")
    @PostMapping("/list")
    public TableDataInfo<VoteComment> list(@RequestBody VoteComment voteComment) {
        startPage();
        List<VoteComment> list = voteCommentService.selectVoteCommentList(voteComment);
        return getDataTable(list);
    }

    /**
     * 导出投票评论列表
     */
    @Log(title = "投票评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VoteComment voteComment) {
        List<VoteComment> list = voteCommentService.selectVoteCommentList(voteComment);
        ExcelUtil<VoteComment> util = new ExcelUtil<VoteComment>(VoteComment.class);
        return util.exportExcel(list, "投票评论数据");
    }

    /**
     * 获取投票评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:votecomment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<VoteComment> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(voteCommentService.selectVoteCommentById(id));
    }

    /**
     * 新增投票评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:votecomment:add')")
    @Log(title = "投票评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoteComment voteComment) {
        return toAjax(voteCommentService.insertVoteComment(voteComment));
    }

    /**
     * 修改投票评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:votecomment:edit')")
    @Log(title = "投票评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoteComment voteComment) {
        return toAjax(voteCommentService.updateVoteComment(voteComment));
    }

    /**
     * 删除投票评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:votecomment:remove')")
    @Log(title = "投票评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(voteCommentService.deleteCommentByIds(ids,delFlag));
    }
}
