示例#1
0
        public void UpdateAllUsers()
        {
            RoadFlow.Platform.Organize organize  = new RoadFlow.Platform.Organize();
            UsersRelation usersRelation          = new UsersRelation();
            List <RoadFlow.Data.Model.Users> all = new Users().GetAll();
            DataTable dataTable = new DataTable
            {
                Columns =
                {
                    {
                        "姓名",
                        "".GetType()
                    },
                    {
                        "帐号",
                        "".GetType()
                    },
                    {
                        "微信号",
                        "".GetType()
                    },
                    {
                        "手机号",
                        "".GetType()
                    },
                    {
                        "邮箱",
                        "".GetType()
                    },
                    {
                        "所在部门",
                        "".GetType()
                    },
                    {
                        "职位",
                        "".GetType()
                    }
                }
            };

            foreach (RoadFlow.Data.Model.Users item in all)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (RoadFlow.Data.Model.UsersRelation item2 in usersRelation.GetAllByUserID(item.ID))
                {
                    RoadFlow.Data.Model.Organize organize2 = organize.Get(item2.OrganizeID);
                    if (organize2 != null)
                    {
                        stringBuilder.Append(organize2.IntID);
                        stringBuilder.Append(",");
                    }
                }
                DataRow dataRow = dataTable.NewRow();
                dataRow["姓名"]   = replaceName(item.Name);
                dataRow["帐号"]   = item.Account;
                dataRow["微信号"]  = item.WeiXin;
                dataRow["手机号"]  = item.Mobile;
                dataRow["邮箱"]   = item.Email;
                dataRow["所在部门"] = stringBuilder.ToString().TrimEnd(',');
                dataRow["职位"]   = "";
                dataTable.Rows.Add(dataRow);
            }
            string text = Files.FilePath + "WeiXinCsv\\";

            if (!Directory.Exists(text))
            {
                Directory.CreateDirectory(text);
            }
            string text2 = text + Guid.NewGuid().ToString("N") + ".csv";

            NPOIHelper.ExportCSV(dataTable, text2);
            string text3 = new Media(Config.GetSecret("weixinagents_organize")).UploadTemp(text2, "file");

            if (!text3.IsNullOrEmpty())
            {
                string url   = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser?access_token=" + GetAccessToken();
                string text4 = "{\"media_id\":\"" + text3 + "\"}";
                string str   = HttpHelper.SendPost(url, text4);
                Log.Add("调用了微信同步所有人员", "返回:" + str, Log.Types.微信企业号, text4);
            }
        }
示例#2
0
        public void UpdateAllOrganize()
        {
            RoadFlow.Platform.Organize          organize = new RoadFlow.Platform.Organize();
            List <RoadFlow.Data.Model.Organize> all      = organize.GetAll();
            DataTable dataTable = new DataTable
            {
                Columns =
                {
                    {
                        "部门名称",
                        "".GetType()
                    },
                    {
                        "部门ID",
                        1.GetType()
                    },
                    {
                        "父部门ID",
                        1.GetType()
                    },
                    {
                        "排序",
                        1.GetType()
                    }
                }
            };

            foreach (RoadFlow.Data.Model.Organize item in all)
            {
                int num = -1;
                if (item.ParentID.IsEmptyGuid())
                {
                    num = 1;
                }
                else
                {
                    RoadFlow.Data.Model.Organize organize2 = organize.Get(item.ParentID);
                    if (organize2 != null)
                    {
                        num = organize2.IntID;
                    }
                }
                if (num != -1)
                {
                    DataRow dataRow = dataTable.NewRow();
                    dataRow["部门名称"]  = replaceName(item.Name);
                    dataRow["部门ID"]  = item.IntID;
                    dataRow["父部门ID"] = num;
                    dataRow["排序"]    = item.Sort;
                    dataTable.Rows.Add(dataRow);
                }
            }
            string text = Files.FilePath + "WeiXinCsv\\";

            if (!Directory.Exists(text))
            {
                Directory.CreateDirectory(text);
            }
            string text2 = text + Guid.NewGuid().ToString("N") + ".csv";

            NPOIHelper.ExportCSV(dataTable, text2);
            string text3 = new Media(Config.GetSecret("weixinagents_organize")).UploadTemp(text2, "file");

            if (!text3.IsNullOrEmpty())
            {
                string url   = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty?access_token=" + GetAccessToken();
                string text4 = "{\"media_id\":\"" + text3 + "\"}";
                string str   = HttpHelper.SendPost(url, text4);
                Log.Add("调用了微信同步整个组织架构", "返回:" + str, Log.Types.微信企业号, text4);
            }
        }