public_org.py 1.54 KB

from atdd.PcPost import PcPost
import random

class PulbicOrg(PcPost):
    url_ListChildren = "/Contact/Apicp/Department/ListChildren"

    # 获取顶级部门的ID
    def get_top_org(self):
        url = "/Contact/Apicp/Department/List"
        data = {
            "_identifier": 'contact',
            "limit": 99999
        }
        result = self.PcPost(url,data)
        top_dpId = result['result']['list'][0]['dpId']
        return top_dpId

    # 查找某一个部门以及其子部门的dpId,以list格式返回
    def get_all_dpId(self,dpParentId):
        data = {
            "dpParentId":dpParentId
        }
        result = self.PcPost(self.url_ListChildren,data)
        orglist = result['result']['list']     # 组织列表的list信息
        dpIdList = []
        for i in range(len(orglist)):
            dpId = orglist[i]['dpId'].split()
            # 将dpId加入到dpIdList中
            dpIdList[len(dpIdList):len(dpIdList)] = dpId
        return dpIdList

    # 获取组织下的人员总数
    def get_org_user_total(self,dpParentId):
        data = {
            "dpParentId": dpParentId
        }
        result = self.PcPost(self.url_ListChildren,data)
        user_total = result['result']['list'][0]['user_total']
        return user_total

    # 随机取一个部门,返回部门ID
    def get_random_dptId(self):
        top_Id = self.get_top_org()
        dpId_all = self.get_all_dpId(top_Id)  # 所有部门的dpId
        x = random.randint(0, len(dpId_all) - 1)  # 在所有部门中随机取一个部门
        return dpId_all[x]