public string MoveUser()
        {
            string toOrgId = Request.Forms("toOrgId");
            string isjz    = Request.Forms("isjz");
            string userId  = Request.Querys("userid");

            if (!toOrgId.IsGuid(out Guid toId))
            {
                return("没有选择要调往的组织");
            }
            var organizeModel = new Business.Organize().Get(toId);

            if (null == organizeModel)
            {
                return("没有找到要调往的组织");
            }
            if (!userId.IsGuid(out Guid uId))
            {
                return("人员ID错误");
            }
            Business.OrganizeUser organizeUser = new Business.OrganizeUser();
            if ("1".Equals(isjz))//兼职调动
            {
                Model.OrganizeUser organizeUserModel = new Model.OrganizeUser
                {
                    Id         = Guid.NewGuid(),
                    IsMain     = 0,
                    OrganizeId = toId,
                    UserId     = uId,
                    Sort       = organizeUser.GetMaxSort(organizeModel.ParentId)
                };
                organizeUser.Add(organizeUserModel);
            }
            else //全职
            {
                List <Tuple <Model.OrganizeUser, int> > tuples = new List <Tuple <Model.OrganizeUser, int> >();
                var organizeUsers = organizeUser.GetListByUserId(uId);
                foreach (var organizeUserModel in organizeUsers)
                {
                    if (organizeUserModel.IsMain == 1)
                    {
                        organizeUserModel.OrganizeId = toId;
                        organizeUserModel.Sort       = organizeUser.GetMaxSort(organizeModel.ParentId);
                        tuples.Add(new Tuple <Model.OrganizeUser, int>(organizeUserModel, 2));
                    }
                    else
                    {
                        tuples.Add(new Tuple <Model.OrganizeUser, int>(organizeUserModel, 0));
                    }
                }
                organizeUser.Update(tuples);
                //同步企业微信人员(更新人员所在职务)
                if (Config.Enterprise_WeiXin_IsUse)
                {
                    new Business.EnterpriseWeiXin.Organize().UpdateUser(new Business.User().Get(uId));
                }
            }
            Business.Log.Add("调动了人员-" + uId + ("1".Equals(isjz) ? "-兼任" : "-全职"), toOrgId, Business.Log.Type.系统管理);
            return("调动成功!");
        }
Exemple #2
0
        public string Member_GetNote()
        {
            string id = Request.Querys("id");

            if (id.IsNullOrWhiteSpace())
            {
                return("");
            }
            Business.Organize     organize     = new Business.Organize();
            Business.User         user         = new Business.User();
            Business.OrganizeUser organizeUser = new Business.OrganizeUser();
            if (id.StartsWith(Business.Organize.PREFIX_USER))//人员
            {
                var organizeUserModel = organizeUser.GetMainByUserId(id.RemoveUserPrefix().ToGuid());
                return(organize.GetParentsName(organizeUserModel.OrganizeId) + " \\ " + organize.GetName(organizeUserModel.OrganizeId));
            }
            else if (id.StartsWith(Business.Organize.PREFIX_RELATION))//兼职人员
            {
                var organizeUserModel = organizeUser.Get(id.RemoveUserRelationPrefix().ToGuid());
                return(organize.GetParentsName(organizeUserModel.OrganizeId) + " \\ " + organize.GetName(organizeUserModel.OrganizeId) + "[兼任]");
            }
            else if (id.StartsWith(Business.Organize.PREFIX_WORKGROUP))//工作组
            {
                return("");
            }
            else if (id.IsGuid(out Guid gid))
            {
                return(organize.GetParentsName(gid) + " \\ " + organize.GetName(gid));
            }
            return("");
        }
        public string TreeRefresh()
        {
            int    showType  = Request.Querys("showtype").ToString().ToInt(0);
            bool   showUser  = !"0".Equals(Request.Querys("shouser"));
            string refreshId = Request.Querys("refreshid");

            Business.Organize           organize = new Business.Organize();
            Newtonsoft.Json.Linq.JArray jArray   = new Newtonsoft.Json.Linq.JArray();

            #region 显示工作组
            if (1 == showType)
            {
                return("");
            }
            #endregion

            if (refreshId.IsGuid(out Guid guid))
            {
                var childs = organize.GetChilds(guid);
                foreach (var child in childs)
                {
                    Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                    {
                        { "id", child.Id },
                        { "parentID", child.ParentId },
                        { "title", child.Name },
                        { "ico", "" },
                        { "link", "" },
                        { "type", child.Type },
                        { "hasChilds", organize.HasChilds(child.Id) ? 1 : showUser?organize.HasUsers(child.Id) ? 1 : 0 : 0 }
                    };
                    jArray.Add(jObject);
                }
                if (showUser)
                {
                    var users         = organize.GetUsers(guid);
                    var organizeUsers = new Business.OrganizeUser().GetListByOrganizeId(guid);
                    foreach (var userModel in users)
                    {
                        var  organizeUserModel1 = organizeUsers.Find(p => p.UserId == userModel.Id);
                        bool isPartTime         = organizeUserModel1.IsMain != 1;//是否是兼职
                        Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", isPartTime ? organizeUserModel1.Id : userModel.Id },
                            { "parentID", guid },
                            { "title", userModel.Name + (isPartTime ? "<span style='color:#666;'>[兼任]</span>" : "") },
                            { "ico", "fa-user" },
                            { "link", "" },
                            { "userID", userModel.Id },
                            { "type", isPartTime ? 6 : 4 },
                            { "hasChilds", 0 }
                        };
                        jArray.Add(jObject);
                    }
                }
            }
            return(jArray.ToString());
        }
        public string UserSortSave()
        {
            string sort  = Request.Forms("sort");
            string orgId = Request.Querys("orgparentid");

            Business.OrganizeUser     organizeUser  = new Business.OrganizeUser();
            List <Model.OrganizeUser> organizeUsers = organizeUser.GetListByOrganizeId(orgId.ToGuid());
            int i = 0;

            foreach (string id in sort.Split(','))
            {
                if (id.IsGuid(out Guid userId))
                {
                    var organizeUserModel = organizeUsers.Find(p => p.UserId == userId);
                    if (null != organizeUserModel)
                    {
                        organizeUserModel.Sort = i += 5;
                    }
                }
            }
            organizeUser.Update(organizeUsers.ToArray());
            return("排序成功!");
        }
        public string Tree1()
        {
            int    showType   = Request.Querys("showtype").ToString().ToInt(0);//显示类型 0组织架构 1角色组
            string rootId     = Request.Querys("rootid");
            string searchWord = Request.Querys("searchword");
            bool   showUser   = !"0".Equals(Request.Querys("shouser"));

            Business.Organize     organize     = new Business.Organize();
            Business.User         user         = new Business.User();
            Business.WorkGroup    workGroup    = new Business.WorkGroup();
            Business.OrganizeUser organizeUser = new Business.OrganizeUser();
            var  organizeUserList = organizeUser.GetAll();
            Guid orgRootId        = organize.GetRootId();

            Newtonsoft.Json.Linq.JArray jArray = new Newtonsoft.Json.Linq.JArray();

            #region 搜索
            if (!searchWord.IsNullOrWhiteSpace())
            {
                Guid parentId = Guid.NewGuid();
                if (1 == showType)//搜索工作组
                {
                    var workGroups = workGroup.GetAll().FindAll(p => p.Name.ContainsIgnoreCase(searchWord.Trim()));
                    Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                    {
                        { "id", parentId },
                        { "parentID", Guid.Empty },
                        { "title", "查询“" + searchWord + "”的结果" },
                        { "ico", "fa-search" },
                        { "link", "" },
                        { "type", 1 },
                        { "hasChilds", workGroups.Count }
                    };
                    jArray.Add(jObject);
                    Newtonsoft.Json.Linq.JArray jArray1 = new Newtonsoft.Json.Linq.JArray();
                    foreach (var group in workGroups)
                    {
                        Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", group.Id },
                            { "parentID", parentId },
                            { "title", group.Name },
                            { "ico", "fa-slideshare" },
                            { "link", "" },
                            { "type", 5 },
                            { "hasChilds", 0 }
                        };
                        jArray1.Add(jObject1);
                    }
                    jObject.Add("childs", jArray1);
                }
                else //搜索组织和人员
                {
                    var organizes = organize.GetAll().FindAll(p => p.Name.ContainsIgnoreCase(searchWord.Trim()));
                    var users     = user.GetAll().FindAll(p => p.Name.ContainsIgnoreCase(searchWord.Trim()));
                    Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                    {
                        { "id", parentId },
                        { "parentID", Guid.Empty },
                        { "title", "查询“" + searchWord + "”的结果" },
                        { "ico", "fa-search" },
                        { "link", "" },
                        { "type", 1 },
                        { "hasChilds", organizes.Count + users.Count }
                    };
                    jArray.Add(jObject);
                    Newtonsoft.Json.Linq.JArray jArray1 = new Newtonsoft.Json.Linq.JArray();
                    foreach (var organizeModel in organizes)
                    {
                        Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", organizeModel.Id },
                            { "parentID", parentId },
                            { "title", organizeModel.Name },
                            { "ico", "" },
                            { "link", "" },
                            { "type", organizeModel.Type },
                            { "hasChilds", organize.HasChilds(organizeModel.Id) ? 1 : 0 }
                        };
                        jArray1.Add(jObject1);
                    }
                    foreach (var userModel in users)
                    {
                        Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", userModel.Id },
                            { "parentID", parentId },
                            { "title", userModel.Name },
                            { "ico", "fa-user" },
                            { "link", "" },
                            { "userID", userModel.Id },
                            { "type", 4 },
                            { "hasChilds", 0 }
                        };
                        jArray1.Add(jObject1);
                    }
                    jObject.Add("childs", jArray1);
                }
                return(jArray.ToString());
            }
            #endregion

            #region 显示角色组
            if (1 == showType)
            {
                var workgroups = workGroup.GetAll();
                foreach (var workgroupModel in workgroups)
                {
                    Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                    {
                        { "id", workgroupModel.Id },
                        { "parentID", Guid.Empty },
                        { "title", workgroupModel.Name },
                        { "ico", "fa-slideshare" },
                        { "link", "" },
                        { "type", 5 },
                        { "hasChilds", 0 }
                    };
                    jArray.Add(jObject);
                }
                return(jArray.ToString());
            }
            #endregion

            if (rootId.IsNullOrWhiteSpace())
            {
                rootId = orgRootId.ToString();
            }
            #region 添加根节点
            string[] rootIdArray = rootId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string root in rootIdArray)
            {
                if (root.IsGuid(out Guid guid))//组织机构
                {
                    var organizeModel = organize.Get(guid);
                    if (null != organizeModel)
                    {
                        Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", organizeModel.Id },
                            { "parentID", organizeModel.ParentId },
                            { "title", organizeModel.Name },
                            { "ico", organizeModel.Id == orgRootId ? "fa-sitemap" : "" },
                            { "link", "" },
                            { "type", organizeModel.Type },
                            { "hasChilds", organize.HasChilds(organizeModel.Id) ? 1 : showUser?organize.HasUsers(organizeModel.Id) ? 1 : 0 : 0 }
                        };
                        jArray.Add(jObject);
                    }
                }
                else if (root.StartsWith(Business.Organize.PREFIX_USER))//人员
                {
                    var userModel = user.Get(root.RemoveUserPrefix().ToGuid());
                    if (null != userModel)
                    {
                        Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", userModel.Id },
                            { "parentID", Guid.Empty },
                            { "title", userModel.Name },
                            { "ico", "fa-user" },
                            { "link", "" },
                            { "type", 4 },
                            { "hasChilds", 0 }
                        };
                        jArray.Add(jObject);
                    }
                }
                else if (root.StartsWith(Business.Organize.PREFIX_RELATION))//兼职人员
                {
                    var organizeUserModel = organizeUser.Get(root.RemoveUserRelationPrefix().ToGuid());
                    if (null != organizeUserModel)
                    {
                        var userModel = user.Get(organizeUserModel.UserId);
                        if (null != userModel)
                        {
                            Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                            {
                                { "id", organizeUserModel.Id },
                                { "parentID", Guid.Empty },
                                { "title", userModel.Name + "<span style='color:#666;'>[兼任]</span>" },
                                { "ico", "fa-user" },
                                { "link", "" },
                                { "type", 6 },
                                { "userID", userModel.Id },
                                { "hasChilds", 0 }
                            };
                            jArray.Add(jObject);
                        }
                    }
                }
                else if (root.StartsWith(Business.Organize.PREFIX_WORKGROUP))//工作组
                {
                    var workgroupModel = workGroup.Get(root.RemoveWorkGroupPrefix().ToGuid());
                    if (null != workgroupModel)
                    {
                        Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", workgroupModel.Id },
                            { "parentID", Guid.Empty },
                            { "title", workgroupModel.Name },
                            { "ico", "fa-slideshare" },
                            { "link", "" },
                            { "type", 5 },
                            { "hasChilds", workGroup.GetAllUsers(workgroupModel.Id).Count }
                        };
                        jArray.Add(jObject);
                    }
                }
            }
            #endregion

            #region 只有一个根时显示二级
            if (rootIdArray.Length == 1)
            {
                string rootIdString = rootIdArray[0];
                if (rootIdString.IsGuid(out Guid guid))
                {
                    var jObject0 = (Newtonsoft.Json.Linq.JObject)jArray[0];
                    Newtonsoft.Json.Linq.JArray jArray0 = new Newtonsoft.Json.Linq.JArray();
                    var childs        = organize.GetChilds(guid);
                    var organizeUser1 = organizeUserList.FindAll(p => p.OrganizeId == guid);
                    foreach (var child in childs)
                    {
                        Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", child.Id },
                            { "parentID", child.ParentId },
                            { "title", child.Name },
                            { "ico", "" },
                            { "link", "" },
                            { "type", child.Type },
                            { "hasChilds", organize.HasChilds(child.Id) ? 1 : showUser?organize.HasUsers(child.Id) ? 1 : 0 : 0 }
                        };
                        jArray0.Add(jObject);
                    }
                    if (showUser)
                    {
                        var users = organize.GetUsers(guid);
                        foreach (var userModel in users)
                        {
                            var  organizeUserModel1 = organizeUser1.Find(p => p.UserId == userModel.Id);
                            bool isPartTime         = organizeUserModel1.IsMain != 1;//是否是兼职
                            Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                            {
                                { "id", isPartTime ? organizeUserModel1.Id : userModel.Id },
                                { "parentID", guid },
                                { "title", userModel.Name + (isPartTime ? "<span style='color:#666;'>[兼任]</span>" : "") },
                                { "ico", "fa-user" },
                                { "link", "" },
                                { "userID", userModel.Id },
                                { "type", isPartTime ? 6 : 4 },
                                { "hasChilds", 0 }
                            };
                            jArray0.Add(jObject);
                        }
                    }
                    jObject0.Add("childs", jArray0);
                }
                else if (rootIdString.StartsWith(Business.Organize.PREFIX_WORKGROUP))
                {
                    var jObject0 = (Newtonsoft.Json.Linq.JObject)jArray[0];
                    Newtonsoft.Json.Linq.JArray jArray0 = new Newtonsoft.Json.Linq.JArray();
                    var users = workGroup.GetAllUsers(rootIdString.RemoveWorkGroupPrefix().ToGuid());
                    foreach (var userModel in users)
                    {
                        Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject()
                        {
                            { "id", userModel.Id },
                            { "parentID", rootIdString.RemoveWorkGroupPrefix() },
                            { "title", userModel.Name },
                            { "ico", "fa-user" },
                            { "link", "" },
                            { "type", 4 },
                            { "hasChilds", 0 }
                        };
                        jArray0.Add(jObject);
                    }
                    jObject0.Add("childs", jArray0);
                }
            }
            #endregion

            return(jArray.ToString());
        }