Esempio n. 1
0
 def create_api(self, url, **kwargs):
     """
     构造接口的函数
     :param url:
     :param kwargs:
     :return:
     """
     kwargs = {
         key: value
         for key, value in kwargs.items() if value is not None
     }
     data = str(kwargs).replace('\'', '\"')
     # 如果接口地址包含fw则为中台接口,token使用中台token
     req_body = body(data,
                     guid=self.Guid,
                     token=self.access_token,
                     app_key=app_key)
     if '/fw/' in url:
         req_body = body(data,
                         app_id=self.zt_tid,
                         guid=self.zt_guid,
                         token=self.zt_token,
                         app_key=app_key)
     api_name = url.split("/")[-1]
     logger.info(f'接口{api_name}请求body:{req_body}')
     result = requests.post(url=url, json=req_body, verify=False)
     if result.json()['Code'] in [50001]:
         logger.error(f'接口{api_name} 返回参数:{result.json()}')
     else:
         logger.info(f'接口{api_name} 返回参数:{result.json()}')
     return result
Esempio n. 2
0
    def get_source(self, url, FromSpName=None):
        """
        # 获取派遣端录名单时需要的来源
        :param FromSpName: 来源,可选,默认为空
        :return:
        """
        # 获取谁送给我
        res = self.create_api(url)
        res = res.json()
        # 来源不为空,获取来源列表
        agentlist = res['Data']['RecordList']
        # 遍历列表寻找指定名称的id
        for agent in agentlist:
            # 找到id后赋值给FromSpID
            if FromSpName == agent['SpShortName']:
                self.FromSpID = agent['SpId']
                break

        # 打印日志
        if self.FromSpID:
            logger.info(f'获取到来源:{self.FromSpID},{FromSpName}')
        else:
            logger.error(f'没有来源{FromSpName},请检查')
            raise
        return res
Esempio n. 3
0
 def get_labor(self, url, LaborName=None):
     """
     # 获取招聘、派遣端录名单时需要的去向
     :param url: 调用获取去向劳务的接口地址,必填
     :param LaborName: 去向劳务,可选,默认为空
     :return:
     """
     res = self.create_api(url).json()
     if url == get_labor:
         self.TargetSpId = int(get_api_result(res, 'SpId')[0])
         self.SpName = get_api_result(res, 'SpShortName')[0]
     else:
         # 企业不为空,获取企业列表
         laborlist = res['Data']['RecordList']
         # 遍历列表寻找指定名称的id,找到id后赋值给SpEntID,没找到传入的名称抛出异常
         for labor in laborlist:
             if labor['SpShortName'] == LaborName:
                 self.TargetSpId = labor['SpId']
                 self.SpName = LaborName
                 break
     # 打印日志
     if self.TargetSpId:
         logger.info(f'获取到去向:{self.SpName},{self.TargetSpId}')
     else:
         logger.error(f'未找到去向:{LaborName}')
         raise
     return res
Esempio n. 4
0
def djy_get_vcode(phonenum, app_id, app_key):
    """
    大佳营模板获取验证码
    :param phonenum:
    :param url:
    :return: vcode
    """
    data = databuild(SPhone=phonenum)
    Body = body(data=data, guid=0, app_id=app_id, app_key=app_key)
    response = requests.post(url=get_vcode_api, json=Body)
    try:
        vcode = response.json()['Data']
        logger.info(f'获取到验证码:{vcode}')
        return vcode
    except Exception:
        logger.error(f'未获取到验证码,请定位,{response.json}')
Esempio n. 5
0
def labor_pre_login(phonenum, vcode, app_key):
    """
    大佳营模板预登陆接口
    :param phonenum:
    :param vcode:
    :param url:
    :return: tenanttype
    """
    data = databuild(Mobile=phonenum, VerifyCode=vcode)
    Body = body(data=data, guid=0, app_id='1000001', app_key=app_key)
    response = requests.post(url=labor_pre_login_api, json=Body)
    try:
        tenanttype = response.json()['Data']['TenantType']
        logger.info(f'预登陆成功,tenanttype为{tenanttype}')
        return tenanttype
    except Exception:
        logger.error(f'预登陆失败,请定位,{response.json}')
Esempio n. 6
0
 def get_entbrorrow(self, entbrorrowname=''):
     """
     # 获取招聘、派遣端创建时需要的企业
     :param entbrorrowname: 企业名称,可选,默认为空
     :return:
     """
     res = self.create_api(get_entborrow).json()
     entbrorrows = res['Data']['RecordList']
     # 遍历列表寻找指定名称的id,找到id后赋值给SpEntID,没找到传入的名称抛出异常
     for entbrorrow in entbrorrows:
         if entbrorrowname == entbrorrow['EntBorrowName']:
             self.entbrorrowid = entbrorrow['EntBorrowId']
             self.entbrorrowname = entbrorrowname
             break
     if self.entbrorrowid:
         logger.info(f'获取企业:{self.entbrorrowname},{self.entbrorrowid}')
     else:
         logger.error(f'没有找到企业{entbrorrowname}')
         raise
Esempio n. 7
0
 def get_entbrorrow(self, entbrorrowname=None):
     """
     # 获取招聘、派遣端录名单时需要的企业
     :param entbrorrowname: 企业名称,可选,默认为空
     :return:
     """
     res = self.create_api(get_entborrow).json()
     entbrorrows = res['Data']['RecordList']
     # 遍历列表寻找指定名称的id,找到id后赋值给SpEntID,没找到传入的名称抛出异常
     for entbrorrow in entbrorrows:
         if entbrorrowname == entbrorrow['EntBorrowName']:
             self.entbrorrowid = entbrorrow['EntBorrowId']
             break
     # 打印日志
     if self.entbrorrowid:
         logger.info(f'获取到工种:{self.entbrorrowid},{entbrorrowname}')
     else:
         logger.error(f'未找到企业{entbrorrowname},请检查')
         raise
     return res
Esempio n. 8
0
 def get_agent(self, agentname, orderid=None):
     """
     获取派遣端订单分配的供应商列表
     :param agentname:
     :param orderid:
     :return:
     """
     res = self.create_api(GetZXXOrderReceiveCoop, OrderId=orderid)
     tags = res.json()['Data']['RecordList']
     for tag in tags:
         agents = tag['CoopList']
         for agent in agents:
             if agentname == agent['CoopName']:
                 self.CoopId = agent['CoopId']
                 self.ZtVSpId = agent['ZtVSpId']
                 break
     if self.ZtVSpId:
         logger.info(f'获取到合作商:{agentname},{self.ZtVSpId}')
     else:
         logger.error(f'合作商{agentname}不存在')
Esempio n. 9
0
 def get_labor(self, LaborName=''):
     """
     # 获取招聘、派遣端创建订单时需要的去向
     :param url: 调用获取去向劳务的接口地址,必填
     :param LaborName: 去向劳务,可选,默认为空
     :return:
     """
     api_result = self.create_api(get_vlabor)
     labors = api_result.json()['Data']['RecordList']
     # 遍历列表寻找指定名称的id,找到id后赋值给TargetSpId,没找到传入的名称抛出异常
     for labor in labors:
         if LaborName in labor['SpShortName']:
             self.TargetSpId = labor['SpId']
             self.SpName = LaborName
             break
     # 打印日志
     if self.entbrorrowid:
         logger.info(f'获取到去向:{self.SpName},{self.TargetSpId}')
     else:
         logger.error(f'未找到去向{LaborName}')
         raise
Esempio n. 10
0
def labor_weblogin(phonenum, app_key):
    """
    劳务模板登陆接口
    :param phonenum:
    :return: Data
    """
    vcode = djy_get_vcode(phonenum=phonenum, app_id='1000001', app_key=app_key)
    tenanttype = labor_pre_login(phonenum=phonenum,
                                 vcode=vcode,
                                 app_key=app_key)
    data = databuild(Mobile=phonenum, VerifyCode=vcode, tenanttype=tenanttype)
    Body = body(data=data, guid=0, app_id='1000001', app_key=app_key)
    response = requests.post(url=labor_weblogin_api, json=Body)
    try:
        Data = response.json()['Data']
        # access_token = Data['access_token']
        # zt_tid = Data['zt_tid']
        # Guid = str(Data['Guid'])
        # zt_access_token = Data['zt_access_token']
        # zt_guid = str(Data['zt_guid'])
        # set_ = Set_Section(section_name=phonenum,filename='login_info')
        # isexit = set_.is_exit()
        # if isexit:
        #     # print('jinruhun')
        #     set_.edit_section('access_token',access_token)
        #     set_.edit_section('zt_tid',zt_tid)
        #     set_.edit_section('Guid', Guid)
        #     set_.edit_section('zt_access_token', zt_access_token)
        #     set_.edit_section('zt_guid', zt_guid)
        # else:
        #     set_.add_section('access_token',access_token)
        #     set_.edit_section('zt_tid', zt_tid)
        #     set_.edit_section('Guid',Guid)
        #     set_.edit_section('zt_access_token', zt_access_token)
        #     set_.edit_section('zt_guid', zt_guid)
        logger.info(f'登陆成功,Data{Data}')
        return Data
    except Exception:
        logger.error(f'登陆失败,请定位,{response.json()}')
Esempio n. 11
0
 def get_ent(self, entname, CoopSts=1):
     """
     获取标准企业
     :param entname: 标准企业名称,必填
     :param CoopSts: 合作状态,0 全部,1 合作中,2 不合作
     :return:
     """
     res = self.create_api(GetPaySalaryEntList_Api,
                           CoopSts=CoopSts,
                           RecordIndex=0,
                           RecordSize=9999).json()
     ents = res['Data']['RecordList']
     for ent in ents:
         if entname == ent['EntShortName']:
             self.entid_pq = ent['EntId']
             break
     if self.entid_pq:
         logger.info(f'获取到标准企业:{entname},{self.entid_pq}')
     else:
         logger.error(f'标准企业{entname}不存在')
         raise
     return res
Esempio n. 12
0
    def add_name_pq(self,
                    entname=None,
                    entbrorrowname=None,
                    mobile=None,
                    idnum=None,
                    name=None,
                    gender=1,
                    InterviewDate=nowtime,
                    FromSpName=None):
        """
        派遣端录名单
        :param entbrorrowname: 企业,必填
        :param InterviewDate: 面试日期,可选,默认当天日期
        :param FromSpName: 来源,可选,默认为空
        :return: namelistid(名单中台id), name(名单姓名), IDCardNum(身份证号)
        """
        # 打印日志
        logger.info(f'开始录名单')
        # 加载标准企业
        if entname:
            self.get_ent(entname)
        # 加载企业
        if entbrorrowname:
            self.get_entbrorrow(entbrorrowname)
        # 加载来源
        if FromSpName:
            self.get_source(get_vagent, FromSpName)
        # 加载劳务
        self.get_labor(get_labor)
        # 生成姓名、身份证、手机号,如果未指定姓名、身份证、手机号,则系统自动生成
        if not name:
            name = self.newname_pq = create_name()
            logger.info(f'name{name}')
        if not idnum:
            idnum = self.newidnum_pq = gennerator()
        if not mobile:
            mobile = self.newmobile_pq = create_phone()
        # 录入名单

        res = self.create_api(add_name,
                              InterviewDate=InterviewDate,
                              Name=name,
                              Gender=gender,
                              IDCardNum=idnum,
                              EntId=self.entid_pq,
                              Mobile=mobile,
                              Nation='汉',
                              IDCardExprDate='2030-02-11',
                              Addr='测试地址',
                              SpEntID=self.entbrorrowid,
                              InterviewStatus=0,
                              Remark='测试',
                              FromSpID=self.FromSpID,
                              FromSpName=FromSpName,
                              TargetSpId=self.TargetSpId,
                              SpName=self.SpName,
                              InputType=2)
        # 获取接口返回值
        self.status_code = res.status_code
        self.code = res.json()['Code']
        self.desc = res.json()['Desc']
        self.res_guid = res.json()['Data']['Guid']
        self.newnameid_pq = res.json()['Data']['NameListId']
        self.res_rcrttype = res.json()['Data']['RcrtTyp']
        self.res_uuid = res.json()['Data']['Uuid']
        res = res.json()

        if res['Desc'] != '成功':
            logger.error(f'录入名单失败,{res}')
        return res