package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.riskInfo.domain.dto.RiskInfoVerifyDTO;
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.riskInfo.domain.RiskInfo;
import com.ruoyi.ss.riskInfo.domain.RiskInfoVO;
import com.ruoyi.ss.riskInfo.domain.RiskInfoQuery;
import com.ruoyi.ss.riskInfo.service.RiskInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风控材料Controller
 *
 * @author ruoyi
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/ss/riskInfo")
public class RiskInfoController extends BaseController
{
    @Autowired
    private RiskInfoService riskInfoService;

    /**
     * 查询风控材料列表
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskInfoQuery query)
    {
        startPage();
        startOrderBy();
        List<RiskInfoVO> list = riskInfoService.selectRiskInfoList(query);
        return getDataTable(list);
    }

    /**
     * 导出风控材料列表
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:export')")
    @Log(title = "风控材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskInfoQuery query)
    {
        List<RiskInfoVO> list = riskInfoService.selectRiskInfoList(query);
        ExcelUtil<RiskInfoVO> util = new ExcelUtil<RiskInfoVO>(RiskInfoVO.class);
        util.exportExcel(response, list, "风控材料数据");
    }

    /**
     * 获取风控材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:query')")
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return success(riskInfoService.selectRiskInfoByInfoId(infoId));
    }

    /**
     * 新增风控材料
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:add')")
    @Log(title = "风控材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskInfo riskInfo)
    {
        return toAjax(riskInfoService.insertRiskInfo(riskInfo));
    }

    /**
     * 修改风控材料
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:edit')")
    @Log(title = "风控材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskInfo riskInfo)
    {
        return toAjax(riskInfoService.updateRiskInfo(riskInfo));
    }

    /**
     * 删除风控材料
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:remove')")
    @Log(title = "风控材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(riskInfoService.deleteRiskInfoByInfoIds(infoIds));
    }

    /**
     * 审核风控材料
     */
    @PreAuthorize("@ss.hasPermi('ss:riskInfo:verify')")
    @Log(title = "风控材料", businessType = BusinessType.OTHER)
	@PutMapping("/verify")
    public AjaxResult verify(@RequestBody @Validated RiskInfoVerifyDTO dto) {
        return toAjax(riskInfoService.verify(dto, getLoginUser()));
    }
}
