Compare commits
12 Commits
928e5ec2e1
...
5cb9d62268
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cb9d62268 | |||
| e2e637890a | |||
| b786d65b9a | |||
| 2548efd629 | |||
| acc8fa3b8f | |||
| ccbdbabf67 | |||
| 7d27a335cb | |||
| c4915efecd | |||
| fb84861877 | |||
| 5a53bc26c4 | |||
| 784d4a9383 | |||
| 4243424d71 |
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,12 @@ public class LsfxConstants {
|
|||||||
|
|
||||||
/** 默认角色 */
|
/** 默认角色 */
|
||||||
public static final String DEFAULT_ROLE = "VIEWER";
|
public static final String DEFAULT_ROLE = "VIEWER";
|
||||||
|
|
||||||
|
// 新增:固定值常量(根据文档)
|
||||||
|
public static final String DEFAULT_USER_ID = "902001";
|
||||||
|
public static final String DEFAULT_USER_NAME = "902001";
|
||||||
|
public static final String DEFAULT_APP_ID = "remote_app";
|
||||||
|
public static final String DEFAULT_ORG_CODE = "902000";
|
||||||
|
public static final String DEFAULT_DEPARTMENT_CODE = "902000";
|
||||||
|
public static final String DEFAULT_DATA_CHANNEL_CODE = "ZJRCU";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import com.ruoyi.common.annotation.Anonymous;
|
|||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.lsfx.client.LsfxAnalysisClient;
|
import com.ruoyi.lsfx.client.LsfxAnalysisClient;
|
||||||
|
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 io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -37,17 +40,19 @@ public class LsfxTestController {
|
|||||||
if (StringUtils.isBlank(request.getEntityName())) {
|
if (StringUtils.isBlank(request.getEntityName())) {
|
||||||
return AjaxResult.error("参数不完整:entityName为必填");
|
return AjaxResult.error("参数不完整:entityName为必填");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 必填字段设置默认值
|
||||||
if (StringUtils.isBlank(request.getUserId())) {
|
if (StringUtils.isBlank(request.getUserId())) {
|
||||||
return AjaxResult.error("参数不完整:userId为必填");
|
request.setUserId(LsfxConstants.DEFAULT_USER_ID);
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(request.getUserName())) {
|
if (StringUtils.isBlank(request.getUserName())) {
|
||||||
return AjaxResult.error("参数不完整:userName为必填");
|
request.setUserName(LsfxConstants.DEFAULT_USER_NAME);
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(request.getOrgCode())) {
|
if (StringUtils.isBlank(request.getOrgCode())) {
|
||||||
return AjaxResult.error("参数不完整:orgCode为必填");
|
request.setOrgCode(LsfxConstants.DEFAULT_ORG_CODE);
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(request.getDepartmentCode())) {
|
if (StringUtils.isBlank(request.getDepartmentCode())) {
|
||||||
return AjaxResult.error("参数不完整:departmentCode为必填");
|
request.setDepartmentCode(LsfxConstants.DEFAULT_DEPARTMENT_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GetTokenResponse response = lsfxAnalysisClient.getToken(request);
|
GetTokenResponse response = lsfxAnalysisClient.getToken(request);
|
||||||
@@ -98,6 +103,11 @@ public class LsfxTestController {
|
|||||||
return AjaxResult.error("参数错误:开始日期不能大于结束日期");
|
return AjaxResult.error("参数错误:开始日期不能大于结束日期");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置dataChannelCode默认值
|
||||||
|
if (StringUtils.isEmpty(request.getDataChannelCode())) {
|
||||||
|
request.setDataChannelCode(LsfxConstants.DEFAULT_DATA_CHANNEL_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
FetchInnerFlowResponse response = lsfxAnalysisClient.fetchInnerFlow(request);
|
FetchInnerFlowResponse response = lsfxAnalysisClient.fetchInnerFlow(request);
|
||||||
return AjaxResult.success(response);
|
return AjaxResult.success(response);
|
||||||
}
|
}
|
||||||
@@ -141,4 +151,43 @@ public class LsfxTestController {
|
|||||||
GetBankStatementResponse response = lsfxAnalysisClient.getBankStatement(request);
|
GetBankStatementResponse response = lsfxAnalysisClient.getBankStatement(request);
|
||||||
return AjaxResult.success(response);
|
return AjaxResult.success(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取单个文件上传状态",
|
||||||
|
description = "获取文件解析后的主体名称和账号等信息。status=-5且uploadStatusDesc='data.wait.confirm.newaccount'表示解析成功")
|
||||||
|
@GetMapping("/getFileUploadStatus")
|
||||||
|
public AjaxResult getFileUploadStatus(
|
||||||
|
@Parameter(description = "项目ID") @RequestParam Integer groupId,
|
||||||
|
@Parameter(description = "文件ID(可选,不传则查询所有)") @RequestParam(required = false) Integer logId
|
||||||
|
) {
|
||||||
|
// 参数校验
|
||||||
|
if (groupId == null || groupId <= 0) {
|
||||||
|
return AjaxResult.error("参数不完整:groupId为必填且大于0");
|
||||||
|
}
|
||||||
|
|
||||||
|
GetFileUploadStatusRequest request = new GetFileUploadStatusRequest();
|
||||||
|
request.setGroupId(groupId);
|
||||||
|
request.setLogId(logId);
|
||||||
|
|
||||||
|
GetFileUploadStatusResponse response = lsfxAnalysisClient.getFileUploadStatus(request);
|
||||||
|
return AjaxResult.success(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除文件",
|
||||||
|
description = "删除解析失败或不需要的流水文件")
|
||||||
|
@PostMapping("/deleteFiles")
|
||||||
|
public AjaxResult deleteFiles(@RequestBody DeleteFilesRequest request) {
|
||||||
|
// 参数校验
|
||||||
|
if (request.getGroupId() == null || request.getGroupId() <= 0) {
|
||||||
|
return AjaxResult.error("参数不完整:groupId为必填且大于0");
|
||||||
|
}
|
||||||
|
if (request.getLogIds() == null || request.getLogIds().length == 0) {
|
||||||
|
return AjaxResult.error("参数不完整:logIds为必填且不能为空");
|
||||||
|
}
|
||||||
|
if (request.getUserId() == null) {
|
||||||
|
return AjaxResult.error("参数不完整:userId为必填");
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteFilesResponse response = lsfxAnalysisClient.deleteFiles(request);
|
||||||
|
return AjaxResult.success(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.ruoyi.lsfx.domain.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件请求(接口6)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DeleteFilesRequest {
|
||||||
|
|
||||||
|
/** 项目ID (必填) */
|
||||||
|
private Integer groupId;
|
||||||
|
|
||||||
|
/** 文件ID数组 (必填) */
|
||||||
|
private Integer[] logIds;
|
||||||
|
|
||||||
|
/** 用户柜员号 (必填) */
|
||||||
|
private Integer userId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.lsfx.domain.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个文件上传状态请求(接口5)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GetFileUploadStatusRequest {
|
||||||
|
|
||||||
|
/** 项目ID (必填) */
|
||||||
|
private Integer groupId;
|
||||||
|
|
||||||
|
/** 文件ID (可选,不传则查询所有) */
|
||||||
|
private Integer logId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.ruoyi.lsfx.domain.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件响应(接口6)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DeleteFilesResponse {
|
||||||
|
|
||||||
|
/** 返回码 */
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/** 成功标识 */
|
||||||
|
private Boolean successResponse;
|
||||||
|
|
||||||
|
/** 响应数据 */
|
||||||
|
private DeleteFilesData data;
|
||||||
|
|
||||||
|
/** 响应消息 */
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class DeleteFilesData {
|
||||||
|
/** 删除成功消息 */
|
||||||
|
private String message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package com.ruoyi.lsfx.domain.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个文件上传状态响应(接口5)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GetFileUploadStatusResponse {
|
||||||
|
|
||||||
|
/** 返回码 */
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/** 成功标识 */
|
||||||
|
private Boolean successResponse;
|
||||||
|
|
||||||
|
/** 响应数据 */
|
||||||
|
private FileUploadStatusData data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class FileUploadStatusData {
|
||||||
|
/** 日志列表 */
|
||||||
|
private List<LogItem> logs;
|
||||||
|
|
||||||
|
/** 状态 */
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/** 账号ID */
|
||||||
|
private Integer accountId;
|
||||||
|
|
||||||
|
/** 币种 */
|
||||||
|
private String currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class LogItem {
|
||||||
|
/** 账号列表 */
|
||||||
|
private List<String> accountNoList;
|
||||||
|
|
||||||
|
/** 银行名称 */
|
||||||
|
private String bankName;
|
||||||
|
|
||||||
|
/** 数据类型信息 [格式, 分隔符] */
|
||||||
|
private List<String> dataTypeInfo;
|
||||||
|
|
||||||
|
/** 下载文件名 */
|
||||||
|
private String downloadFileName;
|
||||||
|
|
||||||
|
/** 主体名称列表(重要:用于判断是否需要生成主体) */
|
||||||
|
private List<String> enterpriseNameList;
|
||||||
|
|
||||||
|
/** 文件大小(字节) */
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
/** 文件上传者ID */
|
||||||
|
private Integer fileUploadBy;
|
||||||
|
|
||||||
|
/** 文件上传者用户名 */
|
||||||
|
private String fileUploadByUserName;
|
||||||
|
|
||||||
|
/** 文件上传时间 */
|
||||||
|
private String fileUploadTime;
|
||||||
|
|
||||||
|
/** 是否拆分 */
|
||||||
|
private Integer isSplit;
|
||||||
|
|
||||||
|
/** 企业ID */
|
||||||
|
private Integer leId;
|
||||||
|
|
||||||
|
/** 文件ID */
|
||||||
|
private Integer logId;
|
||||||
|
|
||||||
|
/** 日志元数据 */
|
||||||
|
private String logMeta;
|
||||||
|
|
||||||
|
/** 日志类型 */
|
||||||
|
private String logType;
|
||||||
|
|
||||||
|
/** 登录企业ID */
|
||||||
|
private Integer loginLeId;
|
||||||
|
|
||||||
|
/** 丢失头部 */
|
||||||
|
private List<String> lostHeader;
|
||||||
|
|
||||||
|
/** 真实银行名称 */
|
||||||
|
private String realBankName;
|
||||||
|
|
||||||
|
/** 行数 */
|
||||||
|
private Integer rows;
|
||||||
|
|
||||||
|
/** 来源 */
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/** 状态(-5表示解析成功) */
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/** 模板名称 */
|
||||||
|
private String templateName;
|
||||||
|
|
||||||
|
/** 总记录数 */
|
||||||
|
private Integer totalRecords;
|
||||||
|
|
||||||
|
/** 交易结束日期ID */
|
||||||
|
private Integer trxDateEndId;
|
||||||
|
|
||||||
|
/** 交易开始日期ID */
|
||||||
|
private Integer trxDateStartId;
|
||||||
|
|
||||||
|
/** 上传文件名 */
|
||||||
|
private String uploadFileName;
|
||||||
|
|
||||||
|
/** 上传状态描述 */
|
||||||
|
private String uploadStatusDesc;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package com.ruoyi.lsfx.util;
|
package com.ruoyi.lsfx.util;
|
||||||
|
|
||||||
import com.ruoyi.lsfx.exception.LsfxApiException;
|
import com.ruoyi.lsfx.exception.LsfxApiException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -17,9 +21,69 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
public class HttpUtil {
|
public class HttpUtil {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送GET请求(带查询参数和请求头)
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param params 查询参数
|
||||||
|
* @param headers 请求头
|
||||||
|
* @param responseType 响应类型
|
||||||
|
* @return 响应对象
|
||||||
|
*/
|
||||||
|
public <T> T get(String url, Map<String, Object> params, Map<String, String> headers, Class<T> responseType) {
|
||||||
|
try {
|
||||||
|
// 构建URL with查询参数
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
||||||
|
if (params != null && !params.isEmpty()) {
|
||||||
|
params.forEach((key, value) -> {
|
||||||
|
if (value != null) {
|
||||||
|
builder.queryParam(key, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
String fullUrl = builder.toUriString();
|
||||||
|
log.debug("【HTTP GET】请求URL: {}", fullUrl);
|
||||||
|
|
||||||
|
// 创建请求头
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
if (headers != null) {
|
||||||
|
headers.forEach(httpHeaders::add);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建请求实体
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(httpHeaders);
|
||||||
|
|
||||||
|
// 执行GET请求
|
||||||
|
ResponseEntity<String> response = restTemplate.exchange(
|
||||||
|
fullUrl,
|
||||||
|
HttpMethod.GET,
|
||||||
|
entity,
|
||||||
|
String.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.debug("【HTTP GET】响应状态: {}", response.getStatusCode());
|
||||||
|
log.debug("【HTTP GET】响应内容: {}", response.getBody());
|
||||||
|
|
||||||
|
// 解析响应
|
||||||
|
if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
|
||||||
|
return objectMapper.readValue(response.getBody(), responseType);
|
||||||
|
} else {
|
||||||
|
throw new LsfxApiException("GET请求失败: " + response.getStatusCode());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("【HTTP GET】请求异常: url={}, error={}", url, e.getMessage(), e);
|
||||||
|
throw new LsfxApiException("GET请求异常: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送GET请求(带请求头)
|
* 发送GET请求(带请求头)
|
||||||
* @param url 请求URL
|
* @param url 请求URL
|
||||||
|
|||||||
@@ -124,6 +124,9 @@ lsfx:
|
|||||||
fetch-inner-flow: /watson/api/project/getJZFileOrZjrcuFile
|
fetch-inner-flow: /watson/api/project/getJZFileOrZjrcuFile
|
||||||
check-parse-status: /watson/api/project/upload/getpendings
|
check-parse-status: /watson/api/project/upload/getpendings
|
||||||
get-bank-statement: /watson/api/project/getBSByLogId
|
get-bank-statement: /watson/api/project/getBSByLogId
|
||||||
|
# 新增接口
|
||||||
|
get-file-upload-status: /watson/api/project/bs/upload
|
||||||
|
delete-files: /watson/api/project/batchDeleteUploadFile
|
||||||
|
|
||||||
# RestTemplate配置
|
# RestTemplate配置
|
||||||
connection-timeout: 30000 # 连接超时30秒
|
connection-timeout: 30000 # 连接超时30秒
|
||||||
|
|||||||
Reference in New Issue
Block a user