87 lines
3.0 KiB
C#
87 lines
3.0 KiB
C#
using YLErp.QdpModule;
|
|
|
|
namespace YLErp.Modules.EodModule
|
|
{
|
|
/// <summary>
|
|
/// Eod数据帮助类
|
|
/// </summary>
|
|
public class EodDataHelper
|
|
{
|
|
/// <summary>
|
|
/// 获取date及之前收盘成功的最后一个结算日
|
|
/// </summary>
|
|
public static DateTime GetLastSettleDate(DateTime date)
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var lastDate = db.eodStatus.Where(t => t.Status == "已收盘" && t.ValueDate <= date && (t.VolTypeFlag & VolTypeFlagEnum.PositionVol) > 0)
|
|
.Max(t => (DateTime?)t.ValueDate);
|
|
|
|
if (lastDate.HasValue)
|
|
{
|
|
return lastDate.Value.Date;
|
|
}
|
|
|
|
//如果最后结算日为null则取上一交易日
|
|
return QdpCalendarHelper.PrevBizDayShift(date);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取date之前收盘成功的最后一个结算日
|
|
/// </summary>
|
|
public static DateTime GetPreSettleDate(DateTime date, VolTypeFlagEnum voltype = VolTypeFlagEnum.None)
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var lastDate = db.eodStatus.Where(t => t.Status == "已收盘" && t.ValueDate < date && (t.VolTypeFlag & voltype) == voltype)
|
|
.Max(t => (DateTime?)t.ValueDate);
|
|
|
|
if (lastDate.HasValue)
|
|
{
|
|
return lastDate.Value.Date;
|
|
}
|
|
|
|
//如果最后结算日为null则取上一交易日
|
|
return QdpCalendarHelper.BizDayShift(date, offset: -1);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取date及之后收盘成功的第一个结算日
|
|
/// </summary>
|
|
public static DateTime GetFristSettleDate(DateTime date)
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var lastDate = db.eodStatus.Where(t => t.Status == "已收盘" && t.ValueDate >= date)
|
|
.Min(t => (DateTime?)t.ValueDate);
|
|
|
|
if (lastDate.HasValue)
|
|
{
|
|
return lastDate.Value.Date;
|
|
}
|
|
|
|
//如果最后结算日为null则取未来(含当日)的第一个交易日
|
|
return QdpCalendarHelper.GetNonHoliday(date);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取停牌的标的ID集合
|
|
/// </summary>
|
|
public static IEnumerable<int> GetSuspensionUnderlyingIds()
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var query = from u in db.underlying_manager
|
|
where u.UnderlyingInstrumentType == ConsGlobal.InstrumentType.Stock
|
|
&& u.UnderlyingStatus == underlying_manager.Status_Suspension
|
|
select u.id;
|
|
|
|
return query.ToArray();
|
|
}
|
|
}
|
|
}
|
|
}
|