Esempio n. 1
0
        /// <summary>
        /// 获取指定部门下  指定手机号的人员
        /// </summary>
        /// <param name="FK_Dept">部门编号</param>
        /// <param name="Tel">手机号</param>
        /// <returns></returns>
        public UserInfoBelongDept GetUserListByDeptIDAndTel(string FK_Dept, string Tel = null)
        {
            string access_token = getAccessToken();
            string url          = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token= " + access_token + "&department_id=" + FK_Dept + "&status=0";

            try
            {
                string          str   = new HttpWebResponseUtility().HttpResponseGet(url);
                UsersBelongDept users = FormatToJson.ParseFromJson <UsersBelongDept>(str);

                //指定人员
                if (Tel != null)
                {
                    foreach (UserInfoBelongDept user in users.userlist)
                    {
                        if (user.mobile == Tel)
                        {
                            return(user);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 钉钉,删除人员同步钉钉
        /// </summary>
        /// <param name="userid">人员编号</param>
        /// <returns></returns>
        public Ding_Post_ReturnVal GPM_Ding_DeleteEmp(string userid)
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/user/delete?access_token=" + access_token + "&userid=" + userid;

            try
            {
                string str = new HttpWebResponseUtility().HttpResponseGet(url);
                Ding_Post_ReturnVal postVal = FormatToJson.ParseFromJson <Ding_Post_ReturnVal>(str);

                //请求返回信息
                if (postVal != null)
                {
                    if (postVal.errcode != "0")
                    {
                        BP.DA.Log.DefaultLogWriteLineError("钉钉删除人员失败:" + postVal.errcode + "-" + postVal.errmsg);
                    }

                    return(postVal);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 3
0
        private string appsecret = BP.Sys.SystemConfig.WX_AppSecret; // "KfFkE9AZ3Zp09zTuKvmqWLgtLj-_cHMPTvV992apOWgSKJHcbjpbu1jYVXh7gI7K";
        public string getAccessToken()
        {
            string accessToken = string.Empty;
            string url         = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + appid + "&corpsecret=" + appsecret + "";

            try
            {
                AccessToken     AT       = new AccessToken();
                HttpWebResponse response = new HttpWebResponseUtility().CreateGetHttpResponse(url, 10000, null, null);
                StreamReader    reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string          str      = reader.ReadToEnd();
                AT = FormatToJson.ParseFromJson <AccessToken>(str);
                reader.Dispose();
                reader.Close();
                if (response != null)
                {
                    response.Close();
                }
                if (AT != null)
                {
                    accessToken = AT.access_token;
                }
            }
            catch
            {
            }
            return(accessToken);
        }
Esempio n. 4
0
        /// <summary>
        /// 钉钉,新增部门同步钉钉
        /// </summary>
        /// <param name="dept">部门基本信息</param>
        /// <returns></returns>
        public CreateDepartMent_PostVal GPM_Ding_CreateDept(Dept dept)
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/department/create?access_token=" + access_token;

            try
            {
                IDictionary <string, object> list = new Dictionary <string, object>();
                list.Add("name", dept.Name);
                list.Add("parentid", dept.ParentNo);
                //list.Add("order", "1");
                list.Add("createDeptGroup", "true");

                string str = BP.Tools.Json.ToJson(list);
                str = new HttpWebResponseUtility().HttpResponsePost_Json(url, str);
                CreateDepartMent_PostVal postVal = FormatToJson.ParseFromJson <CreateDepartMent_PostVal>(str);

                //请求返回信息
                if (postVal != null)
                {
                    if (postVal.errcode != "0")
                    {
                        BP.DA.Log.DefaultLogWriteLineError("钉钉新增部门失败:" + postVal.errcode + "-" + postVal.errmsg);
                    }

                    return(postVal);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// 带有超链接消息
        /// </summary>
        /// <param name="dingMsg"></param>
        /// <returns></returns>
        public static Ding_Post_ReturnVal Msg_AgentLink_Send(Ding_Msg_Link dingMsg)
        {
            string url = "https://oapi.dingtalk.com/message/send?access_token=" + dingMsg.Access_Token;

            try
            {
                StringBuilder append_Json = new StringBuilder();
                append_Json.Append("{");
                append_Json.Append("\"touser\":\"" + dingMsg.touser + "\"");
                append_Json.Append(",\"msgtype\":\"link\"");
                append_Json.Append(",\"agentid\":\"" + dingMsg.agentid + "\"");
                append_Json.Append(",\"link\":{");
                append_Json.Append("\"messageUrl\":\"" + dingMsg.messageUrl + "\"");
                append_Json.Append(",\"picUrl\":\"" + dingMsg.picUrl + "\"");
                append_Json.Append(",\"title\":\"" + dingMsg.title + "\"");
                append_Json.Append(",\"text\":\"" + dingMsg.text + "\"");
                append_Json.Append("}");
                append_Json.Append("}");
                string str = new HttpWebResponseUtility().HttpResponsePost_Json(url, append_Json.ToString());
                Ding_Post_ReturnVal postVal = FormatToJson.ParseFromJson <Ding_Post_ReturnVal>(str);
                return(postVal);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// 发送新闻消息
        /// </summary>
        /// <param name="msgNews">消息实体类</param>
        /// <returns>发送消息结果</returns>
        public static MessageErrorModel PostMsgOfNews(WX_Msg_News msgNews)
        {
            string url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + msgNews.Access_Token;

            try
            {
                StringBuilder append_Json = new StringBuilder();
                append_Json.Append("{");
                append_Json.Append("\"msgtype\":\"news\"");
                //按人员
                if (!string.IsNullOrEmpty(msgNews.touser))
                {
                    append_Json.Append(",\"touser\":\"" + msgNews.touser + "\"");
                }
                //按部门
                if (!string.IsNullOrEmpty(msgNews.toparty))
                {
                    append_Json.Append(",\"toparty\":\"" + msgNews.toparty + "\"");
                }
                //标签
                if (!string.IsNullOrEmpty(msgNews.totag))
                {
                    append_Json.Append(",\"totag\":\"" + msgNews.totag + "\"");
                }

                append_Json.Append(",\"agentid\":\"" + msgNews.agentid + "\"");
                append_Json.Append(",\"news\":{");

                append_Json.Append("\"articles\":[");
                foreach (News_Articles item in msgNews.articles)
                {
                    append_Json.Append("{");
                    append_Json.Append("\"title\":\"" + item.title + "\"");
                    append_Json.Append(",\"description\":\"" + item.description + "\"");
                    if (!string.IsNullOrEmpty(item.url))
                    {
                        append_Json.Append(",\"url\":\"" + item.url + "\"");
                    }
                    if (!string.IsNullOrEmpty(item.picurl))
                    {
                        append_Json.Append(",\"picurl\":\"" + item.picurl + "\"");
                    }
                    append_Json.Append("},");
                }
                append_Json.Remove(append_Json.Length - 1, 1);

                append_Json.Append("]}");
                append_Json.Append("}");
                string            str     = new HttpWebResponseUtility().HttpResponsePost_Json(url, append_Json.ToString());
                MessageErrorModel postVal = FormatToJson.ParseFromJson <MessageErrorModel>(str);
                return(postVal);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Esempio n. 7
0
        public MessageErrorModel PostWeiXinMsg(StringBuilder sb)
        {
            string            wxStr = string.Empty;
            string            url   = "https://qyapi.weixin.qq.com/cgi-bin/message/send?";
            MessageErrorModel m     = new MessageErrorModel();

            wxStr = PostForWeiXin(sb, url);
            m     = FormatToJson.ParseFromJson <MessageErrorModel>(wxStr);
            return(m);
        }
Esempio n. 8
0
        /// <summary>
        /// 发送OA型消息
        /// </summary>
        /// <param name="dingMsg"></param>
        /// <returns></returns>
        public static Ding_Post_ReturnVal Msg_OAText_Send(Ding_Msg_OA dingMsg)
        {
            string url = "https://oapi.dingtalk.com/message/send?access_token=" + dingMsg.Access_Token;

            try
            {
                StringBuilder append_Json = new StringBuilder();
                append_Json.Append("{");
                append_Json.Append("\"touser\":\"" + dingMsg.touser + "\"");
                append_Json.Append(",\"msgtype\":\"oa\"");
                append_Json.Append(",\"agentid\":\"" + dingMsg.agentid + "\"");
                append_Json.Append(",\"oa\":{");
                append_Json.Append("\"message_url\":\"" + dingMsg.messageUrl + "\"");

                append_Json.Append(",\"head\":{");
                append_Json.Append("\"bgcolor\":\"" + dingMsg.head_bgcolor + "\"");
                append_Json.Append(",\"text\":\"" + dingMsg.head_text + "\"");
                append_Json.Append("}");

                append_Json.Append(",\"body\":{");
                append_Json.Append("\"title\":\"" + dingMsg.body_title + "\"");
                if (dingMsg.body_form.Count > 0)
                {
                    append_Json.Append(",\"form\":[");
                    foreach (string itemKey in dingMsg.body_form.Keys)
                    {
                        append_Json.Append("{");
                        append_Json.Append("\"key\":\"" + itemKey + "\"");
                        append_Json.Append(",\"value\":\"" + dingMsg.body_form[itemKey] + "\"");
                        append_Json.Append("},");
                    }
                    append_Json.Remove(append_Json.Length - 1, 1);
                    append_Json.Append("]");
                }

                append_Json.Append(",\"author\":\"" + dingMsg.body_author + "\"");
                append_Json.Append("}");
                append_Json.Append("}");
                append_Json.Append("}");
                string str = new HttpWebResponseUtility().HttpResponsePost_Json(url, append_Json.ToString());
                Ding_Post_ReturnVal postVal = FormatToJson.ParseFromJson <Ding_Post_ReturnVal>(str);
                return(postVal);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// 钉钉,新增人员同步钉钉
        /// </summary>
        /// <param name="emp">部门基本信息</param>
        /// <returns></returns>
        public CreateUser_PostVal GPM_Ding_CreateEmp(Emp emp)
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/user/create?access_token=" + access_token;

            try
            {
                IDictionary <string, object> list = new Dictionary <string, object>();
                //如果用户编号存在则按照此账号进行新建
                if (!(DataType.IsNullOrEmpty(emp.No) || string.IsNullOrWhiteSpace(emp.No)))
                {
                    list.Add("userid", emp.No);
                }
                list.Add("name", emp.Name);
                //部门数组
                List <string> listArrary = new List <string>();
                listArrary.Add(emp.FK_Dept);

                list.Add("department", listArrary);
                list.Add("mobile", emp.Tel);
                list.Add("email", emp.Email);

                string str = BP.Tools.FormatToJson.ToJson_FromDictionary(list);
                str = new HttpWebResponseUtility().HttpResponsePost_Json(url, str);
                CreateUser_PostVal postVal = FormatToJson.ParseFromJson <CreateUser_PostVal>(str);

                //请求返回信息
                if (postVal != null)
                {
                    if (postVal.errcode != "0")
                    {
                        //在钉钉通讯录已经存在
                        if (postVal.errcode == "60102")
                        {
                            postVal.userid = emp.No;
                        }
                        BP.DA.Log.DefaultLogWriteLineError("钉钉新增人员失败:" + postVal.errcode + "-" + postVal.errmsg);
                    }
                    return(postVal);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 10
0
        /// <summary>
        /// 获取部门下的人员
        /// </summary>
        /// <returns></returns>
        private DepartMentUser_List GenerDeptUser_List(string access_token, string department_id)
        {
            string url = "https://oapi.dingtalk.com/user/list?access_token=" + access_token + "&department_id=" + department_id;

            try
            {
                string str = new HttpWebResponseUtility().HttpResponseGet(url);
                DepartMentUser_List departMentUserList = FormatToJson.ParseFromJson <DepartMentUser_List>(str);

                //部门人员集合
                if (departMentUserList != null && departMentUserList.userlist != null && departMentUserList.userlist.Count > 0)
                {
                    return(departMentUserList);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 11
0
        /// <summary>
        /// 获取部门集合
        /// </summary>
        public DeptMent_GetList GetDeptMentList()
        {
            string access_token = getAccessToken();
            string url          = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + access_token;

            try
            {
                string           str            = new HttpWebResponseUtility().HttpResponseGet(url);
                DeptMent_GetList departMentList = FormatToJson.ParseFromJson <DeptMent_GetList>(str);

                //部门集合
                if (departMentList != null)
                {
                    return(departMentList);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 12
0
        /// <summary>
        /// 获取用户ID
        /// </summary>
        /// <param name="code"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public string GetUserID(string code)
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/user/getuserinfo?access_token=" + access_token + "&code=" + code;

            try
            {
                string             str  = new HttpWebResponseUtility().HttpResponseGet(url);
                CreateUser_PostVal user = new CreateUser_PostVal();
                user = FormatToJson.ParseFromJson <CreateUser_PostVal>(str);
                //BP.DA.Log.DefaultLogWriteLineError(access_token + "code:" + code + "1." + user.userid + "2." + user.errcode + "3." + user.errmsg);
                if (!DataType.IsNullOrEmpty(user.userid))
                {
                    return(user.userid);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
                return(ex.Message);
            }
            return("");
        }
Esempio n. 13
0
        /// <summary>
        /// 钉钉,编辑部门同步钉钉
        /// </summary>
        /// <param name="dept">部门基本信息</param>
        /// <returns></returns>
        public Ding_Post_ReturnVal GPM_Ding_EditDept(Dept dept)
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/department/update?access_token=" + access_token;

            try
            {
                IDictionary <string, object> list = new Dictionary <string, object>();
                list.Add("id", dept.No);
                list.Add("name", dept.Name);
                //根目录不允许修改
                if (dept.No != "1")
                {
                    list.Add("parentid", dept.ParentNo);
                }

                string str = BP.Tools.FormatToJson.ToJson_FromDictionary(list);
                str = new HttpWebResponseUtility().HttpResponsePost_Json(url, str);
                Ding_Post_ReturnVal postVal = FormatToJson.ParseFromJson <Ding_Post_ReturnVal>(str);

                //请求返回信息
                if (postVal != null)
                {
                    if (postVal.errcode != "0")
                    {
                        BP.DA.Log.DefaultLogWriteLineError("钉钉修改部门失败:" + postVal.errcode + "-" + postVal.errmsg);
                    }

                    return(postVal);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 14
0
        /// <summary>
        /// 同步钉钉通讯录到CCGPM
        /// </summary>
        /// <returns></returns>
        public bool AnsyOrgToCCGPM()
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/department/list?access_token=" + access_token;

            try
            {
                string          str            = new HttpWebResponseUtility().HttpResponseGet(url);
                DepartMent_List departMentList = FormatToJson.ParseFromJson <DepartMent_List>(str);
                //部门集合
                if (departMentList != null && departMentList.department != null && departMentList.department.Count > 0)
                {
                    //删除旧数据
                    ClearOrg_Old();
                    //获取根部门
                    DepartMentDetailInfo rootDepartMent = new DepartMentDetailInfo();
                    foreach (DepartMentDetailInfo deptMenInfo in departMentList.department)
                    {
                        if (deptMenInfo.id == "1")
                        {
                            rootDepartMent = deptMenInfo;
                            break;
                        }
                    }
                    //增加跟部门
                    int  deptIdx  = 0;
                    Dept rootDept = new Dept();
                    rootDept.No       = rootDepartMent.id;
                    rootDept.Name     = rootDepartMent.name;
                    rootDept.ParentNo = "0";
                    rootDept.DirectInsert();


                    //部门信息
                    foreach (DepartMentDetailInfo deptMentInfo in departMentList.department)
                    {
                        //增加部门,排除根目录
                        if (deptMentInfo.id != "1")
                        {
                            Dept dept = new Dept();
                            dept.No       = deptMentInfo.id;
                            dept.Name     = deptMentInfo.name;
                            dept.ParentNo = deptMentInfo.parentid;
                            dept.DirectInsert();
                        }

                        //部门人员
                        DepartMentUser_List userList = GenerDeptUser_List(access_token, deptMentInfo.id);
                        if (userList != null)
                        {
                            foreach (DepartMentUserInfo userInfo in userList.userlist)
                            {
                                Emp     emp     = new Emp();
                                DeptEmp deptEmp = new DeptEmp();
                                //如果账户存在则人员信息不添加,添加关联表
                                if (emp.IsExit(EmpAttr.No, userInfo.userid) == true)
                                {
                                    deptEmp.MyPK    = deptMentInfo.id + "_" + emp.No;
                                    deptEmp.FK_Dept = deptMentInfo.id;
                                    deptEmp.FK_Emp  = emp.No;
                                    deptEmp.DirectInsert();
                                    continue;
                                }

                                //增加人员
                                emp.No      = userInfo.userid;
                                emp.Name    = userInfo.name;
                                emp.FK_Dept = deptMentInfo.id;
                                emp.Tel     = userInfo.mobile;
                                emp.Email   = userInfo.email;
                                //emp.Idx = DataType.IsNullOrEmpty(userInfo.order) == true ? 0 : Int32.Parse(userInfo.order);
                                emp.DirectInsert();

                                //增加人员与部门对应表
                                deptEmp.MyPK    = deptMentInfo.id + "_" + emp.No;
                                deptEmp.FK_Dept = deptMentInfo.id;
                                deptEmp.FK_Emp  = emp.No;
                                deptEmp.DirectInsert();
                            }
                        }
                    }

                    #region 处理部门名称全程
                    //OrgInit_NameOfPath nameOfPath = new OrgInit_NameOfPath();
                    //if (nameOfPath.IsCanDo)
                    //    nameOfPath.Do();
                    #endregion

                    return(true);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(false);
        }
Esempio n. 15
0
        /// <summary>
        /// 增量同步组织结构
        /// </summary>
        /// <returns></returns>
        public string AnsyIncrementOrgToGPM()
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/department/list?access_token=" + access_token;

            try
            {
                StringBuilder   append         = new StringBuilder();
                string          str            = new HttpWebResponseUtility().HttpResponseGet(url);
                DepartMent_List departMentList = FormatToJson.ParseFromJson <DepartMent_List>(str);
                if (departMentList == null || departMentList.department == null || departMentList.department.Count == 0)
                {
                    return("钉钉获取部门出错。");
                }

                #region 获取钉钉组织结构,进行更新与新增
                //增加跟部门
                int  deptIdx     = 0;
                bool doSomeThing = false;
                //部门信息
                foreach (DepartMentDetailInfo deptMentInfo in departMentList.department)
                {
                    deptIdx++;
                    doSomeThing = false;
                    //增加部门,排除根目录
                    if (deptMentInfo.id != "1")
                    {
                        Dept dept = new Dept();
                        if (dept.IsExit(DeptAttr.No, deptMentInfo.id) == true)
                        {
                            if (dept.No == deptMentInfo.id && !dept.Name.Equals(deptMentInfo.name))
                            {
                                doSomeThing = true;
                                append.Append("\r\n部门名称发生变化:" + dept.Name + " --> " + deptMentInfo.name);
                            }
                            if (!dept.ParentNo.Equals(deptMentInfo.parentid))
                            {
                                doSomeThing = true;
                                append.Append("\r\n部门父级发生变化:" + dept.ParentNo + " --> " + deptMentInfo.parentid);
                            }
                            //有变化,更新
                            if (doSomeThing == true)
                            {
                                dept.No       = deptMentInfo.id;
                                dept.Name     = deptMentInfo.name;
                                dept.ParentNo = deptMentInfo.parentid;
                                dept.DirectUpdate();
                            }
                        }
                        else
                        {
                            //不存在则新增
                            dept.No       = deptMentInfo.id;
                            dept.Name     = deptMentInfo.name;
                            dept.ParentNo = deptMentInfo.parentid;
                            dept.DirectInsert();
                            append.Append("\r\n新增部门:" + deptMentInfo.id + " - " + deptMentInfo.name);
                        }
                    }
                    //部门人员
                    DepartMentUser_List userList = GenerDeptUser_List(access_token, deptMentInfo.id);
                    if (userList != null)
                    {
                        foreach (DepartMentUserInfo userInfo in userList.userlist)
                        {
                            Emp emp = new Emp();
                            emp.No = userInfo.userid;

                            DeptEmp deptEmp = new DeptEmp();
                            //如果账户存在则人员信息不添加,添加关联表
                            if (emp.RetrieveFromDBSources() > 0)
                            {
                                if (!emp.Name.Equals(userInfo.name))
                                {
                                    emp.Name = userInfo.name;
                                    emp.DirectUpdate();
                                    append.Append("\r\n人员名称发生变化:" + emp.Name + " --> " + userInfo.name);
                                }

                                deptEmp.MyPK = deptMentInfo.id + "_" + emp.No;
                                if (deptEmp.RetrieveFromDBSources() > 0)
                                {
                                    continue;
                                }

                                //增加人员归属部门
                                deptEmp.FK_Dept = deptMentInfo.id;
                                deptEmp.FK_Emp  = emp.No;
                                deptEmp.DirectInsert();
                                append.Append("\r\n增加人员归属部门:" + emp.Name + " - " + deptMentInfo.name);
                                continue;
                            }

                            //增加人员
                            emp.No      = userInfo.userid;
                            emp.Name    = userInfo.name;
                            emp.FK_Dept = deptMentInfo.id;
                            emp.Tel     = userInfo.mobile;
                            emp.Email   = userInfo.email;
                            //emp.Idx = DataType.IsNullOrEmpty(userInfo.order) == true ? 0 : Int32.Parse(userInfo.order);
                            emp.DirectInsert();
                            append.Append("\r\n增加人员:" + emp.Name + "  所属部门:" + deptMentInfo.name);

                            //增加人员与部门对应表
                            deptEmp.MyPK    = deptMentInfo.id + "_" + emp.No;
                            deptEmp.FK_Dept = deptMentInfo.id;
                            deptEmp.FK_Emp  = emp.No;
                            deptEmp.DirectInsert();
                        }
                    }
                }
                #endregion

                #region GPM组织结构,在钉钉不存在进行删除部门与人员关系表,人员表不进行删除,删除业务人员表WF_Emp
                Depts gpm_Depts = new Depts();
                gpm_Depts.RetrieveAllFromDBSource();
                foreach (Dept gpm_Dept in gpm_Depts)
                {
                    bool isHave = false;
                    foreach (DepartMentDetailInfo ding_Dept in departMentList.department)
                    {
                        if (gpm_Dept.No.Equals(ding_Dept.id))
                        {
                            isHave = true;
                            break;
                        }
                    }

                    //部门在钉钉不存在则进行删除:部门表、部门人员、部门人员岗位、部门职位、部门岗位
                    if (isHave == false)
                    {
                        //部门岗位
                        DeptStation deptStation  = new DeptStation();
                        int         iDeptStation = deptStation.Delete(DeptStationAttr.FK_Dept, gpm_Dept.No);

                        //部门人员岗位
                        DeptEmpStation deptEmpStation  = new DeptEmpStation();
                        int            iDeptEmpStation = deptEmpStation.Delete(DeptEmpStationAttr.FK_Dept, gpm_Dept.No);
                        //部门人员
                        DeptEmp deptEmp  = new DeptEmp();
                        int     iDeptEmp = deptEmp.Delete(DeptEmpAttr.FK_Dept, gpm_Dept.No);
                        //部门表
                        Dept dt = new Dept(gpm_Dept.No);
                        dt.Delete();
                        append.Append("\r\n删除部门:" + gpm_Dept.Name + " 部门全路径:" + gpm_Dept.NameOfPath);
                        append.Append("\r\n        部门岗位 " + iDeptStation + " 条记录");
                        append.Append("\r\n        部门人员岗位 " + iDeptEmpStation + " 条记录");
                        append.Append("\r\n        部门人员 " + iDeptEmp + " 条记录");
                    }
                    else
                    {
                        //组织结构人员
                        DeptEmps    deptEmps = new DeptEmps();
                        QueryObject obj      = new QueryObject(deptEmps);
                        obj.AddWhere(DeptEmpAttr.FK_Dept, gpm_Dept.No);
                        obj.addAnd();
                        obj.AddWhereNotIn(DeptEmpAttr.FK_Emp, "'admin'");
                        obj.DoQuery();

                        //部门下没有人员不需要处理
                        if (deptEmps == null || deptEmps.Count == 0)
                        {
                            continue;
                        }

                        //钉钉部门人员
                        DepartMentUser_List userList = GenerDeptUser_List(access_token, gpm_Dept.No);
                        //部门下没有人员,清除部门下的所有人员
                        if (userList == null || userList.userlist.Count == 0)
                        {
                            append.Append("\r\n删除部门下的人员,部门:" + gpm_Dept.Name + " 部门全路径:" + gpm_Dept.NameOfPath);
                            foreach (DeptEmp dt in deptEmps)
                            {
                                dt.Delete();
                                Emp ep = new Emp();
                                ep.No = dt.FK_Emp;
                                ep.RetrieveFromDBSources();
                                append.Append("\r\n        人员编号:" + dt.FK_Emp + " 姓名:" + ep.Name);
                            }
                            continue;
                        }

                        //判断部门下的人员是否存在
                        foreach (DeptEmp deptEmp in deptEmps)
                        {
                            isHave = false;
                            foreach (DepartMentUserInfo userInfo in userList.userlist)
                            {
                                if (deptEmp.FK_Emp.Equals(userInfo.userid))
                                {
                                    isHave = true;
                                    break;
                                }
                            }

                            //不存在,删除
                            if (isHave == false)
                            {
                                deptEmp.Delete();
                                Emp ep = new Emp();
                                ep.No = deptEmp.FK_Emp;
                                ep.RetrieveFromDBSources();
                                append.Append("\r\n删除部门下的人员,部门:" + gpm_Dept.Name + " 部门全路径:" + gpm_Dept.NameOfPath);
                                append.Append("\r\n        人员编号:" + deptEmp.FK_Emp + " 姓名:" + ep.Name);
                            }
                        }
                    }
                }
                //删除没包含在部门的人员

                #endregion

                #region 处理部门名称全程
                //OrgInit_NameOfPath nameOfPath = new OrgInit_NameOfPath();
                //if (nameOfPath.IsCanDo)
                //    nameOfPath.Do();
                #endregion
                return(append.ToString());
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 16
0
        /// <summary>
        /// 钉钉,编辑人员同步钉钉
        /// </summary>
        /// <param name="emp">部门基本信息</param>
        /// <returns></returns>
        public Ding_Post_ReturnVal GPM_Ding_EditEmp(Emp emp, List <string> deptIds = null)
        {
            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/user/update?access_token=" + access_token;

            try
            {
                IDictionary <string, object> list = new Dictionary <string, object>();
                list.Add("userid", emp.No);
                list.Add("name", emp.Name);
                list.Add("email", emp.Email);
                list.Add("mobile", emp.Tel);
                list.Add("position", "");
                //钉钉根据此从其他部门删除或增加到其他部门
                if (deptIds != null && deptIds.Count > 0)
                {
                    list.Add("department", deptIds);
                }
                string str = BP.Tools.FormatToJson.ToJson_FromDictionary(list);
                str = new HttpWebResponseUtility().HttpResponsePost_Json(url, str);
                Ding_Post_ReturnVal postVal = FormatToJson.ParseFromJson <Ding_Post_ReturnVal>(str);

                //请求返回信息
                if (postVal != null)
                {
                    bool create_Ding_user = false;
                    //40022企业中的手机号码和登陆钉钉的手机号码不一致,暂时不支持修改用户信息,可以删除后重新添加
                    if (postVal.errcode == "40022" || postVal.errcode == "40021")
                    {
                        create_Ding_user = true;
                        postVal          = GPM_Ding_DeleteEmp(emp.No);
                        //删除失败
                        if (postVal.errcode != "0")
                        {
                            create_Ding_user = false;
                        }
                    }
                    else if (postVal.errcode == "60121")//60121找不到该用户
                    {
                        create_Ding_user = true;
                    }

                    //需要新增人员
                    if (create_Ding_user == true)
                    {
                        CreateUser_PostVal postUserVal = GPM_Ding_CreateEmp(emp);
                        //消息传递
                        postVal.errcode = postUserVal.errcode;
                        postVal.errmsg  = postUserVal.errmsg;
                    }

                    if (postVal.errcode != "0")
                    {
                        BP.DA.Log.DefaultLogWriteLineError("钉钉修改人员失败:" + postVal.errcode + "-" + postVal.errmsg);
                    }
                    return(postVal);
                }
            }
            catch (Exception ex)
            {
                BP.DA.Log.DefaultLogWriteLineError(ex.Message);
            }
            return(null);
        }
Esempio n. 17
0
        /// <summary>
        /// 下载钉钉所有头像
        /// </summary>
        /// <param name="savePath"></param>
        /// <returns></returns>
        public bool DownLoadUserIcon(string savePath)
        {
            if (Directory.Exists(savePath) == false)
            {
                Directory.CreateDirectory(savePath);
            }

            string access_token = getAccessToken();
            string url          = "https://oapi.dingtalk.com/department/list?access_token=" + access_token;

            try
            {
                string          str            = new HttpWebResponseUtility().HttpResponseGet(url);
                DepartMent_List departMentList = FormatToJson.ParseFromJson <DepartMent_List>(str);
                //部门集合
                if (departMentList != null && departMentList.department != null && departMentList.department.Count > 0)
                {
                    //部门信息
                    foreach (DepartMentDetailInfo deptMentInfo in departMentList.department)
                    {
                        //部门人员
                        DepartMentUser_List userList = GenerDeptUser_List(access_token, deptMentInfo.id);
                        if (userList != null)
                        {
                            foreach (DepartMentUserInfo userInfo in userList.userlist)
                            {
                                if (DataType.IsNullOrEmpty(userInfo.avatar))
                                {
                                    //大图标
                                    string UserIcon = savePath + "\\" + userInfo.userid + "Biger.png";
                                    File.Copy(savePath + "\\DefaultBiger.png", UserIcon, true);

                                    //小图标
                                    UserIcon = savePath + "\\" + userInfo.userid + "Smaller.png";
                                    File.Copy(savePath + "\\DefaultSmaller.png", UserIcon, true);

                                    //正常图标
                                    UserIcon = savePath + "\\" + userInfo.userid + ".png";
                                    File.Copy(savePath + "\\Default.png", UserIcon, true);
                                }
                                else
                                {
                                    //大图标
                                    string headimgurl = userInfo.avatar;
                                    string UserIcon   = savePath + "\\" + userInfo.userid + "Biger.png";
                                    BP.DA.DataType.HttpDownloadFile(headimgurl, UserIcon);

                                    //小图标
                                    UserIcon = savePath + "\\" + userInfo.userid + "Smaller.png";
                                    BP.DA.DataType.HttpDownloadFile(headimgurl, UserIcon);

                                    //正常图标
                                    UserIcon = savePath + "\\" + userInfo.userid + ".png";
                                    BP.DA.DataType.HttpDownloadFile(headimgurl, UserIcon);
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
            }
            return(false);
        }