namespace YLErp.Modules.EodModule.QueryModule { /// /// 日终清算--了结信息流水 /// public class EodCloseInfoQueryService : YLBaseService { public EodCloseInfoQueryService(EodSettleInfoQueryContext context) : base(context) { } public IEnumerable GetEodCloseInfoList(DateTime valueDate, List clientIdsOfInside = null) { valueDate = valueDate.Date; var tradeQuery = DbContext.trade.AsQueryable(); if (clientIdsOfInside != null) { tradeQuery = tradeQuery.Where(a => !clientIdsOfInside.Contains(a.ClientId)); } var query = from tc in DbContext.trade_cash join td in tradeQuery on tc.TradeId equals td.id //join tcSwap in DbContext.trade_cash_swap on tc.id equals tcSwap.TradeId into tcSwap_t //from tcSwap in tcSwap_t.DefaultIfEmpty() where tc.ValueDate == valueDate && tc.ValidState != ConsGlobal.InValid && !tc.IsDeleted && (tc.Action == ClientCashInCashOut.系统操作_行权费 || tc.Action == ClientCashInCashOut.系统操作_平仓费 || tc.Action == ClientCashInCashOut.系统操作_票息 && tc.IsLastAction) && td.ValidState != ConsGlobal.InValid && td.IsGroup != 2 select new { td.ClientId, td.TradeNumber, td.TradeType, td.StructureType, td.TradePrice, td.BuySell, td.TradeDate, td.OptionType, td.UnderlyingCode, tcAction = tc.Action, tcAmount = tc.Amount, tc.UnwindPercentRate }; var datas = query.ToArray(); var list = new List(datas.Length); var tradeNumberList = datas.Where(O => O.TradeType == "收益互换").Select(O => O.TradeNumber).ToHashSet(); var swapDict = (from t in DbContext.trade join ts in DbContext.trade_swap on t.id equals ts.TradeId where tradeNumberList.Contains(t.TradeNumber) select new { t.TradeNumber, LongShort = ts.IsGetFloatingProfit ? ts.GetLongShort : ts.PayLongShort, }).ToDictionary(K => K.TradeNumber, V => V.LongShort); foreach (var n in datas) { var um = DataCacheProvider.GetUnderlyingDataSource().GetData(n.UnderlyingCode); var f = new EodCloseInfoField { TradeNumber = n.TradeNumber, TradeType = n.TradeType, StructureType = n.StructureType, TradeSide = n.BuySell, TradeDate = n.TradeDate.OtcFormatDate(), CallPut = n.TradeType == "收益互换" && swapDict.ContainsKey(n.TradeNumber) ? swapDict[n.TradeNumber] : ConsGlobal.CallPut.IsCall(n.OptionType) ? "多头" : "空头", UnderlyingCode = n.UnderlyingCode, UnderlyingName = um?.UnderlyingName, CloseFee = 0, ClientNumber = null, CloseProfit = CalculationModule.TradeCalcHelper.CalcWinLoss(tradeType: n.TradeType, buySell: n.BuySell, tradePrice: n.TradePrice ?? 0, tcUnwindPercent: n.UnwindPercentRate ?? 0, tcAmount: n.tcAmount) }; if (_context.TryGetClientInfo(n.ClientId, out var clientInfo)) { f.ClientNumber = clientInfo.Number; } list.Add(f); } return list; } } /// /// 日终清算--了结信息流水 /// public class EodCloseInfoField { /// /// 交易编号 /// public string TradeNumber { get; set; } /// /// 子账户编码 /// public string ClientNumber { get; set; } /// /// 交易类型 /// public string TradeType { get; set; } /// /// 交易日期 /// public string TradeDate { get; set; } /// /// 交易方向 /// public string TradeSide { get; set; } /// /// 看涨看跌 /// public string CallPut { get; set; } /// /// 标的代码 /// public string UnderlyingCode { get; set; } /// /// 标的名称 /// public string UnderlyingName { get; set; } /// /// 结构类型 /// public string StructureType { get; set; } /// /// 平仓盈亏 /// public double CloseProfit { get; set; } /// /// 手续费 /// public double CloseFee { get; set; } } }