/// <summary> /// 保存数据源关联信息 /// </summary> /// <param name="attributes"></param> protected void SaveDataSourceAttribute(SqlSugarClient db, ISet <string> datasources) { // 删除这个步骤原来关联的数据源,注意需要ExecuteCommand db.Deleteable <DmeRuleStepDataSource>().Where(rsds => rsds.RuleStepId == step.Id).ExecuteCommand(); List <DmeRuleStepDataSource> newRefDatasources = new List <DmeRuleStepDataSource>(); foreach (var item in datasources) { DmeDataSource dmeDataSource = db.Queryable <DmeDataSource>().Single(ds => ds.SysCode == item); if (null == dmeDataSource) { continue; } newRefDatasources.Add(new DmeRuleStepDataSource { DataSourceId = dmeDataSource.Id, ModelId = this.step.ModelId, VersionId = this.step.VersionId, RuleStepId = this.step.Id }); } if (newRefDatasources.Count > 0) { // 注意需要ExecuteCommand db.Insertable <DmeRuleStepDataSource>(newRefDatasources).ExecuteCommand(); } }
public IList <string> ListMongoDataBase(string datasourceCode) { DmeDataSource dmeDataSource = IsMongodbAndReturn(datasourceCode); MongodbHost host = JsonConvert.DeserializeObject <MongodbHost>(dmeDataSource.Connection); return(MongodbManager <object> .ListDataBases(host.ConnectionString)); }
public object AddDataSource(DatasourceAddDTO datasourceAddDTO) { DmeDataSource dataSource = ClassValueCopier <DmeDataSource> .Copy(datasourceAddDTO); dataSource.CreateTime = DateUtil.CurrentTimeMillis; dataSource.SysCode = GuidUtil.NewGuid(); return(base.Repository.GetDbContext().Insertable <DmeDataSource>(dataSource).ExecuteReturnEntity()); }
public IList <string> ListMongoCollection(string datasourceCode) { DmeDataSource dmeDataSource = IsMongodbAndReturn(datasourceCode); MongodbHost host = JsonConvert.DeserializeObject <MongodbHost>(dmeDataSource.Connection); if (string.IsNullOrEmpty(host.DataBase)) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, "mongodb的DataBase不能为空"); } return(MongodbManager <object> .ListCollections(host.ConnectionString, host.DataBase)); }
/// <summary> /// 验证是否mongodb类型,并返回 /// </summary> /// <param name="datasourceCode"></param> /// <returns></returns> private DmeDataSource IsMongodbAndReturn(string datasourceCode) { var db = base.Repository.GetDbContext(); DmeDataSource dmeDataSource = db.Queryable <DmeDataSource>().Single(ds => ds.SysCode == datasourceCode); if (!nameof(EnumDataSourceType.MONGODB).Equals(dmeDataSource.Type)) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"数据源类型[{dmeDataSource.Type}]不是mongodb类型,请选择mongodb数据源类型"); } return(dmeDataSource); }
public object DeleteDataSource(string code) { DmeDataSource dmeDataSource = base.Db.Queryable <DmeDataSource>().Single(ds => ds.SysCode == code); if (null == dmeDataSource) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"数据源[{code}]不存在"); } LOG.Info($"删除步骤与数据源[{code}]的关联数据"); base.Db.Deleteable <DmeRuleStepDataSource>().Where(rsds => rsds.DataSourceId == dmeDataSource.Id).ExecuteCommand(); LOG.Info($"删除数据源[{code}]的信息"); base.Db.Deleteable <DmeDataSource>().Where(ds => ds.SysCode == code).ExecuteCommand(); return(true); }
public object AddDmeFileSystemSource(string name, IList <DmeFileSystemMeta> metas) { DmeDataSource dmeDataSource = new DmeDataSource { SysCode = GuidUtil.NewGuid(), Name = name, Type = nameof(EnumDataSourceType.DME_FILESYSTEM), CreateTime = DateUtil.CurrentTimeMillis, Remark = "dme文件系统来源" }; if (metas?.Count > 0) { dmeDataSource.Connection = JsonConvert.SerializeObject(metas); } base.Db.Insertable <DmeDataSource>(dmeDataSource).ExecuteCommandIdentityIntoEntity(); return(dmeDataSource); }
public Result Run() { // 找到算法输入依赖的算法实体 AlgorithmDTO dto = this.ruleStepMeta.GetAlgorithm(); // 找到这个步骤注入的参数值 var db = base.repository.GetDbContext(); List <DmeRuleStepAttribute> stepAttributes = db.Queryable <DmeRuleStepAttribute>().Where(rsa => rsa.RuleStepId == this.step.Id).ToList(); if (0 == stepAttributes?.Count) { LOG.Warn("没有找到步骤关联的参数设置,停止执行"); return(new Result(EnumSystemStatusCode.DME_FAIL, "没有找到步骤关联的参数设置,停止执行", null)); } IDictionary <string, Property> inputParams = dto.AlgorithmInstance.InParams; // 载入参数值 IDictionary <string, Property> paraValues = new Dictionary <string, Property>(); foreach (var item in stepAttributes) { if (!inputParams.ContainsKey(item.AttributeCode)) { continue; } Property inputParaProperty = inputParams[item.AttributeCode]; if (1 == item.IsNeedPrecursor) { // 前驱参数 if (null == item.AttributeValue || string.IsNullOrEmpty(item.AttributeValue.ToString()) || !item.AttributeValue.ToString().Contains(":")) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤[{step.SysCode}]的参数[{item.AttributeCode}]无效,值[{inputParaProperty.Value}]"); } string preStepName = item.AttributeValue.ToString().Split(":")[0]; string preAttributeName = item.AttributeValue.ToString().Split(":")[1]; DmeRuleStepAttribute preRuleStepAttribute = db.Queryable <DmeRuleStepAttribute, DmeRuleStep> ((rsa, rs) => new object[] { rs.Id == rsa.RuleStepId }) .Where((rsa, rs) => rs.ModelId == step.ModelId && rs.Name == preStepName && rsa.AttributeCode == preAttributeName) .Single(); if (null == preRuleStepAttribute) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤[{step.SysCode}]的参数[{item.AttributeCode}]无效,找不到前驱参数信息"); } paraValues[item.AttributeCode] = base.GetStepAttributeValue(preStepName, preAttributeName);// new Property(item.AttributeCode, item.AttributeCode, EnumValueMetaType.TYPE_UNKNOWN, preRuleStepAttribute.AttributeValue); } else { if (inputParaProperty.DataType == (int)EnumValueMetaType.TYPE_FEATURECLASS) { // 这种类型,要注意解析数据源 JObject featureClassJson = JObject.Parse(item.AttributeValue.ToString()); string featureClassName = featureClassJson.GetValue("name").Value <string>(); string sourceId = featureClassJson.GetValue("source").Value <string>(); // 根据sourceId查找数据源实体 DmeDataSource dataSource = base.repository.GetDbContext().Queryable <DmeDataSource>().Single(ds => ds.SysCode == sourceId); InputFeatureClassDTO inputFeatureClassDTO = new InputFeatureClassDTO { Name = featureClassName, Source = ClassValueCopier <DataSourceDTO> .Copy(dataSource) }; paraValues[item.AttributeCode] = new Property(item.AttributeCode, item.AttributeCode, EnumValueMetaType.TYPE_OBJECT, inputFeatureClassDTO); } else { paraValues[item.AttributeCode] = new Property(item.AttributeCode, item.AttributeCode, EnumValueMetaType.TYPE_UNKNOWN, item.AttributeValue); } } } dto.AlgorithmInstance.Init(paraValues); Result result = dto.AlgorithmInstance.Execute(); // 保存输出 if (result != null && EnumUtil.GetEnumDisplayName(EnumSystemStatusCode.DME_SUCCESS).Equals(result.Status)) { base.SaveOutput(dto.AlgorithmInstance.OutParams); return(new Result(EnumSystemStatusCode.DME_SUCCESS, "执行完毕", true)); } return(new Result(EnumSystemStatusCode.DME_FAIL, "执行失败,无异常信息", false)); }
public Result Run() { IDictionary <string, Property> attributes = this.ruleStepMeta.ReadAttributes(); string database = Convert.ToString(attributes[nameof(this.ruleStepMeta.Database)].Value); string collection = Convert.ToString(attributes[nameof(this.ruleStepMeta.Collection)].Value); IList <MongoFieldDTO> mongoFields = (IList <MongoFieldDTO>)attributes[nameof(this.ruleStepMeta.MongoFields)].Value; if (0 == mongoFields?.Count) { return(new Result(EnumSystemStatusCode.DME_FAIL, "没有输出的字段信息,停止计算", null)); } DmeDataSource dmeDataSource = (DmeDataSource)attributes[nameof(this.ruleStepMeta.Source)].Value; MongodbHost mongodbHost = JsonConvert.DeserializeObject <MongodbHost>(dmeDataSource.Connection); if (!string.IsNullOrEmpty(database)) { mongodbHost.DataBase = database; } mongodbHost.Collection = collection; JObject json = new JObject { { new JProperty("TaskId", this.taskId) }, { new JProperty("RuleStepId", this.step.Id) } }; foreach (var item in mongoFields) { string fieldName = item.Name; if (0 == item.IsNeedPrecursor) { LOG.Info($"当前[{item.Name}]为非前驱参数"); if (0 == item.IsUseName) { LOG.Info($"IsUseName为[{item.IsUseName}],将会使用NewName"); fieldName = item.NewName; } LOG.Info($"fieldName值为[{fieldName}]"); if (string.IsNullOrEmpty(fieldName)) { LOG.Error("mongo输出字段名称为空,不能构建"); continue; } if (null == item.ConstantValue) { LOG.Error($"mongo输出字段[{fieldName}]的值不能为NULL"); continue; } json.Add(new JProperty(fieldName, item.ConstantValue)); } else { LOG.Info($"当前[{item.Name}]为前驱参数"); // 前驱参数 if (string.IsNullOrEmpty(item.Name) || !item.Name.ToString().Contains(":")) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤[{step.SysCode}]的前驱参数[{item.Name}]无效"); } string preStepName = item.Name.Split(":")[0]; string preAttributeName = item.Name.Split(":")[1]; Property property = base.GetStepAttributeValue(preStepName, preAttributeName); if (null == property) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤名[{preStepName}]的参数[{preAttributeName}]无效"); } if (0 == item.IsUseName) { fieldName = item.NewName; } else { fieldName = preAttributeName; } if (string.IsNullOrEmpty(fieldName)) { LOG.Error("mongo输出字段名称为空,不能构建"); continue; } if (null == property.Value) { LOG.Error($"mongo输出字段[{fieldName}]的值不能为NULL"); continue; } json.Add(new JProperty(fieldName, property.Value)); } } // LOG.Info("JSON对象,方法ToJson:" + json.ToJson()); // LOG.Info("JSON对象,方法ToString:" + json.ToString()); // PS:不能使用json.ToJson()和json.ToBsonDocument构建一个BsonDocument,否则插入进去的实体对象不对; // 需要使用json.ToString() BsonDocument document = BsonDocument.Parse(json.ToString()); MongodbHelper <BsonDocument> .Add(mongodbHost, document); return(new Result(EnumSystemStatusCode.DME_SUCCESS, $"模型[{step.ModelId}]的步骤[{step.SysCode}]运算完毕", null)); }