fix:风控引擎的数据库对象不再采用全局,防止追踪所有查询出的对象
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Qdp.Foundation.Utilities;
|
||||
using System.Reflection;
|
||||
using YLErp.BLL;
|
||||
@@ -309,11 +309,14 @@ namespace YLErp.Modules.RiskEngine
|
||||
|
||||
try
|
||||
{
|
||||
_logger.Info($"[风控引擎] EvaluateRisk 开始 - TradeId: {context?.TradeId}, TriggerPoint: {triggerPoint}");
|
||||
if (context != null && context.DbContext == null)
|
||||
{
|
||||
context.DbContext = DbContext;
|
||||
}
|
||||
using var ruleDbContext = DbContextFactory.GetYLDbContext();
|
||||
ruleDbContext.ChangeTracker.QueryTrackingBehavior = Microsoft.EntityFrameworkCore.QueryTrackingBehavior.NoTracking;
|
||||
|
||||
context ??= new RiskContext();
|
||||
context.TriggerPoint = triggerPoint;
|
||||
context.DbContext = ruleDbContext;
|
||||
|
||||
_logger.Info($"[风控引擎] EvaluateRisk 开始 - TradeId: {context.TradeId}, TriggerPoint: {triggerPoint}");
|
||||
|
||||
// ============================================================
|
||||
// Step 1: 从内存缓存读取规则定义和规则应用(启动时已预热)
|
||||
@@ -343,8 +346,8 @@ namespace YLErp.Modules.RiskEngine
|
||||
// 2. 同一维度内多选按并集处理;
|
||||
// 3. 不同维度之间按交集处理;
|
||||
// 4. 某维度留空表示该维度不限制。
|
||||
var trade = context != null && context.TradeId > 0
|
||||
? DbContext.trade.FirstOrDefault(t => t.id == context.TradeId)
|
||||
var trade = context.TradeId > 0
|
||||
? context.DbContext.trade.AsNoTracking().FirstOrDefault(t => t.id == context.TradeId)
|
||||
: null;
|
||||
|
||||
var matchedApplications = triggerMatchedApps
|
||||
|
||||
Reference in New Issue
Block a user