diff --git a/UnitTestProject/Modules/SwapModule/SwapApproveStatusStuckTest.cs b/UnitTestProject/Modules/SwapModule/SwapApproveStatusStuckTest.cs index e5682ba5..013388ae 100644 --- a/UnitTestProject/Modules/SwapModule/SwapApproveStatusStuckTest.cs +++ b/UnitTestProject/Modules/SwapModule/SwapApproveStatusStuckTest.cs @@ -69,32 +69,6 @@ namespace YLErp.Modules.SwapModule Console.WriteLine($"\n其中有互换事件(疑似审核卡死): {stuckWithSwap} 笔"); - // 额外检查:平仓(eventType=2)+到期+确认成交 是否也卡死 - Console.WriteLine($"\n--- 平仓到期卡死检查 ---"); - int stuckWithClose = 0; - int stuckWithPartialClose = 0; - foreach (var t in stuckTrades.Take(50)) - { - var closeEvents = db.swap_event - .Where(x => x.SwapTradeId == t.id && x.EventType == (int)SwapEventTypeEnum.平仓 && !x.Invalid) - .ToList(); - if (closeEvents.Any()) - { - stuckWithClose++; - var latest = closeEvents.OrderByDescending(x => x.id).First(); - var ud = !string.IsNullOrEmpty(latest.EventData) - ? Newtonsoft.Json.JsonConvert.DeserializeObject(latest.EventData) : null; - int cm = ud?.CloseMethod ?? 0; - if (cm != (int)CloseMethodEnum.全部平仓) - { - stuckWithPartialClose++; - if (stuckWithPartialClose <= 3) - Console.WriteLine($" ⚠ 平仓部分平仓+到期: {t.TradeNumber} CloseMethod={cm}({(CloseMethodEnum)cm}) Status={t.TradeStatus}"); - } - } - } - Console.WriteLine($" 平仓事件+到期+确认成交: {stuckWithClose} 笔(其中部分平仓: {stuckWithPartialClose})"); - if (stuckTrades.Count == 0) { Console.WriteLine("(无卡死交易,可能已全部修复或无到期交易)"); @@ -268,78 +242,5 @@ namespace YLErp.Modules.SwapModule db?.Dispose(); } } - - /// - /// Step3:验证修复后逻辑——模拟 ApproveSwapTrade 的状态流转判断。 - /// - /// 修复后代码(cs:1579后): - /// if (eventType==互换 && td.ExerciseDate <= unwindData.ValueDate) → 已到期 - /// - /// 本方法找所有有效互换事件,模拟修复后的条件判断,验证: - /// - 到期互换(ExerciseDate<=ValueDate) → 应判为"已到期" ✅ - /// - 非到期互换(ExerciseDate>ValueDate) → 仍走"确认成交" ✅ - /// - 平仓事件 → 不受影响(eventType≠互换)✅ - /// - [TestMethod] - [TestCategory("DBRecording")] - public void Step3_VerifyFixedStatusTransition() - { - YLContext db; - try { db = DbContextFactory.GetYLDbContext(); } - catch (Exception ex) - { - Assert.Inconclusive($"无法连接测试库(CI/无DB环境正常跳过):{ex.Message}"); - return; - } - - try - { - Console.WriteLine($"===== 验证修复后状态流转逻辑 =====\n"); - - // 取所有有效互换事件,模拟修复后的条件判断 - var swapEvents = db.swap_event - .Where(x => x.EventType == (int)SwapEventTypeEnum.互换 && !x.Invalid) - .ToList(); - - int toMaturity = 0; // 到期互换 → 应判已到期 - int stayConfirmed = 0; // 非到期互换 → 仍确认成交 - int parseFail = 0; - - foreach (var e in swapEvents) - { - var td = db.trade.FirstOrDefault(t => t.id == e.SwapTradeId); - if (td == null) continue; - - var unwindData = !string.IsNullOrEmpty(e.EventData) - ? Newtonsoft.Json.JsonConvert.DeserializeObject(e.EventData) - : null; - if (unwindData == null) { parseFail++; continue; } - - // 模拟修复后条件(cs:1579后) - bool isMaturity = td.ExerciseDate <= unwindData.ValueDate; - string expectedStatus = isMaturity ? "已到期" : "确认成交"; - if (isMaturity) toMaturity++; - else stayConfirmed++; - } - - Console.WriteLine($"[互换事件状态流转模拟] 共 {swapEvents.Count} 条有效互换事件"); - Console.WriteLine($" → 判为'已到期'(ExerciseDate<=ValueDate): {toMaturity} 条"); - Console.WriteLine($" → 仍'确认成交'(ExerciseDate>ValueDate): {stayConfirmed} 条"); - Console.WriteLine($" → 解析失败: {parseFail} 条"); - - Console.WriteLine($"\n[验证]"); - Console.WriteLine($" 修复后:到期互换审核 → TradeStatus='已到期' → 在 TradeCompleteStatus 内 → 收盘通过 ✅"); - Console.WriteLine($" 修复后:非到期互换审核 → 仍'确认成交'+HasPartialUnWind(部分平仓语义)✅"); - Console.WriteLine($" 修复后:平仓审核(eventType=2) → 不进到期判断(条件 eventType==互换 排除)✅"); - - // 绿灯断言:到期互换应该被正确判为"已到期" - Assert.IsTrue(toMaturity >= 0, "修复后到期互换状态流转逻辑正确"); - Console.WriteLine($"\n ✅ 修复逻辑验证通过"); - } - finally - { - db?.Dispose(); - } - } } } diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index f36b22f1..1f357ded 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -1575,15 +1575,6 @@ namespace YLErp.Modules.SwapModule } td.Notional = td.TradeAmount; - // 到期互换审核通过后应设为"已到期"(与 SwapIncome cs:1512-1517 对齐)。 - // 必须放在 td.Notional = td.TradeAmount 之后,否则清零会被覆盖。 - // 仅对互换(eventType=3)生效,不影响平仓(eventType=2)审核。 - if (eventType == (int)SwapEventTypeEnum.互换 && td.ExerciseDate <= swapEvent.unwindData.ValueDate) - { - td.Notional = 0; - td.StockEqvNotional = 0; - td.TradeStatus = "已到期"; - } UpdateInitalPosition(flowList, swapEvent.unwindData, eventType); DbContext.SaveChanges();