Ejemplo n.º 1
0
        public IActionResult EditDuplicateRule(Guid id)
        {
            EditDuplicateRuleModel model = new EditDuplicateRuleModel();

            if (!id.Equals(Guid.Empty))
            {
                var entity = _duplicateRuleFinder.FindById(id);
                if (entity != null)
                {
                    entity.CopyTo(model);
                    model.Conditions = _duplicateRuleConditionService.Query(n => n.Where(w => w.DuplicateRuleId == entity.DuplicateRuleId));
                    return(View(model));
                }
            }
            return(NotFound());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重复规则命中
        /// </summary>
        /// <param name="organizationService"></param>
        /// <param name="data"></param>
        /// <param name="entityMetadata"></param>
        /// <param name="attributeMetadatas"></param>
        /// <returns></returns>
        public virtual IEnumerable <DuplicateRuleHitResult> ExecuteCore(Entity data, Schema.Domain.Entity entityMetadata, List <Schema.Domain.Attribute> attributeMetadatas)
        {
            if (!entityMetadata.DuplicateEnabled)
            {
                yield break;
            }
            var duplicateRules = _duplicateRuleFinder.QueryByEntityId(entityMetadata.EntityId, RecordState.Enabled);

            if (duplicateRules.NotEmpty())
            {
                var languageId = _appContext.GetFeature <ICurrentUser>().UserSettings.LanguageId;
                foreach (var rule in duplicateRules)
                {
                    rule.Conditions = _duplicateRuleConditionService.Query(n => n.Where(w => w.DuplicateRuleId == rule.DuplicateRuleId));
                    var             attrid     = rule.Conditions.Select(s => s.AttributeId).ToArray();
                    var             attributes = attributeMetadatas.Where(w => attrid.Contains(w.AttributeId));
                    QueryExpression qe         = new QueryExpression(data.Name, languageId);
                    qe.AddColumns(attributes.Select(s => s.Name).ToArray());
                    FilterExpression filter = new FilterExpression(LogicalOperator.And);
                    foreach (var item in qe.ColumnSet.Columns)
                    {
                        if (!data.ContainsKey(item))
                        {
                            continue;
                        }
                        var    attr  = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(item));
                        object value = data.UnWrapAttributeValue(attr);
                        //忽略空值
                        if (rule.Conditions.Find(x => x.AttributeId == attr.AttributeId).IgnoreNullValues)
                        {
                            if (value == null || value.ToString().IsEmpty())
                            {
                                continue;
                            }
                        }
                        filter.AddCondition(item, ConditionOperator.NotNull);
                        filter.AddCondition(item, ConditionOperator.Equal, value);
                    }
                    if (filter.Conditions.NotEmpty() && data.ContainsKey(data.IdName))
                    {
                        //排除自身的比较
                        filter.AddCondition(data.IdName, ConditionOperator.NotEqual, data.GetIdValue());
                    }
                    if (filter.Conditions.NotEmpty())
                    {
                        qe.Criteria.AddFilter(filter);
                        var record = _dataFinder.Retrieve(qe, true);
                        if (record != null && record.Count > 0)
                        {
                            yield return(new DuplicateRuleHitResult {
                                Rule = rule, Target = record
                            });
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public IActionResult Post(EditDuplicateRuleModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = _duplicateRuleFinder.FindById(model.DuplicateRuleId.Value);
                entity.Description = model.Description;
                entity.Name        = model.Name;
                entity.Intercepted = model.Intercepted;
                _duplicateRuleUpdater.Update(entity);
                var conditions = _duplicateRuleConditionService.Query(n => n.Where(w => w.DuplicateRuleId == entity.DuplicateRuleId));
                int i          = 0;
                foreach (var item in model.AttributeId)
                {
                    var id        = model.DetailId[i];
                    var condition = new DuplicateRuleCondition();
                    condition.DuplicateRuleId  = entity.DuplicateRuleId;
                    condition.EntityId         = model.EntityId;
                    condition.IgnoreNullValues = model.IgnoreNullValues[i];
                    condition.IsCaseSensitive  = model.IsCaseSensitive[i];
                    condition.AttributeId      = item;
                    if (id.Equals(Guid.Empty))
                    {
                        condition.DuplicateRuleConditionId = Guid.NewGuid();
                        _duplicateRuleConditionService.Create(condition);
                    }
                    else
                    {
                        condition.DuplicateRuleConditionId = id;
                        _duplicateRuleConditionService.Update(condition);
                        conditions.Remove(conditions.Find(n => n.DuplicateRuleConditionId == id));
                    }

                    i++;
                }
                //delete lost detail
                var lostid = conditions.Select(n => n.DuplicateRuleConditionId).ToList();
                _duplicateRuleConditionService.DeleteById(lostid);

                return(UpdateSuccess(new { id = entity.DuplicateRuleId }));
            }
            var msg = GetModelErrors(ModelState);

            return(UpdateFailure(msg));
        }