Example #1
0
 public IList <CV_PM_WECHAT_USER_DEPARTMENT> GetUsersByDepartmentGuid(Guid depID)
 {
     try
     {
         return(userDepBO.GetUsersByDepartmentGuid(depID));
     }
     catch (Exception)
     {
         throw;
     }
 }
        //获得组织树
        public List <UserGroupNode> getGroupTree2(string userID)
        {
            //用户userID查找到所属部门
            IList <CV_PM_WECHAT_USER_DEPARTMENT> myuserdepartmentlist = new List <CV_PM_WECHAT_USER_DEPARTMENT>();
            CV_PM_WECHAT_USER_DEPARTMENT         mydepartment         = new CV_PM_WECHAT_USER_DEPARTMENT()
            {
                UserID = userID
            };

            myuserdepartmentlist = user_departbo.GetUserDepartmentbyuserID(mydepartment);
            //根据用户所属部门的级别查询同级别和级别以下的部门
            IList <CV_PM_WECHAT_DEPARTMENT> departmentlistupper = new List <CV_PM_WECHAT_DEPARTMENT>();

            departmentlistupper = departbo.GetSameLevelDepartment(myuserdepartmentlist[0].ParentID.Value);
            //用nodes集合接收树结构
            List <UserGroupNode> nodes = new List <UserGroupNode>();
            //先获得根节点
            IList <CV_PM_WECHAT_DEPARTMENT>     departmentList = departbo.GetEntities();
            Dictionary <int, UserGroupLeftNode> departNode     = new Dictionary <int, UserGroupLeftNode>();


            for (int i = departmentList.Count - 1; i >= 0; i--)
            {
                CV_PM_WECHAT_DEPARTMENT department = departmentList[i];
                log.Info("department departid-->" + department.ID.Value);
                //查询部门所属用户
                IList <CV_PM_WECHAT_USER_DEPARTMENT> userList = user_departbo.GetUsersByDepartmentGuid(department.DepartmentGuid.Value);
                if (userList != null && userList.Count > 0)
                {
                    bool flag = true;
                    foreach (CV_PM_WECHAT_DEPARTMENT de in departmentlistupper)
                    {
                        if (de.DepartmentGuid.Value == department.DepartmentGuid.Value)
                        {
                            flag = false;
                            break;
                        }
                    }
                    //当前部门有人员
                    UserGroupNode currentNode = new UserGroupNode()
                    {
                        title           = department.Name,
                        expand          = false,
                        guid            = department.DepartmentGuid.Value,
                        disableCheckbox = flag,
                        children        = new List <UserGroupLeftNode>()
                    };


                    log.Info("department.ID.Value-->" + department.ID.Value);
                    departNode.Add(department.ID.Value, currentNode);

                    //获得用户
                    foreach (CV_PM_WECHAT_USER_DEPARTMENT user in userList)
                    {
                        UserGroupLeftNode userNode = new UserGroupLeftNode()
                        {
                            userid          = user.UserID,
                            title           = user.Name,
                            expand          = false,
                            pGuid           = user.DepartmentGuid.Value,
                            disableCheckbox = flag,
                            guid            = user.UserGuid.Value
                        };
                        currentNode.children.Add(userNode);
                    }



                    log.Info("department.ParentID.Value-->" + department.ParentID.Value);
                    if (departNode.ContainsKey(department.ParentID.Value))
                    {
                        log.Info("=============2=============");
                        ((UserGroupNode)departNode[department.ParentID.Value]).children.Add(currentNode);
                    }
                    else
                    {
                        log.Info("=============1=============");
                        nodes.Add(currentNode);
                    }
                }
                else
                {
                    //当前部门无人员
                    log.Info("=============3=============");
                    UserGroupLeftNode currentNode = new UserGroupLeftNode()
                    {
                        title           = department.Name,
                        expand          = false,
                        guid            = department.DepartmentGuid.Value,
                        disableCheckbox = true
                    };

                    if (departNode.ContainsKey(department.ParentID.Value))
                    {
                        ((UserGroupNode)departNode[department.ParentID.Value]).children.Add(currentNode);
                    }
                }
            }



            // nodes.Add(rootNode);

            return(nodes);
        }