从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using YLErp.DBModels.Abstract;
|
||||
using YLErp.DBModels.Consts;
|
||||
using YLErp.Modules.DataProviderModule;
|
||||
using YLErp.Plugins.TradeDocGenerator.Abstracts;
|
||||
|
||||
namespace YLErp.Modules.TradeModule.DocGenerateModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 交易结算生成上下文
|
||||
/// </summary>
|
||||
public class MarginReportGenerateContext : ConfirmationGenerateContext, ITradeMarginReportGeneratorContext
|
||||
{
|
||||
private readonly trade_span _tradeSpan;
|
||||
|
||||
public MarginReportGenerateContext(int tradeCashId, trade tradeObj, trade_span tradeSpan, string contractType, OptUserInfo userInfo)
|
||||
: base(tradeCashId, tradeObj, contractType, userInfo)
|
||||
{
|
||||
_tradeSpan = tradeSpan ?? throw new ArgumentNullException(nameof(tradeSpan));
|
||||
}
|
||||
|
||||
|
||||
//交易确认书对象
|
||||
trade_contract_document _contractDoc;
|
||||
double? _underlyingSettlePrice = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取交易确认书
|
||||
/// </summary>
|
||||
public ITradeContractDocument GetTradeContractDocument()
|
||||
{
|
||||
if (_contractDoc == null)
|
||||
{
|
||||
var db = DbContextFactory.GetYLDbContext();
|
||||
var query = from contractDoc in db.trade_contract_document
|
||||
join tcr in db.trade_contract_r on contractDoc.Code equals tcr.ContractCode
|
||||
where tcr.TradeId == Trade.id && contractDoc.Type == ContractTypeEnum.Trade && tcr.Type == ContractTypeEnum.Trade && tcr.IsValid
|
||||
select contractDoc;
|
||||
_contractDoc = query.FirstOrDefault();
|
||||
}
|
||||
|
||||
if (_contractDoc == null)
|
||||
{
|
||||
throw new ServiceException($"未找到交易确认书(交易ID:{Trade.id},交易编号:{Trade.TradeNumber})");
|
||||
}
|
||||
|
||||
return _contractDoc;
|
||||
}
|
||||
|
||||
public trade_span GetTradeSpan()
|
||||
{
|
||||
return _tradeSpan;
|
||||
}
|
||||
|
||||
public bool OnMarginReportGenerated()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public double GetUnderlyingSettlePrice()
|
||||
{
|
||||
if (_underlyingSettlePrice == null)
|
||||
{
|
||||
if (EodPriceQueryService.TryGetEodPrice(_tradeSpan.ValueDate, Trade.UnderlyingCode, out var eodPrice))
|
||||
{
|
||||
_underlyingSettlePrice = eodPrice.GetPrice(Trade.SettlementType);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServiceException($"未找到交易{Trade.TradeNumber}对应标的{Trade.UnderlyingCode}的{Trade.GetSettlementTypeDesc()}");
|
||||
}
|
||||
}
|
||||
|
||||
return _underlyingSettlePrice.Value;
|
||||
}
|
||||
|
||||
public override DateTime SystemValueDate => _tradeSpan.ValueDate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user