# -*- encoding=utf8 -*-
from common.fileUtls import FileUtils

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,a1供货关系申请_客户类型_医院_登录_医院登录获取医院id,id2255,id2255-1,sit,on
主数据平台:a1供货关系申请_客户类型_医院_登录_医院登录获取医院id 
"""

from common.common_func import commonFuc
from air_case.mdm_login.登录外网系统.登录外网系统 import login_system
from airtest.core.api import using
import sys
#type=1是默认，医院是之前注册的医院
def h_login(type=1):
    module = "a4_mdm3_cm"
    # pro_path=commonFuc().get_pro_path()
    # sys.path.append(pro_path+r'\\air_case\\mdm3_hs\\注册医院审核通过.air')
    # using(pro_path+r'\\air_case\\mdm3_hs\\注册医院审核通过.air')
    # from 注册医院审核通过 import reg_and_audit_hospital
    # h_name=reg_and_audit_hospital()

    info = FileUtils().r_info("a3_mdm3_hs", "医院信息")
    print(info,'aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbccccccccccccccc')
    h_name = info['h_name']
    print(h_name)
    """
     场景:a1供货关系申请_客户类型_医院_登录_医院登录获取医院id
     用例名称：a1供货关系申请_客户类型_医院_登录_医院登录获取医院id
     输入：用户名,密码
     输出："rtn_msg": token,projectCode,uxid,corpId,h_name
    """
    #供货关系申请_客户类型_医院_登录_医院登录获取医院id
    module = "a4_mdm3_cm"
    #如果需要h0347医院账号登录,这里就从data文件获取登录医院的用户名
    #username = commonFuc().get_business_data(module, "username")
    if type==1:
        username = h_name
        password = commonFuc().get_business_data(module, "password")
        print('医院名称',username)
    else:
        username =  commonFuc().get_business_data(module, "username")
        password = commonFuc().get_business_data(module, "password1")
        print('医院名称', username)
    print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    import time
    while True:
        try:
            token,projectCode,uxid,corpId,info= login_system(username, password).get_token()
        except:
            time.sleep(6)
            continue
        else:
            return token,projectCode,uxid,corpId,h_name

h_login(1)