package com.ruoyi.web.controller.risk;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
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.system.domain.RiskReport;
import com.ruoyi.system.service.IRiskReportService;

/**
 * 报告管理控制器
 */
@Controller
@RequestMapping("/risk/report")
public class RiskReportController extends BaseController
{
    private String prefix = "risk/report";

    @Autowired
    private IRiskReportService riskReportService;

    @RequiresPermissions("risk:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    @RequiresPermissions("risk:report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskReport riskReport)
    {
        startPage();
        List<RiskReport> list = riskReportService.selectRiskReportList(riskReport);
        return getDataTable(list);
    }

    @Log(title = "报告管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("risk:report:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskReport riskReport)
    {
        List<RiskReport> list = riskReportService.selectRiskReportList(riskReport);
        ExcelUtil<RiskReport> util = new ExcelUtil<RiskReport>(RiskReport.class);
        return util.exportExcel(list, "报告管理数据");
    }

    @RequiresPermissions("risk:report:list")
    @GetMapping("/{reportId}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return AjaxResult.success().put("data", riskReportService.selectRiskReportById(reportId));
    }

    @RequiresPermissions("risk:report:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @RequiresPermissions("risk:report:add")
    @Log(title = "报告管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated RiskReport riskReport)
    {
        riskReport.setCreateBy(getLoginName());
        return toAjax(riskReportService.insertRiskReport(riskReport));
    }

    @RequiresPermissions("risk:report:edit")
    @GetMapping("/edit/{reportId}")
    public String edit(@PathVariable("reportId") Long reportId, ModelMap mmap)
    {
        mmap.put("riskReport", riskReportService.selectRiskReportById(reportId));
        return prefix + "/edit";
    }

    @RequiresPermissions("risk:report:edit")
    @Log(title = "报告管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated RiskReport riskReport)
    {
        riskReport.setUpdateBy(getLoginName());
        return toAjax(riskReportService.updateRiskReport(riskReport));
    }

    @RequiresPermissions("risk:report:remove")
    @Log(title = "报告管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskReportService.deleteRiskReportByIds(ids));
    }
}
