112 lines
3.6 KiB
C#
112 lines
3.6 KiB
C#
using YLErp.Modules.TradeModule.AccumulatorOptionModule;
|
|
|
|
namespace YLErp.Modules.TradeModule
|
|
{
|
|
/// <summary>
|
|
/// 期权交易步骤还原服务(等待设计完善)
|
|
/// </summary>
|
|
public class OptionTradeActionRestoreService : TradeServiceBase
|
|
{
|
|
public OptionTradeActionRestoreService(YLBaseService baseService) : base(baseService)
|
|
{
|
|
|
|
}
|
|
|
|
public OptionTradeActionRestoreService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将交易数据还原到编辑状态
|
|
/// </summary>
|
|
public bool RestoreTradeDataForEditiing(OtcOptionTradeFull td, out List<TradeActionType> restoredActions)
|
|
{
|
|
restoredActions = null;
|
|
|
|
if (td is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var valueDate = td.TradeDate.Value;
|
|
|
|
if (td.TradeType == "累计期权")
|
|
{
|
|
var query = from a in DbContext.TradeAction.AsNoTracking()
|
|
where a.IsValid && a.TradeId == td.id && a.ValueDate == valueDate && a.ActionType == TradeActionType.AccumulatorChange
|
|
select new { a.ActionData };
|
|
|
|
var action = query.FirstOrDefault();
|
|
|
|
if (action != null)
|
|
{
|
|
restoredActions = new List<TradeActionType> { TradeActionType.AccumulatorChange };
|
|
TradeAccumulatorHelper.RestoreAccumulatorChangeData(td, action.ActionData);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将交易数据还原到特定日期
|
|
/// </summary>
|
|
public bool RestoreTradeDataToSpecialDay(trade td, DateTime valueDate)
|
|
{
|
|
if (td is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (td.TradeType == "累计期权")
|
|
{
|
|
var query = from a in DbContext.TradeAction.AsNoTracking()
|
|
where a.IsValid && a.TradeId == td.id && a.ValueDate <= valueDate && a.ActionType == TradeActionType.AccumulatorChange
|
|
orderby a.ValueDate descending
|
|
select new { a.ActionData };
|
|
|
|
var action = query.FirstOrDefault();
|
|
|
|
if (action != null)
|
|
{
|
|
TradeAccumulatorHelper.RestoreAccumulatorChangeData(td, action.ActionData);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将交易基础要素还原到特定日期
|
|
/// </summary>
|
|
public bool RestoreTradeDataToSpecialDay2(OtcTradeBase td, DateTime valueDate)
|
|
{
|
|
if (td is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (td.TradeType == "累计期权")
|
|
{
|
|
var query = from a in DbContext.TradeAction.AsNoTracking()
|
|
where a.IsValid && a.TradeId == td.id && a.ValueDate <= valueDate && a.ActionType == TradeActionType.AccumulatorChange
|
|
orderby a.ValueDate descending
|
|
select new { a.ActionData };
|
|
|
|
var action = query.FirstOrDefault();
|
|
|
|
if (action != null)
|
|
{
|
|
TradeAccumulatorHelper.RestoreAccumulatorChangeData(td, tdAcc: default(trade_accumulator_option), changeDataJson: action.ActionData);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|