package com.ruoyi.invest.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.invest.domain.CreditReportQueryRecord;
import com.ruoyi.invest.domain.dto.CreditReportQueryRecordDto;
import com.ruoyi.invest.domain.vo.CreditReportQueryRecordVo;
import com.ruoyi.invest.service.ICreditReportQueryRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * 征信报告查询记录Controller
 *
 * @author tianyongbao
 * @date 2024-03-20
 */
@Api(tags=" 征信报告查询记录")
@RestController
@RequestMapping("/creditQueryRecord")
public class CreditReportQueryRecordController extends BaseController
{
    @Resource
    private ICreditReportQueryRecordService creditReportQueryRecordService;

    /**
     * 查询征信报告查询记录列表
     */
    @ApiOperation(value="查询征信报告查询记录列表",response = CreditReportQueryRecordVo.class)
    @RequiresPermissions("invest:creditQueryRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(CreditReportQueryRecordDto creditReportQueryRecordDto)
    {
        startPage();
        List<CreditReportQueryRecordVo> list = creditReportQueryRecordService.selectCreditReportQueryRecordList(creditReportQueryRecordDto);
        return getDataTable(list);
    }

    /**
     * 查询征信机构列表
     */
    @ApiOperation(value="查询征信报告查询记录列表",response = CreditReportQueryRecordVo.class)
    @RequiresPermissions("invest:creditQueryRecord:list")
    @GetMapping("/listQueryInstitution")
    public TableDataInfo listQueryInstitution(CreditReportQueryRecordDto creditReportQueryRecordDto)
    {
        startPage();
        List<CreditReportQueryRecordVo> list = creditReportQueryRecordService.selectQueryInstitutionList(creditReportQueryRecordDto);
        return getDataTable(list);
    }


    /**
     * 导出征信报告查询记录列表
     */
    @ApiOperation(value="导出征信报告查询记录列表")
    @RequiresPermissions("invest:creditQueryRecord:export")
    @Log(title = "征信报告查询记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CreditReportQueryRecordDto creditReportQueryRecordDto)
    {
        List<CreditReportQueryRecordVo> list = creditReportQueryRecordService.selectCreditReportQueryRecordList(creditReportQueryRecordDto);
        ExcelUtil<CreditReportQueryRecordVo> util = new ExcelUtil<CreditReportQueryRecordVo>(CreditReportQueryRecordVo.class);
        util.exportExcel(response, list, "征信报告查询记录数据");
    }

    /**
     * 获取征信报告查询记录详细信息
     */
    @ApiOperation(value="获取征信报告查询记录详细信息")
    @RequiresPermissions("invest:creditQueryRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(creditReportQueryRecordService.selectCreditReportQueryRecordById(id));
    }

    /**
     * 新增征信报告查询记录
     */
    @ApiOperation(value="新增征信报告查询记录")
    @RequiresPermissions("invest:creditQueryRecord:add")
    @Log(title = "征信报告查询记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CreditReportQueryRecord creditReportQueryRecord)
    {
        return toAjax(creditReportQueryRecordService.insertCreditReportQueryRecord(creditReportQueryRecord));
    }

    /**
     * 修改征信报告查询记录
     */
    @ApiOperation(value="修改征信报告查询记录")
    @RequiresPermissions("invest:creditQueryRecord:edit")
    @Log(title = "征信报告查询记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CreditReportQueryRecord creditReportQueryRecord)
    {
        return toAjax(creditReportQueryRecordService.updateCreditReportQueryRecord(creditReportQueryRecord));
    }

    /**
     * 删除征信报告查询记录
     */
    @ApiOperation(value="删除征信报告查询记录")
    @RequiresPermissions("invest:creditQueryRecord:remove")
    @Log(title = "征信报告查询记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(creditReportQueryRecordService.deleteCreditReportQueryRecordByIds(ids));
    }

    /**
     * 获取征信报告查询记录统计
     */
    @ApiOperation(value="获取征信报告查询记录统计")
    @RequiresPermissions("invest:creditQueryRecord:query")
    @GetMapping(value = "/analysis")
    public AjaxResult getAnalysis(CreditReportQueryRecordDto creditReportQueryRecordDto)
    {
        return success(creditReportQueryRecordService.selectCreditReportAnalysis(creditReportQueryRecordDto));
    }
}
