修复外部查询接口GET参数调用

This commit is contained in:
wkc
2026-05-11 16:33:16 +08:00
parent abc8b127e1
commit 366d8e499a
6 changed files with 129 additions and 15 deletions

View File

@@ -6,7 +6,9 @@ import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.loanpricing.domain.vo.CustomerMapRecordVO;
import java.net.URI;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -30,6 +32,9 @@ public class LoanPricingCustomerMapService
@Value("${customer-map.corporate-url}")
private String corporateUrl;
@Value("${loan-pricing-external.app-code:}")
private String appCode;
public LoanPricingCustomerMapService()
{
this(new RestTemplate());
@@ -41,10 +46,16 @@ public class LoanPricingCustomerMapService
}
LoanPricingCustomerMapService(RestTemplate restTemplate, String personalUrl, String corporateUrl)
{
this(restTemplate, personalUrl, corporateUrl, null);
}
LoanPricingCustomerMapService(RestTemplate restTemplate, String personalUrl, String corporateUrl, String appCode)
{
this.restTemplate = restTemplate;
this.personalUrl = personalUrl;
this.corporateUrl = corporateUrl;
this.appCode = appCode;
}
public List<CustomerMapRecordVO> queryPersonal(String custId)
@@ -64,15 +75,12 @@ public class LoanPricingCustomerMapService
{
throw new ServiceException("客户号不能为空");
}
URI uri = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("cust_id", normalizedCustId)
.build()
.encode()
.toUri();
URI uri = buildGetParamUri(url, "cust_id", normalizedCustId);
Map<String, String> requestParams = buildRequestParamLog("cust_id", normalizedCustId);
CustomerMapResponse response = restTemplate.getForObject(uri, CustomerMapResponse.class);
log.info("后端外部接口调用完成\n请求URL{}\n请求参数\n{}\n返回参数\n{}",
uri,
HttpUtils.formatLogValue(Collections.singletonMap("cust_id", normalizedCustId)),
HttpUtils.formatLogValue(requestParams),
HttpUtils.formatLogValue(response));
if (response == null)
{
@@ -85,6 +93,34 @@ public class LoanPricingCustomerMapService
return response.getData() == null ? Collections.emptyList() : response.getData();
}
private URI buildGetParamUri(String url, String paramName, String paramValue)
{
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
.replaceQueryParam("appCode")
.replaceQueryParam(paramName);
String normalizedAppCode = StringUtils.trimWhitespace(appCode);
if (StringUtils.hasText(normalizedAppCode))
{
builder.queryParam("appCode", normalizedAppCode);
}
return builder.queryParam(paramName, paramValue)
.build()
.encode()
.toUri();
}
private Map<String, String> buildRequestParamLog(String paramName, String paramValue)
{
Map<String, String> requestParams = new LinkedHashMap<>();
String normalizedAppCode = StringUtils.trimWhitespace(appCode);
if (StringUtils.hasText(normalizedAppCode))
{
requestParams.put("appCode", normalizedAppCode);
}
requestParams.put(paramName, paramValue);
return requestParams;
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
static class CustomerMapResponse

View File

@@ -6,7 +6,9 @@ import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.loanpricing.domain.vo.HistoryLoanContractVO;
import java.net.URI;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -24,6 +26,9 @@ public class LoanRateHistoryService
@Value("${loan-rate-history.url}")
private String historyUrl;
@Value("${loan-pricing-external.app-code:}")
private String appCode;
public LoanRateHistoryService()
{
this(new RestTemplate());
@@ -35,9 +40,15 @@ public class LoanRateHistoryService
}
LoanRateHistoryService(RestTemplate restTemplate, String historyUrl)
{
this(restTemplate, historyUrl, null);
}
LoanRateHistoryService(RestTemplate restTemplate, String historyUrl, String appCode)
{
this.restTemplate = restTemplate;
this.historyUrl = historyUrl;
this.appCode = appCode;
}
public List<HistoryLoanContractVO> query(String custIsn)
@@ -47,15 +58,12 @@ public class LoanRateHistoryService
{
throw new ServiceException("客户内码不能为空");
}
URI uri = UriComponentsBuilder.fromHttpUrl(historyUrl)
.queryParam("cust_isn", normalizedCustIsn)
.build()
.encode()
.toUri();
URI uri = buildGetParamUri(historyUrl, "cust_isn", normalizedCustIsn);
Map<String, String> requestParams = buildRequestParamLog("cust_isn", normalizedCustIsn);
HistoryLoanContractResponse response = restTemplate.getForObject(uri, HistoryLoanContractResponse.class);
log.info("后端外部接口调用完成\n请求URL{}\n请求参数\n{}\n返回参数\n{}",
uri,
HttpUtils.formatLogValue(Collections.singletonMap("cust_isn", normalizedCustIsn)),
HttpUtils.formatLogValue(requestParams),
HttpUtils.formatLogValue(response));
if (response == null)
{
@@ -68,6 +76,34 @@ public class LoanRateHistoryService
return response.getData() == null ? Collections.emptyList() : response.getData();
}
private URI buildGetParamUri(String url, String paramName, String paramValue)
{
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
.replaceQueryParam("appCode")
.replaceQueryParam(paramName);
String normalizedAppCode = StringUtils.trimWhitespace(appCode);
if (StringUtils.hasText(normalizedAppCode))
{
builder.queryParam("appCode", normalizedAppCode);
}
return builder.queryParam(paramName, paramValue)
.build()
.encode()
.toUri();
}
private Map<String, String> buildRequestParamLog(String paramName, String paramValue)
{
Map<String, String> requestParams = new LinkedHashMap<>();
String normalizedAppCode = StringUtils.trimWhitespace(appCode);
if (StringUtils.hasText(normalizedAppCode))
{
requestParams.put("appCode", normalizedAppCode);
}
requestParams.put(paramName, paramValue);
return requestParams;
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
static class HistoryLoanContractResponse