优化字段类型

This commit is contained in:
尹峰
2026-06-29 18:34:46 +08:00
parent 94da9748a2
commit 10b08f8f21
4 changed files with 42 additions and 67 deletions
@@ -157,7 +157,7 @@ namespace YLErp.Modules.RiskEngine
var rules = LoadRulesFromDb();
var applications = LoadApplicationsFromDb();
List<int> res = new List<int>();
List<long> res = new List<long>();
foreach(var i in applications)
{
if(i.Status!= RiskRuleStatus.Active)
+1 -1
View File
@@ -10,7 +10,7 @@ namespace YLErp.Modules.RiskEngine
public class RiskRule
{
// === 基础信息 ===
public int Id { get; set; }
public long Id { get; set; }
public string RuleName { get; set; }
public string RuleText { get; set; }
@@ -25,7 +25,7 @@ namespace YLErp.Modules.RiskEngine
/// 应用配置主键ID。
/// 用于唯一标识一条规则应用记录。
/// </summary>
public int Id { get; set; }
public long Id { get; set; }
/// <summary>
/// 关联的规则ID列表。
+39 -64
View File
@@ -534,6 +534,41 @@ namespace YLErp.Modules.RiskEngine
return string.Join(", ", names);
}
/// <summary>
/// 构建 Scope 字段的 OR 过滤谓词(逗号分隔值精确匹配)
/// </summary>
private static IQueryable<glms_risk_rule_application> ApplyScopeFilter(
IQueryable<glms_risk_rule_application> query,
Expression<Func<glms_risk_rule_application, string>> fieldSelector,
string csvValues)
{
var ids = csvValues.Split(',', StringSplitOptions.RemoveEmptyEntries);
if (ids.Length == 0)
return query;
Expression<Func<glms_risk_rule_application, bool>> predicate = null;
var param = fieldSelector.Parameters[0];
var member = fieldSelector.Body;
foreach (var trimmed in ids.Select(id => id.Trim()))
{
var eq = Expression.Equal(member, Expression.Constant(trimmed));
var startsExpr = Expression.Call(member, nameof(string.StartsWith), null,
Expression.Constant(trimmed + ","));
var endsExpr = Expression.Call(member, nameof(string.EndsWith), null,
Expression.Constant("," + trimmed));
var containsExpr = Expression.Call(member, nameof(string.Contains), null,
Expression.Constant("," + trimmed + ","));
var orExpr = Expression.OrElse(Expression.OrElse(eq, startsExpr),
Expression.OrElse(endsExpr, containsExpr));
var lambda = Expression.Lambda<Func<glms_risk_rule_application, bool>>(orExpr, param);
predicate = predicate == null ? lambda : predicate.Or(lambda);
}
return predicate != null ? query.Where(predicate) : query;
}
private static string GetStrategyName(RiskControlStrategy strategy)
{
return strategy switch
@@ -930,76 +965,16 @@ namespace YLErp.Modules.RiskEngine
}
if (!string.IsNullOrWhiteSpace(req.ScopeClientIds))
{
var ids = req.ScopeClientIds.Split(',', StringSplitOptions.RemoveEmptyEntries);
Expression<Func<glms_risk_rule_application, bool>> scopePredicate = null;
foreach (var id in ids)
{
var idCopy = id;
Expression<Func<glms_risk_rule_application, bool>> expr = a =>
a.ScopeClientIds == idCopy ||
a.ScopeClientIds.StartsWith(idCopy + ",") ||
a.ScopeClientIds.EndsWith("," + idCopy) ||
a.ScopeClientIds.Contains("," + idCopy + ",");
scopePredicate = scopePredicate == null ? expr : scopePredicate.Or(expr);
}
if (scopePredicate != null)
query = query.Where(scopePredicate);
}
query = ApplyScopeFilter(query, a => a.ScopeClientIds, req.ScopeClientIds);
if (!string.IsNullOrWhiteSpace(req.ScopeUnderlyingTypes))
{
var types = req.ScopeUnderlyingTypes.Split(',', StringSplitOptions.RemoveEmptyEntries);
Expression<Func<glms_risk_rule_application, bool>> scopePredicate = null;
foreach (var type in types)
{
var typeCopy = type;
Expression<Func<glms_risk_rule_application, bool>> expr = a =>
a.ScopeUnderlyingTypes == typeCopy ||
a.ScopeUnderlyingTypes.StartsWith(typeCopy + ",") ||
a.ScopeUnderlyingTypes.EndsWith("," + typeCopy) ||
a.ScopeUnderlyingTypes.Contains("," + typeCopy + ",");
scopePredicate = scopePredicate == null ? expr : scopePredicate.Or(expr);
}
if (scopePredicate != null)
query = query.Where(scopePredicate);
}
query = ApplyScopeFilter(query, a => a.ScopeUnderlyingTypes, req.ScopeUnderlyingTypes);
if (!string.IsNullOrWhiteSpace(req.ScopeTradeTypes))
{
var types = req.ScopeTradeTypes.Split(',', StringSplitOptions.RemoveEmptyEntries);
Expression<Func<glms_risk_rule_application, bool>> scopePredicate = null;
foreach (var type in types)
{
var typeCopy = type;
Expression<Func<glms_risk_rule_application, bool>> expr = a =>
a.ScopeTradeTypes == typeCopy ||
a.ScopeTradeTypes.StartsWith(typeCopy + ",") ||
a.ScopeTradeTypes.EndsWith("," + typeCopy) ||
a.ScopeTradeTypes.Contains("," + typeCopy + ",");
scopePredicate = scopePredicate == null ? expr : scopePredicate.Or(expr);
}
if (scopePredicate != null)
query = query.Where(scopePredicate);
}
query = ApplyScopeFilter(query, a => a.ScopeTradeTypes, req.ScopeTradeTypes);
if (!string.IsNullOrWhiteSpace(req.ScopeAssetBookIds))
{
var ids = req.ScopeAssetBookIds.Split(',', StringSplitOptions.RemoveEmptyEntries);
Expression<Func<glms_risk_rule_application, bool>> scopePredicate = null;
foreach (var id in ids)
{
var idCopy = id;
Expression<Func<glms_risk_rule_application, bool>> expr = a =>
a.ScopeAssetBookIds == idCopy ||
a.ScopeAssetBookIds.StartsWith(idCopy + ",") ||
a.ScopeAssetBookIds.EndsWith("," + idCopy) ||
a.ScopeAssetBookIds.Contains("," + idCopy + ",");
scopePredicate = scopePredicate == null ? expr : scopePredicate.Or(expr);
}
if (scopePredicate != null)
query = query.Where(scopePredicate);
}
query = ApplyScopeFilter(query, a => a.ScopeAssetBookIds, req.ScopeAssetBookIds);
var pagedResult = query.OrderByDescending(a => a.UpdateDate)
.Select(a => new RiskApplicationListItem