Exemplo n.º 1
0
        /// <summary>
        /// 部门更新
        /// </summary>
        /// <returns></returns>
        public static OapiDepartmentUpdateResponse UpdateDep(OapiDepartmentUpdateRequest deptinfo)
        {
            DefaultDingTalkClient        client   = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/update");
            OapiDepartmentUpdateResponse response = client.Execute(deptinfo, AccessToken);

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="id">部门id</param>
        /// <param name="lang">通讯录语言(默认zh_CN另外支持en_US)</param>
        /// <param name="name">部门名称,长度限制为1~64个字符,不允许包含字符‘-’‘,’以及‘,’</param>
        /// <param name="parentId">父部门id,根部门id为1</param>
        /// <param name="order">在父部门中的排序值,order值小的排序靠前</param>
        /// <param name="createDeptGroup">是否创建一个关联此部门的企业群</param>
        /// <param name="groupContainSubDept">部门群是否包含子部门</param>
        /// <param name="groupContainOuterDept">部门群是否包含外包部门</param>
        /// <param name="groupContainHiddenDept">部门群是否包含隐藏部门</param>
        /// <param name="autoAddUser">如果有新人加入部门是否会自动加入部门群</param>
        /// <param name="deptManagerUseridList">部门的主管列表,取值为由主管的userid组成的字符串,不同的userid使用“|”符号进行分割</param>
        /// <param name="deptHiding">是否隐藏部门, true表示隐藏 false表示显示</param>
        /// <param name="deptPermits">可以查看指定隐藏部门的其他部门列表,如果部门隐藏,则此值生效,取值为其他的部门id组成的的字符串,使用“|”符号进行分割。总数不能超过200</param>
        /// <param name="userPermits">可以查看指定隐藏部门的其他人员列表,如果部门隐藏,则此值生效,取值为其他的人员userid组成的字符串,使用“|”符号进行分割。总数不能超过200</param>
        /// <param name="outerDept">是否本部门的员工仅可见员工自己, 为true时,本部门员工默认只能看到员工自己</param>
        /// <param name="outerPermitDepts">本部门的员工仅可见员工自己为true时,可以配置额外可见部门,值为部门id组成的的字符串,使用|符号进行分割。总数不能超过200</param>
        /// <param name="outerPermitUsers">本部门的员工仅可见员工自己为true时,可以配置额外可见人员,值为userid组成的的字符串,使用|符号进行分割。总数不能超过200</param>
        /// <param name="outerDeptOnlySelf">outerDept为true时,可以配置该字段,为true时,表示只能看到所在部门及下级部门通讯录</param>
        /// <param name="orgDeptOwner">企业群群主</param>
        /// <param name="sourceIdentifier">部门标识字段,开发者可用该字段来唯一标识一个部门,并与钉钉外部通讯录里的部门做映射</param>
        /// <returns></returns>
        public OapiDepartmentUpdateResponse Update(string accessToken, long id, string lang = "zh_CN", string name = "", string parentId = "", string order = "", bool createDeptGroup = false, bool groupContainSubDept = false, bool groupContainOuterDept = false, bool groupContainHiddenDept = false, bool autoAddUser = false, string deptManagerUseridList = "", bool deptHiding = false, string deptPermits = "", string userPermits = "", bool outerDept = false, string outerPermitDepts = "", string outerPermitUsers = "", bool outerDeptOnlySelf = false, string orgDeptOwner = "", string sourceIdentifier = "")
        {
            IDingTalkClient             client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/update");
            OapiDepartmentUpdateRequest request = new OapiDepartmentUpdateRequest();

            request.Id                     = id;
            request.Lang                   = lang;
            request.Name                   = name;
            request.Parentid               = parentId;
            request.Order                  = order;
            request.CreateDeptGroup        = createDeptGroup;
            request.GroupContainSubDept    = groupContainSubDept;
            request.GroupContainOuterDept  = groupContainOuterDept;
            request.GroupContainHiddenDept = groupContainHiddenDept;
            request.AutoAddUser            = autoAddUser;
            request.DeptManagerUseridList  = deptManagerUseridList;
            request.DeptHiding             = deptHiding;
            request.DeptPermits            = deptPermits;
            request.UserPermits            = userPermits;
            request.OuterDept              = outerDept;
            request.OuterPermitDepts       = outerPermitDepts;
            request.OuterPermitUsers       = outerPermitUsers;
            request.OuterDeptOnlySelf      = outerDeptOnlySelf;
            request.OrgDeptOwner           = orgDeptOwner;
            request.SourceIdentifier       = sourceIdentifier;
            OapiDepartmentUpdateResponse response = client.Execute(request, accessToken);

            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="department">部门信息</param>
        /// <returns></returns>
        public static bool UpdateDepartment(string accessToken, DepartmentInfo department)
        {
            try
            {
                IDingTalkClient             client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/update");
                OapiDepartmentUpdateRequest request = new OapiDepartmentUpdateRequest();
                request.Parentid         = department.Parentid;
                request.CreateDeptGroup  = department.CreateDeptGroup;
                request.Order            = department.Order;
                request.Name             = department.Name;
                request.OuterDept        = department.OuterDept;
                request.OuterPermitDepts = department.OuterPermitDepts;
                request.OuterPermitUsers = department.OuterPermitUsers;
                OapiDepartmentUpdateResponse response = client.Execute(request, accessToken);

                if (response != null)
                {
                    if (response.Errcode == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        throw new Exception(response.ErrMsg);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(false);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 执行创建和更新部门
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="deptlist"></param>
 public static void CreateUpdateDep(DataTable dt, List <OapiDepartmentListResponse.DepartmentDomain> deptlist)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         long   DDID       = Convert.ToInt32(dt.Rows[i]["DDID"]);        //部门ID
         string Parentid   = Convert.ToString(dt.Rows[i]["ParentOUID"]); //父级部门ID
         string Name       = Convert.ToString(dt.Rows[i]["OUName"]);     //部门名称
         string Order      = Convert.ToString(dt.Rows[i]["OrderIndex"]); //排序
         int    OUID       = Convert.ToInt32(dt.Rows[i]["OUID"]);        //部门ID
         string ddParentid = GETParentID(Parentid);
         if (deptlist != null)
         {
             List <OapiDepartmentListResponse.DepartmentDomain> newlist = deptlist.Where(x => x.Id == DDID).ToList();
             if (newlist != null)//存在执行更新
             {
                 OapiDepartmentUpdateRequest DeptInfo = new OapiDepartmentUpdateRequest();
                 DeptInfo.Id       = DDID;
                 DeptInfo.Parentid = ddParentid;
                 DeptInfo.Name     = Name;
                 DeptInfo.Order    = Order;
                 OapiDepartmentUpdateResponse response = UpdateDep(DeptInfo);
                 if (response.Errcode == 0)
                 {
                     Res("执行更新部门成功:部门名称->" + Name + ",部门ID->" + OUID + "");
                 }
                 else
                 {
                     Res("执行更新部门失败:部门名称->" + Name + ",部门ID->" + OUID + ",原因:" + response.Errmsg + "");
                 }
             }
         }
         else//不存在执行创建
         {
             OapiDepartmentCreateRequest DeptInfo = new OapiDepartmentCreateRequest();
             DeptInfo.Parentid = ddParentid;
             DeptInfo.Name     = Name;
             DeptInfo.Order    = Order;
             OapiDepartmentCreateResponse response = CreateDep(DeptInfo);
             if (response.Errcode == 0)
             {
                 Res("执行创建部门成功:部门名称->" + Name + ",部门ID->" + OUID + "");
                 BPM2DD(OUID, response.Id);
             }
             else
             {
                 Res("执行创建部门失败:部门名称->" + Name + ",部门ID->" + OUID + ",原因:" + response.Errmsg + "");
             }
         }
     }
 }