Exemplo n.º 1
0
        /// <summary>
        /// 处理步骤属性信息
        /// </summary>
        /// <param name="db"></param>
        /// <param name="model"></param>
        /// <param name="version"></param>
        /// <param name="subStepAdd"></param>
        /// <param name="step"></param>
        private void HandleAttributes(SqlSugarClient db, DmeModel model, DmeModelVersion version, RuleStepAddDTO subStepAdd, DmeRuleStep step)
        {
            IList <AttributeReqDTO> properties = subStepAdd.Attributes;

            if (properties?.Count == 0)
            {
                LOG.Warn("没有可处理的步骤属性信息");
                return;
            }
            if (Register.RuleStepPluginsMap.ContainsKey(subStepAdd.StepType.Code))
            {
                RuleStepPluginRegisterDTO ruleStepPluginRegisterDTO = Register.RuleStepPluginsMap[subStepAdd.StepType.Code];
                String        baseDir      = AppDomain.CurrentDomain.BaseDirectory;
                string        assemblyPath = Path.Combine(baseDir, ruleStepPluginRegisterDTO.Assembly);
                Assembly      assembly     = Assembly.LoadFile(assemblyPath);
                IRuleStepData ruleStepData = (IRuleStepData)assembly.CreateInstance(ruleStepPluginRegisterDTO.ClassId, true, BindingFlags.CreateInstance, null
                                                                                    , new object[] { Repository, null, step }, null, null);
                if (null == ruleStepData)
                {
                    LOG.Warn($"无法创建步骤实体[{ruleStepPluginRegisterDTO.ClassId}]");
                    return;
                }
                IDictionary <string, Property> attributes = new Dictionary <string, Property>();
                // DmeRuleStepAttribute dmeRuleStepAttribute = null;
                foreach (var p in properties)
                {
                    EnumValueMetaType enumValueMetaType = new EnumValueMetaType();
                    if (string.IsNullOrEmpty(p.DataTypeCode))
                    {
                        enumValueMetaType = EnumValueMetaType.TYPE_UNKNOWN;
                    }
                    else
                    {
                        enumValueMetaType = EnumUtil.GetEnumObjByName <EnumValueMetaType>(p.DataTypeCode);
                    }
                    attributes[p.Name] = new Property(p.Name, p.Name, enumValueMetaType, p.Value,
                                                      null, null, null, 1, 0, 1, p.DataSourceCode, p.IsNeedPrecursor, p.Type);
                }
                ruleStepData.SaveAttributes(attributes);
            }
        }
Exemplo n.º 2
0
        public object SaveRuleStepInfos(ModelRuleStepInfoDTO info)
        {
            var db = base.Repository.GetDbContext();

            // 开始事务
            return(db.Ado.UseTran <object>(() =>
            {
                // 根据模型版本号,获取模型版本信息
                DmeModelVersion modelVersion = base.Repository.GetDbContext().Queryable <DmeModelVersion>().Single(mv => mv.SysCode == info.ModelVersionCode);
                // 清除模型的步骤信息
                db.Deleteable <DmeRuleStep>(rs => rs.ModelId == modelVersion.ModelId && rs.VersionId == modelVersion.Id).ExecuteCommand();
                // 清除步骤属性信息
                db.Deleteable <DmeRuleStepAttribute>(rsa => rsa.ModelId == modelVersion.ModelId && rsa.VersionId == modelVersion.Id).ExecuteCommand();
                // 根据key建立起关系
                if (info.RuleSteps?.Count > 0)
                {
                    // 客户端传过来的key和业务id映射关系
                    IDictionary <string, int> key2BizId = new Dictionary <string, int>();
                    foreach (var step in info.RuleSteps)
                    {
                        DmeRuleStep stepEntity = new DmeRuleStep
                        {
                            SysCode = GuidUtil.NewGuid(),
                            ModelId = modelVersion.ModelId,
                            VersionId = modelVersion.Id
                        };
                        stepEntity.Id = db.Insertable <DmeRuleStep>(stepEntity).ExecuteReturnIdentity();
                        key2BizId[step.Key] = stepEntity.Id;
                        // 处理步骤属性
                        if (step.Attributes?.Count > 0)
                        {
                            IRuleStepData ruleStepData = RuleStepFactory.GetRuleStepData(step.TypeCode, base.Repository, null, stepEntity);
                            ruleStepData.SaveAttributes(step.Attributes);
                            //IList<DmeRuleStepAttribute> attributeEntities = new List<DmeRuleStepAttribute>();
                            //foreach (var att in step.Attributes)
                            //{
                            //    attributeEntities.Add(new DmeRuleStepAttribute
                            //    {
                            //        RuleStepId = stepEntity.Id,
                            //        ModelId = stepEntity.ModelId,
                            //        VersionId = stepEntity.VersionId,
                            //        AttributeCode = att.Key,
                            //        AttributeValue = att.Value
                            //    });
                            //}
                            //db.Insertable<DmeRuleStepAttribute>(attributeEntities).ExecuteCommand();
                        }
                    }
                    // 处理步骤的向量关系
                    if (info.Vectors?.Count > 0)
                    {
                        IList <DmeRuleStepHop> ruleStepHops = new List <DmeRuleStepHop>();
                        foreach (var vector in info.Vectors)
                        {
                            // 只要向量的信息不完整,都不需要保存连接信息
                            if (!key2BizId.ContainsKey(vector.StepFromName) || !key2BizId.ContainsKey(vector.StepToName))
                            {
                                continue;
                            }
                            ruleStepHops.Add(new DmeRuleStepHop
                            {
                                ModelId = modelVersion.ModelId,
                                VersionId = modelVersion.Id,
                                StepFromId = key2BizId[vector.StepFromName],
                                StepToId = key2BizId[vector.StepToName],
                                Enabled = vector.Enabled
                            });
                        }
                        db.Insertable <DmeRuleStepHop>(ruleStepHops).ExecuteCommandAsync();
                    }
                }
                return true;
            }).Data);
        }