package com.ruoyi.frequency.workscomment.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.workscomment.entity.WorksComment;
import com.ruoyi.frequency.workscomment.service.WorksCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品评论Controller
 * 
 * @author liwenlong
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/frequency/workscomment")
public class WorksCommentController extends BaseController
{
    @Autowired
    private WorksCommentService worksCommentService;

    /**
     * 查询作品评论列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:workscomment:list')")
    @PostMapping("/list")
    public TableDataInfo<WorksComment> list(@RequestBody WorksComment worksComment)
    {
        startPage();
        List<WorksComment> list = worksCommentService.selectWorksCommentList(worksComment);
        return getDataTable(list);
    }

    /**
     * 导出作品评论列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:workscomment:export')")
    @Log(title = "作品评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorksComment worksComment)
    {
        List<WorksComment> list = worksCommentService.selectWorksCommentList(worksComment);
        ExcelUtil<WorksComment> util = new ExcelUtil<WorksComment>(WorksComment.class);
        return util.exportExcel(list, "作品评论数据");
    }

    /**
     * 获取作品评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:workscomment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<WorksComment> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(worksCommentService.selectWorksCommentById(id));
    }

    /**
     * 新增作品评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:workscomment:add')")
    @Log(title = "作品评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorksComment worksComment)
    {
        return toAjax(worksCommentService.insertWorksComment(worksComment));
    }

    /**
     * 修改作品评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:workscomment:edit')")
    @Log(title = "作品评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorksComment worksComment)
    {
        return toAjax(worksCommentService.updateWorksComment(worksComment));
    }

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