88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
using YLErp.Models;
|
|
using YLErp.Modules.EodModule.QueryModule;
|
|
using YLErp.Modules.EodModule.SettlementModule;
|
|
|
|
namespace YLErp.Modules.EodModule
|
|
{
|
|
/// <summary>
|
|
/// 兴证服务
|
|
/// </summary>
|
|
public class XingZhengService
|
|
{
|
|
public static void EodExecute(EodSettlementContextV2 context)
|
|
{
|
|
if (context is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
try
|
|
{
|
|
var configFolder = OtcAppContext.MapPath("/App_Data/XingZheng/eod_ftp_cfg.json");
|
|
|
|
Directory.CreateDirectory(configFolder);
|
|
|
|
var configFilePath = Path.Combine(configFolder, "eod_ftp_cfg.json");
|
|
|
|
if (!File.Exists(configFilePath))
|
|
{
|
|
context.LogError("兴证FTP未配置, 上传到数据中心失败");
|
|
return;
|
|
}
|
|
|
|
var json = File.ReadAllText(configFilePath);
|
|
var settings = JsonHelper.Deserialize<FtpSettings>(json);
|
|
|
|
if (string.IsNullOrEmpty(settings.FtpHost))
|
|
{
|
|
context.LogError("兴证FTP主机未配置, 上传到数据中心失败");
|
|
return;
|
|
}
|
|
|
|
var valueDate = context.SettleDate;
|
|
var clienIds = context.Request.ClientIds;
|
|
FtpUploadEodPosition(context.UserInfo, valueDate, settings,clienIds);
|
|
|
|
context.LogInfo($"兴证日终持仓数据上传数据中心的FTP服务器:成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
context.LogError($"兴证日终持仓数据上传数据中心的FTP服务器:失败", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传日终持仓数据到FTP
|
|
/// </summary>
|
|
/// <param name="user"></param>
|
|
/// <param name="valueDate"></param>
|
|
/// <param name="settings"></param>
|
|
public static void FtpUploadEodPosition(OptUserInfo user, DateTime valueDate, FtpSettings settings, System.Collections.Generic.IEnumerable<int> clienIds=null)
|
|
{
|
|
if (settings == null)
|
|
{
|
|
throw new Exception("参数无效");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(settings.FtpHost))
|
|
{
|
|
throw new Exception("缺少FTP主机配置");
|
|
}
|
|
|
|
if (!int.TryParse(settings.FtpPort, out var port) || port < 1)
|
|
{
|
|
port = 21;
|
|
}
|
|
|
|
var service = new EodTradePositionExportService(user);
|
|
var bytes = service.ExportXingZhengZipFile(valueDate, out var zipFileName, clienIds);
|
|
var helper = new YieldChain.Helpers.FtpHelper(ftpAddress: $"ftp://{settings.FtpHost}:{port}",
|
|
userName: settings.FtpUser, password: settings.FtpPwd, usePassive: settings.FtpMode == "被动");
|
|
using (var ms = new MemoryStream(bytes))
|
|
{
|
|
helper.UploadFile(ms, settings.FtpRoot + "/" + zipFileName);
|
|
}
|
|
}
|
|
}
|
|
}
|