public static bool IsTrue(this FilterRule rule, IAttributeFinder attributeFinder, Entity record) { bool flag = true; if (rule.Conditions.IsNotEmpty()) { var ruleConditions = new FilterRuleConditions(); ruleConditions = ruleConditions.DeserializeFromJson(rule.Conditions); foreach (var cnd in ruleConditions.Conditions) { if (cnd.CompareAttributeName.IsNotEmpty()) { cnd.Values.Add(record.GetValue <object>(cnd.CompareAttributeName)); } var attr = attributeFinder.Find(rule.EntityId, cnd.AttributeName); flag = cnd.IsTrue(attr, record.GetValue <object>(cnd.AttributeName)); if (ruleConditions.LogicalOperator == LogicalOperator.Or && flag) { break; } if (ruleConditions.LogicalOperator == LogicalOperator.And && !flag) { break; } } } return(flag); }
public List <Schema.Domain.Attribute> GetRequireds(FilterRule entity) { if (entity.Conditions.IsNotEmpty()) { //条件依赖于字段 var ruleConditions = new FilterRuleConditions().DeserializeFromJson(entity.Conditions); var attributeNames = ruleConditions.Conditions.Select(s => s.AttributeName); return(_attributeFinder.Query(x => x.Where(f => f.EntityId == entity.EntityId && f.Name.In(attributeNames)))); } return(null); }