package com.ruoyi.frequency.report.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.report.entity.Report;
import com.ruoyi.frequency.report.service.ReportService;
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-11-17
 */
@RestController
@RequestMapping("/frequency/report")
public class ReportController extends BaseController
{
    @Autowired
    private ReportService reportService;

    /**
     * 查询举报用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:report:list')")
    @PostMapping("/list")
    public TableDataInfo<Report> list(@RequestBody Report report)
    {
        startPage();
        List<Report> list = reportService.selectReportList(report);
        return getDataTable(list);
    }

    /**
     * 导出举报用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:report:export')")
    @Log(title = "举报用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Report report)
    {
        List<Report> list = reportService.selectReportList(report);
        ExcelUtil<Report> util = new ExcelUtil<Report>(Report.class);
        return util.exportExcel(list, "举报用户数据");
    }

    /**
     * 获取举报用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Report> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(reportService.selectReportById(id));
    }

    /**
     * 新增举报用户
     */
    @PreAuthorize("@ss.hasPermi('frequency:report:add')")
    @Log(title = "举报用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Report report)
    {
        return toAjax(reportService.insertReport(report));
    }

    /**
     * 修改举报用户
     */
    @PreAuthorize("@ss.hasPermi('frequency:report:edit')")
    @Log(title = "举报用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Report report)
    {
        return toAjax(reportService.updateReport(report));
    }

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

    /**
     * 举报处理
     */
    @PreAuthorize("@ss.hasPermi('frequency:report:handle')")
    @Log(title = "举报用户", businessType = BusinessType.UPDATE)
    @PostMapping("/handle")
    public AjaxResult handle(@RequestBody Report report)
    {
        return reportService.handle(report);
    }
}
