コード例 #1
0
        private List <IRouteValue> GetTableShardingValues(ShardingRule shardingRule, TableRule tableRule, ShardingCondition shardingCondition)
        {
            IShardingStrategy tableShardingStrategy = shardingRule.GetTableShardingStrategy(tableRule);

            return(IsGettingShardingValuesFromHint(tableShardingStrategy)
                    ? GetTableShardingValuesFromHint() : GetShardingValuesFromShardingConditions(shardingRule, tableShardingStrategy.GetShardingColumns(), shardingCondition));
        }
コード例 #2
0
        /**
         * Load table meta data.
         *
         * @param logicTableName logic table name
         * @param databaseType database type
         * @return table meta data
         * @throws SQLException SQL exception
         */
        public TableMetaData Load(string logicTableName, IDatabaseType databaseType)
        {
            TableRule tableRule = shardingRule.GetTableRule(logicTableName);

            if (!isCheckingMetaData)
            {
                DataNode dataNode = tableRule.ActualDataNodes.First();
                var      rawMasterDataSourceName = shardingRule.ShardingDataSourceNames.GetRawMasterDataSourceName(dataNode.GetDataSourceName());
                return(TableMetaDataLoader.Load(dataSourceMap[rawMasterDataSourceName], dataNode.GetTableName(), databaseType.GetName()));
            }
            var dataNodeGroups = tableRule.GetDataNodeGroups();
            ConcurrentDictionary <string, TableMetaData> actualTableMetaDataMap = new ConcurrentDictionary <string, TableMetaData>();

            var tasks = dataNodeGroups.SelectMany(o => o.Value.Select(dataNode => Task.Run(() =>
            {
                var tableMetaData = Load(dataNode, databaseType);
                actualTableMetaDataMap.TryAdd(dataNode.GetTableName(), tableMetaData);
            }))).ToArray();

            Task.WaitAll(tasks);


            CheckUniformed(logicTableName, actualTableMetaDataMap);
            return(actualTableMetaDataMap.Select(o => o.Value).FirstOrDefault());
        }
コード例 #3
0
        /// <summary>
        /// 从模板复制目录
        /// </summary>
        /// <param name="newDirList"></param>
        /// <param name="oldDirList"></param>
        /// <param name="nodePid"></param>
        /// <param name="parent"></param>
        /// <param name="tableName"></param>
        /// <param name="dirIfno"></param>
        public void CopyGeneralDir(List <BsonDocument> newDirList, List <BsonDocument> oldDirList, int nodePid, BsonDocument parent, string tableName, BsonDocument dirIfno)
        {
            var dir = oldDirList.Where(m => m.Int("nodePid") == nodePid).ToList();

            if (!dir.Any())
            {
                return;
            }
            var    tableEntity  = new TableRule(tableName + "Dir");
            var    tableEntity1 = new TableRule(tableName);//模板或项目目录数据项
            string primaryKey;
            string primaryKey1;

            if (tableEntity1 == null)
            {
                primaryKey  = "nodeDirId";
                primaryKey1 = "nodeId";
            }
            else
            {
                primaryKey1 = tableEntity1.PrimaryKey;
                if (tableEntity == null)
                {
                    primaryKey = primaryKey1.Substring(0, primaryKey1.Length - 2);
                    primaryKey = primaryKey + "Id";
                }
                else
                {
                    primaryKey = tableEntity.PrimaryKey;
                }
            }
            foreach (var tempDir in dir)
            {
                #region   制目录
                var newTempDir = new BsonDocument();
                newTempDir.Add("srcId", tempDir.String(primaryKey));
                newTempDir.Add("name", tempDir.String("name"));
                newTempDir.Add("typeId", "0");
                newTempDir.Add("isFill", tempDir.String("isFill"));
                newTempDir.Add("isTime", tempDir.String("isTime"));
                if (tableName == "CostEcoIndicator" || tableName == "KeyTechEcoIndicator")
                {
                    newTempDir.Add("content", tempDir.String("content"));
                }
                newTempDir.Add("colsType", tempDir.String("colsType"));
                newTempDir.Add(primaryKey1, dirIfno.String(primaryKey1));
                newTempDir.Add("nodePid", parent != null ? parent.String(primaryKey) : "0");
                #endregion

                var result = this._ctx.Insert(tableName + "Dir", newTempDir);
                if (result.Status != Status.Successful)
                {
                    return;
                }
                newTempDir = result.BsonInfo;
                newDirList.Add(newTempDir);
                CopyGeneralDir(newDirList, oldDirList, tempDir.Int(primaryKey), newTempDir, tableName, dirIfno);
            }
        }
コード例 #4
0
        /// <summary>
        /// 保存版本目录
        /// </summary>
        /// <param name="newDirList"></param>
        /// <param name="oldDirList"></param>
        /// <param name="nodePid"></param>
        /// <param name="parent"></param>
        /// <param name="tableName"></param>
        /// <param name="dirIfno"></param>
        /// <param name="sourceDirTb"></param>
        /// <param name="filed"></param>
        public void SaveVerDir(List <BsonDocument> newDirList, List <BsonDocument> oldDirList, int nodePid, BsonDocument parent, string tableName, BsonDocument dirIfno, string sourceDirTb, List <string> filed)
        {
            var dir = oldDirList.Where(m => m.Int("nodePid") == nodePid).ToList();

            if (!dir.Any())
            {
                return;
            }
            string sourceKey    = new TableRule(sourceDirTb) != null?new TableRule(sourceDirTb).GetPrimaryKey():string.Empty;
            var    tableEntity  = new TableRule(tableName + "Dir");
            var    tableEntity1 = new TableRule(tableName);//模板或项目目录数据项
            string primaryKey;
            string primaryKey1;

            if (tableEntity1 == null)
            {
                primaryKey  = "nodeDirId";
                primaryKey1 = "nodeId";
            }
            else
            {
                primaryKey1 = tableEntity1.PrimaryKey;
                if (tableEntity == null)
                {
                    primaryKey = primaryKey1.Substring(0, primaryKey1.Length - 2);
                    primaryKey = primaryKey + "Id";
                }
                else
                {
                    primaryKey = tableEntity.PrimaryKey;
                }
            }
            foreach (var tempDir in dir)
            {
                #region   制目录
                var newTempDir = new BsonDocument();
                newTempDir.Add("src" + primaryKey, tempDir.String(primaryKey));
                newTempDir.Add("name", tempDir.String("name"));
                newTempDir.Add("typeId", "0");
                newTempDir.Add("isFill", tempDir.String("isFill"));
                newTempDir.Add("colsType", tempDir.String("colsType"));
                newTempDir.Add(primaryKey1, dirIfno.String(primaryKey1));
                foreach (var tempFiled in filed)
                {
                    newTempDir.Add(tempFiled, tempDir.String(tempFiled));
                }
                newTempDir.Add("nodePid", parent != null ? parent.String(primaryKey) : "0");
                #endregion

                var result = this._ctx.Insert(tableName + "Dir", newTempDir);
                if (result.Status != Status.Successful)
                {
                    return;
                }
                newTempDir = result.BsonInfo;
                newDirList.Add(newTempDir);
                SaveVerDir(newDirList, oldDirList, tempDir.Int(sourceKey), newTempDir, tableName, dirIfno, sourceDirTb, filed);
            }
        }
コード例 #5
0
        /// <summary>
        /// 初始化项目信息
        /// </summary>
        /// <param name="projId"></param>
        /// <param name="templateDC">传入表名和对应的模板Id</param>
        public void ProjectInfoInit(int projId, Dictionary <string, int> templateDC)
        {
            InvokeResult result  = new InvokeResult();
            BsonDocument project = this._ctx.FindOneByQuery("Project", Query.EQ("projId", projId.ToString()));//项目信息

            if (project == null)
            {
                throw new ArgumentNullException();
            }
            foreach (var dc in templateDC)
            {
                int       templateId  = dc.Value;
                TableRule tableEntity = new TableRule(dc.Key);
                string    primaryKey  = tableEntity.GetPrimaryKey();
                if (string.IsNullOrEmpty(primaryKey))
                {
                    throw new ArgumentNullException();
                }
                BsonDocument templateInfo = this._ctx.FindOneByQuery(dc.Key, Query.EQ(primaryKey, dc.Value.ToString()));
                if (templateInfo == null)
                {
                    templateInfo = this._ctx.FindOneByQuery(dc.Key, Query.EQ("isTemplate", "1"));//传入模板Id不存在,查找默认模板
                }
                if (templateInfo != null)
                {
                    templateId = templateInfo.Int(primaryKey);                                                     //模板Id
                    List <BsonDocument> templateDataSubList = new List <BsonDocument>();                           //模板详细目录

                    BsonDocument entity = this._ctx.FindOneByQuery(dc.Key, Query.EQ("projId", projId.ToString())); //项目对应表目录实体
                    if (entity == null)
                    {
                        entity = new BsonDocument();
                        entity.Add("name", project != null ? project.String("name") : string.Empty + "目录");
                        entity.Add("projId", projId.ToString());
                        entity.Add("isTemplate", "0");
                        entity.Add("srcId", templateId.ToString());
                        result = this._ctx.Insert(dc.Key, entity);
                        entity = result.BsonInfo;
                    }
                    List <BsonDocument> dataSubList = this._ctx.FindAllByQuery(dc.Key + "Dir", Query.EQ(primaryKey, entity.String(primaryKey))).ToList();
                    if (dataSubList.Count() > 0)
                    {
                        this._ctx.Delete(dc.Key + "Dir", Query.EQ(primaryKey, entity.String(primaryKey)));//删除旧信息
                    }
                    if (result.Status == Status.Successful || result.Status == Status.Invaild)
                    {
                        templateDataSubList = this._ctx.FindAllByQuery(dc.Key + "Dir", Query.EQ(primaryKey, templateId.ToString())).ToList();
                        TemplateDirBll      tdBll  = TemplateDirBll._();
                        List <BsonDocument> newDir = new List <BsonDocument>();
                        tdBll.CopyGeneralDir(newDir, templateDataSubList, 0, null, dc.Key, entity);
                    }
                    else
                    {
                        throw new ArgumentNullException();
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// 复制树形结构目录
        /// </summary>
        /// <param name="tableName">树形结构的表名称</param>
        /// <param name="dataList">被复制的树型结构列表</param>
        /// <param name="fields">要复制的字段</param>
        /// <param name="keyValueDict">固定加入的值:比如树形目录挂在项目下可能就要加入项目的主键Id</param>
        /// <returns></returns>
        public List <BsonDocument> CopyTreeTable(string tableName, List <BsonDocument> dataList, string projId, string versionId, string[] fields, Dictionary <string, string> keyValueDict, bool hasTemplateId)
        {
            TableRule tableRule  = new TableRule(tableName);
            string    primaryKey = tableRule.ColumnRules.Where(t => t.IsPrimary == true).First().Name;

            int count = dataList.Count;
            List <BsonDocument>         datas   = new List <BsonDocument>(count);
            Dictionary <string, string> keyDict = new Dictionary <string, string>();
            Dictionary <string, List <BsonDocument> > tbDirDict = new Dictionary <string, List <BsonDocument> >();

            foreach (var d in dataList.OrderBy(s => s.String("nodeKey")))
            {
                BsonDocument record = new BsonDocument();
                foreach (var s in fields)
                {
                    record.Add(s, d.String(s));
                    record.Add(s + "_bak", d.String(s));//初始化暂存区数据
                }

                foreach (var dict in keyValueDict)
                {
                    record.Add(dict.Key, dict.Value);
                }

                string keyValue = d.String(primaryKey);
                record.Add("srcId", keyValue); //记录被复制节点的主键值
                string copyKey = "srcId";
                if (hasTemplateId)             //非模板拷贝,传入拷贝"templateId"
                {
                    copyKey = "srcId";         //模板
                }
                else//模板拷贝
                {
                    record.Add("templateId", keyValue);                      //记录模板的字段值
                    copyKey = "templateId";                                  //模板
                }
                CalcRelId(tbDirDict, d, record, projId, versionId, copyKey); //计算工程量关联的信息
                string oldNodePid = d.String("nodePid");                     //获取被复制节点的父节点id;
                string nodePid    = "0";

                //获取对应父节点
                if (keyDict.ContainsKey(oldNodePid))
                {
                    nodePid = keyDict[oldNodePid];
                }
                record.Add("nodePid", nodePid);

                var result = _ctx.Insert(tableName, record);
                if (result.Status == Status.Successful)
                {
                    keyDict.Add(d.String(primaryKey), result.BsonInfo.String(primaryKey));//记录树形对应节点的主键对
                }
                datas.Add(record);
            }
            return(datas);
        }
コード例 #7
0
        private ICollection <DataNode> Route0(ShardingRule shardingRule, TableRule tableRule, List <IRouteValue> databaseShardingValues, List <IRouteValue> tableShardingValues)
        {
            ICollection <String>   routedDataSources = RouteDataSources(shardingRule, tableRule, databaseShardingValues);
            ICollection <DataNode> result            = new LinkedList <DataNode>();

            foreach (var routedDataSource in routedDataSources)
            {
                result.AddAll(RouteTables(shardingRule, tableRule, routedDataSource, tableShardingValues));
            }
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// 获取关联信息
        /// </summary>
        /// <param name="tbDirDict"></param>
        /// <param name="relTable"></param>
        /// <param name="versionId"></param>
        /// <param name="key"></param>
        /// <param name="relId"></param>
        /// <returns></returns>
        private BsonDocument GetRelInfo(Dictionary <string, List <BsonDocument> > tbDirDict, string relTable, string versionId, string key, int relId)
        {
            if (!tbDirDict.ContainsKey(relTable))
            {
                tbDirDict.Add(relTable, GetPolicyDirs(relTable, versionId, key));
            }
            TableRule dirRule = new TableRule(relTable + "Dir");
            string    dirKey  = dirRule.PrimaryKey;

            return(tbDirDict[relTable].SingleOrDefault(s => s.Int(dirKey) == relId));//获取工程量
        }
コード例 #9
0
        /// <summary>
        /// 获取目录树形
        /// </summary>
        /// <param name="tbName"></param>
        /// <param name="moveId"></param>
        /// <param name="ddirId">目录树Id</param>
        /// <returns></returns>
        public ActionResult GetCategoryTree(string tbName, string moveId, string libId)
        {
            TableRule tbRule = new TableRule(tbName);

            string tbKey = tbRule.PrimaryKey;

            List <BsonDocument> catList  = dataOp.FindAllByQuery(tbName, Query.EQ("libId", libId)).ToList();//获取模板下的目录
            List <TreeNode>     treeList = TreeHelper.GetSingleTreeList(catList);

            return(new XmlTree(treeList));
        }
コード例 #10
0
 private ICollection <DataNode> GetDataNodes(ShardingRule shardingRule, TableRule tableRule)
 {
     if (IsRoutingByHint(shardingRule, tableRule))
     {
         return(RouteByHint(shardingRule, tableRule));
     }
     if (IsRoutingByShardingConditions(shardingRule, tableRule))
     {
         return(RouteByShardingConditions(shardingRule, tableRule));
     }
     return(RouteByMixedConditions(shardingRule, tableRule));
 }
コード例 #11
0
ファイル: Common.cs プロジェクト: zluckymn/Remote.Quartz.Jobs
        public ActionResult DelePostInfo(FormCollection saveForm)
        {
            InvokeResult result = new InvokeResult();

            string tbName   = saveForm["tbName"] != null ? saveForm["tbName"] : "";
            string queryStr = saveForm["queryStr"] != null ? saveForm["queryStr"] : "";
            string dataStr  = "";

            int       primaryKey = 0;
            TableRule rule       = new TableRule(tbName);
            string    keyName    = rule.GetPrimaryKey();
            var       isLogicDel = rule.isLogicDel;

            if (!isLogicDel)
            {
                #region  除文档

                if (!string.IsNullOrEmpty(queryStr))
                {
                    var query     = TypeConvert.NativeQueryToQuery(queryStr);
                    var recordDoc = dataOp.FindOneByQuery(tbName, query);
                    saveForm["keyValue"] = result.BsonInfo.Text(keyName);
                    if (recordDoc != null)
                    {
                        primaryKey = recordDoc.Int(keyName);
                    }

                    FileOperationHelper opHelper = new FileOperationHelper();
                    result = opHelper.DeleteFile(tbName, keyName, primaryKey.ToString());
                }
                #endregion

                #region  除数据
                BsonDocument curData = new BsonDocument();  //当前数据,即操作前数据

                if (queryStr.Trim() != "")
                {
                    curData = dataOp.FindOneByQuery(tbName, TypeConvert.NativeQueryToQuery(queryStr));
                }

                dataOp.SetOperationData(tbName, queryStr, dataStr);

                result = dataOp.Delete();
                #endregion
                //删除文件
            }
            else
            {
                return(logicDelePostInfo(saveForm));
            }

            return(Json(TypeConvert.InvokeResultToPageJson(result)));
        }
コード例 #12
0
        /// <summary>
        /// 获取模板的目录信息
        /// </summary>
        /// <param name="dept"></param>
        /// <returns></returns>
        public List <BsonDocument> GetTemplateDirs(string dept)
        {
            var tableRule  = new TableRule(dept);
            var primaryKey = tableRule.ColumnRules.Single(s => s.IsPrimary).Name;

            var dirTable = dept + "Dir";

            var priKeyValue = _ctx.FindOneByQuery(dept, Query.EQ("isTemplate", "1")).String(primaryKey);
            var dirs        = _ctx.FindAllByQuery(dirTable, Query.EQ(primaryKey, priKeyValue)).ToList();

            return(dirs);
        }
コード例 #13
0
        /// <summary>
        /// 确认总办,市场,设计数据
        /// </summary>
        /// <param name="tbName"></param>
        /// <param name="versionId"></param>
        private void ConfirmCommonData(string tbName, string versionId, int belong = -1)
        {
            IList <string>       keys    = PolicyDataInfo.PolicyDataDict[tbName];
            IList <BsonDocument> dirList = GetTableDirsByVersionId(tbName, versionId);//获取目录名称

            if (belong > -1)
            {
                dirList = dirList.Where(s => s.Int("belong") == belong).ToList();
            }
            TableRule dirRule = new TableRule(tbName + "Dir");

            ConfirmData(dirRule, dirList, keys);
        }
コード例 #14
0
        /// <summary>
        /// 获取主键字段名
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static string KeyField(this BsonDocument bsonDoc)
        {
            var        tbName        = bsonDoc.TableName();
            var        keyField      = string.Empty;
            TableRule  childTable    = new TableRule(tbName);                                                   //获取子表的表结构
            ColumnRule foreignColumn = childTable.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault(); //子表指向源表的外键字段

            if (foreignColumn != null)
            {
                keyField = foreignColumn.Name;
            }
            return(keyField);
        }
コード例 #15
0
        private ICollection <string> RouteDataSources(ShardingRule shardingRule, TableRule tableRule, List <IRouteValue> databaseShardingValues)
        {
            if (databaseShardingValues.IsEmpty())
            {
                return(tableRule.GetActualDatasourceNames());
            }
            ICollection <string> result = new HashSet <string>(shardingRule.GetDatabaseShardingStrategy(tableRule).DoSharding(tableRule.GetActualDatasourceNames(), databaseShardingValues, this.Properties));

            ShardingAssert.If(result.IsEmpty(), "no database route info");
            ShardingAssert.Else(tableRule.GetActualDatasourceNames().All(o => result.Contains(o)), $"Some routed data sources do not belong to configured data sources. routed data sources: `{result}`, configured data sources: `{tableRule.GetActualDatasourceNames()}`");

            return(result);
        }
コード例 #16
0
        /// <summary>
        /// Uses a delegate to return a default table if no table id is provided.
        /// </summary>
        public CustomVariantResolver SetDefaultTable(GetTableWithContextDelegate inGetter)
        {
            if (inGetter == null)
            {
                throw new ArgumentNullException("inGetter");
            }

            if (m_DefaultTable == null)
            {
                m_DefaultTable = new TableRule();
            }
            m_DefaultTable.SetDelegate(inGetter);
            return(this);
        }
コード例 #17
0
        /// <summary>
        /// 创建地块目录
        /// </summary>
        /// <param name="tbName"></param>
        /// <param name="landId"></param>
        /// <param name="templateId"></param>
        public void LandDirCreate(string tbName, int landId, int templateId)
        {
            InvokeResult result      = new InvokeResult();
            TableRule    tableEntity = new TableRule(tbName);
            string       primaryKey  = tableEntity.GetPrimaryKey();

            if (string.IsNullOrEmpty(primaryKey))
            {
                throw new ArgumentNullException();
            }
            BsonDocument templateInfo = this._ctx.FindOneByQuery(tbName, Query.EQ(primaryKey, templateId.ToString()));

            if (templateInfo == null)
            {
                templateInfo = this._ctx.FindOneByQuery(tbName, Query.EQ("isTemplate", "1"));//传入模板Id不存在,查找默认模板
            }
            if (templateInfo != null)
            {
                templateId = templateInfo.Int(primaryKey);                                                            //模板Id
                List <BsonDocument> templateDataSubList = new List <BsonDocument>();                                  //模板详细目录
                BsonDocument        land   = this._ctx.FindOneByQuery("Land", Query.EQ("landId", landId.ToString())); //地块信息
                BsonDocument        entity = this._ctx.FindOneByQuery(tbName, Query.EQ("landId", landId.ToString())); //地块对应表目录实体
                if (entity == null)
                {
                    entity = new BsonDocument();
                    entity.Add("name", land != null ? land.String("name") : string.Empty + "目录");
                    entity.Add("landId", landId.ToString());
                    entity.Add("isTemplate", "0");
                    entity.Add("srcId", templateId.ToString());
                    result = this._ctx.Insert(tbName, entity);
                    entity = result.BsonInfo;
                }
                List <BsonDocument> dataSubList = this._ctx.FindAllByQuery(tbName + "Dir", Query.EQ(primaryKey, entity.String(primaryKey))).ToList();
                if (dataSubList.Count() > 0)
                {
                    this._ctx.Delete(tbName + "Dir", Query.EQ(primaryKey, entity.String(primaryKey)));
                }
                if (result.Status == Status.Successful || result.Status == Status.Invaild)
                {
                    templateDataSubList = this._ctx.FindAllByQuery(tbName + "Dir", Query.EQ(primaryKey, templateId.ToString())).ToList();
                    TemplateDirBll      tdBll  = TemplateDirBll._();
                    List <BsonDocument> newDir = new List <BsonDocument>();
                    tdBll.CopyGeneralDir(newDir, templateDataSubList, 0, null, tbName, entity);
                }
                else
                {
                    throw new ArgumentNullException();
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Sets the default table if no table id is provided.
        /// </summary>
        public CustomVariantResolver SetDefaultTable(VariantTable inTable)
        {
            if (inTable == null)
            {
                throw new ArgumentNullException("inTable");
            }

            if (m_DefaultTable == null)
            {
                m_DefaultTable = new TableRule();
            }
            m_DefaultTable.SetConst(inTable);
            return(this);
        }
コード例 #19
0
        private ICollection <DataNode> RouteTables(ShardingRule shardingRule, TableRule tableRule, string routedDataSource, List <IRouteValue> tableShardingValues)
        {
            ICollection <string> availableTargetTables = tableRule.GetActualTableNames(routedDataSource);
            ICollection <string> routedTables          = new HashSet <string>(tableShardingValues.IsEmpty() ? availableTargetTables
                    : shardingRule.GetTableShardingStrategy(tableRule).DoSharding(availableTargetTables, tableShardingValues, this.Properties));

            ShardingAssert.If(routedTables.IsEmpty(), "no table route info");
            ICollection <DataNode> result = new LinkedList <DataNode>();

            foreach (var routedTable in routedTables)
            {
                result.Add(new DataNode(routedDataSource, routedTable));
            }
            return(result);
        }
コード例 #20
0
        /// <summary>
        /// 上一个版本拷贝
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="name"></param>
        /// <param name="projId"></param>
        /// <param name="preVersionId">上一个版本Id</param>
        /// <param name="versionId"></param>
        /// <param name="fields">要拷贝的字段数组</param>
        public void CopyFromPreVersion(string tableName, string name, string projId, string preVersionId, string versionId, string[] fields)
        {
            TableRule    tableRule  = new TableRule(tableName);
            string       primaryKey = tableRule.ColumnRules.Where(t => t.IsPrimary == true).First().Name;
            BsonDocument preNode    = _ctx.FindOneByQuery(tableName, Query.And(Query.EQ("versionId", preVersionId), Query.EQ("projId", projId)));//上一个版本的数据
            BsonDocument dirParent  = new BsonDocument {
                { "versionId", versionId }, { "name", name }, { "projId", projId }
            };                                                                                                                                            //挂载目录的
            var projNodeResult = _ctx.Insert(tableName, dirParent);
            List <BsonDocument>         templateDirs = _ctx.FindAllByQuery(tableName + "Dir", Query.EQ(primaryKey, preNode.String(primaryKey))).ToList(); //获取上一个节点的目录结构
            Dictionary <string, string> keyValueDict = new Dictionary <string, string>();

            keyValueDict.Add(primaryKey, projNodeResult.BsonInfo.String(primaryKey));
            CopyTreeTable(tableName + "Dir", templateDirs, projId, versionId, fields, keyValueDict, true);//拷贝目录信息
        }
コード例 #21
0
        /// <summary>
        /// 从模板中拷贝目录结构
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="name"></param>
        /// <param name="versionId"></param>
        /// <param name="fields"></param>
        private void CopyPolicyDateFromTemplate(string tableName, string name, string projId, string versionId, string[] fields)
        {
            TableRule    tableRule  = new TableRule(tableName);
            string       primaryKey = tableRule.ColumnRules.Where(t => t.IsPrimary == true).First().Name;
            BsonDocument template   = _ctx.FindOneByQuery(tableName, Query.EQ("isTemplate", "1"));//找出系统模板
            BsonDocument dirParent  = new BsonDocument {
                { "versionId", versionId }, { "name", name }, { "projId", projId }
            };                                                                                                               //挂载目录的
            var projNodeResult = _ctx.Insert(tableName, dirParent);
            List <BsonDocument>         templateDirs = _ctx.FindAllByQuery(tableName + "Dir", Query.EQ(primaryKey, template.String(primaryKey))).ToList();
            Dictionary <string, string> keyValueDict = new Dictionary <string, string>();

            keyValueDict.Add(primaryKey, projNodeResult.BsonInfo.String(primaryKey));
            CopyTreeTable(tableName + "Dir", templateDirs, projId, versionId, fields, keyValueDict, false);//拷贝目录信息
        }
コード例 #22
0
        private ICollection <RouteUnit> GetAllRouteUnits(ShardingRule shardingRule, String logicTableName)
        {
            ICollection <RouteUnit> result = new LinkedList <RouteUnit>();
            TableRule tableRule            = shardingRule.GetTableRule(logicTableName);

            foreach (var dataNode in tableRule.ActualDataNodes)
            {
                RouteUnit routeUnit = new RouteUnit(new RouteMapper(dataNode.GetDataSourceName(), dataNode.GetDataSourceName()), new List <RouteMapper>()
                {
                    new RouteMapper(logicTableName, dataNode.GetTableName())
                });
                result.Add(routeUnit);
            }

            return(result);
        }
コード例 #23
0
        /// <summary>
        /// 从模板中拷贝目录结构
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="name"></param>
        /// <param name="versionId"></param>
        /// <param name="fields"></param>
        /// <param name="keyValueDict"></param>
        private void CopyPolicyDateFromTemplate(string tableName, string name, string projId, string versionId, string[] fields)
        {
            var tableRule  = new TableRule(tableName);
            var primaryKey = tableRule.PrimaryKey;
            var template   = _ctx.FindOneByQuery(tableName, Query.EQ("isTemplate", "1"));//找出系统模板
            var dirParent  = new BsonDocument {
                { "versionId", versionId }, { "name", name }, { "projId", projId }
            };                                                                                                      //挂载目录的
            var projNodeResult = _ctx.Insert(tableName, dirParent);
            var templateDirs   = _ctx.FindAllByQuery(tableName + "Dir", Query.EQ(primaryKey, template.String(primaryKey))).ToList();
            var keyValueDict   = new Dictionary <string, string> {
                { primaryKey, projNodeResult.BsonInfo.String(primaryKey) }
            };

            CopyTreeTable(tableName + "Dir", templateDirs, fields, keyValueDict, false);//拷贝目录信息
        }
コード例 #24
0
 /// <summary>
 /// 确认决策数据
 /// </summary>
 /// <param name="rule"></param>
 /// <param name="dirList"></param>
 /// <param name="keys"></param>
 private void ConfirmData(TableRule rule, IEnumerable <BsonDocument> dirList, IEnumerable <string> keys)
 {
     foreach (var dir in dirList)
     {
         BsonDocument update = new BsonDocument();
         foreach (var key in keys)
         {
             string bakVal = dir.String(key + "_bak");
             if (!string.IsNullOrEmpty(bakVal))
             {
                 update.Add(key, bakVal);
             }
         }
         _ctx.Update(rule.Name, Query.EQ(rule.PrimaryKey, dir.String(rule.PrimaryKey)), update);
     }
 }
コード例 #25
0
        /// <summary>
        /// 从上一个版本拷贝数据
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="name"></param>
        /// <param name="projId"></param>
        /// <param name="preVersionId"></param>
        /// <param name="versionId"></param>
        /// <param name="fields"></param>
        private void CreateVersionFromPre(string tableName, string name, string projId, string preVersionId, string versionId, string[] fields)
        {
            var tableRule  = new TableRule(tableName);
            var primaryKey = tableRule.PrimaryKey;
            var preNode    = _ctx.FindOneByQuery(tableName, Query.And(Query.EQ("versionId", preVersionId), Query.EQ("projId", projId)));//上一个版本的数据
            var dirParent  = new BsonDocument {
                { "versionId", versionId }, { "name", name }, { "projId", projId }
            };                                                                                                                      //挂载目录的
            var projNodeResult = _ctx.Insert(tableName, dirParent);
            var templateDirs   = _ctx.FindAllByQuery(tableName + "Dir", Query.EQ(primaryKey, preNode.String(primaryKey))).ToList(); //获取上一个节点的目录结构
            var keyValueDict   = new Dictionary <string, string> {
                { primaryKey, projNodeResult.BsonInfo.String(primaryKey) }
            };

            CopyTreeTable(tableName + "Dir", templateDirs, fields, keyValueDict, true);//拷贝目录信息
        }
コード例 #26
0
        /// <summary>
        /// 同步主键
        /// 当主键表中所存的的值小于对应表中实际最大主键值时
        /// 修改主键表中的值为该最大值
        /// </summary>
        /// <returns></returns>
        public JsonResult SyncPK()
        {
            InvokeResult       result   = new InvokeResult();
            List <StorageData> dataList = new List <StorageData>();
            var pkCounter    = dataOp.FindAll("TablePKCounter").ToList();
            var allRules     = TableRule.GetAllTables();
            var allTempRules = allRules.Select(i => new
            {
                tbName = i.Name,
                key    = i.GetPrimaryKey()
            }).ToList();

            foreach (var counter in pkCounter)
            {
                var    tbName  = counter.Text("tbName");
                var    curMax  = counter.Int("count");//当前主键表所存主键值
                int    factMax = 0;
                var    rule    = allTempRules.Where(i => i.tbName == tbName).FirstOrDefault();
                string key     = string.Empty;
                if (rule != null)
                {
                    key = rule.key ?? string.Empty;
                }
                string current = string.Empty;

                if (!string.IsNullOrWhiteSpace(key))
                {
                    var allDatas = dataOp.FindAll(tbName).SetFields(key).ToList();
                    if (allDatas.Count > 0)
                    {
                        factMax = allDatas.Max(i => i.Int(key));
                        if (curMax < factMax)
                        {
                            StorageData data = new StorageData();
                            data.Name     = "TablePKCounter";
                            data.Query    = Query.And(Query.EQ("tbName", tbName), Query.EQ("count", curMax.ToString()));
                            data.Type     = StorageType.Update;
                            data.Document = new BsonDocument().Add("count", factMax.ToString());
                            dataList.Add(data);
                        }
                    }
                }
            }
            result = dataOp.BatchSaveStorageData(dataList);
            return(Json(TypeConvert.InvokeResultToPageJson(result)));
        }
コード例 #27
0
        /// <summary>
        /// 复制树形结构目录
        /// </summary>
        /// <param name="tableName">树形结构的表名称</param>
        /// <param name="dataList">被复制的树型结构列表</param>
        /// <param name="fields">要复制的字段</param>
        /// <param name="keyValueDict">固定加入的值:比如树形目录挂在项目下可能就要加入项目的主键Id</param>
        /// <returns></returns>
        public List <BsonDocument> CopyTreeTable(string tableName, List <BsonDocument> dataList, string[] fields, Dictionary <string, string> keyValueDict, bool hasTemplateId)
        {
            var tableRule  = new TableRule(tableName);
            var primaryKey = tableRule.PrimaryKey;

            var count   = dataList.Count;
            var datas   = new List <BsonDocument>(count);
            var keyDict = new Dictionary <string, string>();

            foreach (var d in dataList.OrderBy(s => s.String("nodeKey")))
            {
                var record = new BsonDocument();
                foreach (var s in fields)
                {
                    record.Add(s, d.String(s));
                    record.Add(s + "_bak", d.String(s));//初始化暂存区数据
                }

                foreach (var dict in keyValueDict)
                {
                    record.Add(dict.Key, dict.Value);
                }

                var keyValue = d.String(primaryKey);
                record.Add("srcId", keyValue);          //记录被复制节点的主键值
                if (!hasTemplateId)                     //没有传入拷贝templateId字段,则表示要记录拷贝的Id为模板Id
                {
                    record.Add("templateId", keyValue); //记录模板的字段值
                }
                var oldNodePid = d.String("nodePid");   //获取被复制节点的父节点id;
                var nodePid    = "0";

                if (keyDict.ContainsKey(oldNodePid))
                {
                    nodePid = keyDict[oldNodePid];
                }
                record.Add("nodePid", nodePid);
                var result = _ctx.Insert(tableName, record);
                if (result.Status == Status.Successful)
                {
                    keyDict.Add(d.String(primaryKey), result.BsonInfo.String(primaryKey));//记录树形对应节点的主键对
                }
                datas.Add(record);
            }
            return(datas);
        }
コード例 #28
0
        /// <summary>
        /// 删除部门目录数据
        /// </summary>
        /// <param name="tbName"></param>
        /// <param name="projId"></param>
        /// <param name="versionId"></param>
        private void DeletePolicyDeptDate(string tbName, string versionId)
        {
            var dirs = new List <BsonDocument>();

            if (!string.IsNullOrEmpty(tbName))
            {
                var dirName    = tbName + "Dir";
                var tbRule     = new TableRule(tbName);
                var primaryKey = tbRule.PrimaryKey;
                var dirRule    = new TableRule(dirName);
                var dirKey     = dirRule.PrimaryKey;
                //找出对应从模板拷贝的目录信息
                var dirParent = _ctx.FindOneByQuery(tbName, Query.EQ("versionId", versionId));
                _ctx.Delete(tbName, Query.EQ("_id", TypeConvert.ToObjectId(dirParent.String("_id")))); //删除
                var dirIds = _ctx.FindAllByQuery(dirName, Query.EQ(primaryKey, dirParent.String(primaryKey))).Select(s => s.String("_id")).ToList();
                _ctx.Delete(dirName, Query.In("_id", TypeConvert.ToObjectIdList(dirIds)));             //删除目录
            }
        }
コード例 #29
0
        /// <summary>
        /// 通过表名,项目id,版本id获取对应表的目录信息,
        /// </summary>
        /// <param name="tbName">表名</param>
        /// <param name="projId"></param>
        /// <param name="versionId"></param>
        /// <returns></returns>
        public List <BsonDocument> GetTableDirsByVersionId(string tbName, string versionId)
        {
            var dirs = new List <BsonDocument>();

            if (!string.IsNullOrEmpty(tbName))
            {
                var tbRule     = new TableRule(tbName);
                var primaryKey = tbRule.PrimaryKey;

                var dirName = tbName + "Dir";     //目录表
                var dirRule = new TableRule(dirName);
                var dirKey  = dirRule.PrimaryKey; //目录主键
                //找出对应从模板拷贝的目录信息
                var dirParent = _ctx.FindOneByQuery(tbName, Query.EQ("versionId", versionId));
                dirs = _ctx.FindAllByQuery(dirName, Query.EQ(primaryKey, dirParent.String(primaryKey))).ToList();
            }
            return(dirs);
        }
コード例 #30
0
        /// <summary>
        /// 通过表名,项目id,版本id获取对应表的目录信息,
        /// </summary>
        /// <param name="tbName">表名</param>
        /// <param name="projId"></param>
        /// <param name="versionId"></param>
        /// <returns></returns>
        public List <BsonDocument> GetTableDirs(string tbName, string projId, string versionId)
        {
            var dirs = new List <BsonDocument>();

            if (!string.IsNullOrEmpty(tbName))
            {
                var dirName    = tbName + "Dir";
                var tbRule     = new TableRule(tbName);
                var primaryKey = tbRule.ColumnRules.Single(s => s.IsPrimary).Name;

                var dirRule = new TableRule(dirName);
                var dirKey  = dirRule.ColumnRules.Single(s => s.IsPrimary).Name;
                //找出对应从模板拷贝的目录信息
                var dirParent = _ctx.FindOneByQuery(tbName, Query.And(Query.EQ("versionId", versionId), Query.EQ("projId", projId)));
                dirs = _ctx.FindAllByQuery(dirName, Query.EQ(primaryKey, dirParent.String(primaryKey))).ToList();
            }
            return(dirs);
        }