Esempio n. 1
0
        /// <summary>
        /// 通过关键字搜索获取社区树结构
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="communityId"></param>
        /// <returns></returns>
        public AreaTreeDto GetCommunityTreeBySearch(string communityId, string keyword)
        {
            var modal = _areaRepository.GetById(communityId);

            if (modal != null)
            {
                var querySql = "select * from biz_Area as a where ParentCode in ";
                querySql += "(select Code from biz_Area as b where AreaType = 10 and ParentCode in ";
                querySql += "(select code from biz_Area where AreaType = 9 and ParentCode in ";
                querySql += "(select Code from biz_Area where AreaType = 8 and AreaUUID = '{0}')))";
                querySql += " and a.AreaType = 11 {1}";
                querySql += " union ";
                //--取单元
                querySql += "select t_unit.* from biz_Area as t_unit inner join(";
                querySql += "select * from biz_Area as a where ";
                querySql += "ParentCode in (select Code from biz_Area as b where AreaType = 10 and ParentCode in (select code from biz_Area where AreaType = 9 and ParentCode in (select Code from biz_Area where AreaType = 8 and AreaUUID = '{0}')) )";
                querySql += "and a.AreaType = 11 {1}) as t_room on t_room.ParentCode = t_unit.Code";
                //--取楼栋
                querySql += " union ";
                querySql += " select t_building.*from biz_area as t_building inner join";
                querySql += "(select t_unit.* from biz_Area as t_unit inner join";
                querySql += "(select * from biz_Area as a where";
                querySql += " ParentCode in (select Code from biz_Area as b where AreaType = 10 and ParentCode in (select code from biz_Area where AreaType = 9 and ParentCode in (select Code from biz_Area where AreaType = 8  and AreaUUID = '{0}')))";
                querySql += " and a.AreaType = 11 {1}) as t_room on t_room.ParentCode = t_unit.Code) as t_unit2 on t_unit2.parentcode = t_building.Code";
                // var querySql = @"with tab as
                //(
                // select * from [dbo].[biz_Area] where AreaUUID='{0}'--父节点
                //{1}
                // union all
                // select b.*
                // from
                //  tab a,--父节点数据集
                //  [dbo].[biz_Area] b--子节点数据集
                // where b.[ParentCode]=a.Code and b.Deleted=0 {1}--子节点数据集.ID=父节点数据集.parendID
                //)
                //select * from tab;";
                var keyFilth = string.Empty;
                if (!keyword.IsBlank())
                {
                    keyFilth = string.Format(" and a.ChineseName like '%{0}%'", keyword);
                }

                string cmdText = string.Format(querySql, communityId, keyFilth);
                var    query   = _dbContext.SqlQuery <AreaEntity>(cmdText).ToList();


                var dto = new AreaTreeDto();
                dto.AreaUUID = modal.AreaUUID;
                dto.AreaName = modal.ChineseName;
                dto.AreaCode = modal.Code;
                dto.Children = SortForTree(modal.Code, query);

                return(dto);
            }
            return(null);
        }
Esempio n. 2
0
        public IHttpActionResult GetTree(string communityId, string keyword = null)
        {
            AreaTreeDto result = areaService.GetCommunityTreeBySearch(communityId, keyword);

            return(Ok(new
            {
                code = 0,
                msg = "success",
                data = result
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// 获取社区树结构列表(社区、幢、单元、门)
        /// </summary>
        /// <returns></returns>
        public IList <AreaTreeDto> GetCommunityTreeList()
        {
            var query         = _areaRepository.Table.Where(a => !a.Deleted);
            var communityList = query.Where(a => a.AreaType == 8);
            var list          = new List <AreaTreeDto>();

            foreach (var item in communityList)
            {
                var dto = new AreaTreeDto();
                dto.AreaUUID = item.AreaUUID;
                dto.AreaCode = item.Code;
                dto.AreaName = item.ChineseName;
                dto.Children = SortForTree(item.Code, query.ToList());
                list.Add(dto);
            }
            return(list);
        }
Esempio n. 4
0
        /// <summary>
        /// 递归树结构
        /// </summary>
        /// <param name="parentId">父节点</param>
        /// <returns></returns>
        private List <AreaTreeDto> SortForTree(string parentId, IList <AreaEntity> areaList)
        {
            var model = new List <AreaTreeDto>();

            if (areaList != null)
            {
                foreach (var p in areaList.Where(t => t.ParentCode == parentId).OrderBy(t => t.OrderID))
                {
                    var area = new AreaTreeDto
                    {
                        AreaUUID = p.AreaUUID,
                        AreaName = p.ChineseName,
                    };
                    area.Children.AddRange(SortForTree(p.Code, areaList));
                    model.Add(area);
                }
            }
            return(model);
        }
Esempio n. 5
0
        //  此接口暂无没用到
        /// <summary>
        /// 获取单个社区树结构(社区、幢、单元、门)
        /// </summary>
        /// <param name="areaId"></param>
        /// <returns></returns>
        public AreaTreeDto GetCommunityTree(string areaId)
        {
            var modal = _areaRepository.GetById(areaId);

            if (modal != null)
            {
                var query = _areaRepository.Table.Where(a => !a.Deleted);
                var list  = SortForTree(modal.Code, query.ToList());

                var dto = new AreaTreeDto()
                {
                    AreaUUID = modal.AreaUUID,
                    AreaCode = modal.Code,
                    AreaName = modal.ChineseName
                };
                dto.Children = list;
                return(dto);
            }
            return(null);
        }