Ejemplo n.º 1
0
        public WorkJsonResult UpdateDepartment(UpdateDepartmentDto dto)
        {
            //dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.UpdateDepartment(dto.AccessToken, dto.ID, dto.Name, dto.ParentId, dto.Order);

            return(result);
        }
Ejemplo n.º 2
0
        public JsonResult PostDept(DepartmentList objModal, int?Id)
        {
            //验证错误
            if (!BeforeAddOrUpdate(objModal, Id))
            {
                return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet));
            }

            //objModal.id = int.Parse(Request["deptid"]);
            try
            {
                if (Id.HasValue && Id.Value > 0)
                {
                    MailListApi.UpdateDepartment(GetToken(), objModal);
                }
                else
                {
                    MailListApi.CreateDepartment(GetToken(), objModal);
                }
            }
            catch (ErrorJsonResultException ex)
            {
                WxJsonResult jsResult = ex.JsonResult;
                string       errorMsg = ((ReturnCode_QY)jsResult.errcode).ToString();
                return(ErrorNotification(errorMsg));
            }

            _cacheManager.Remove("DepartmentList");

            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 更新部门信息到微信与数据库
 /// </summary>
 /// <param name="UserID">操作者ID</param>
 /// <param name="errMsg">返回信息</param>
 /// <returns>操作是否成功</returns>
 public bool UpdateDepartment(string UserID, ref string errMsg)
 {
     try
     {
         QYConfig.RegistWX();
         var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId);
         var result      = MailListApi.UpdateDepartment(accessToken, DepartmentID, Name, int.Parse(ParentDepartmentID));
         if (result.errcode.ToString() == "请求成功")
         {
             if (DepartmentDA.UpdateDepartmentByPkID(ID.ToString(), ParentDepartmentID, Name, wcOrder, UserID))
             {
                 return(true);
             }
             else
             {
                 errMsg = "数据库修改部门失败";
                 return(false);
             }
         }
         else
         {
             Logger.Log4Net.Error(result.errcode + ":" + result.errmsg);
             errMsg = result.errcode + ":" + result.errmsg;
         }
     }
     catch (Exception e)
     {
         Logger.Log4Net.Error("Delete department error:" + e);
         errMsg = "操作失敗:" + e.Message;
         return(false);
     }
     return(false);
 }
Ejemplo n.º 4
0
        //[TestMethod]
        public void UpdateDepartmentTest(long id)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.UpdateDepartment(accessToken, id, "更新test", 1);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
        private int GetTargetDepartmentId(int accountManageId, string groupName, int groupId, List <DepartmentList> departments, int parentId)
        {
            int targetId = 0;

            //groupName = (groupId - 10000)+ "_" + groupName;
            if (groupName.Length > 32)
            {
                groupName = groupName.Substring(0, 32);
            }
            //var groupDepartment = departments.Find(d => d.name.Trim().Equals(groupName, StringComparison.CurrentCultureIgnoreCase));
            var groupDepartment         = departments.Find(d => d.id == groupId);
            var groupDepartmentSameName = departments.Find(d => d.name.Trim().Equals(groupName, StringComparison.CurrentCultureIgnoreCase) && d.parentid == parentId);

            if (groupDepartment == null)
            {
                if (groupDepartmentSameName != null)
                {
                    targetId = groupDepartmentSameName.id;
                }
                else
                {
                    var ret = MailListApi.CreateDepartment(GetToken(accountManageId), groupName, parentId, 1, groupId);
                    if (ret.errcode == Weixin.ReturnCode_QY.请求成功)
                    {
                        targetId = ret.id;
                        departments.Add(new DepartmentList()
                        {
                            id = ret.id, name = groupName, parentid = parentId, level = 0, order = 1
                        });
                    }
                }
            }
            else
            {
                targetId = groupDepartment.id;
                if (!groupDepartment.name.Equals(groupName, StringComparison.CurrentCultureIgnoreCase) ||
                    groupDepartment.parentid != parentId)
                {
                    var ret = MailListApi.UpdateDepartment(GetToken(accountManageId), groupId.ToString(), groupName, parentId);
                    if (ret.errcode == Weixin.ReturnCode_QY.请求成功)
                    {
                        groupDepartment.name     = groupName;
                        groupDepartment.parentid = parentId;
                    }
                }
            }
            return(targetId);
        }
Ejemplo n.º 6
0
        public WorkJsonResult WX_UpdateBranch(JH_Auth_Branch Model)
        {
            WorkJsonResult Ret = new WorkJsonResult();

            if (Qyinfo.IsUseWX == "Y")
            {
                int pid = 0;
                var bm  = new JH_Auth_BranchB().GetEntity(p => p.DeptCode == Model.DeptRoot && p.ComId == Model.ComId);
                if (bm != null)
                {
                    pid = Int32.Parse(bm.WXBMCode.ToString());
                }
                Ret = MailListApi.UpdateDepartment(GetToken(), long.Parse(Model.WXBMCode.ToString()), Model.DeptName, pid, Model.DeptShort);
            }
            return(Ret);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新部门信息
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="_name"></param>
        /// <param name="_parentid"></param>
        /// <param name="_order"></param>
        /// <returns></returns>
        public static bool UpdateDepartment(int _id, string _name, int _parentid, int _order)
        {
            AccessTokenResult access_token_result = new AccessTokenResult();
            QYConfigInfo      config = GetQYConfig();

            access_token_result = CommonApi.GetToken(config.QYCorpId, config.QYSecret);
            //调用接口
            var result = MailListApi.UpdateDepartment(access_token_result.access_token, _id.ToString(), _name, _parentid, _order);

            if (result.errmsg == "updated")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
Archivo: WxFO.cs Proyecto: Luyingjin/Qy
        /// <summary>
        /// 更新组织
        /// </summary>
        /// <param name="QyID">企业ID</param>
        /// <param name="id">部门id</param>
        /// <param name="name">更新的部门名称。长度限制为0~64个字符。修改部门名称时指定该参数</param>
        /// <param name="parentId">父亲部门id。根部门id为1 </param>
        /// <param name="order">在父部门中的次序。从1开始,数字越大排序越靠后</param>
        /// <returns></returns>
        public QyJsonResult UpdateDepartment(string QyID, string id, string name, int parentId, int order = 1)
        {
            QyJsonResult result = null;

            try
            {
                result = MailListApi.UpdateDepartment(GetAccessToken(QyID), id, name, parentId, order);
            }
            catch (Exception ex)
            {
                LogWriter.Error(ex, string.Format("更新QyID为{0}的部门失败", QyID));
                result = MailListApi.UpdateDepartment(GetAccessToken(QyID, true), id, name, parentId, order);
            }
            if (result.errcode != ReturnCode_QY.请求成功)
            {
                LogWriter.Info(string.Format("更新QyID为{0}的部门失败,原因:{1}", QyID, result.errmsg));
            }
            return(result);
        }
Ejemplo n.º 9
0
        public ActionResult UploadUser()
        {
            try
            {
                //同步部门
                GetDepartmentListResult result = MailListApi.GetDepartmentList(WeixinWorkService.GetToken());
                var departments = dbContext.SysDepartment.OrderByDescending(c => c.DepartmentName).ToList();
                foreach (var item in departments)
                {
                    if (item.DepartmentId == Guid.Parse("2379788E-45F0-417B-A103-0B6440A9D55D"))
                    {
                        continue;
                    }

                    var            parentId = Convert.ToInt64(departments.Where(c => c.DepartmentId == item.ParentId).FirstOrDefault().WeixinWorkId);
                    DepartmentList qyDep    = result.department.Where(c => c.id == item.WeixinWorkId).FirstOrDefault();
                    if (qyDep == null)
                    {
                        var createResult = MailListApi.CreateDepartment(WeixinWorkService.GetToken(), item.DepartmentName, parentId == 0 ? 1 : parentId, 1000 - (item.OrderNo.HasValue ? item.OrderNo.Value : 0));
                        item.WeixinWorkId = createResult.id;
                    }
                    else
                    {
                        MailListApi.UpdateDepartment(WeixinWorkService.GetToken(), qyDep.id, item.DepartmentName, parentId == 0 ? 1 : parentId, 1000 - (item.OrderNo.HasValue ? item.OrderNo.Value : 0));
                    }
                    dbContext.SaveChanges();
                }
                //同步用户
                var users = dbContext.SysUser.Where(c => c.UserCode != "admin").ToList();
                foreach (var userItem in users)
                {
                    long[] longArr = new long[1];
                    longArr[0] = Convert.ToInt64(dbContext.SysDepartment.Where(c => c.DepartmentId == userItem.DepartmentId).FirstOrDefault().WeixinWorkId);
                    try
                    {
                        var memberResult = MailListApi.GetMember(WeixinWorkService.GetToken(), userItem.UserCode);
                        if (memberResult.errcode == Senparc.Weixin.ReturnCode_Work.UserID不存在)
                        {
                            MemberCreateRequest request = new MemberCreateRequest();
                            request.email      = userItem.Email;
                            request.department = longArr;
                            request.enable     = 1;
                            request.mobile     = userItem.Mobile;
                            request.name       = userItem.UserName;
                            request.userid     = userItem.UserCode;
                            MailListApi.CreateMember(WeixinWorkService.GetToken(), request);
                        }
                        else
                        {
                            MemberUpdateRequest updateRequest = new MemberUpdateRequest();
                            updateRequest.department = longArr;
                            updateRequest.email      = userItem.Email;
                            updateRequest.enable     = 1;
                            updateRequest.mobile     = userItem.Mobile;
                            updateRequest.name       = userItem.UserName;
                            updateRequest.userid     = userItem.UserCode;
                            MailListApi.UpdateMember(WeixinWorkService.GetToken(), updateRequest);
                        }
                    }
                    catch { }
                }
                return(Json(new { Code = 0, Msg = "同步成功!" }));
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog(ex);
                return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" }));
            }
        }
Ejemplo n.º 10
0
        public WorkJsonResult Update(long id, string name, long parentId, int order)
        {
            var result = MailListApi.UpdateDepartment(APP_KEY, id, name, parentId, order);

            return(result);
        }
Ejemplo n.º 11
0
 public QyCallResult UpdateDepartment(string accessToken, Department department)
 {
     return(MailListApi.UpdateDepartment(accessToken, department.Id.ToString(), department.Name, department.ParentId, department.Order).ToQyCallResult());
 }
Ejemplo n.º 12
0
        public static bool UpdateWxDepartment(int departmentId, string departmentName, int parentDepartmentId, int order)
        {
            var result = MailListApi.UpdateDepartment(GetToken(), departmentId.ToString(), departmentName, parentDepartmentId, order);

            return(result.errcode == ReturnCode_QY.请求成功);
        }