Beispiel #1
0
        /// <summary>
        /// 创建分类信息
        /// </summary>
        /// <param name="accid"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public override async Task CreateAsync(string accid, AssetCategory data)
        {
            await base.CreateAsync(accid, data);

            #region 添加tree节点
            {
                var pNode = await _DbContext.AssetCategoryTrees.Where(x => x.ObjId == data.ParentId && x.OrganizationId == data.OrganizationId).FirstOrDefaultAsync();

                if (pNode != null)
                {
                    var oTree = new AssetCategoryTree();
                    oTree.NodeType       = data.Type;
                    oTree.Name           = data.Name;
                    oTree.ObjId          = data.Id;
                    oTree.OrganizationId = data.OrganizationId;
                    oTree.ParentId       = pNode.Id;
                    await _AssetCategoryTreeRepository.AddChildNode(oTree);
                }
                else
                {
                    var oTree = new AssetCategoryTree();
                    oTree.NodeType           = data.Type;
                    oTree.Name               = data.Name;
                    oTree.ObjId              = data.Id;
                    oTree.LValue             = 1;
                    oTree.RValue             = 2;
                    oTree.OrganizationId     = data.OrganizationId;
                    oTree.RootOrganizationId = data.OrganizationId;
                    _DbContext.AssetCategoryTrees.Add(oTree);
                    await _DbContext.SaveChangesAsync();
                }
            }
            #endregion
        }
Beispiel #2
0
        /// <summary>
        ///  获取所有分类,已经整理为树结构
        /// </summary>
        /// <param name="type"></param>
        /// <param name="organId"></param>
        /// <returns></returns>
        public async Task <AssetCategoryDTO> GetCategoryAsync(string type, string organId)
        {
            //之所以采用这个方式,是因为tree表里面没有active标记,不清楚分类节点是否已经属于删除状态
            var rootCatTreeNodeQ = from tree in _DbContext.AssetCategoryTrees
                                   join cat in _DbContext.AssetCategories on tree.ObjId equals cat.Id
                                   where cat.ActiveFlag == AppConst.I_DataState_Active && cat.OrganizationId == organId && tree.NodeType == type && tree.LValue == 1
                                   select tree;
            var rootCatTreeNode = await rootCatTreeNodeQ.FirstAsync();

            var tmpQ = from cat in _DbContext.AssetCategories
                       join tree in _DbContext.AssetCategoryTrees on cat.Id equals tree.ObjId
                       where cat.ActiveFlag == AppConst.I_DataState_Active && tree.OrganizationId == organId && tree.NodeType == rootCatTreeNode.NodeType && tree.LValue >= rootCatTreeNode.LValue && tree.RValue <= rootCatTreeNode.RValue
                       select cat;

            var templist = await tmpQ.ToListAsync();


            LinkedList <AssetCategory> list = new LinkedList <AssetCategory>();

            foreach (var item in templist)
            {
                list.AddLast(item);
            }
            AssetCategoryDTO root = FindRoot(list);

            FindChildren(list, root);

            if (root == null)
            {
                AssetCategory rootNode = new AssetCategory();
                rootNode.Id             = GuidGen.NewGUID();
                rootNode.ParentId       = "";
                rootNode.OrganizationId = organId;
                rootNode.Type           = type;
                rootNode.Name           = type + "_root";
                rootNode.Icon           = "";
                rootNode.Description    = "auto generated node for " + type + ", do not need to display this node";
                rootNode.ResourceType   = (int)ResourceTypeEnum.Organizational;
                _DbContext.AssetCategories.Add(rootNode);
                await _DbContext.SaveChangesAsync();

                #region 添加tree节点
                {
                    var oTree = new AssetCategoryTree();
                    oTree.NodeType       = type;
                    oTree.Name           = rootNode.Name;
                    oTree.ObjId          = rootNode.Id;
                    oTree.OrganizationId = organId;
                    await _AssetCategoryTreeRepository.AddNewNode(oTree);
                }
                #endregion

                root = rootNode.ToDTO();
            }

            return(root);
        }