修复外部查询接口GET参数调用
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# 2026-05-11 外部查询接口 GET 参数调用修复实施记录
|
||||
|
||||
## 实施内容
|
||||
|
||||
- 修复客户号查询客户内码的个人、企业两个外部接口调用方式。
|
||||
- `LoanPricingCustomerMapService` 构建请求地址时先移除同名 `appCode`、`cust_id` 参数,再通过 GET query param 追加配置中的公共 `appCode` 和真实客户号。
|
||||
- 修复历史贷款记录查询外部接口调用方式。
|
||||
- `LoanRateHistoryService` 构建请求地址时先移除同名 `appCode`、`cust_isn` 参数,再通过 GET query param 追加配置中的公共 `appCode` 和真实客户内码。
|
||||
- 调整 profile 外部地址配置。
|
||||
- `application-pro.yml`、`application-dev.yml`、`application-uat.yml` 新增同一个 `loan-pricing-external.app-code` 配置项。
|
||||
- 生产 profile 三条查询 URL 仅保留接口地址,不再在 URL 中写 `appCode` 或空业务参数。
|
||||
- 补充服务层单元测试。
|
||||
- 覆盖个人客户映射、企业客户映射、历史贷款记录三条接口最终均按 GET query param 生成公共 `appCode` 和各自业务参数。
|
||||
- 测试文件位于 `*/src/test/`,按仓库 `.gitignore` 规则不纳入提交范围,仅用于本地验证。
|
||||
|
||||
## 涉及文件
|
||||
|
||||
- `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/service/LoanPricingCustomerMapService.java`
|
||||
- `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/service/LoanRateHistoryService.java`
|
||||
- `ruoyi-admin/src/main/resources/application-pro.yml`
|
||||
- `ruoyi-admin/src/main/resources/application-dev.yml`
|
||||
- `ruoyi-admin/src/main/resources/application-uat.yml`
|
||||
- `ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/service/LoanPricingCustomerMapServiceTest.java`
|
||||
- `ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/service/LoanRateHistoryServiceTest.java`
|
||||
|
||||
## 验证记录
|
||||
|
||||
- 已执行:`mvn -pl ruoyi-loan-pricing -am -Dtest=LoanPricingCustomerMapServiceTest,LoanRateHistoryServiceTest -Dsurefire.failIfNoSpecifiedTests=false test`
|
||||
- 结果:通过,`Tests run: 9, Failures: 0, Errors: 0, Skipped: 0`。
|
||||
- 日志验证:
|
||||
- 个人客户映射最终请求 URL 为 `http://mock/personal?appCode=abc&cust_id=P001`。
|
||||
- 企业客户映射最终请求 URL 为 `http://mock/corporate?appCode=abc&cust_id=C001`。
|
||||
- 历史贷款记录最终请求 URL 为 `http://mock/history?appCode=abc&cust_isn=81033011438`。
|
||||
@@ -82,6 +82,9 @@ model:
|
||||
personal-url: http://localhost:63310/rate/pricing/mock/invokeModel/personal
|
||||
corporate-url: http://localhost:63310/rate/pricing/mock/invokeModel/corporate
|
||||
|
||||
loan-pricing-external:
|
||||
app-code: 1a89fa84abda480ba93ed73fd01ffd07
|
||||
|
||||
customer-map:
|
||||
personal-url: http://localhost:63310/rate/pricing/mock/customer-map/personal
|
||||
corporate-url: http://localhost:63310/rate/pricing/mock/customer-map/corporate
|
||||
|
||||
@@ -82,12 +82,15 @@ model:
|
||||
personal-url: http://64.202.32.40:8083/api/service/interface/invokeService/syllcs
|
||||
corporate-url: http://64.202.32.40:8083/api/service/interface/invokeService/sydgllcs
|
||||
|
||||
loan-pricing-external:
|
||||
app-code: 1a89fa84abda480ba93ed73fd01ffd07
|
||||
|
||||
customer-map:
|
||||
personal-url: http://552f7aff0acd4c09ac3b83dbfee57fa0.apigateway.res.dc-pdt-zj96596.com/shangyu_lilvcesuan_ind_idmapno?appCode=1a89fa84abda480ba93ed73fd01ffd07&cust_id=
|
||||
corporate-url: http://552f7aff0acd4c09ac3b83dbfee57fa0.apigateway.res.dc-pdt-zj96596.com/shangyu_lilvcesuan_ent_idmapno?appCode=1a89fa84abda480ba93ed73fd01ffd07&cust_id=
|
||||
personal-url: http://552f7aff0acd4c09ac3b83dbfee57fa0.apigateway.res.dc-pdt-zj96596.com/shangyu_lilvcesuan_ind_idmapno
|
||||
corporate-url: http://552f7aff0acd4c09ac3b83dbfee57fa0.apigateway.res.dc-pdt-zj96596.com/shangyu_lilvcesuan_ent_idmapno
|
||||
|
||||
loan-rate-history:
|
||||
url: http://552f7aff0acd4c09ac3b83dbfee57fa0.apigateway.res.dc-pdt-zj96596.com/shangyu_loan_rate_history?appCode=1a89fa84abda480ba93ed73fd01ffd07
|
||||
url: http://552f7aff0acd4c09ac3b83dbfee57fa0.apigateway.res.dc-pdt-zj96596.com/shangyu_loan_rate_history
|
||||
|
||||
security:
|
||||
password-transfer:
|
||||
|
||||
@@ -82,6 +82,9 @@ model:
|
||||
personal-url: http://localhost:63310/rate/pricing/mock/invokeModel/personal
|
||||
corporate-url: http://localhost:63310/rate/pricing/mock/invokeModel/corporate
|
||||
|
||||
loan-pricing-external:
|
||||
app-code: 1a89fa84abda480ba93ed73fd01ffd07
|
||||
|
||||
customer-map:
|
||||
personal-url: http://localhost:63310/rate/pricing/mock/customer-map/personal
|
||||
corporate-url: http://localhost:63310/rate/pricing/mock/customer-map/corporate
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user