feat(lsfx): Client实现获取文件上传状态和删除文件方法
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package com.ruoyi.lsfx.client;
|
package com.ruoyi.lsfx.client;
|
||||||
|
|
||||||
import com.ruoyi.lsfx.constants.LsfxConstants;
|
import com.ruoyi.lsfx.constants.LsfxConstants;
|
||||||
|
import com.ruoyi.lsfx.domain.request.DeleteFilesRequest;
|
||||||
import com.ruoyi.lsfx.domain.request.FetchInnerFlowRequest;
|
import com.ruoyi.lsfx.domain.request.FetchInnerFlowRequest;
|
||||||
import com.ruoyi.lsfx.domain.request.GetBankStatementRequest;
|
import com.ruoyi.lsfx.domain.request.GetBankStatementRequest;
|
||||||
|
import com.ruoyi.lsfx.domain.request.GetFileUploadStatusRequest;
|
||||||
import com.ruoyi.lsfx.domain.request.GetTokenRequest;
|
import com.ruoyi.lsfx.domain.request.GetTokenRequest;
|
||||||
import com.ruoyi.lsfx.domain.response.*;
|
import com.ruoyi.lsfx.domain.response.*;
|
||||||
import com.ruoyi.lsfx.exception.LsfxApiException;
|
import com.ruoyi.lsfx.exception.LsfxApiException;
|
||||||
@@ -15,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -55,6 +58,12 @@ public class LsfxAnalysisClient {
|
|||||||
@Value("${lsfx.api.endpoints.get-bank-statement}")
|
@Value("${lsfx.api.endpoints.get-bank-statement}")
|
||||||
private String getBankStatementEndpoint;
|
private String getBankStatementEndpoint;
|
||||||
|
|
||||||
|
@Value("${lsfx.api.endpoints.get-file-upload-status}")
|
||||||
|
private String getFileUploadStatusEndpoint;
|
||||||
|
|
||||||
|
@Value("${lsfx.api.endpoints.delete-files}")
|
||||||
|
private String deleteFilesEndpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Token
|
* 获取Token
|
||||||
*/
|
*/
|
||||||
@@ -251,4 +260,108 @@ public class LsfxAnalysisClient {
|
|||||||
throw new LsfxApiException("获取银行流水失败: " + e.getMessage(), e);
|
throw new LsfxApiException("获取银行流水失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个文件上传状态(接口5)
|
||||||
|
* 用途: 获取文件解析后的主体名称和账号等信息
|
||||||
|
*
|
||||||
|
* 关键判断:
|
||||||
|
* - status=-5 且 uploadStatusDesc="data.wait.confirm.newaccount" 表示解析成功
|
||||||
|
* - enterpriseNameList仅有一个空字符串""时,表示流水文件未生成主体
|
||||||
|
*
|
||||||
|
* @param request 请求参数(groupId必填, logId可选)
|
||||||
|
* @return 文件上传状态信息
|
||||||
|
*/
|
||||||
|
public GetFileUploadStatusResponse getFileUploadStatus(GetFileUploadStatusRequest request) {
|
||||||
|
log.info("【流水分析】获取文件上传状态: groupId={}, logId={}",
|
||||||
|
request.getGroupId(), request.getLogId());
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String url = baseUrl + getFileUploadStatusEndpoint;
|
||||||
|
|
||||||
|
// GET请求,构建查询参数
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("groupId", request.getGroupId());
|
||||||
|
if (request.getLogId() != null) {
|
||||||
|
params.put("logId", request.getLogId());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
|
||||||
|
|
||||||
|
GetFileUploadStatusResponse response = httpUtil.get(url, params, headers,
|
||||||
|
GetFileUploadStatusResponse.class);
|
||||||
|
|
||||||
|
long elapsed = System.currentTimeMillis() - startTime;
|
||||||
|
if (response != null && response.getData() != null) {
|
||||||
|
log.info("【流水分析】获取文件上传状态成功: logId数量={}, 耗时={}ms",
|
||||||
|
response.getData().getLogs() != null ? response.getData().getLogs().size() : 0,
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件/主体(接口6)
|
||||||
|
* 用途: 删除解析失败或不需要的流水文件
|
||||||
|
*
|
||||||
|
* 使用场景:
|
||||||
|
* - 文件解析失败时清理文件
|
||||||
|
* - 删除错误上传的文件
|
||||||
|
*
|
||||||
|
* @param request 请求参数(groupId, logIds, userId必填)
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
|
public DeleteFilesResponse deleteFiles(DeleteFilesRequest request) {
|
||||||
|
log.info("【流水分析】删除文件请求: groupId={}, logIds={}, userId={}",
|
||||||
|
request.getGroupId(), Arrays.toString(request.getLogIds()), request.getUserId());
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String url = baseUrl + deleteFilesEndpoint;
|
||||||
|
|
||||||
|
// 构建form-data参数
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("groupId", request.getGroupId());
|
||||||
|
params.put("logIds", request.getLogIds()); // 数组
|
||||||
|
params.put("userId", request.getUserId());
|
||||||
|
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put(LsfxConstants.HEADER_CLIENT_ID, clientId);
|
||||||
|
|
||||||
|
DeleteFilesResponse response = httpUtil.postFormData(url, params, headers,
|
||||||
|
DeleteFilesResponse.class);
|
||||||
|
|
||||||
|
long elapsed = System.currentTimeMillis() - startTime;
|
||||||
|
if (response != null && response.getData() != null) {
|
||||||
|
log.info("【流水分析】删除文件成功: message={}, 耗时={}ms",
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user