package com.ruoyi.post.frequency.posreport.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.post.frequency.posreport.entity.PostReport;
import com.ruoyi.post.frequency.posreport.service.PostReportService;
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-26
 */
@RestController
@RequestMapping("/frequency/posreport")
public class PostReportController extends BaseController
{
    @Autowired
    private PostReportService postReportService;

    /**
     * 查询论坛举报列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:list')")
    @PostMapping("/list")
    public TableDataInfo<PostReport> list(@RequestBody PostReport postReport)
    {
        startPage();
        List<PostReport> list = postReportService.selectPostReportList(postReport);
        return getDataTable(list);
    }

    /**
     * 导出论坛举报列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:export')")
    @Log(title = "论坛举报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PostReport postReport)
    {
        List<PostReport> list = postReportService.selectPostReportList(postReport);
        ExcelUtil<PostReport> util = new ExcelUtil<PostReport>(PostReport.class);
        return util.exportExcel(list, "论坛举报数据");
    }

    /**
     * 获取论坛举报详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<PostReport> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(postReportService.selectPostReportById(id));
    }

    /**
     * 新增论坛举报
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:add')")
    @Log(title = "论坛举报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostReport postReport)
    {
        return toAjax(postReportService.insertPostReport(postReport));
    }

    /**
     * 修改论坛举报
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:edit')")
    @Log(title = "论坛举报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostReport postReport)
    {
        return toAjax(postReportService.updatePostReport(postReport));
    }

    /**
     * 删除论坛举报
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:remove')")
    @Log(title = "论坛举报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable Long[] ids,@PathVariable Integer delFlag)
    {
        return toAjax(postReportService.deletePostReportByIds(ids,delFlag));
    }


    /**
     * 举报处理
     */
    @PreAuthorize("@ss.hasPermi('frequency:posreport:handle')")
    @Log(title = "论坛举报", businessType = BusinessType.UPDATE)
    @PostMapping("/handle")
    public AjaxResult handle(@RequestBody PostReport postReport)
    {
        return postReportService.handle(postReport);
    }
}
