package com.ruoyi.info.collection.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.collection.domain.dto.CcdiCreditInfoQueryDTO;
import com.ruoyi.info.collection.domain.vo.CreditInfoListVO;
import com.ruoyi.info.collection.service.ICcdiCreditInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

/**
 * 征信维护 Controller
 */
@Tag(name = "征信维护")
@RestController
@RequestMapping("/ccdi/creditInfo")
public class CcdiCreditInfoController extends BaseController {

    @Resource
    private ICcdiCreditInfoService creditInfoService;

    @Operation(summary = "上传征信 HTML")
    @PreAuthorize("@ss.hasPermi('ccdi:creditInfo:upload')")
    @Log(title = "征信维护", businessType = BusinessType.IMPORT)
    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("files") MultipartFile[] files) {
        return AjaxResult.success("上传成功", creditInfoService.upload(Arrays.asList(files)));
    }

    @Operation(summary = "查询征信维护列表")
    @PreAuthorize("@ss.hasPermi('ccdi:creditInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcdiCreditInfoQueryDTO queryDTO) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Page<CreditInfoListVO> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<CreditInfoListVO> result = creditInfoService.selectCreditInfoPage(page, queryDTO);
        return getDataTable(result.getRecords(), result.getTotal());
    }

    @Operation(summary = "查询征信维护详情")
    @PreAuthorize("@ss.hasPermi('ccdi:creditInfo:query')")
    @GetMapping("/{personId}")
    public AjaxResult detail(@PathVariable String personId) {
        return success(creditInfoService.selectDetailByPersonId(personId));
    }

    @Operation(summary = "删除征信维护数据")
    @PreAuthorize("@ss.hasPermi('ccdi:creditInfo:remove')")
    @Log(title = "征信维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{personId}")
    public AjaxResult remove(@PathVariable String personId) {
        return toAjax(creditInfoService.deleteByPersonId(personId));
    }
}
