package com.ruoyi.powerdistribution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
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.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.powerdistribution.domain.PdmRiskRole;
import com.ruoyi.powerdistribution.service.IPdmRiskRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险规则Controller
 *
 * @author ruoyi
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/power/riskRole")
public class PdmRiskRoleController extends BaseController
{
    @Autowired
    private IPdmRiskRoleService pdmRiskRoleService;

    /**
     * 查询风险规则列表
     */
    @ApiOperation(value = "查询风险规则列表分页")
    @PreAuthorize("@ss.hasPermi('system:role:list')")
    @GetMapping("/page")
    public TableDataInfo page(PdmRiskRole pdmRiskRole)
    {
        startPage();
        List<PdmRiskRole> list = pdmRiskRoleService.selectPdmRiskRoleList(pdmRiskRole);
        return getDataTable(list);
    }

    /**
     * 查询风险规则列表(不分页)
     */
    @ApiOperation(value = "查询风险规则列表(不分页)")
    @GetMapping("/list")
    public TableDataInfo list(PdmRiskRole pdmRiskRole)
    {
        startPage();
        List<PdmRiskRole> list = pdmRiskRoleService.selectPdmRiskRoleList(pdmRiskRole);
        return getDataTable(list);
    }

    /**
     * 导出风险规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:role:export')")
    @Log(title = "风险规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmRiskRole pdmRiskRole)
    {
        List<PdmRiskRole> list = pdmRiskRoleService.selectPdmRiskRoleList(pdmRiskRole);
        ExcelUtil<PdmRiskRole> util = new ExcelUtil<PdmRiskRole>(PdmRiskRole.class);
        util.exportExcel(response, list, "风险规则数据");
    }

    /**
     * 获取风险规则详细信息
     */
    @ApiOperation(value = "获取风险规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmRiskRoleService.selectPdmRiskRoleById(id));
    }

    /**
     * 新增风险规则
     */
    @ApiOperation(value = "新增风险规则")
    @PreAuthorize("@ss.hasPermi('system:role:add')")
    @Log(title = "风险规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PdmRiskRole pdmRiskRole)
    {
        return toAjax(pdmRiskRoleService.insertPdmRiskRole(pdmRiskRole));
    }

    /**
     * 修改风险规则
     */
    @ApiOperation(value = "修改风险规则")
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "风险规则", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public AjaxResult edit(@RequestBody PdmRiskRole pdmRiskRole)
    {
        return toAjax(pdmRiskRoleService.updatePdmRiskRole(pdmRiskRole));
    }

    /**
     * 删除风险规则
     */
    @ApiOperation(value = "删除风险规则")
    @PreAuthorize("@ss.hasPermi('system:role:remove')")
    @Log(title = "风险规则", businessType = BusinessType.DELETE)
	@GetMapping("delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmRiskRoleService.deletePdmRiskRoleByIds(ids));
    }
}
