fix: 兼容TRS日终推送历史利息腿类别为空
This commit is contained in:
@@ -140,7 +140,7 @@ namespace YLErp.Modules.EodModule
|
||||
.ToList();
|
||||
var positionIds = eodPositions.Select(x => x.PositionId).Distinct().ToList();
|
||||
var swapPositions = _dbContext.swap_position
|
||||
.Where(x => positionIds.Contains(x.id) && !x.Invalid && x.category_tag == InterestCategory)
|
||||
.Where(x => positionIds.Contains(x.id) && !x.Invalid)
|
||||
.AsNoTracking()
|
||||
.ToDictionary(x => x.id);
|
||||
|
||||
@@ -167,18 +167,27 @@ namespace YLErp.Modules.EodModule
|
||||
}
|
||||
|
||||
var positions = eodPositions.Where(x => x.SwapTradeId == eodSwap.SwapTradeId).ToList();
|
||||
var floating = positions.Where(x => !string.IsNullOrWhiteSpace(x.UnderlyingCode) && swapPositions.ContainsKey(x.PositionId)).ToList();
|
||||
var interest = positions.Where(x => string.IsNullOrWhiteSpace(x.UnderlyingCode)
|
||||
var floating = positions.Where(x => !string.IsNullOrWhiteSpace(x.UnderlyingCode)).ToList();
|
||||
var interestCandidates = positions.Where(x => string.IsNullOrWhiteSpace(x.UnderlyingCode)
|
||||
&& ConsTrade.InterestModels.Contains(x.InterestMode)
|
||||
&& swapPositions.TryGetValue(x.PositionId, out var swapPosition)
|
||||
&& swapPosition.category_tag == InterestCategory).ToList();
|
||||
&& (swapPosition.category_tag == InterestCategory || string.IsNullOrWhiteSpace(swapPosition.category_tag)))
|
||||
.ToList();
|
||||
|
||||
if (floating.Count != 1 || interest.Count != 1)
|
||||
// 互换利率腿优先;同类别多腿按当前查询顺序取第一条。历史类别为空时保留利息方向,
|
||||
// 但 fixedRate 按约定置 0,避免把未标注类别的历史值当作已确认利率。
|
||||
var interest = interestCandidates.FirstOrDefault(x =>
|
||||
swapPositions.TryGetValue(x.PositionId, out var swapPosition)
|
||||
&& swapPosition.category_tag == InterestCategory);
|
||||
var isUncategorizedInterest = interest == null && interestCandidates.Count > 0;
|
||||
interest ??= interestCandidates.FirstOrDefault();
|
||||
|
||||
if (floating.Count != 1 || interest == null)
|
||||
{
|
||||
throw new InvalidOperationException($"TRS legs invalid, swapTradeId:{eodSwap.SwapTradeId}, floating:{floating.Count}, interest:{interest.Count}");
|
||||
throw new InvalidOperationException($"TRS legs invalid, swapTradeId:{eodSwap.SwapTradeId}, floating:{floating.Count}, interest:{(interest == null ? 0 : 1)}");
|
||||
}
|
||||
|
||||
var interestLeg = interest[0];
|
||||
var interestLeg = interest;
|
||||
var floatingLeg = floating[0];
|
||||
return new TrsContractSnapshotItem
|
||||
{
|
||||
@@ -193,7 +202,7 @@ namespace YLErp.Modules.EodModule
|
||||
Dv01 = eodSwap.dv01 ?? 0,
|
||||
StartDate = trade.StartDate?.ToString(DateFormat),
|
||||
MaturityDate = trade.ExerciseDate?.ToString(DateFormat),
|
||||
FixedRate = interestLeg.InterestRateDefault,
|
||||
FixedRate = isUncategorizedInterest ? 0 : interestLeg.InterestRateDefault,
|
||||
InterestDirection = interestLeg.InterestDirection,
|
||||
FloatingDirection = floatingLeg.PositionType,
|
||||
InitMarginGain = eodSwap.InitMarginGain,
|
||||
|
||||
Reference in New Issue
Block a user