package com.ruoyi.frequency.comment.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.frequency.comment.entity.Comment;
import com.ruoyi.frequency.comment.service.CommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评论(新闻)Controller
 * 
 * @author liwenlong
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/frequency/comment")
public class CommentController extends BaseController
{
    @Autowired
    private CommentService commentService;

    /**
     * 查询评论(新闻)列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:comment:list')")
    @PostMapping("/list")
    public TableDataInfo<Comment> list(@RequestBody Comment comment)
    {
        startPage();
        List<Comment> list = commentService.selectCommentList(comment);
        return getDataTable(list);
    }

    /**
     * 导出评论(新闻)列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:comment:export')")
    @Log(title = "评论(新闻)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Comment comment)
    {
        List<Comment> list = commentService.selectCommentList(comment);
        ExcelUtil<Comment> util = new ExcelUtil<Comment>(Comment.class);
        return util.exportExcel(list, "评论(新闻)数据");
    }

    /**
     * 获取评论(新闻)详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Comment> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(commentService.selectCommentById(id));
    }

    /**
     * 新增评论(新闻)
     */
    @PreAuthorize("@ss.hasPermi('frequency:comment:add')")
    @Log(title = "评论(新闻)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Comment comment)
    {
        return toAjax(commentService.insertComment(comment));
    }

    /**
     * 修改评论(新闻)
     */
    @PreAuthorize("@ss.hasPermi('frequency:comment:edit')")
    @Log(title = "评论(新闻)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Comment comment)
    {
        return toAjax(commentService.updateComment(comment));
    }

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