Merge branch 'glms/feature/1.4.2' of http://git.yiliantech.com/gitlab/otc-dev/zszq-trs into glms/feature/1.4.2
This commit is contained in:
@@ -773,9 +773,9 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
bool adjustCashDividendPrice = true)
|
||||
{
|
||||
// 价格调整模式除权参考价 =
|
||||
// 收盘价 * 10 - 【每股派息 * 10 * (1-分红税率)】 + 配股数 * 配股价
|
||||
// - -----------------------------------------------------
|
||||
// (10 + 送股数 + 配股数) * 拆股倍数
|
||||
// 登记日收盘价 * 10 - 【每股派息 * 10 * (1-分红税率)】 + 配股数 * 配股价
|
||||
// ---------------------------------------------------------------
|
||||
// (10 + 送股数 + 配股数) * 拆股倍数
|
||||
// 场内链路默认继续把现金派息计入除权参考价;
|
||||
// TRS Stock/Fund 现金模式显式关闭该项 :“【】” 号内数据。
|
||||
var cashPriceAdjustment = adjustCashDividendPrice
|
||||
@@ -784,8 +784,8 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
// 拆股倍数
|
||||
var splitFactor = GetSplitFactor(info);
|
||||
// 除权参考价(TRS) :
|
||||
// 收盘价 * 10 + 配股数 * 配股价
|
||||
// ------------------------------
|
||||
// 登记日收盘价 * 10 + 配股数 * 配股价
|
||||
// -------------------------------------
|
||||
// (10 + 送股数 + 配股数) * 拆股倍数
|
||||
var exDividendPrice = ((closePrice * 10m - cashPriceAdjustment
|
||||
+ info.RationedSharesAmount * info.RationedSharesPrice)
|
||||
@@ -1159,9 +1159,10 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
}
|
||||
else
|
||||
{
|
||||
if (checkDividendInfoExecuteStatus(dividend))
|
||||
var executingTradeNumber = GetDividendInfoExecutingTradeNumber(dividend);
|
||||
if (!string.IsNullOrWhiteSpace(executingTradeNumber))
|
||||
{
|
||||
errMsg = $"{dividend.UnderlyingCode} {dividend.ExDividendDate?.ToString("yyyy-MM-dd")}除权信息保存失败,该信息已被执行,不允许修改!";
|
||||
errMsg = $"不可修改,有交易【{executingTradeNumber}】使用了该条除权除息数据";
|
||||
return false;
|
||||
}
|
||||
var conflictingDividend = FindExDividendByBusinessKey(underlying.id, itemDate, dividend.id);
|
||||
@@ -1223,6 +1224,14 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
public bool checkDividendInfoExecuteStatus(ex_dividend_info info)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(GetDividendInfoExecutingTradeNumber(info));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回仍在引用已执行公司行为的交易编号;无引用时返回空字符串。
|
||||
/// </summary>
|
||||
public string GetDividendInfoExecutingTradeNumber(ex_dividend_info info)
|
||||
{
|
||||
// TRS 公司行为以 EffectiveDate 为真正生效边界。登记日创建待生效事件不应锁定
|
||||
// 维护;只有交易已经完成 EffectiveDate(例如收盘到 7 月 30 日,而真实除权日为
|
||||
@@ -1230,34 +1239,37 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
if (info?.EffectiveDate.HasValue == true)
|
||||
{
|
||||
var effectiveDate = info.EffectiveDate.Value.Date;
|
||||
var trsTradeIds = DbContext.trade
|
||||
var trsTrades = DbContext.trade
|
||||
.Where(x => x.ValidState != ConsGlobal.InValid
|
||||
&& x.TradeType == "收益互换"
|
||||
&& x.UnderlyingCode == info.UnderlyingCode
|
||||
&& x.TradeDate <= effectiveDate
|
||||
&& x.ExerciseDate >= effectiveDate)
|
||||
.Select(x => x.id)
|
||||
.Select(x => new { x.id, x.TradeNumber })
|
||||
.ToList();
|
||||
if (trsTradeIds.Count > 0)
|
||||
if (trsTrades.Count > 0)
|
||||
{
|
||||
// 是否仍被交易引用以当前有效 EOD 为准。公司行为事件本身是不可篡改
|
||||
// 历史,交易回退后仍会保留;若仅凭 Applied 事件锁定,回退到登记日前
|
||||
// 也无法纠错。生效日及以后还有有效 EOD 才表示当前仍已执行。
|
||||
var hasAppliedEod = DbContext.eod_swap_position.Any(x =>
|
||||
var trsTradeIds = trsTrades.Select(x => x.id).ToList();
|
||||
var appliedTradeId = DbContext.eod_swap_position.Where(x =>
|
||||
trsTradeIds.Contains(x.SwapTradeId)
|
||||
&& !x.Invalid
|
||||
&& x.UnderlyingCode == info.UnderlyingCode
|
||||
&& x.ValueDate >= effectiveDate);
|
||||
if (hasAppliedEod)
|
||||
&& x.ValueDate >= effectiveDate)
|
||||
.Select(x => x.SwapTradeId)
|
||||
.FirstOrDefault();
|
||||
if (appliedTradeId > 0)
|
||||
{
|
||||
return true;
|
||||
return trsTrades.First(x => x.id == appliedTradeId).TradeNumber;
|
||||
}
|
||||
|
||||
// EffectiveDate 已存在时,当前有效 EOD 是唯一执行状态来源。
|
||||
// 回退会清理生效日及之后的 EOD,但不会删除 eodStatus 或不可篡改的
|
||||
// 公司行为审计事件;此处不能继续落入旧的登记日 eodStatus 判断,
|
||||
// 否则交易已回退仍会被错误判定为“已执行”而无法修改。
|
||||
return false;
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1268,20 +1280,22 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
var tradeQuery = from t in DbContext.trade.Where(O => O.UnderlyingCode == info.UnderlyingCode && O.TradeDate <= info.ExDividendDate && O.ExerciseDate >= info.ExDividendDate && O.DividendDate >= O.TradeDate)
|
||||
join et in DbContext.eod_trade.Where(O => ConsTrade.LiveTradeStatusList.Contains(O.TradeStatus))
|
||||
on new { t.id, ValueDate = t.TradeDate.Value } equals new { id = et.TradeId, et.ValueDate }
|
||||
select et.id;
|
||||
if (tradeQuery.Any())
|
||||
select t.TradeNumber;
|
||||
var executingTradeNumber = tradeQuery.FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(executingTradeNumber))
|
||||
{
|
||||
return true;
|
||||
return executingTradeNumber;
|
||||
}
|
||||
//查询篮子标的对应交易是否执行过收盘操作;
|
||||
var umList = DataCacheProvider.GetUnderlyingDataSource().AsQueryable(O => O.CommodityCode == "篮子标的" && O.SubData != null && O.SubData.Contains(info.UnderlyingCode)).Select(O => O.UnderlyingCode).ToArray();
|
||||
tradeQuery = from t in DbContext.trade.Where(O => umList.Contains(O.UnderlyingCode) && O.TradeDate <= info.ExDividendDate && O.ExerciseDate >= info.ExDividendDate && O.DividendDate >= O.TradeDate)
|
||||
join et in DbContext.eod_trade.Where(O => ConsTrade.LiveTradeStatusList.Contains(O.TradeStatus))
|
||||
on new { t.id, ValueDate = t.TradeDate.Value } equals new { id = et.TradeId, et.ValueDate }
|
||||
select et.id;
|
||||
if (tradeQuery.Any())
|
||||
select t.TradeNumber;
|
||||
executingTradeNumber = tradeQuery.FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(executingTradeNumber))
|
||||
{
|
||||
return true;
|
||||
return executingTradeNumber;
|
||||
}
|
||||
//查询多标的对应交易是否执行过收盘操作;
|
||||
tradeQuery = from ts in DbContext.trade_swap_detail.Where(O => O.UnderlyingCode == info.UnderlyingCode)
|
||||
@@ -1289,13 +1303,14 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
on ts.TradeId equals t.id
|
||||
join et in DbContext.eod_trade.Where(O => ConsTrade.LiveTradeStatusList.Contains(O.TradeStatus))
|
||||
on new { t.id, ValueDate = t.TradeDate.Value } equals new { id = et.TradeId, et.ValueDate }
|
||||
select et.id;
|
||||
if (tradeQuery.Any())
|
||||
select t.TradeNumber;
|
||||
executingTradeNumber = tradeQuery.FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(executingTradeNumber))
|
||||
{
|
||||
return true;
|
||||
return executingTradeNumber;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public List<DividendTrade> QueryDividendTrade(DividendTradeReq req)
|
||||
|
||||
Reference in New Issue
Block a user