package com.clx.performance.controller.pc.carrier;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.param.pc.carrier.PageSettlementOrderChildRiskParam;
import com.clx.performance.param.pc.owner.settle.OwnerSettlementOrderChildRiskProcessUpdateParam;
import com.clx.performance.service.settle.SettlementOrderChildRiskService;
import com.clx.performance.vo.pc.carrier.settle.SettlementOrderChildRiskVO;
import com.msl.common.base.PageData;
import com.msl.common.convertor.aspect.UnitCovert;
import com.msl.common.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping(value="/pc/carrier/settlementOrderChildRisk")
@Validated
@Tag(name = "承运端-风控管理")
@AllArgsConstructor
public class SettlementOrderChildRiskController {

    private final SettlementOrderChildRiskService settlementOrderChildRiskService;

    @Operation(summary = "风控处理",description = "<br>By:李瑞新")
    @PostMapping("/updateProcessRisk")
    public Result updateRiskProcess(@RequestBody @Validated OwnerSettlementOrderChildRiskProcessUpdateParam param) {
        settlementOrderChildRiskService.updateRiskProcess(param);
        return Result.ok();
    }

    @Operation(summary = "风控异常处理列表",description = "<br>By:杨启发")
    @PostMapping("/pageSettlementOrderChildRisk")
    @UnitCovert(param = false)
    public Result<PageData<SettlementOrderChildRiskVO>> pageSettlementOrderChildRisk(@RequestBody @Validated PageSettlementOrderChildRiskParam param) {
        IPage<SettlementOrderChildRiskVO> page = settlementOrderChildRiskService.pageSettlementOrderChildRisk(param);
        return Result.page(page.getRecords(),page.getTotal(),page.getPages());
    }

    @Operation(summary = "导出风控异常处理",description = "<br>By:杨启发")
    @PostMapping("/exportSettlementOrderChildRisk")
    public void exportSettlementOrderChildRisk(@RequestBody @Validated PageSettlementOrderChildRiskParam param, HttpServletResponse response) throws Exception {
        try (SXSSFWorkbook workbook = settlementOrderChildRiskService.exportSettlementOrderChildRisk(param)) {
            response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
            workbook.write(response.getOutputStream());
        }
    }
}
