Files
zszq-trs/YLErpDAL/Modules/EodModule/SettlementModule/EodCopyPreSettlePrice.cs
T
2024-05-09 14:06:26 +08:00

111 lines
4.2 KiB
C#

namespace YLErp.Modules.EodModule.SettlementModule
{
/// <summary>
/// 为处于节假日的交易标的复制上日收盘价
/// </summary>
class EodCopyPreSettlePrice : EodSettleServiceBaseV2
{
public const string Step = "为处于节假日的交易标的复制上日收盘价";
public EodCopyPreSettlePrice(EodSettlementContextV2 context) : base(context)
{
}
/// <summary>
/// 为处于节假日的交易标的复制上日收盘价
/// </summary>
public void Execute()
{
var settleDate = _context.SettleDate;
var curPriceProvider = _context.GetEodPriceProvider();
//日终商品标的价格
using (var db = DbContextFactory.GetYLDbContext())
{
var query1 = db.eod_commodity_future_price.Where(n => n.ValueDate == settleDate);
var query2 = from a in db.eod_commodity_future_price.AsNoTracking()
where a.ValueDate == _context.PreSettleDate
&& !query1.Any(n => n.UnderlyingCode == a.UnderlyingCode)
select a;
var datas = query2.ToArray();
foreach (var d in datas)
{
var un = DataCacheProvider.GetUnderlyingDataSource().GetData(d.UnderlyingCode);
if (un != null && _context.ExchangeStatus.IsHoliday(un.MarketCode))
{
var clone = d.Clone();
clone.id = 0;
clone.ValueDate = settleDate;
db.eod_commodity_future_price.Add(clone);
curPriceProvider.SetPrice(new Models.EodPrice
{
ClosePrice = clone.ClosePrice,
IsStock = false,
HighPrice = clone.HighPrice,
LowPrice = clone.LowPrice,
ReferencePrice = clone.ReferencePrice,
SettlePrice = clone.SettlePrice,
UnderlyingCode = clone.UnderlyingCode,
UnderlyingStatus = null,
UnderlyingId = un.id,
ValueDate = settleDate
});
}
}
db.SaveChanges();
}
//日终权益标的价格
using (var db = DbContextFactory.GetYLDbContext())
{
var query1 = db.eod_stock_price.Where(n => n.ValueDate == settleDate);
var query2 = from a in db.eod_stock_price.AsNoTracking()
where a.ValueDate == _context.PreSettleDate
&& !query1.Any(n => n.UnderlyingCode == a.UnderlyingCode)
select a;
var datas = query2.ToArray();
foreach (var d in datas)
{
var un = DataCacheProvider.GetUnderlyingDataSource().GetData(d.UnderlyingCode);
if (un != null && _context.ExchangeStatus.IsHoliday(un.MarketCode))
{
var clone = d.Clone();
clone.id = 0;
clone.ValueDate = settleDate;
db.eod_stock_price.Add(clone);
curPriceProvider.SetPrice(new Models.EodPrice
{
ClosePrice = clone.ClosePrice,
IsStock = true,
HighPrice = clone.HighPrice,
LowPrice = clone.LowPrice,
ReferencePrice = clone.ReferencePrice,
SettlePrice = clone.SettlePrice,
UnderlyingCode = clone.UnderlyingCode,
UnderlyingStatus = clone.UnderlyingStatus,
UnderlyingId = un.id,
ValueDate = settleDate,
});
}
}
db.SaveChanges();
}
}
}
}