namespace YLErp.Modules.TradeModule.QueryModule { public class TradeCloseInfoQueryApiService : YLBaseService { public TradeCloseInfoQueryApiService(OptUserInfo userInfo) : base(userInfo) { } public IEnumerable GetTradeCloseInfoList(TradeCloseInfoRequestModel req) { int[] clientIds = null; using (var clientDB = DbContextFactory.GetClientDbContext(OptUser)) { if (!string.IsNullOrEmpty(req.ClientNumber)) { clientIds = clientDB.client.Where(n => n.Number == req.ClientNumber).Select(n => n.id).ToArray(); } else if (!string.IsNullOrEmpty(req.ClientName)) { clientIds = clientDB.client.Where(n => n.Name == req.ClientName).Select(n => n.id).ToArray(); } if (clientIds != null && !clientIds.Any()) { return Enumerable.Empty(); } } var tdPredicate = PredicateBuilder.Create(t => t.ValidState != ConsGlobal.InValid); if (clientIds != null) { tdPredicate = tdPredicate.And(t => clientIds.Contains(t.ClientId)); } var tcActions = new[] { ClientCashInCashOut.系统操作_平仓费, ClientCashInCashOut.系统操作_行权费 }; var query = from tc in DbContext.trade_cash.AsNoTracking() join td in DbContext.trade.AsNoTracking().Where(tdPredicate) on tc.TradeId equals td.id join et in DbContext.eod_trade.Where(O => O.ValueDate == req.ValueDate) on td.id equals et.TradeId into tempEt from et in tempEt.DefaultIfEmpty() where tc.ValidState != ConsGlobal.InValid && tc.ValueDate == req.ValueDate && tcActions.Contains(tc.Action) select new { et, trade = td, detail = new OtcTradeDetail { TcId = tc.id, TcValueDate = tc.HappenedDate != null ? tc.HappenedDate : tc.ValueDate, TcFinalPrice = tc.FinalPrice, TcUnwindPrice = tc.UnwindPrice, TcUnwindPricePercent = tc.UnwindPricePercentRate, TcAmount = tc.Amount, UnWindNotional = tc.UnwindNotional ?? tc.Notional, TcUnwindTradeAmount = tc.UnwindTradeAmount, TcUnwindPercent = tc.UnwindPercentRate, TcAction = tc.Action, TcExerciseWay = tc.ExerciseWay, } }; var list = query.ToList(); return list.Select(n => { YLAutoMapper.Map(n.et?.trade ?? n.trade, n.detail); return n.detail; }).ToList(); } } }