using YLErp.Models; using YLErp.Modules.EodModule.QueryModule; using YLErp.Modules.EodModule.SettlementModule; namespace YLErp.Modules.EodModule { /// /// 兴证服务 /// 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(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); } } /// /// 上传日终持仓数据到FTP /// /// /// /// public static void FtpUploadEodPosition(OptUserInfo user, DateTime valueDate, FtpSettings settings, System.Collections.Generic.IEnumerable 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); } } } }