- 新增 ExternalCashFlowService 用于调用外部银行流水接口 - 在出入金列表页面添加获取银行流水按钮 - 新增 BankFlowId 字段存储银行流水ID - 实现银行流水数据自动导入为出入金记录 - 添加相关配置项和模型类
110 lines
4.5 KiB
C#
110 lines
4.5 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using YLErp.Model.ExternalCashFlow;
|
|
using Qdp.Foundation.Utilities;
|
|
using YLErp.Modules.ApiModule;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace YLErp.Services.CashRecordModule
|
|
{
|
|
/// <summary>
|
|
/// 外部资金流水接口调用服务
|
|
/// </summary>
|
|
public interface IExternalCashFlowService
|
|
{
|
|
/// <summary>
|
|
/// 获取资金流水数据
|
|
/// </summary>
|
|
/// <param name="token">令牌</param>
|
|
/// <param name="account">账号</param>
|
|
/// <param name="beginDate">开始日期</param>
|
|
/// <param name="endDate">结束日期</param>
|
|
/// <returns>资金流水数据</returns>
|
|
Task<ExternalCashFlowResponse> GetCashFlowDataAsync(string token, string account, string beginDate, string endDate);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 外部资金流水接口调用服务实现
|
|
/// </summary>
|
|
public class ExternalCashFlowService : IExternalCashFlowService
|
|
{
|
|
private static readonly IYcLogger logger = LogFactory.GetLogger<ExternalCashFlowService>();
|
|
private readonly string _baseUrl;
|
|
private readonly int _timeoutSeconds;
|
|
|
|
public ExternalCashFlowService(IOptions<ExternalCashFlowOptions> options)
|
|
{
|
|
var config = options?.Value ?? new ExternalCashFlowOptions();
|
|
_baseUrl = config.BaseUrl ?? "http://10.99.56.25:8082";
|
|
_timeoutSeconds = config.TimeoutSeconds > 0 ? config.TimeoutSeconds : 60;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取资金流水数据
|
|
/// </summary>
|
|
/// <param name="token">令牌</param>
|
|
/// <param name="account">账号</param>
|
|
/// <param name="beginDate">开始日期</param>
|
|
/// <param name="endDate">结束日期</param>
|
|
/// <returns>资金流水数据</returns>
|
|
public async Task<ExternalCashFlowResponse> GetCashFlowDataAsync(string token, string account, string beginDate, string endDate)
|
|
{
|
|
try
|
|
{
|
|
// 构建请求 URL
|
|
var apiUrl = $"{_baseUrl}/eusp/queryStatement";
|
|
var queryString = $"?token={Uri.EscapeDataString(token)}" +
|
|
$"&account={Uri.EscapeDataString(account)}" +
|
|
$"&beginDate={Uri.EscapeDataString(beginDate)}" +
|
|
$"&endDate={Uri.EscapeDataString(endDate)}";
|
|
|
|
var requestUrl = apiUrl + queryString;
|
|
logger.Info($"调用外部资金流水接口:{requestUrl}");
|
|
|
|
// 创建 HttpClient 并设置超时
|
|
using (var httpClient = new HttpClient())
|
|
{
|
|
httpClient.Timeout = TimeSpan.FromSeconds(_timeoutSeconds);
|
|
|
|
// 发送 GET 请求
|
|
var response = await httpClient.GetAsync(requestUrl);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
// 读取响应内容
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
logger.Info($"外部资金流水接口返回:{responseContent}");
|
|
|
|
// 反序列化为响应对象
|
|
var responseObj = JsonHelper.Deserialize<ExternalCashFlowResponse>(responseContent);
|
|
|
|
if (responseObj == null)
|
|
{
|
|
logger.Error("外部资金流水接口响应为空");
|
|
throw new Exception("外部资金流水接口响应为空");
|
|
}
|
|
|
|
if (responseObj.code != "0")
|
|
{
|
|
logger.Error($"外部资金流水接口调用失败:code={responseObj.code}, message={responseObj.message}");
|
|
throw new Exception($"外部资金流水接口调用失败:{responseObj.message}");
|
|
}
|
|
|
|
return responseObj;
|
|
}
|
|
}
|
|
catch (TaskCanceledException ex)
|
|
{
|
|
logger.Error($"调用外部资金流水接口超时:{ex.Message}", ex);
|
|
throw new Exception("调用外部资金流水接口超时,请检查网络连接");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error($"调用外部资金流水接口失败:{ex.Message}", ex);
|
|
throw new Exception($"调用外部资金流水接口失败:{ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|