Exemple #1
0
        /// <summary>
        /// 得到一个机构下人员
        /// </summary>
        /// <param name="id">机构ID</param>
        /// <param name="hasPartTime">是否包含兼任人员</param>
        /// <returns></returns>
        public List <Model.User> GetUsers(Guid id, bool hasPartTime = true)
        {
            List <Model.User> users        = new List <Model.User>();
            OrganizeUser      organizeUser = new OrganizeUser();
            User user          = new User();
            var  organizeUsers = organizeUser.GetListByOrganizeId(id);

            foreach (var organizeUserModel in organizeUsers)
            {
                if (!hasPartTime && organizeUserModel.IsMain != 1)//如果不包含兼任人员,则跳过
                {
                    continue;
                }
                var userModel = user.Get(organizeUserModel.UserId);
                if (organizeUserModel.IsMain == 0)
                {
                    userModel.PartTimeId = organizeUserModel.Id;
                }
                if (null != userModel)
                {
                    users.Add(userModel);
                }
            }
            return(users.Distinct(new Model.User()).ToList());
        }
Exemple #2
0
        /// <summary>
        /// 得到一个人员所在的组织架构ID
        /// </summary>
        /// <param name="userId">guid(人ID),u_guid(人ID),r_guid(关系表ID)</param>
        /// <returns></returns>
        public Guid GetOrganizeId(string userId)
        {
            Guid organizeId = Guid.Empty;

            if (userId.IsGuid(out Guid uid))
            {
                var organizeUser = new OrganizeUser().GetMainByUserId(uid);
                if (null != organizeUser)
                {
                    organizeId = organizeUser.OrganizeId;
                }
            }
            else if (userId.StartsWith(Organize.PREFIX_USER))
            {
                var organizeUser = new OrganizeUser().GetMainByUserId(userId.RemoveUserPrefix().ToGuid());
                if (null != organizeUser)
                {
                    organizeId = organizeUser.OrganizeId;
                }
            }
            else if (userId.StartsWith(Organize.PREFIX_RELATION))
            {
                var organizeUser = new OrganizeUser().Get(userId.RemoveUserRelationPrefix().ToGuid());
                if (null != organizeUser)
                {
                    organizeId = organizeUser.OrganizeId;
                }
            }
            return(organizeId);
        }
Exemple #3
0
 /// <summary>
 /// 得到用户实际ID(有可能字符串是r_关系ID)
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public Guid GetUserId(string userId)
 {
     if (userId.IsNullOrWhiteSpace())
     {
         return(Guid.Empty);
     }
     else if (userId.StartsWith(Organize.PREFIX_USER))
     {
         return(userId.RemoveUserPrefix().ToGuid());
     }
     else if (userId.IsGuid(out Guid uid))
     {
         return(uid);
     }
     else if (userId.StartsWith(Organize.PREFIX_RELATION))
     {
         var orgId   = userId.RemoveUserRelationPrefix().ToGuid();
         var orgUser = new OrganizeUser().Get(orgId);
         if (null != orgUser)
         {
             return(orgUser.UserId);
         }
     }
     return(Guid.Empty);
 }
Exemple #4
0
 /// <summary>
 /// 根据兼职ID得到一个用户
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Model.User GetByRelationId(string id)
 {
     if (id.StartsWith(Organize.PREFIX_RELATION))
     {
         var organizeUserModel = new OrganizeUser().Get(id.RemoveUserRelationPrefix().ToGuid());
         return(null != organizeUserModel?Get(organizeUserModel.UserId) : null);
     }
     else
     {
         return(null);
     }
 }
Exemple #5
0
        /// <summary>
        /// 得到一个人员的主要组织显示
        /// </summary>
        /// <param name="id">人员ID</param>
        /// <param name="isShowRoot">是否显示根</param>
        /// <returns></returns>
        public string GetOrganizeMainShowHtml(Guid id, bool isShowRoot = true)
        {
            var organizeUser = new OrganizeUser().GetMainByUserId(id);

            if (null == organizeUser)
            {
                return("");
            }
            else
            {
                Organize organize    = new Organize();
                string   parentsName = organize.GetParentsName(organizeUser.OrganizeId, isShowRoot);
                return((parentsName.IsNullOrWhiteSpace() ? "" : parentsName + " \\ ") + organize.GetName(organizeUser.OrganizeId));
            }
        }
Exemple #6
0
        /// <summary>
        /// 根据ID字符串得到所有人员
        /// </summary>
        /// <param name="idString">u_人员,id,w_工作且,r_兼职</param>
        /// <returns></returns>
        public List <Model.User> GetAllUsers(string idString)
        {
            List <Model.User> users = new List <Model.User>();

            if (idString.IsNullOrWhiteSpace())
            {
                return(users);
            }
            User         user         = new User();
            OrganizeUser organizeUser = new OrganizeUser();
            WorkGroup    workGroup    = new WorkGroup();

            foreach (string id in idString.Split(','))
            {
                if (id.IsGuid(out Guid guid))
                {
                    users.AddRange(GetAllUsers(guid));
                }
                else if (id.StartsWith(PREFIX_USER)) //ID是一个人员ID
                {
                    var userModel = user.Get(id.RemoveUserPrefix().ToGuid());
                    if (null != userModel)
                    {
                        users.Add(userModel);
                    }
                }
                else if (id.StartsWith(PREFIX_RELATION)) //ID是一个人员兼职ID
                {
                    var organizeUserModel = organizeUser.Get(id.RemoveUserRelationPrefix().ToGuid());
                    if (null != organizeUserModel)
                    {
                        var userModel = user.Get(organizeUserModel.UserId);
                        if (null != userModel)
                        {
                            userModel.PartTimeId = organizeUserModel.Id;
                            users.Add(userModel);
                        }
                    }
                }
                else if (id.StartsWith(PREFIX_WORKGROUP)) //ID是一个工作组ID
                {
                    users.AddRange(workGroup.GetAllUsers(id.RemoveWorkGroupPrefix().ToGuid()));
                }
            }
            var y = users.Distinct(new Model.User()).ToList();

            return(users.Distinct(new Model.User()).ToList());
        }
Exemple #7
0
        /// <summary>
        /// 删除一个用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(Guid id)
        {
            var organizeUsers = new OrganizeUser().GetListByUserId(id);//要删除人员与组织机构之间关系表
            var userModel     = Get(id);

            if (null == userModel)
            {
                return(0);
            }
            //同步企业微信人员
            if (Config.Enterprise_WeiXin_IsUse)
            {
                new EnterpriseWeiXin.Organize().DeleteUser(userModel.Account);
            }
            Log.Add("删除了一个用户-" + userModel.Name, userModel.ToString(), Log.Type.系统管理, others: Newtonsoft.Json.JsonConvert.SerializeObject(organizeUsers));
            return(userData.Delete(userModel, organizeUsers.ToArray()));
        }
Exemple #8
0
        /// <summary>
        /// 删除一个组织机构
        /// </summary>
        /// <param name="id"></param>
        /// <param name="localizer">语言包</param>
        /// <returns></returns>
        public int Delete(Guid id, IStringLocalizer localizer = null)
        {
            var org = Get(id);

            if (null == org)
            {
                return(0);
            }
            if (id == GetRootId())//不能删除根
            {
                Log.Add(localizer == null ? "删除组织架构根节点失败-不能删除根" : localizer["Delete_CanotRootLog"], "", Log.Type.系统管理);
                return(0);
            }
            var allChilds = GetAllChilds(id);//要删除所有下级机构;

            allChilds.Add(org);
            List <Model.User>         allUsers        = new List <Model.User>();         //要删除机构下所有人员
            List <Model.OrganizeUser> allOrganizeUser = new List <Model.OrganizeUser>(); //要删除所有机构与人员关系
            OrganizeUser organizeUser = new OrganizeUser();

            foreach (var child in allChilds)
            {
                allUsers.AddRange(GetAllUsers(child.Id, false));
                allOrganizeUser.AddRange(organizeUser.GetListByOrganizeId(child.Id));
            }
            int i = organizeData.Delete(allChilds.ToArray(), allUsers.ToArray(), allOrganizeUser.ToArray());

            //同步企业微信人员
            if (Config.Enterprise_WeiXin_IsUse)
            {
                EnterpriseWeiXin.Organize wxOrganize = new EnterpriseWeiXin.Organize();
                foreach (var user in allUsers)
                {
                    wxOrganize.DeleteUser(user.Account);
                }
            }

            Log.Add((localizer == null ? "删除了组织架构及其下级和人员-" : localizer["Delete_Log"]) + org.Name + (localizer == null ? "-共" : localizer["Delete_Log1"]) + i.ToString() + (localizer == null ? "条数据" : localizer["Delete_Log2"])
                    , (localizer == null ? "组织:" : localizer["Delete_Log3"]) + Newtonsoft.Json.JsonConvert.SerializeObject(allChilds) +
                    (localizer == null ? "人员:" : localizer["Delete_Log4"]) + Newtonsoft.Json.JsonConvert.SerializeObject(allUsers) +
                    (localizer == null ? "人员与架构关系:" : localizer["Delete_Log5"]) + Newtonsoft.Json.JsonConvert.SerializeObject(allOrganizeUser), Log.Type.系统管理);
            return(i);
        }
Exemple #9
0
        /// <summary>
        /// 根据ID字符串得到名称
        /// </summary>
        /// <param name="idString">逗号分开的人员ID,机构ID,工作组ID等</param>
        /// <returns></returns>
        public string GetNames(string idString)
        {
            if (idString.IsNullOrWhiteSpace())
            {
                return("");
            }
            User          user          = new User();
            OrganizeUser  organizeUser  = new OrganizeUser();
            StringBuilder stringBuilder = new StringBuilder();
            WorkGroup     workGroup     = new WorkGroup();

            foreach (string id in idString.Split(','))
            {
                if (id.IsGuid(out Guid orgId))
                {
                    stringBuilder.Append(GetName(orgId));
                    stringBuilder.Append("、");
                }
                else if (id.StartsWith(PREFIX_USER))
                {
                    stringBuilder.Append(user.GetName(id.RemoveUserPrefix().ToGuid()));
                    stringBuilder.Append("、");
                }
                else if (id.StartsWith(PREFIX_RELATION))
                {
                    var organizeUserModel = organizeUser.Get(id.RemoveUserRelationPrefix().ToGuid());
                    if (null != organizeUserModel)
                    {
                        stringBuilder.Append(user.GetName(organizeUserModel.UserId));
                        stringBuilder.Append("、");
                    }
                }
                else if (id.StartsWith(PREFIX_WORKGROUP))
                {
                    stringBuilder.Append(workGroup.GetName(id.RemoveWorkGroupPrefix().ToGuid()));
                    stringBuilder.Append("、");
                }
            }
            return(stringBuilder.ToString().TrimEnd('、'));
        }
Exemple #10
0
        /// <summary>
        /// 判断一个用户是否被冻结(所在岗位部门被冻结也算)
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsFrozen(Model.User user)
        {
            if (user.Status != 0)
            {
                return(true);
            }
            var      organzieUsers = new OrganizeUser().GetListByUserId(user.Id);
            Organize organize      = new Organize();

            foreach (var organizeUser in organzieUsers)
            {
                var organizeModel = organize.Get(organizeUser.OrganizeId);
                if (null != organizeModel)
                {
                    if (organizeModel.Status != 0 || organize.GetAllParents(organizeModel.Id, false).Exists(p => p.Status != 0))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #11
0
        /// <summary>
        /// 得到一个人员的所在组织显示
        /// </summary>
        /// <param name="id">人员ID</param>
        /// <param name="isShowRoot">是否显示根</param>
        /// <returns></returns>
        public string GetOrganizesShowHtml(Guid id, bool isShowRoot = true)
        {
            var           organizeUsers = new OrganizeUser().GetListByUserId(id);
            StringBuilder stringBuilder = new StringBuilder();
            Organize      organize      = new Organize();

            foreach (var organizeUser in organizeUsers)
            {
                var parentsName = organize.GetParentsName(organizeUser.OrganizeId, isShowRoot);
                stringBuilder.Append("<div>");
                if (!parentsName.IsNullOrWhiteSpace())
                {
                    stringBuilder.Append(parentsName + " \\ ");
                }
                stringBuilder.Append(organize.GetName(organizeUser.OrganizeId));
                if (organizeUser.IsMain == 0)
                {
                    stringBuilder.Append("<span style='color:#999;'>[兼任]</span>");
                }
                stringBuilder.Append("</div>");
            }
            return(stringBuilder.ToString());
        }
Exemple #12
0
        /// <summary>
        /// 根据一组ID字符串得到人员的姓名
        /// </summary>
        /// <param name="id">逗号分开的ID</param>
        /// <returns></returns>
        public string GetNames(string ids)
        {
            if (ids.IsNullOrEmpty())
            {
                return(string.Empty);
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (string id in ids.Split(','))
            {
                string userId = id;
                if (id.StartsWith(Organize.PREFIX_USER))
                {
                    userId = id.RemoveUserPrefix();
                }
                else if (id.StartsWith(Organize.PREFIX_RELATION))
                {
                    var organizeUser = new OrganizeUser().Get(id.RemoveUserRelationPrefix().ToGuid());
                    if (null != organizeUser)
                    {
                        userId = organizeUser.UserId.ToString();
                    }
                }
                if (!userId.IsGuid(out Guid uid))
                {
                    continue;
                }
                var userModel = Get(uid);
                if (null != userModel)
                {
                    stringBuilder.Append(userModel.Name);
                    stringBuilder.Append("、");
                }
            }
            return(stringBuilder.ToString().TrimEnd('、'));
        }
Exemple #13
0
        /// <summary>
        /// 得到一个用户实体
        /// </summary>
        /// <param name="id">如果id以r_开头则表示是兼职organizeuser表id</param>
        /// <returns></returns>
        public Model.User Get(string id)
        {
            Guid userId    = Guid.Empty;
            Guid orgUserId = Guid.Empty;

            if (id.IsGuid(out Guid uid))
            {
                userId = uid;
            }
            else if (id.StartsWith(Organize.PREFIX_USER))
            {
                userId = id.RemoveUserPrefix().ToGuid();
            }
            else if (id.StartsWith(Organize.PREFIX_RELATION))
            {
                var model = new OrganizeUser().Get(id.RemoveUserRelationPrefix().ToGuid());
                if (null != model)
                {
                    userId    = model.UserId;
                    orgUserId = model.Id;
                }
            }
            if (userId.IsEmptyGuid())
            {
                return(null);
            }
            else
            {
                var userModel = Get(userId);
                if (null != userModel && orgUserId.IsNotEmptyGuid())
                {
                    userModel.PartTimeId = orgUserId;
                }
                return(userModel);
            }
        }