group by问题修复

This commit is contained in:
吴方海
2024-06-11 10:35:57 +08:00
parent cb5e691c9c
commit 2d9d5763c4
4 changed files with 8 additions and 8 deletions
@@ -218,10 +218,10 @@ namespace YLErp.BLL.Eod
var latestRecord = DbContext.intraday_trade_position.OrderByDescending(x => x.OptDate).FirstOrDefault();
//SetDebugSqlLog();
Dictionary<int, DateTime?> dicIntradayTradePosition = DbContext.intraday_trade_position.Where(x => clientIds.Contains(x.ClientId)).GroupBy(p => p.ClientId).Select(p => new { p.Key, OptDate = p.Max(d => d.OptDate) })
Dictionary<int, DateTime?> dicIntradayTradePosition = DbContext.intraday_trade_position.Where(x => clientIds.Contains(x.ClientId)).AsEnumerable().GroupBy(p => p.ClientId).Select(p => new { p.Key, OptDate = p.Max(d => d.OptDate) })
.ToDictionary(p => p.Key, p => p.OptDate);
Dictionary<int, DateTime?> dicCashInOut = DbContext.ClientCashInCashOut.Where(x => clientIds.Contains((int)x.ClientId)).GroupBy(p => (int)p.ClientId).Select(p => new { p.Key, OptDate = p.Max(d => d.OptDate) }).ToDictionary(p => p.Key, p => p.OptDate);
Dictionary<int, DateTime?> dicCashInOut = DbContext.ClientCashInCashOut.Where(x => clientIds.Contains((int)x.ClientId)).AsEnumerable().GroupBy(p => (int)p.ClientId).Select(p => new { p.Key, OptDate = p.Max(d => d.OptDate) }).ToDictionary(p => p.Key, p => p.OptDate);
foreach (var item in _clientBalanceDic.Values)
{
@@ -1387,7 +1387,7 @@ namespace YLErp.BLL.Eod
balance.PositionCount= tradeIds.Count();
balance.PositionNotionalPrincipal = Convert.ToDouble(positions.Sum(s=>s.PosiNotionalValue));//实时
}
var eodSwapQuery = DbContext.eod_swap.Where(x => clientIds.Contains(x.ClientId) && x.ValueDate >= lastSettletDate && x.ValueDate <= startDate).GroupBy(x => x.SwapTradeId)
var eodSwapQuery = DbContext.eod_swap.Where(x => clientIds.Contains(x.ClientId) && x.ValueDate >= lastSettletDate && x.ValueDate <= startDate).AsEnumerable().GroupBy(x => x.SwapTradeId)
.Select(g => g.OrderByDescending(x => x.ValueDate).FirstOrDefault()).ToList();
var eodTradeIds = eodSwapQuery.Select(s => s.SwapTradeId).ToList();
var eodTrades = DbContext.trade.Where(t => (ConsTrade.TradeStatusAfterConfirmed.Contains(t.TradeStatus)) && tradeIds.Contains(t.id) && t.ValidState != "InValid" && startDate >= t.StartDate);
@@ -514,7 +514,7 @@ namespace YLErp.BLL.Eod
var swapFlows = db.swap_flow.Where(x => x.DataState == (int)SwapFlowDateStateEnum.).ToList();
using var bondDb = new BondOmsDBContext();
var clientPositions = bondDb.client_position.AsEnumerable();
var eodSwaps = db.eod_swap_position.Where(x => tradeIdList.Contains(x.SwapTradeId) && x.PosiDirection > 0).GroupBy(p => p.SwapTradeId)
var eodSwaps = db.eod_swap_position.Where(x => tradeIdList.Contains(x.SwapTradeId) && x.PosiDirection > 0).AsEnumerable().GroupBy(p => p.SwapTradeId)
.Select(g => g.OrderByDescending(p => p.ValueDate).First()).ToList();
#endregion
@@ -533,7 +533,7 @@ namespace YLErp.BLL.Eod
td,
p
};
var positionGroup = query.GroupBy(x => new { x.p.UnderlyingCode, x.td.ClientId,x.p.PosiDirection});
var positionGroup = query.AsEnumerable().GroupBy(x => new { x.p.UnderlyingCode, x.td.ClientId,x.p.PosiDirection});
var dealSwapFlowIds = new List<long>();
SwapTradeAutoService swapTradeAutoService = new SwapTradeAutoService(optUser);
var datenow = DateTime.Now;
@@ -599,7 +599,7 @@ namespace YLErp.BLL.Eod
var nodealSwapFlows = swapFlows.Where(x => !dealSwapFlowIds.Contains(x.id));
if (nodealSwapFlows.Any())
{
var nodealSwapFlowGroup = nodealSwapFlows.GroupBy(g => new { g.ClientId, g.UnderlyingCode });
var nodealSwapFlowGroup = nodealSwapFlows.AsEnumerable().GroupBy(g => new { g.ClientId, g.UnderlyingCode });
foreach (var swapFlowGroup in nodealSwapFlowGroup)
{
var client = DataCacheProvider.GetClientDataSource().GetData(swapFlowGroup.Key.ClientId ?? 0);
@@ -56,7 +56,7 @@ namespace YLErp.Modules.SwapModule
public void SwapFlowEventCompose(DateTime tradeDate)
{
new SysJobService(UserInfo).UpdateJob("互换流水合成持仓", 41, "互换流水合成持仓进行中");
var eventQueryGroup = DbContext.swap_flow_event.Where(n => n.DataState == (int)SwapFlowDateStateEnum. && n.EventDate == tradeDate).GroupBy(g => g.SwapTradeId);
var eventQueryGroup = DbContext.swap_flow_event.Where(n => n.DataState == (int)SwapFlowDateStateEnum. && n.EventDate == tradeDate).AsEnumerable().GroupBy(g => g.SwapTradeId);
foreach (var eventQueryGroupItem in eventQueryGroup)
{
ComposePage(eventQueryGroupItem.Key, eventQueryGroupItem.ToList(), tradeDate);
@@ -37,7 +37,7 @@ namespace YLErp.Modules.SwapModule
new SysJobService(UserInfo).UpdateJob("互换流水合成持仓", 31, "互换流水开平仓事件进行中");
//同一交易代码、交易日期、标的、买卖方向 最多存在2条记录
var flowqueryGroup = DbContext.swap_flow_merge.Where(n => n.DataState == (int)SwapFlowDateStateEnum. && n.OccurTime == tradeDate).GroupBy(g => g.SwapTradeId);
var flowqueryGroup = DbContext.swap_flow_merge.Where(n => n.DataState == (int)SwapFlowDateStateEnum. && n.OccurTime == tradeDate).AsEnumerable().GroupBy(g => g.SwapTradeId);
foreach (var flowMergeGroupItem in flowqueryGroup)
{
MergePageEvent(flowMergeGroupItem.Key ?? 0, flowMergeGroupItem.ToList(), tradeDate);