package com.ruoyi.lsfx.client; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.lsfx.domain.response.CreditParseInvokeResponse; import com.ruoyi.lsfx.exception.LsfxApiException; import com.ruoyi.lsfx.util.HttpUtil; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; @Slf4j @Component public class CreditParseClient { @Resource private HttpUtil httpUtil; @Value("${credit-parse.api.url}") private String creditParseUrl; @Value("${credit-parse.api.org-code:902000}") private String orgCode; @Value("${credit-parse.api.run-type:1}") private String runType; @Value("${credit-parse.api.model:LXCUSTALL}") private String defaultModel; public CreditParseInvokeResponse parse(String remotePath) { return parse(defaultModel, remotePath); } public CreditParseInvokeResponse parse(String model, String remotePath) { long startTime = System.currentTimeMillis(); String actualModel = StringUtils.isBlank(model) ? defaultModel : model; log.info("【征信解析】开始调用: model={}, remotePath={}", actualModel, remotePath); try { Map params = new HashMap<>(); params.put("serialNum", buildSerialNum()); params.put("orgCode", orgCode); params.put("runType", runType); params.put("remotePath", remotePath); params.put("model", actualModel); CreditParseInvokeResponse response = httpUtil.postUrlEncodedForm( creditParseUrl, params, null, CreditParseInvokeResponse.class); long elapsed = System.currentTimeMillis() - startTime; log.info("【征信解析】调用完成: success={}, code={}, businessStatusCode={}, cost={}ms", response != null ? response.getSuccess() : null, response != null ? response.getCode() : null, response != null && response.getData() != null && response.getData().getMappingOutputFields() != null ? response.getData().getMappingOutputFields().getStatusCode() : null, elapsed); return response; } catch (Exception e) { log.error("【征信解析】调用失败: model={}, remotePath={}, error={}", actualModel, remotePath, e.getMessage(), e); throw new LsfxApiException("征信解析调用失败: " + e.getMessage(), e); } } private String buildSerialNum() { return "CCDI_CREDIT_" + System.currentTimeMillis() + "_" + IdUtils.fastSimpleUUID(); } }