fix(lsfx): 修复流水分析对接模块的代码质量问题

1. 修复配置问题
   - 替换app-secret占位符为正确的密钥dXj6eHRmPv

2. 添加异常处理
   - HttpUtil所有方法添加完整的异常处理
   - 统一使用LsfxApiException包装异常
   - 检查HTTP状态码和响应体

3. 添加日志记录
   - Client所有方法添加详细的日志记录
   - 记录请求参数、响应结果、耗时
   - 异常情况记录错误日志

4. 完善参数校验
   - 接口1:添加6个必填字段校验
   - 接口2:添加groupId和文件校验,限制文件大小10MB
   - 接口3:添加7个参数校验和日期范围校验
   - 接口4:添加groupId和inprogressList校验

5. 性能优化
   - RestTemplate使用Apache HttpClient连接池
   - 最大连接数100,每个路由最大20个连接
   - 支持连接复用,提升性能

6. 代码审查文档
   - 添加详细的代码审查报告
   - 记录发现的问题和改进建议

修改的文件:
- ccdi-lsfx/pom.xml
- ccdi-lsfx/src/main/java/com/ruoyi/lsfx/client/LsfxAnalysisClient.java
- ccdi-lsfx/src/main/java/com/ruoyi/lsfx/config/RestTemplateConfig.java
- ccdi-lsfx/src/main/java/com/ruoyi/lsfx/controller/LsfxTestController.java
- ccdi-lsfx/src/main/java/com/ruoyi/lsfx/util/HttpUtil.java
- ruoyi-admin/src/main/resources/application-dev.yml
- doc/implementation/lsfx-code-review-20260302.md
This commit is contained in:
wkc
2026-03-03 09:35:27 +08:00
parent 921c15ffad
commit b022ec75b8
13 changed files with 3927 additions and 64 deletions

View File

@@ -3,8 +3,10 @@ package com.ruoyi.lsfx.client;
import com.ruoyi.lsfx.constants.LsfxConstants;
import com.ruoyi.lsfx.domain.request.*;
import com.ruoyi.lsfx.domain.response.*;
import com.ruoyi.lsfx.exception.LsfxApiException;
import com.ruoyi.lsfx.util.HttpUtil;
import com.ruoyi.lsfx.util.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -15,6 +17,7 @@ import java.util.Map;
/**
* 流水分析平台客户端
*/
@Slf4j
@Component
public class LsfxAnalysisClient {
@@ -52,67 +55,153 @@ public class LsfxAnalysisClient {
* 获取Token
*/
public GetTokenResponse getToken(GetTokenRequest request) {
String secretCode = MD5Util.generateSecretCode(
request.getProjectNo(),
request.getEntityName(),
appSecret
);
request.setAppSecretCode(secretCode);
request.setAppId(appId);
log.info("【流水分析】获取Token请求: projectNo={}, entityName={}", request.getProjectNo(), request.getEntityName());
long startTime = System.currentTimeMillis();
if (request.getAnalysisType() == null) {
request.setAnalysisType(LsfxConstants.ANALYSIS_TYPE);
}
if (request.getRole() == null) {
request.setRole(LsfxConstants.DEFAULT_ROLE);
}
try {
String secretCode = MD5Util.generateSecretCode(
request.getProjectNo(),
request.getEntityName(),
appSecret
);
request.setAppSecretCode(secretCode);
request.setAppId(appId);
String url = baseUrl + getTokenEndpoint;
return httpUtil.postJson(url, request, null, GetTokenResponse.class);
if (request.getAnalysisType() == null) {
request.setAnalysisType(LsfxConstants.ANALYSIS_TYPE);
}
if (request.getRole() == null) {
request.setRole(LsfxConstants.DEFAULT_ROLE);
}
String url = baseUrl + getTokenEndpoint;
GetTokenResponse response = httpUtil.postJson(url, request, null, GetTokenResponse.class);
long elapsed = System.currentTimeMillis() - startTime;
if (response != null && response.getData() != null) {
log.info("【流水分析】获取Token成功: projectId={}, 耗时={}ms",
response.getData().getProjectId(), elapsed);
} else {
log.warn("【流水分析】获取Token响应异常: 耗时={}ms", elapsed);
}
return response;
} catch (LsfxApiException e) {
log.error("【流水分析】获取Token失败: projectNo={}, error={}", request.getProjectNo(), e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("【流水分析】获取Token未知异常: projectNo={}", request.getProjectNo(), e);
throw new LsfxApiException("获取Token失败: " + e.getMessage(), e);
}
}
/**
* 上传文件
*/
public UploadFileResponse uploadFile(Integer groupId, org.springframework.core.io.Resource file) {
String url = baseUrl + uploadFileEndpoint;
log.info("【流水分析】上传文件请求: groupId={}, fileName={}", groupId, file.getFilename());
long startTime = System.currentTimeMillis();
Map<String, Object> params = new HashMap<>();
params.put("groupId", groupId);
params.put("files", file);
try {
String url = baseUrl + uploadFileEndpoint;
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
Map<String, Object> params = new HashMap<>();
params.put("groupId", groupId);
params.put("files", file);
return httpUtil.uploadFile(url, params, headers, UploadFileResponse.class);
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
UploadFileResponse response = httpUtil.uploadFile(url, params, headers, UploadFileResponse.class);
long elapsed = System.currentTimeMillis() - startTime;
if (response != null && response.getData() != null) {
log.info("【流水分析】上传文件成功: uploadStatus={}, 耗时={}ms",
response.getData().getUploadStatus(), elapsed);
} else {
log.warn("【流水分析】上传文件响应异常: 耗时={}ms", elapsed);
}
return response;
} catch (LsfxApiException e) {
log.error("【流水分析】上传文件失败: groupId={}, error={}", groupId, e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("【流水分析】上传文件未知异常: groupId={}", groupId, e);
throw new LsfxApiException("上传文件失败: " + e.getMessage(), e);
}
}
/**
* 拉取行内流水
*/
public FetchInnerFlowResponse fetchInnerFlow(FetchInnerFlowRequest request) {
String url = baseUrl + fetchInnerFlowEndpoint;
log.info("【流水分析】拉取行内流水请求: groupId={}, customerNo={}", request.getGroupId(), request.getCustomerNo());
long startTime = System.currentTimeMillis();
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
try {
String url = baseUrl + fetchInnerFlowEndpoint;
return httpUtil.postJson(url, request, headers, FetchInnerFlowResponse.class);
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
FetchInnerFlowResponse response = httpUtil.postJson(url, request, headers, FetchInnerFlowResponse.class);
long elapsed = System.currentTimeMillis() - startTime;
if (response != null && response.getData() != null) {
log.info("【流水分析】拉取行内流水完成: code={}, message={}, 耗时={}ms",
response.getData().getCode(), response.getData().getMessage(), elapsed);
} else {
log.warn("【流水分析】拉取行内流水响应异常: 耗时={}ms", elapsed);
}
return response;
} catch (LsfxApiException e) {
log.error("【流水分析】拉取行内流水失败: groupId={}, error={}", request.getGroupId(), e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("【流水分析】拉取行内流水未知异常: groupId={}", request.getGroupId(), e);
throw new LsfxApiException("拉取行内流水失败: " + e.getMessage(), e);
}
}
/**
* 检查文件解析状态
*/
public CheckParseStatusResponse checkParseStatus(Integer groupId, String inprogressList) {
String url = baseUrl + checkParseStatusEndpoint;
log.info("【流水分析】检查文件解析状态: groupId={}, inprogressList={}", groupId, inprogressList);
long startTime = System.currentTimeMillis();
Map<String, Object> params = new HashMap<>();
params.put("groupId", groupId);
params.put("inprogressList", inprogressList);
try {
String url = baseUrl + checkParseStatusEndpoint;
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
Map<String, Object> params = new HashMap<>();
params.put("groupId", groupId);
params.put("inprogressList", inprogressList);
return httpUtil.postJson(url, params, headers, CheckParseStatusResponse.class);
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
CheckParseStatusResponse response = httpUtil.postJson(url, params, headers, CheckParseStatusResponse.class);
long elapsed = System.currentTimeMillis() - startTime;
if (response != null && response.getData() != null) {
log.info("【流水分析】检查解析状态完成: parsing={}, pendingList.size={}, 耗时={}ms",
response.getData().getParsing(),
response.getData().getPendingList() != null ? response.getData().getPendingList().size() : 0,
elapsed);
} else {
log.warn("【流水分析】检查解析状态响应异常: 耗时={}ms", elapsed);
}
return response;
} catch (LsfxApiException e) {
log.error("【流水分析】检查解析状态失败: groupId={}, error={}", groupId, e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("【流水分析】检查解析状态未知异常: groupId={}", groupId, e);
throw new LsfxApiException("检查解析状态失败: " + e.getMessage(), e);
}
}
/**
@@ -123,11 +212,35 @@ public class LsfxAnalysisClient {
* @return 流水明细列表
*/
public GetBankStatementResponse getBankStatement(GetBankStatementRequest request) {
String url = baseUrl + getBankStatementEndpoint;
log.info("【流水分析】获取银行流水请求: groupId={}, logId={}, pageNow={}, pageSize={}",
request.getGroupId(), request.getLogId(), request.getPageNow(), request.getPageSize());
long startTime = System.currentTimeMillis();
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
try {
String url = baseUrl + getBankStatementEndpoint;
return httpUtil.postJson(url, request, headers, GetBankStatementResponse.class);
Map<String, String> headers = new HashMap<>();
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
GetBankStatementResponse response = httpUtil.postJson(url, request, headers, GetBankStatementResponse.class);
long elapsed = System.currentTimeMillis() - startTime;
if (response != null && response.getData() != null) {
log.info("【流水分析】获取银行流水成功: totalCount={}, 耗时={}ms",
response.getData().getTotalCount(), elapsed);
} else {
log.warn("【流水分析】获取银行流水响应异常: 耗时={}ms", elapsed);
}
return response;
} catch (LsfxApiException e) {
log.error("【流水分析】获取银行流水失败: groupId={}, logId={}, error={}",
request.getGroupId(), request.getLogId(), e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("【流水分析】获取银行流水未知异常: groupId={}, logId={}",
request.getGroupId(), request.getLogId(), e);
throw new LsfxApiException("获取银行流水失败: " + e.getMessage(), e);
}
}
}