package com.ruoyi.web.controller.ss;

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

import com.ruoyi.common.core.domain.ValidGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.ss.risk.domain.Risk;
import com.ruoyi.ss.risk.domain.RiskVO;
import com.ruoyi.ss.risk.domain.RiskQuery;
import com.ruoyi.ss.risk.service.RiskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风控Controller
 *
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/ss/risk")
public class RiskController extends BaseController
{
    @Autowired
    private RiskService riskService;

    /**
     * 查询风控列表
     */
    @PreAuthorize("@ss.hasPermi('ss:risk:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskQuery query)
    {
        startPage();
        startOrderBy();
        List<RiskVO> list = riskService.selectRiskList(query);
        return getDataTable(list);
    }

    /**
     * 导出风控列表
     */
    @PreAuthorize("@ss.hasPermi('ss:risk:export')")
    @Log(title = "风控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskQuery query)
    {
        List<RiskVO> list = riskService.selectRiskList(query);
        ExcelUtil<RiskVO> util = new ExcelUtil<RiskVO>(RiskVO.class);
        util.exportExcel(response, list, "风控数据");
    }

    /**
     * 获取风控详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:risk:query')")
    @GetMapping(value = "/{riskId}")
    public AjaxResult getInfo(@PathVariable("riskId") Long riskId)
    {
        return success(riskService.selectRiskByRiskId(riskId));
    }

    /**
     * 新增风控
     */
    @PreAuthorize("@ss.hasPermi('ss:risk:add')")
    @Log(title = "风控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Risk risk)
    {
        return toAjax(riskService.insertRisk(risk));
    }

    /**
     * 修改风控
     */
    @PreAuthorize("@ss.hasPermi('ss:risk:edit')")
    @Log(title = "风控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) Risk risk)
    {
        return toAjax(riskService.updateRisk(risk));
    }

    /**
     * 删除风控
     */
    @PreAuthorize("@ss.hasPermi('ss:risk:remove')")
    @Log(title = "风控", businessType = BusinessType.DELETE)
	@DeleteMapping("/{riskIds}")
    public AjaxResult remove(@PathVariable Long[] riskIds)
    {
        return toAjax(riskService.deleteRiskByRiskIds(riskIds));
    }
}
