コード例 #1
0
        /// <summary>
        /// 添加标签成员
        /// </summary>
        /// <returns></returns>
        public JsonResult addTagMember(string[] userlist, int[] partylist, string tagId)
        {
            string accessToken = GetToken();

            using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew,
                                                               new TransactionOptions {
                IsolationLevel = IsolationLevel.RepeatableRead
            }))
            {
                if (userlist != null)
                {
                    foreach (var userId in userlist)
                    {
                        _addressBookService.addMemberTag(userId, Int32.Parse(tagId));
                    }
                }
                var ret = MailListApi.AddTagMember(accessToken, Int32.Parse(tagId), userlist, partylist);
                if (ret.errcode == Weixin.ReturnCode_QY.请求成功)
                {
                    transactionScope.Complete();
                }
            }
            WeChatCommonService.ClearDepartmentTagMapCache(this.AccountManageID);
            WeChatCommonService.ClearTagCache(int.Parse(tagId));
            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        /// <summary>
        /// 添加标签成员
        /// </summary>
        /// <returns></returns>
        public JsonResult addTagMember(string[] userlist, string tagId)
        {
            string accessToken = GetToken();

            MailListApi.AddTagMember(accessToken, Int32.Parse(tagId), userlist);
            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
ファイル: TagTest.cs プロジェクト: wuqihui/WeiXinMPSDK
        //[TestMethod]
        public void AddTagMemberTest(int tagId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId);
            var result      = MailListApi.AddTagMember(accessToken, tagId, new[] { "TYSZCC" });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode.请求成功);
        }
コード例 #4
0
ファイル: WXHelp.cs プロジェクト: jaysue/zyweb
        public QyJsonResult WX_AddTagMember(JH_Auth_UserRole Model)
        {
            var          role = new JH_Auth_RoleB().GetEntity(p => p.RoleCode == Model.RoleCode);
            QyJsonResult Ret  = new QyJsonResult();

            if (Qyinfo.IsUseWX == "Y")
            {
                string[] userList = { Model.UserName };
                int      bqid     = Int32.Parse(role.WXBQCode.ToString());
                Ret = MailListApi.AddTagMember(GetToken(), bqid, userList, null);
            }
            return(Ret);
        }
コード例 #5
0
        public int UpdateEmployee(LocalSADEntity entity)
        {
            var updateEmployee = Repository.Entities.Where(t => t.LilyId.ToUpper() == entity.LillyID.ToUpper()).FirstOrDefault();

            if (updateEmployee == null)
            {
                return(0);
            }

            updateEmployee.EmployeeTime = entity.ACTL_HIRE_DT;
            updateEmployee.BaseLocation = entity.BS_LCTN_GLBL;
            updateEmployee.Tag          = CommonService.GetSysConfig("TagNameNewEmployee", "");

            //过滤条件暂时删除
            //if (updateEmployee.EmployeeTime < DateTime.Now.AddMonths(-6).Date)
            //{
            //    return 0;
            //}

            if (!string.IsNullOrEmpty(updateEmployee.Tag))
            {
                var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == updateEmployee.Tag);
                int tagid   = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0;

                string[] userlist = new string[1];
                userlist[0] = entity.LillyID;
                //不超过6个月时,添加标签
                if (tagid != 0 && DateTime.Today <= (updateEmployee.EmployeeTime.AddMonths(6)))
                {
                    var tagMemberResult = MailListApi.GetTagMember(WeChatCommonService.GetWeiXinToken(0), tagid);
                    var hasTag          = tagMemberResult.userlist.Select(a => a.userid.ToUpper() == entity.LillyID.ToUpper()).FirstOrDefault();
                    if (!hasTag)
                    {
                        MailListApi.AddTagMember(WeChatCommonService.GetWeiXinToken(0), tagid, userlist);
                    }
                }

                //超过7个月时,移除标签
                if (tagid != 0 && DateTime.Today > (updateEmployee.EmployeeTime.AddMonths(7)))
                {
                    MailListApi.DelTagMember(WeChatCommonService.GetWeiXinToken(0), tagid, userlist);
                }
            }



            return(Repository.Update(updateEmployee));
        }
コード例 #6
0
        public JsonResult AddDepartmentToTag(IList <int> departments, string tagId)
        {
            if (string.IsNullOrEmpty(tagId))
            {
                return(ErrorNotification("数据异常!"));
            }

            departments = departments ?? new List <int>();

            var accessToken = GetToken();

            var partList = MailListApi.GetTagMember(accessToken, int.Parse(tagId)).partylist;

            var deletedList = partList.Where(x => departments.All(y => y != x)).ToArray();
            var addedList   = departments.Where(x => !partList.Any(y => y == x)).ToArray();

            if (addedList.Any())
            {
                var addResult = MailListApi.AddTagMember(accessToken, Int32.Parse(tagId), null, addedList);

                if (addResult.errcode != ReturnCode_QY.请求成功)
                {
                    return(ErrorNotification(addResult.errcode.ToString()));
                }
            }

            if (deletedList.Any())
            {
                var delResult = MailListApi.DelTagMember(accessToken, Int32.Parse(tagId), null, deletedList);

                if (delResult.errcode != ReturnCode_QY.请求成功)
                {
                    return(ErrorNotification(delResult.errcode.ToString()));
                }
            }

            //if (addedList.Any() || deletedList.Any())
            //{
            //    WeChatCommonService.lstTag.Clear();
            //}

            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        //public List<ArticleConfig> SendArticleToNewEmployee()
        //{
        //var jsonString = CommonService.GetSysConfig("SendArticleCycle", "[]");
        //List<ArticleConfig> config = JsonConvert.DeserializeObject<List<ArticleConfig>>(jsonString);
        //foreach (var item in config)
        //{
        //    item.employeeLst = GetNewEmployee(item);
        //    foreach (var employee in item.employeeLst)
        //    {
        //        item.UserLst += employee.LilyId + "|";
        //    }
        //    item.UserLst = item.UserLst == null ? "" : item.UserLst.Substring(0, item.UserLst.Length - 1);
        //}
        //return config;
        //}


        //NewEmployee表已弃掉
        public int AddNewEmployee(LocalSADEntity entity)
        {
            NewEmployee newEmployee = new NewEmployee();

            newEmployee.Name         = entity.ChineseName;
            newEmployee.LilyId       = entity.LillyID;
            newEmployee.Email        = entity.Email;
            newEmployee.Gender       = entity.Gender;
            newEmployee.Tag          = CommonService.GetSysConfig("TagNameNewEmployee", "");
            newEmployee.EmployeeTime = entity.ACTL_HIRE_DT;
            newEmployee.BaseLocation = entity.BS_LCTN_GLBL;
            if (!string.IsNullOrEmpty(newEmployee.Tag))
            {
                //var taglist = MailListApi.GetTagList(WeChatCommonService.GetWeiXinToken(0)).taglist.Where(x => x.tagname == newEmployee.Tag);
                var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == newEmployee.Tag);
                int tagid   = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0;

                string[] userlist = new string[1];
                userlist[0] = entity.LillyID;
                if (tagid != 0 && DateTime.Today <= (newEmployee.EmployeeTime.AddMonths(6)))
                {
                    MailListApi.AddTagMember(WeChatCommonService.GetWeiXinToken(0), tagid, userlist);
                }
            }
            //过滤条件暂时删除
            //if (newEmployee.EmployeeTime >= DateTime.Now.AddMonths(-6).Date)
            try
            {
                Repository.Insert(newEmployee);
            }
            //else
            catch
            {
                return(0);
            }
            return(1);
        }
コード例 #8
0
        private string ImportToTag()
        {
            Dictionary <string, Stream>    dic  = new Dictionary <string, Stream>();
            Dictionary <string, TagImport> dics = new Dictionary <string, TagImport>();
            //获取accesstoken
            string accessToken = GetToken();
            string invalidList = string.Empty;

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase objFile = Request.Files[i];
                var f = new byte[objFile.InputStream.Length];
                //将csv文件一次性读出来
                objFile.InputStream.Read(f, 0, (int)objFile.InputStream.Length);
                //定义数据格式UTF-8
                string str = System.Text.Encoding.GetEncoding("UTF-8").GetString(f);
                //获取第一行数据然后取两列数据WeChatUserID,TagID
                string[] sArray = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                string[] rowOne = sArray[0].Split(',');
                int      TagidIndex = 0, WeChatUserIDIndex = 0;
                //循环判断返回数组对应列下标
                for (int s = 0; s < rowOne.Length; s++)
                {
                    if (string.Equals(rowOne[s], "TagID", StringComparison.OrdinalIgnoreCase))
                    {
                        TagidIndex = s;
                    }
                    else if (string.Equals(rowOne[s], "WeChatUserID", StringComparison.OrdinalIgnoreCase))
                    {
                        WeChatUserIDIndex = s;
                    }
                }

                //循环其他行去把对应下标的数据封装成TagImport对象
                for (int x = 1; x < sArray.Length; x++)
                {
                    string[]  rowX         = sArray[x].Split(',');
                    string    tagid        = rowX[TagidIndex];
                    string    WeChatUserID = rowX[WeChatUserIDIndex];
                    TagImport tagimport    = null;
                    //确认dics是否有tagid 有add,没有就新建对象
                    if (dics.ContainsKey(tagid))
                    {
                        tagimport = dics[tagid];
                        tagimport.userlist.Add(WeChatUserID);
                    }
                    else
                    {
                        tagimport          = new TagImport();
                        tagimport.tagid    = tagid;
                        tagimport.userlist = new List <string>();
                        tagimport.userlist.Add(WeChatUserID);
                        tagimport.partylist = new List <int>();
                        dics.Add(tagid, tagimport);
                    }
                }

                //返回invalidlist
                AddTagMemberResult addResult = new AddTagMemberResult();

                //先根据tagid去取当前tagid的userlist再删除掉成员
                foreach (var b in dics.Keys)
                {
                    var lstTagUser = MailListApi.GetTagMember(accessToken, int.Parse(b)).userlist;
                    if (lstTagUser == null || lstTagUser.Count <= 0)
                    {
                        break;
                    }

                    List <string> userList = new List <string>();
                    lstTagUser.ForEach(a =>
                    {
                        userList.Add(a.userid);
                    });
                    MailListApi.DelTagMember(accessToken, int.Parse(b), userList.ToArray(), null);
                }

                //封装完后循环dics,序列化后调用API的接口Post过去
                foreach (var a in dics)
                {
                    var           strs = string.Join(",", a.Value.userlist.ToArray());
                    List <string> lst  = new List <string>();
                    GetStr(strs, lst);

                    foreach (var b in lst)
                    {
                        addResult = MailListApi.AddTagMember(
                            accessToken,
                            int.Parse(a.Key),
                            b.Split(',')
                            );
                        if (!string.IsNullOrEmpty(addResult.invalidlist))
                        {
                            invalidList = invalidList + '|' + addResult.invalidlist;
                        }
                    }
                }
                dic.Add(objFile.FileName, objFile.InputStream);
            }

            return(invalidList);
        }
コード例 #9
0
        public JsonResult PostUser(GetMemberResult objModal, string Id)
        {
            //验证错误
            if (!BeforeAddOrUpdate(objModal, Id) || !ModelState.IsValid)
            {
                return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet));
            }

            int[] strs = Request["departmentAll"].Split(',').Select(a => int.Parse(a)).ToArray();

            objModal.department = strs;

            objModal.userid   = objModal.userid.Trim();
            objModal.name     = objModal.name.Trim();
            objModal.position = objModal.position != null?objModal.position.Trim() : "";

            objModal.weixinid = objModal.weixinid != null?objModal.weixinid.Trim() : "";

            objModal.mobile = objModal.mobile != null?objModal.mobile.Trim() : "";

            objModal.email     = objModal.email.Trim();
            objModal.entryDate = objModal.entryDate;

            LocalSADEntity employee = new LocalSADEntity();

            employee.ChineseName  = objModal.name;
            employee.LillyID      = objModal.userid;
            employee.ACTL_HIRE_DT = Convert.ToDateTime(objModal.entryDate);
            employee.Tag          = CommonService.GetSysConfig("TagNameNewEmployee", "[]");
            employee.Gender       = Convert.ToString(objModal.gender);
            employee.Email        = objModal.email;

            string[] userList = new string[1];
            userList[0] = objModal.userid;

            //var taglist = MailListApi.GetTagList(GetToken()).taglist.Where(x => x.tagname == employee.Tag);
            var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == employee.Tag);
            int tagid   = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0;

            try
            {
                if (!string.IsNullOrEmpty(Id) && Id != "0")
                {
                    MailListApi.UpdateMember(GetToken(), objModal);

                    employee.Id = !_localservice.Repository.Entities.Where(a => a.LillyID == objModal.userid).AsNoTracking().IsEmpty() ?
                                  _localservice.Repository.Entities.Where(a => a.LillyID == objModal.userid).AsNoTracking().First().Id : 0;

                    if (employee.Id == 0)
                    {
                        _localservice.Repository.Insert(employee);
                    }
                    else
                    {
                        List <string> columns = new List <string>();
                        columns.Add("ChineseName");
                        columns.Add("Gender");
                        columns.Add("Email");
                        columns.Add("ACTL_HIRE_DT");

                        _localservice.Repository.Update(employee, columns);
                    }
                }
                else
                {
                    objModal.to_invite = false;
                    MailListApi.CreateMember(GetToken(), objModal);

                    _localservice.Repository.Insert(employee);
                }
            }
            catch (ErrorJsonResultException ex)
            {
                if (ex.JsonResult.errcode == (ReturnCode)60102)
                {
                    return(ErrorNotification(null, "用户已存在"));
                }
            }
            //不超过6个月时,添加标签
            if (tagid != 0 && DateTime.Today <= (employee.ACTL_HIRE_DT.AddMonths(6)))
            {
                MailListApi.AddTagMember(GetToken(), tagid, userList);
            }

            //超过7个月时,移除标签
            if (tagid != 0 && DateTime.Today > (employee.ACTL_HIRE_DT.AddMonths(7)))
            {
                MailListApi.DelTagMember(GetToken(), tagid, userList);
            }

            //添加或更新后会清除掉缓存
            if (WeChatCommonService.lstUser != null)
            {
                cacheManager.Remove("UserItem");
            }

            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
コード例 #10
0
        private string ImportToTag()
        {
            var dic  = new Dictionary <string, Stream>();
            var dics = new Dictionary <string, TagImport>();
            //获取accesstoken
            string accessToken = GetToken();
            string invalidList = string.Empty;

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase objFile = Request.Files[i];
                if (objFile != null)
                {
                    var f = new byte[objFile.InputStream.Length];
                    //将csv文件一次性读出来
                    objFile.InputStream.Read(f, 0, (int)objFile.InputStream.Length);
                    //定义数据格式UTF-8
                    string str = System.Text.Encoding.GetEncoding("UTF-8").GetString(f);
                    //获取第一行数据然后取两列数据lillyID,TagID
                    string[] sArray = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    string[] rowOne = sArray[0].Split(',');
                    int      tagidIndex = 0, lillyIdIndex = 0;
                    //循环判断返回数组对应列下标
                    for (int s = 0; s < rowOne.Length; s++)
                    {
                        if (string.Equals(rowOne[s], "TagID", StringComparison.OrdinalIgnoreCase))
                        {
                            tagidIndex = s;
                        }
                        else if (string.Equals(rowOne[s], "LillyID", StringComparison.OrdinalIgnoreCase))
                        {
                            lillyIdIndex = s;
                        }
                    }

                    //循环其他行去把对应下标的数据封装成TagImport对象
                    for (int x = 1; x < sArray.Length; x++)
                    {
                        string[]  rowX      = sArray[x].Split(',');
                        string    tagid     = rowX[tagidIndex];
                        string    lillyid   = rowX[lillyIdIndex] == null ? rowX[lillyIdIndex] : rowX[lillyIdIndex].Trim();
                        TagImport tagimport = null;
                        //确认dics是否有tagid 有add,没有就新建对象
                        if (dics.ContainsKey(tagid))
                        {
                            tagimport = dics[tagid];
                            tagimport.userlist.Add(lillyid);
                        }
                        else
                        {
                            tagimport = new TagImport
                            {
                                tagid    = tagid,
                                userlist = new List <string> {
                                    lillyid
                                },
                                partylist = new List <int>()
                            };
                            dics.Add(tagid, tagimport);
                        }
                    }
                }

                //返回invalidlist
                var addResult = new AddTagMemberResult();

                //先根据tagid去取当前tagid的userlist再删除掉成员
                foreach (var b in dics.Keys)
                {
                    var lstTagUser = MailListApi.GetTagMember(accessToken, int.Parse(b)).userlist;
                    if (lstTagUser == null || lstTagUser.Count <= 0)
                    {
                        break;
                    }

                    var userList = new List <string>();
                    lstTagUser.ForEach(a => userList.Add(a.userid));
                    MailListApi.DelTagMember(accessToken, int.Parse(b), userList.ToArray());
                }

                //封装完后循环dics,序列化后调用API的接口Post过去
                foreach (var a in dics)
                {
                    var strs = string.Join(",", a.Value.userlist.ToArray());
                    var lst  = new List <string>();
                    GetStr(strs, lst);

                    foreach (var b in lst)
                    {
                        try
                        {
                            addResult = MailListApi.AddTagMember(
                                accessToken,
                                int.Parse(a.Key),
                                b.Split(',')
                                );
                        }
                        catch (ErrorJsonResultException e)
                        {
                            //WeChatCommonService.lstUser.
                            var invalidUsers = b.Split(',').Distinct().Where(x => WeChatCommonService.lstUser.All(y => y.userid != x)).ToList();
                            invalidUsers.Add(invalidList);
                            invalidList = string.Join("|", invalidUsers);
                        }

                        if (!string.IsNullOrEmpty(addResult.invalidlist))
                        {
                            invalidList = invalidList + '|' + addResult.invalidlist;
                        }
                    }
                }
                if (objFile != null)
                {
                    dic.Add(objFile.FileName, objFile.InputStream);
                }
            }

            if (invalidList.StartsWith("|"))
            {
                invalidList.Remove(0, 1);
            }
            if (invalidList.EndsWith("|"))
            {
                invalidList.Remove(invalidList.Length - 1, 1);
            }
            return(invalidList);
        }