import sys

from airtest.core.helper import using

from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from common.common_func import commonFuc
from common.db.sql.sql_del_branch_info import delData
from common.db.sql.sql_tools import get_id, process_tuple
from common.fileUtls import FileUtils
import json
import time
from common.timeUtils import timeUtils

# 添加[]
from common.timeUtils import timeUtils


def get_process_list(request_body):
    request_body = "[" + str(request_body) + "]"
    print('request_body', request_body)
    new_request_body = request_body.replace("'", '"')
    new_request_body1 = new_request_body.replace("\\", '\\\\')
    new_request_body2 = new_request_body1.replace("None", 'null')
    print(new_request_body2)
    request_body_json = json.loads(new_request_body2, encoding='utf-8')
    return request_body_json


def compare_text_index(text1, text2):

    import difflib, re
    # 创建SequenceMatcher对象
    matcher = difflib.SequenceMatcher(a=text1, b=text2)
    # 获取差异报告
    diff_report = matcher.get_opcodes()
    # 检查差异报告中是否存在关键词错误
    for tag, i1, i2, j1, j2 in diff_report:
        if tag == 'replace':
            print("{0} with {1}".format(text1[i1:i2], text2[j1:j2]))
        elif tag == 'delete':
            # 检查删除操作中是否包含关键词
            print("{0} with {1}".format(text1[i1:i2], text2[j1:j2]))
        elif tag == 'insert':
            # 检查插入操作中是否包含关键词
            print("{0} with {1}".format(text1[i1:i2], text2[j1:j2]))

    return None


def get_process_list2(request_body):
    request_body = str(request_body)
    print('request_body', request_body)
    new_request_body = request_body.replace("'", '"')
    new_request_body1 = new_request_body.replace("\\", '\\\\')
    new_request_body2 = new_request_body1.replace("None", 'null')
    new_request_body3= new_request_body2.replace("[", '')
    new_request_body4 = new_request_body3.replace("]", '')
    print('new_request_body4',new_request_body4)
    try:
        new_request_body4=json.dumps(new_request_body4)#格式化
        request_body_json = json.loads(new_request_body4)
    except json.decoder.JSONDecodeError:
        print("JSONDecodeError: No valid JSON object could be decoded from the string.")
    else:
        return request_body_json



def get_branch_id():
    return FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]


def get_hosid():
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    return hosId


def approval_center(OBH_ID='OBhxxxxxxxxxxxxxxx'):
    module = "b2_herp3_bs"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "apprCenter_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_6_1_2", OBH_ID)
    print(request_body)
    # # # 发送请求

    result = commonFuc().http_post(url, request_body, headers)

    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', data)
    if total == 0:
        request_body = commonFuc().get_business_data(module, "payload50_6")
    result = commonFuc().http_post(url, request_body, headers)

    # 断言
    # checkDict=commonFuc().get_business_data(module,'checkDict10')
    # commonFuc().check_result(checkDict,result)
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', result)
    data1 = commonFuc().analysis_json('data', data)

    commonFuc().check_text_exist(0, result)
    taskId = commonFuc().analysis_json('taskId', data1[0])

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "approvalBatch_url")

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_7", taskId)
    print(request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    # checkDict=commonFuc().get_business_data(module,'checkDict10')
    # commonFuc().check_result(checkDict,result)
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', result)
    if code >= 0:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)

def approval_center_all(OBH_ID='OBhxxxxxxxxxxxxxxx'):
    module = "b2_herp3_bs"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "apprCenter_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_6")
    print(request_body)
    # # # 发送请求

    result = commonFuc().http_post(url, request_body, headers)

    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', data)
    data1= commonFuc().analysis_json('data', data)
    for i in data1:
        # code = commonFuc().analysis_json('code', result)
        # data = commonFuc().analysis_json('data', result)
        # total = commonFuc().analysis_json('total', result)
        # data1 = commonFuc().analysis_json('data', i)

        taskId = commonFuc().analysis_json('taskId', i)

        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "approvalBatch_url")

        # 请求体
        request_body = commonFuc().get_business_data(module, "payload50_7", taskId)
        print(request_body)
        # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
        # 断言
        # checkDict=commonFuc().get_business_data(module,'checkDict10')
        # commonFuc().check_result(checkDict,result)
        code = commonFuc().analysis_json('code', result)
        data = commonFuc().analysis_json('data', result)
        total = commonFuc().analysis_json('total', result)
        if code >= 0:
            commonFuc().check_text_exist(0, result)
        else:
            commonFuc().check_text_exist('error', result)

def approval_center1():
    module = "b2_herp3_bs"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "apprCenter_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_6")
    print(request_body)
    # # # 发送请求

    result = commonFuc().http_post(url, request_body, headers)

    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)

    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', result)
    data1 = commonFuc().analysis_json('data', data)

    commonFuc().check_text_exist(0, result)
    taskId = commonFuc().analysis_json('taskId', data1[0])

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "approvalBatch_url")

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_7", taskId)
    print(request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    # checkDict=commonFuc().get_business_data(module,'checkDict10')
    # commonFuc().check_result(checkDict,result)
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', result)
    if code >= 0:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


def login(username, password, type=1):
    print('username,password', username, password)
    # 外网登录
    if type == 1:
        from air_case.mdm_login.登录外网系统.登录外网系统 import login_system
        # # 获取token和projectCode
        token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 内网登录
    elif type == 2:
        from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
        token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    else:
        from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
        token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    return token, projectCode, uxid, corpId, info


def settle():  # 结算相关
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")

    print('username,password', username, password)
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    # ================生成结算单列表查询===================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "mcmsOutUnBalance_listVoPage_url")
    print(url)
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    provId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    accountDate1 = timeUtils().get_time_hms(5)
    accountDate2 = timeUtils().get_time_hms(5)
    request_body = commonFuc().get_business_data(module, "payload7", provId, accountDate1, accountDate2, hosId, hosId)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    # 取结算单id
    list_a = []
    for i in data1:
        id = commonFuc().analysis_json('id', i)
        list_a.append(id)
    print(list_a)
    print(list_a[0], list_a[1], type(list_a[0]))
    # ===================生成结算单列表查询======================
    # ================== 生成结算单==============================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsOutUnBalance_genBalanceBill_url")
    print(url)
    request_body = commonFuc().get_business_data(module, "payload8", hosId, list_a[0], list_a[1], hosId)
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # ================== 生成结算单==============================
    # ===================结算单查询返回结算单号====================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_mcmsOutBalance_listVoPage_url")
    print(url)
    request_body = commonFuc().get_business_data(module, "payload22", hosId, hosId)
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    # print('result', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    print('data1', data1[0])
    return commonFuc().analysis_json('id', data1[0])
    # ==================结算单查询返回结算单号====================


def get_stockId(name, type=1):  # 获取仓库id参数是库房名称
    module = "b2_herp3_bs"
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockInfo_stockTree_url")
    # url=url+userid
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload62_1_1_1", get_hosid(), name)
    print('request_body', request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)

    if code == 0 and len(data) >= 1:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
    if type == 1:
        # 增加一段根据库房名称返回id
        print('data', data)
        for i in data:
            cname = commonFuc().analysis_json('cname', i)
            print(cname)
            if cname == name:
                print(cname, 'ccccccccccccccccccccccccccc')
                id1 = commonFuc().analysis_json('id', i)
                # print(id1)
                return id1
                # break
    elif type == 2:
        children = []
        print('data', data)
        for i in data:
            print('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', i)
            children = i['children']
            break
        for i in children:
            cname = i['cname']
            if cname == name:
                id2 = commonFuc().analysis_json('id', i)
                print(id2)
                return id2
    elif type == 3:
        children = []
        print('data', data)
        children = commonFuc().analysis_json('children', commonFuc().analysis_json('children', data))
        print('children', children)
        for i in children:
            id3 = i['id']
            print(id3)
            return id3
def get_stockId_fromdb(name):  # 获取仓库id参数是库房名称

    stockId=process_tuple(
        get_id("select id from mcms_stock_info where stock_name='%s'and branch_id='%s';" % (name,get_branch_id())))
    return stockId


def dept_query_all():  # 科室查询，将科室id写入文件中
    module = "b2_herp3_bs"
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    # print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)
    # b9_科室管理_科室登记_科室查询
    branch_id = FileUtils().r_info(module, '院区新增')["branch_id"]
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "deptPage_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # #请求体
    request_body = commonFuc().get_business_data(module, "payload13", branch_id)
    print(request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', data)
    if total >= 4:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
    # 将deptid写入文件
    data1 = commonFuc().analysis_json('data', data)
    print('data1', data1)
    info = []
    for i in data1:
        deptid = commonFuc().analysis_json('id', i)
        info.append(deptid)
    titlename = ['deptid1', 'deptid2', 'deptid3', 'deptid4']

    FileUtils().w_info8(info, module, '所有科室id', titlename, 'message6')
    info1 = []
    for i in data1:
        ename = commonFuc().analysis_json('ename', i)
        info1.append(ename)
    FileUtils().w_info8(info1, module, '所有科室name', titlename, 'message6')


def get_stockAreaId(dept_id, stockId):  # 获取库区id,参数是部门id和仓库id
    module = "b2_herp3_bs"
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockShelf_page_url")
    # url=url+userid
    print(url)

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload62_4", dept_id, stockId)
    print('request_body查询库区id', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    # pageSize = commonFuc().analysis_json('pageSize', data)
    # print(pageSize, type(pageSize))
    if code == 0 and len(data) >= 1:
        commonFuc().check_text_exist(0, result)

    else:
        commonFuc().check_text_exist('error', result)
    # 增加一段返回库区id
    print('data1', data1)
    for i in data1:
        shelfName = commonFuc().analysis_json('shelfName', i)
        print(shelfName)
        if shelfName == '默认库区' or shelfName == '自动化测试':
            import time
            # time.sleep(60)
            print(shelfName, 'ccccccccccccccccccccccccccc')
            id1 = commonFuc().analysis_json('id', i)
            shelfCode = commonFuc().analysis_json('shelfCode', i)
            areaName = commonFuc().analysis_json('shelfName', i)
            print('get_stockAreaIdssssssssssssssssssssssssssssssssss', id1)
            return id1


def set_dept_user(dept_id, deptName, type=1):
    module = "b2_herp3_bs"
    stockId = 'stockId'
    # 获取库房id=========     开始====
    if type == 1:
        # 中心库房名称
        branch_name = FileUtils().r_info(module, '院区新增')["branch_name"]
        stockId = get_stockId_fromdb(branch_name + '中心库房')
    # 二级库房名称
    elif type == 2:
        stockId = get_stockId_fromdb(deptName + '库房')
        print('stockId', stockId)
    elif type == 3:
        stockId = get_stockId_fromdb(deptName + '库房')
        print(stockId)

    # 获取库房id==========结束============

    # ====获取库区id===== 开始==========

    # stockAreaId = get_stockAreaId(dept_id, stockId)
    stockAreaId=process_tuple(get_id("select id from mcms_stock_shelf  where address='%s' and del_flag=0 order by CREATE_TIME desc LIMIT 1;"%(deptName)))
    print(stockAreaId)
    # ====获取库区id===== 结束==========
    # dept_query_all()

    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8(module, "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token1, projectCode1, uxid1, corpId1, info1 = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    print(token, projectCode, uxid, corpId, info)
    # 查询库区是否已经存在人员，不需要重复添加========
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockUser_page_url")
    # request_body = commonFuc().get_business_data(module, "payload65_3", dept_id, stockAreaId, get_hosid())
    # print('查询库区是否已经存在人员', request_body)
    # result = commonFuc().http_post(url, request_body, headers)
    # print('查询库区是否已经存在人员', result)
    # userCode = commonFuc().analysis_json('userCode',
    #                                      commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    userCode=delData().del_mcms_stock_user(username1,dept_id)
    # print('userCode',userCode)
    if userCode != username1:
        # 查询库区是否已经存在人员，不需要重复添加===============

        # r_d2库房管理_库区设置_人员管理_添加人员
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockUser_insert_url")
        print('url库房管理_库区设置_人员管理_添加人员', url)
        # 获取请求头信息
        headers = commonFuc().get_business_data(module, "json_headers2",
                                                commonFuc().get_business_data(module, "json_contentType"), token,
                                                commonFuc().get_business_data(module, "X-APP-CODE"))

        # # 请求体
        request_body = commonFuc().get_business_data(module, "payload62_9_1_1", dept_id, deptName, get_hosid(),
                                                     stockAreaId,
                                                     username1, uxid1, username1)
        print('url库房管理_库区设置_人员管理_添加人员request_body', request_body)

        request_body_json = get_process_list(request_body)
        # # # # 发送请求
        result = commonFuc().http_post(url, request_body_json, headers)
        print('resultbbbbbbbbbbb', result)
        # 断言
        code = commonFuc().analysis_json('code', result)
        data = commonFuc().analysis_json('data', result)
        data1 = commonFuc().analysis_json('data', data)
        # print(type(data1))
        # pageSize = commonFuc().analysis_json('pageSize', data)
        # print(pageSize, type(pageSize))
        if code == 0 and data == 1:
            commonFuc().check_text_exist(0, result)
        else:
            commonFuc().check_text_exist('error', result)
    else:
        print('库区已经存在人员，无需重复添加')


def call_login(type=1):  # type=1外网登录 2内网登录
    module = "b2_herp3_bs"
    info = FileUtils().r_info8(module, "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token1, projectCode1, uxid1, corpId1, info1 = login(username, password, 2)
    return token1, projectCode1, uxid1, corpId1, info1


def get_udi1(type=1):  # 库存明细查询获取条码
    # type=1低值 2高值 3试剂
    module = "b5_spd3_core_business_flow"
    token, projectCode1, uxid1, corpId1, info1 = call_login()
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "mcmsInvoice_barcode_url")
    print('get_udi', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # # 请求体
    request_body = 'request_body'
    if type == 1:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message2')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17", GoodsId, get_branch_id())
    elif type == 2:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message1')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17", GoodsId, get_branch_id())
    elif type == 3:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17", GoodsId, get_branch_id())

    print('getudi_request_body', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    total=commonFuc().analysis_json('total', commonFuc().analysis_json('data', result))
    if total>=1:
        # pkgcode = data1['pkgCodeSee']
        # pkgcode1 = pkgcode[0:20]
        # pkgcode2 = pkgcode[21:len(pkgcode)]
        # print(pkgcode1, pkgcode2)
        # 013530000003170010333\x1D112404261724110221UT240426000001802
        # print('aaaaaaaaaaaaaaaaa', data1[0]['pkgCodeSee'])
        # pkgcode='pkgcode'
        print('条码库存result', result)
        pkgCodeSee = 'pkgCodeSee'
        for i in data1:
            lockStatus = commonFuc().analysis_json('lockStatus', i)
            if lockStatus == 0:
                print('lockStatus', lockStatus)
                pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', i)
                pkgcode = commonFuc().analysis_json('pkgCodeSee', i)
                # # 将条码信息写入文件
                list_a = []
                list_b = []
                list_c = []
                list_a.append(i)
                list_b.append(i)
                list_c.append(i)
                # print('list_a', len(list_a), list_a)
                info = (list_a, list_b, list_c)
                titlename = ('list_a', 'list_b', 'list_c')
                # 将条码信息写入文件
                FileUtils().w_info8(info, module, '条码信息', titlename, 'message18')
                break
        return pkgCodeSee
    else:
        print('没有库存，没有库存没有库存没有库存没有库存')
    # for i in data1:
    #     lockStatus = commonFuc().analysis_json('lockStatus', i)
    #     if lockStatus == 0:
    #         print('lockStatus',lockStatus)
    #         pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', i)
    #         pkgcode = commonFuc().analysis_json('pkgCodeSee', i)
    #         # # 将条码信息写入文件
    #         list_a = []
    #         list_b = []
    #         list_c = []
    #         list_a.append(i)
    #         list_b.append(i)
    #         list_c.append(i)
    #         # print('list_a', len(list_a), list_a)
    #         info = (list_a, list_b, list_c)
    #         titlename = ('list_a', 'list_b', 'list_c')
    #         # 将条码信息写入文件
    #         FileUtils().w_info8(info, module, '条码信息', titlename, 'message18')
    #         break
    #     elif lockStatus == 1:
    #         continue
    # print('pkgcode',pkgcode)
    # return pkgcode


def get_udi2(type=1):  # 二级科室库存明细查询获取条码
    # type=1低值 2高值 3试剂
    module = "b5_spd3_core_business_flow"
    token, projectCode1, uxid1, corpId1, info1 = call_login()
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_stock_barcode_page_url")
    print('get_udi', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # # 请求体
    request_body = 'request_body'
    deptName2 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
    stockId2 = get_stockId(deptName2 + '库房', 2)
    deptid2 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
    if type == 1:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message2')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_2", GoodsId, get_branch_id(), deptid2,stockId2)
    elif type == 2:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message1')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_2_1", GoodsId, get_branch_id(), deptid2,stockId2)

    elif type == 3:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_2_2", GoodsId, get_branch_id(), deptid2,stockId2)

    elif type == 4:  # 试剂单瓶条码
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_3", GoodsId, get_branch_id(), deptid2,stockId2)
    print('getudi_request_body', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    # import pdb
    # pdb.set_trace()
    print('aaaaaaaaaaaaaaaaresult', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))

    print('条码库存result', result)
    pkgCodeSee = 'pkgCodeSee'
    for i in data1:
        lockStatus = commonFuc().analysis_json('lockStatus', i)
        if lockStatus == 0:
            print('lockStatus', lockStatus)
            pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', i)
            pkgcode = commonFuc().analysis_json('pkgCodeSee', i)
            # # 将条码信息写入文件
            list_a = []
            list_b = []
            list_c = []
            list_a.append(i)
            list_b.append(i)
            list_c.append(i)
            # print('list_a', len(list_a), list_a)
            info = (list_a, list_b, list_c)
            titlename = ('list_a', 'list_b', 'list_c')
            # 将条码信息写入文件
            FileUtils().w_info8(info, module, '条码信息', titlename, 'message18')
            break
    return pkgCodeSee

def get_udi3(type=1):  # 三级科室库存明细查询获取条码
    # type=1低值 2高值 3试剂
    module = "b5_spd3_core_business_flow"
    token, projectCode1, uxid1, corpId1, info1 = call_login()
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_stock_barcode_page_url")
    print('get_udi', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # # 请求体
    request_body = 'request_body'
    deptName3 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid3"]
    stockId3 = get_stockId(deptName3 + '库房', 3)
    deptid3 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid3']
    if type == 1:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message2')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_2", GoodsId, get_branch_id(), deptid3,stockId3)
    elif type == 2:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message1')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_2_1", GoodsId, get_branch_id(), deptid3,stockId3)

    elif type == 3:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_2_2", GoodsId, get_branch_id(), deptid3,stockId3)

    elif type == 4:  # 试剂单瓶条码
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17_3", GoodsId, get_branch_id(), deptid3,stockId3)
    print('getudi_request_body', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    # import pdb
    # pdb.set_trace()
    print('aaaaaaaaaaaaaaaaresult', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))

    print('条码库存result', result)
    pkgCodeSee = 'pkgCodeSee'
    for i in data1:
        lockStatus = commonFuc().analysis_json('lockStatus', i)
        if lockStatus == 0:
            print('lockStatus', lockStatus)
            pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', i)
            pkgcode = commonFuc().analysis_json('pkgCodeSee', i)
            # # 将条码信息写入文件
            list_a = []
            list_b = []
            list_c = []
            list_a.append(i)
            list_b.append(i)
            list_c.append(i)
            # print('list_a', len(list_a), list_a)
            info = (list_a, list_b, list_c)
            titlename = ('list_a', 'list_b', 'list_c')
            # 将条码信息写入文件
            FileUtils().w_info8(info, module, '条码信息', titlename, 'message18')
            break
    return pkgCodeSee

def get_udi(type=1):  # 退货出库扫条码
    # type=1低值 2高值 3试剂
    module = "b5_spd3_core_business_flow"
    token, projectCode1, uxid1, corpId1, info1 = call_login()
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "mcmsInvoice_barcode_url")
    print('get_udi', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # # 请求体
    request_body = 'request_body'
    if type == 1:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message2')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17", GoodsId, get_branch_id())
    elif type == 2:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message1')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17", GoodsId, get_branch_id())
    elif type == 3:
        hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        request_body = commonFuc().get_business_data(module, "payload17", GoodsId, get_branch_id())

    print('getudi_request_body', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    pkgCodeSee = 'pkgCodeSee';
    pkgcode = 'pkgcode'
    for i in data1:
        lockStatus = commonFuc().analysis_json('lockStatus', i)
        if lockStatus == 0:
            pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', i)
            pkgcode = commonFuc().analysis_json('pkgCodeSee', i)
            break
        elif lockStatus == 1:
            continue
    # pkgcode = data1[0]['pkgCodeSee']
    # pkgcode1 = pkgcode[0:20]
    # pkgcode2 = pkgcode[21:len(pkgcode)]
    # print(pkgcode1, pkgcode2)
    # 013530000003170010333\x1D112404261724110221UT240426000001802
    print('pkgCodeSee', pkgCodeSee)

    # 退货出库扫条码
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_pick_return_scan_url")
    print('herpService_pick_return_scan_url', url)
    branch_name = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_name"]
    stockId = get_stockId(branch_name + '中心库房')
    areaCode = FileUtils().r_info8("b2_herp3_bs", "shelfinfo", 'message7')['shelfCode']
    request_body = commonFuc().get_business_data(module, "payload18", areaCode, pkgcode, stockId)
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    code=commonFuc().analysis_json('code',result)
    if code==1001:
        commonFuc().check_text_exist_result_text('error', 'succees')
    # # 将条码信息写入文件
    data = commonFuc().analysis_json('data', result)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data)
    list_b.append(data)
    list_c.append(data)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将条码信息写入文件
    FileUtils().w_info8(info, module, '条码信息', titlename, 'message18')
    return pkgcode


def invoice(type=1, OBh_ID='OBhxxxxxxxxxxxxxxx'):
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "供货关系申请2", 'message')
    # print(info)
    username = info['e_username']
    password = commonFuc().get_business_data("b2_herp3_bs", "password1")
    token, projectCode, uxid, corpId, info = login(username, password)
    # print(token, projectCode, uxid, corpId, info)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    module = "a6_mdm3_si"
    # 发票录入列表查询=================================================
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listGoodsPage_url")
    print('发票录入列表查询url', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    if type == 1:
        request_body = commonFuc().get_business_data(module, "payload2_1_1", get_hosid(), get_branch_id())
    elif type == 2:
        request_body = commonFuc().get_business_data(module, "payload2_1_2", get_hosid(), get_branch_id(), OBh_ID)
    else:
        request_body = commonFuc().get_business_data(module, "payload2_1_2", get_hosid(), get_branch_id(), OBh_ID)

    print('request_body_发票录入列表查询', request_body)
    # 发送请求
    i = 1
    while True:
        time.sleep(6)
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
        try:
            data = commonFuc().analysis_json('data', result)
            total = commonFuc().analysis_json('total', data)
            if total == 0:
                print('数据暂时未同步过来，或者内网没有生成结算单')
                i = i + 1
                if i >= 100:
                    print('600秒过去了，数据还未查询出来，调用一下内网结算函数')
                    settle()
                    approval_center()
                continue
            else:
                break
        except:
            continue

    # 将发票信息写入文件
    data = commonFuc().analysis_json('data', result)
    totalInfo = commonFuc().analysis_json('totalInfo', result)
    print('totalInfo', totalInfo)
    data1 = commonFuc().analysis_json('data', data)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data1[0])
    list_b.append(data1[0])
    list_c.append(data1[0])
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将发票信息写入文件
    FileUtils().w_info8(info, module, '结算开票信息', titlename, 'message')
    # 发票录入列表查询=================================================
    # ===========发票暂存=======================================
    if type == 2:
        leftSettleQty, maxSettleAmount = SaveCacheBatch(headers)
    elif type == 3:  # 需要暂存2条结算数据
        SaveCacheBatch2(headers)
        leftSettleQty = commonFuc().analysis_json('totalQty', totalInfo)
        maxSettleAmount = commonFuc().analysis_json('totalAmount', totalInfo)
    else:
        leftSettleQty, maxSettleAmount = SaveCacheBatch(headers)
    # url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "saveCacheBatch_url")
    # print(url)
    # # 从文件中获取必要信息
    # info = FileUtils().r_info8(module, "结算开票信息", 'message')
    # # print('info', info)
    # list_a = info['list_a']
    # # print('list_a', list_a,type(list_a),len(list_a))
    # pid='pid'
    # settleMonth = "settleMonth"
    # hosGoodsId = 'hosGoodsId'
    # batchCode = 'batchCode'
    # distrDetailId = 'distrDetailId'
    # distrId='distrId'
    # distrOrderNo='distrOrderNo';settlePrice='settlePrice';maxSettleQty='maxSettleQty'
    # maxSettleAmount='maxSettleAmount';curSettleQty='curSettleQty';curSettleAmount='curSettleAmount'
    # leftSettleQty='leftSettleQty';leftSettleAmount='leftSettleAmount';hosId='hosId';provId='provId'
    # branchId='branchId'; balanceDetId='balanceDetId'; purMode='purMode';barCode='barCode';viewId='viewId'
    # for i in list_a:
    #     pid = i['pid']
    #     settleMonth = i['settleMonth']
    #     hosGoodsId = i['hosGoodsId']
    #     detailList = i['detailList']
    #     for j in detailList:
    #         batchCode = j['batchCode']
    #         distrDetailId=j['distrDetailId']
    #         distrId = j['distrId']
    #         distrOrderNo = j['distrOrderNo']
    #         settlePrice = j['settlePrice']
    #         maxSettleQty = j['maxSettleQty']
    #         maxSettleAmount = j['maxSettleAmount']
    #         curSettleQty = j['curSettleQty']
    #         curSettleAmount = j['curSettleAmount']
    #         leftSettleQty = j['leftSettleQty']
    #         leftSettleAmount = j['leftSettleAmount']
    #         hosId = j['hosId']
    #         provId = j['provId']
    #         branchId = j['branchId']
    #         balanceDetId = j['balanceDetId']
    #         purMode = j['purMode']
    #         barCode = j['barCode']
    #         viewId=j['viewId']
    #         break
    # # list2=[]
    # # detailList=None
    # # for i in list_a:
    # #     detailList = i['detailList']
    # #     break
    # # list2=detailList
    # # for k in list2:
    # #     maxSettleQty = k['leftSettleQty']
    # #     maxSettleAmount = k['settlePrice']
    # #     curSettleQty = k['curSettleQty']
    # #     curSettleAmount = k['curSettleAmount']
    # #     leftSettleQty = k['leftSettleQty']
    #
    # request_body = commonFuc().get_business_data(module, "payload3_1_1_1", pid, settleMonth, hosGoodsId, batchCode,
    #                                              distrDetailId, distrId, distrOrderNo, settlePrice, maxSettleQty,
    #                                              maxSettleAmount, curSettleQty, curSettleAmount, leftSettleQty,leftSettleAmount, hosId,
    #                                              provId,
    #                                              branchId, balanceDetId,purMode, barCode,viewId)
    # print('request_body', request_body)
    # request_body_json=get_process_list(request_body)
    # result = commonFuc().http_post(url, request_body_json, headers)
    # print('result',result)
    # ===========发票暂存===============================================
    # ==============发票缓存提交===========================================
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "submitCache_url")
    print('发票提交', url)
    hosVersion = 3
    hosName = commonFuc().get_business_data(module, 'hosName')
    invoiceQty = leftSettleQty
    invoiceAmount = maxSettleAmount
    invoiceDate = timeUtils().get_time_hms(5)
    invoiceCode = OBh_ID + str(timeUtils().get_time_hms(5))
    invoiceNumber = OBh_ID + str(timeUtils().get_time_hms(5))
    request_body = commonFuc().get_business_data(module, "payload3_2_2_2", hosName, invoiceQty, invoiceAmount,
                                                 invoiceNumber, invoiceCode, invoiceDate, get_hosid(), hosVersion)
    print('发票缓存提交request_body', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('发票缓存提交', result)
    time.sleep(3)

    print('result', result)
    VI_id = commonFuc().analysis_json('billIds',
                                      commonFuc().analysis_json('data', result))
    VI_id = ' '.join(VI_id)
    print('VI_id', VI_id)
    # ==============发票缓存提交===========================================
    # ===============预开票列表查询====================================
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listVoPage_url1")
    request_body = commonFuc().get_business_data(module, "payload3_3_1")
    print('预开票列表查询request_body', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('预开票列表查询', 'result', result)

    provName = commonFuc().analysis_json('provName',
                                         commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    sumAmount = commonFuc().analysis_json('sumAmount',
                                          commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    settleMonth = commonFuc().analysis_json('settleMonth',
                                            commonFuc().analysis_json('data',
                                                                      commonFuc().analysis_json('data', result)))
    provId = commonFuc().analysis_json('provId',
                                       commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))

    # ===============预开票列表查询====================================
    # ===============预开票提交====================================
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "mcmsOutBalance_submitInvoice_url")
    lastModified = timeUtils().get_time_hms(1)
    createTime = timeUtils().get_time_hms(1)
    invoiceTitle = hosName
    settleMonths = settleMonth
    request_body = commonFuc().get_business_data(module, "payload3_3_2", VI_id, lastModified, createTime, uxid,
                                                 get_hosid(), provId, provName, invoiceAmount, invoiceDate,
                                                 settleMonths, invoiceQty, hosName, invoiceTitle, sumAmount)
    print('预开票提交request_body', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('预开票提交', 'result', result)
    # ===============预开票提交====================================
    # ===============发票确认列表查询
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listVoPage_url1")

    request_body = commonFuc().get_business_data(module, "payload3_3")

    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    id1 = commonFuc().analysis_json('id', data1[0])
    print(id1)
    # ===============发票确认列表查询
    # ===============发票确认
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "invoiceUpdateStatus_url")

    request_body = commonFuc().get_business_data(module, "payload3_4", id1)

    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)

    # ===============发票确认
    # ==============内网发票核对============
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "mcmsInvoice_listVoPage_url")
    print('内网发票核对url', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    request_body = commonFuc().get_business_data(module, "payload9", timeUtils().get_time_hms(5),
                                                 timeUtils().get_time_hms(5), get_hosid(), get_hosid())
    print('内网发票核对request_body', request_body)
    # 发送请求
    i = 1
    while True:
        time.sleep(6)
        result = commonFuc().http_post(url, request_body, headers)
        print('内网发票核对result', result)
        try:
            data = commonFuc().analysis_json('data', result)
            total = commonFuc().analysis_json('total', data)
            data1 = commonFuc().analysis_json('data', data)
            id = commonFuc().analysis_json('id', data1)
            if id == id1:
                VI_id = id1
                break
            else:
                continue
            # if total == 0:
            #     print('数据暂时未同步过来')
            #     i = i + 1
            #     if i >= 100:
            #         print('600秒过去了，数据还未查询出来，检查一下脚本或者被测软件')
            #     continue
            # else:
            #     break
        except:
            continue

    print('result', '内网发票核对', result)

    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    version = commonFuc().analysis_json('version', data1)
    for i in data1:
        id = commonFuc().analysis_json('id', i)
        if id == id1:
            VI_id = id1
            break

    print('id1', id1, 'VI_id', VI_id)
    print('version', version)

    # ==============发票列表查询
    # ==============发票核对提交
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_invoiceUpdateStatusList_url")
    print('发票核对提交url', url)

    request_body = commonFuc().get_business_data(module, "payload10", id1, version, get_hosid())

    print('发票核对提交request_body', request_body)
    while True:
        result = commonFuc().http_post(url, request_body, headers)
        code = commonFuc().analysis_json('code', result)
        if code == 0:
            break
        else:
            time.sleep(6)
    print('发票核对提交result', result)
    # ==============发票核对提交
    # ==============内网发票核对============
    # ==============内网发票提交开始
    # 列表查询
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_listVoPage_url")
    print('url', url)
    request_body = commonFuc().get_business_data(module, "payload11", timeUtils().get_time_hms(5),
                                                 timeUtils().get_time_hms(5), get_hosid(), get_hosid())
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '内网发票提交列表查询结果', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    total = commonFuc().analysis_json('total', commonFuc().analysis_json('data', result))
    VI_id2 = 'VI_id2'
    if total == 0:
        print('检查被测程序，发票提交列表查询数据是否正确')
    else:
        for i in range(total):
            VI_id2 = commonFuc().analysis_json('id', data1[i])
            if VI_id2 == VI_id:
                break
    print('VI_id2', VI_id2)
    # ==============发票提交,下一步归档
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_invoiceUpdateStatusList_url")
    print('url', url)
    version2 = int(version) + 1
    request_body = commonFuc().get_business_data(module, "payload12", VI_id2, version2, get_hosid())
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '发票提交,下一步归档', result)

    # ==============发票提交，下一步归档
    # ==============发票归档列表查询
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_listVoPage_url")
    print('url', url)
    request_body = commonFuc().get_business_data(module, "payload13", timeUtils().get_time_hms(5),
                                                 timeUtils().get_time_hms(5), get_hosid(), get_hosid())
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '发票归档列表查询', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    total = commonFuc().analysis_json('total', commonFuc().analysis_json('data', result))
    VI_id3 = 'VI_id3'
    if total == 0:
        print('检查被测程序，发票归档列表查询查询数据是否正确')
    else:
        for i in range(total):
            VI_id3 = commonFuc().analysis_json('id', data1[i])
            if VI_id3 == VI_id2:
                break
    print('VI_id3', VI_id3)
    # ==============发票归档列表查询
    # ==================发票归档提交
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_invoiceUpdateStatusList_url")
    print('url', url)
    version3 = int(version2) + 1
    request_body = commonFuc().get_business_data(module, "payload14", VI_id3, version3, get_hosid())
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '发票归档提交,下一步付款', result)
    # ==================发票归档提交
    # ==================付款单列表查询
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_listVoPage_url")
    print('url', url)

    request_body = commonFuc().get_business_data(module, "payload15", get_hosid(), get_hosid())
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '付款单列表查询', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    total = commonFuc().analysis_json('total', commonFuc().analysis_json('data', result))
    VI_id4 = 'VI_id4'
    if total == 0:
        print('检查被测程序，发票归档列表查询查询数据是否正确')
    else:
        for i in range(total):
            VI_id4 = commonFuc().analysis_json('id', data1[i])
            if VI_id4 == id1:
                break
    print('VI_id4', VI_id4)
    # ==================付款单列表查询
    # ==================付款提交
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "mcmsInvoice_genPaymentBills_url")
    print('url', url)

    request_body = commonFuc().get_business_data(module, "payload16", VI_id4, get_hosid())
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '付款提交', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == 1:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
    # ==================付款提交
    # ==============内网发票提交
    # ================发票查询列表页面验证

    # ================发票查询列表页面验证


def SaveCacheBatch(headers):
    module = "a6_mdm3_si"
    # 获取请求头信息
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "saveCacheBatch_url")
    print(url)
    # 从文件中获取必要信息
    info = FileUtils().r_info8(module, "结算开票信息", 'message')
    # print('info', info)
    list_a = info['list_a']
    # print('list_a', list_a,type(list_a),len(list_a))
    pid = 'pid'
    settleMonth = "settleMonth"
    hosGoodsId = 'hosGoodsId'
    batchCode = 'batchCode'
    distrDetailId = 'distrDetailId'
    distrId = 'distrId'
    distrOrderNo = 'distrOrderNo';
    settlePrice = 'settlePrice';
    maxSettleQty = 'maxSettleQty'
    maxSettleAmount = 'maxSettleAmount';
    curSettleQty = 'curSettleQty';
    curSettleAmount = 'curSettleAmount'
    leftSettleQty = 'leftSettleQty';
    leftSettleAmount = 'leftSettleAmount';
    hosId = 'hosId';
    provId = 'provId'
    branchId = 'branchId';
    balanceDetId = 'balanceDetId';
    purMode = 'purMode';
    barCode = 'barCode';
    viewId = 'viewId'
    for i in list_a:
        pid = i['pid']
        settleMonth = i['settleMonth']
        hosGoodsId = i['hosGoodsId']
        detailList = i['detailList']
        for j in detailList:
            batchCode = j['batchCode']
            distrDetailId = j['distrDetailId']
            distrId = j['distrId']
            distrOrderNo = j['distrOrderNo']
            settlePrice = j['settlePrice']
            maxSettleQty = j['maxSettleQty']
            maxSettleAmount = j['maxSettleAmount']
            curSettleQty = j['curSettleQty']
            curSettleAmount = j['curSettleAmount']
            leftSettleQty = j['leftSettleQty']
            leftSettleAmount = j['leftSettleAmount']
            hosId = j['hosId']
            provId = j['provId']
            branchId = j['branchId']
            balanceDetId = j['balanceDetId']
            purMode = j['purMode']
            barCode = j['barCode']
            viewId = j['viewId']
            break
    # list2=[]
    # detailList=None
    # for i in list_a:
    #     detailList = i['detailList']
    #     break
    # list2=detailList
    # for k in list2:
    #     maxSettleQty = k['leftSettleQty']
    #     maxSettleAmount = k['settlePrice']
    #     curSettleQty = k['curSettleQty']
    #     curSettleAmount = k['curSettleAmount']
    #     leftSettleQty = k['leftSettleQty']

    request_body = commonFuc().get_business_data(module, "payload3_1_1_1", pid, settleMonth, hosGoodsId, batchCode,
                                                 distrDetailId, distrId, distrOrderNo, settlePrice, maxSettleQty,
                                                 maxSettleAmount, curSettleQty, curSettleAmount, leftSettleQty,
                                                 leftSettleAmount, hosId,
                                                 provId,
                                                 branchId, balanceDetId, purMode, barCode, viewId)
    print('request_body', request_body)
    request_body_json = get_process_list(request_body)
    result = commonFuc().http_post(url, request_body_json, headers)
    print('result', result)
    return leftSettleQty, maxSettleAmount


def SaveCacheBatch2(headers):
    module = "a6_mdm3_si"
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "saveCacheBatch_url")
    print(url)
    # 从文件中获取必要信息
    info = FileUtils().r_info8(module, "结算开票信息", 'message')
    # print('info', info)
    list_a = info['list_a']
    print('list_a', list_a)
    # print('list_a', list_a,type(list_a),len(list_a))
    pid = 'pid'
    settleMonth = "settleMonth"
    hosGoodsId = 'hosGoodsId'
    batchCode = 'batchCode'
    distrDetailId = 'distrDetailId'
    distrId = 'distrId'
    distrOrderNo = 'distrOrderNo';
    settlePrice = 'settlePrice';
    maxSettleQty = 'maxSettleQty'
    maxSettleAmount = 'maxSettleAmount';
    curSettleQty = 'curSettleQty';
    curSettleAmount = 'curSettleAmount'
    leftSettleQty = 'leftSettleQty';
    leftSettleAmount = 'leftSettleAmount';
    hosId = 'hosId';
    provId = 'provId'
    branchId = 'branchId';
    balanceDetId = 'balanceDetId';
    purMode = 'purMode';
    barCode = 'barCode';
    viewId = 'viewId'
    for i in list_a:
        pid = i['pid']
        settleMonth = i['settleMonth']
        hosGoodsId = i['hosGoodsId']
        detailList = i['detailList']
        for j in detailList:
            batchCode = j['batchCode']
            distrDetailId = j['distrDetailId']
            distrId = j['distrId']
            distrOrderNo = j['distrOrderNo']
            settlePrice = j['settlePrice']
            maxSettleQty = j['maxSettleQty']
            maxSettleAmount = j['maxSettleAmount']
            curSettleQty = j['curSettleQty']
            curSettleAmount = j['curSettleAmount']
            leftSettleQty = j['leftSettleQty']
            leftSettleAmount = j['leftSettleAmount']
            hosId = j['hosId']
            provId = j['provId']
            branchId = j['branchId']
            balanceDetId = j['balanceDetId']
            purMode = j['purMode']
            barCode = j['barCode']
            viewId = j['viewId']
            break

    # for i in list_a:
    #     pid2 = i['pid']
    #     settleMonth2 = i['settleMonth']
    #     hosGoodsId2 = i['hosGoodsId']

    detailList2 = commonFuc().analysis_json('detailList', list_a)[1]
    print('detailList2', detailList2)
    pid2 = commonFuc().analysis_json('pid', detailList2)
    settleMonth2 = commonFuc().analysis_json('settleMonth', detailList2)
    hosGoodsId2 = commonFuc().analysis_json('hosGoodsId', detailList2)
    batchCode2 = commonFuc().analysis_json('batchCode', detailList2)
    distrDetailId2 = commonFuc().analysis_json('distrDetailId', detailList2)
    distrId2 = commonFuc().analysis_json('distrId', detailList2)
    distrOrderNo2 = commonFuc().analysis_json('distrOrderNo', detailList2)
    settlePrice2 = commonFuc().analysis_json('settlePrice', detailList2)
    maxSettleQty2 = commonFuc().analysis_json('maxSettleQty', detailList2)
    maxSettleAmount2 = commonFuc().analysis_json('maxSettleAmount', detailList2)
    curSettleQty2 = commonFuc().analysis_json('curSettleQty', detailList2)
    curSettleAmount2 = commonFuc().analysis_json('curSettleAmount', detailList2)
    leftSettleQty2 = commonFuc().analysis_json('leftSettleQty', detailList2)
    leftSettleAmount2 = commonFuc().analysis_json('leftSettleAmount', detailList2)
    balanceDetId2 = commonFuc().analysis_json('balanceDetId', detailList2)
    purMode2 = commonFuc().analysis_json('purMode', detailList2)
    barCode2 = commonFuc().analysis_json('barCode', detailList2)
    viewId2 = commonFuc().analysis_json('viewId', detailList2)
    provId2 = commonFuc().analysis_json('provId', detailList2)
    branchId2 = commonFuc().analysis_json('branchId', detailList2)
    # hosId2 = j['hosId']
    # provId2 = j['provId']
    # branchId2 = j['branchId']
    # balanceDetId2 = j['balanceDetId']
    # purMode2 = j['purMode']
    # barCode2 = j['barCode']
    # viewId2 = j['viewId']
    # for j in detailList2:
    #     batchCode2 = j['batchCode']
    #     distrDetailId2 = j['distrDetailId']
    #     distrId2 = j['distrId']
    #     distrOrderNo2 = j['distrOrderNo']
    #     settlePrice2 = j['settlePrice']
    #     maxSettleQty2 = j['maxSettleQty']
    #     maxSettleAmount2 = j['maxSettleAmount']
    #     curSettleQty2 = j['curSettleQty']
    #     curSettleAmount2 = j['curSettleAmount']
    #     leftSettleQty2 = j['leftSettleQty']
    #     leftSettleAmount2 = j['leftSettleAmount']
    #     hosId2 = j['hosId']
    #     provId2 = j['provId']
    #     branchId2 = j['branchId']
    #     balanceDetId2 = j['balanceDetId']
    #     purMode2 = j['purMode']
    #     barCode2 = j['barCode']
    #     viewId2 = j['viewId']
    #     break
    # list2=[]
    # detailList=None
    # for i in list_a:
    #     detailList = i['detailList']
    #     break
    # list2=detailList
    # for k in list2:
    #     maxSettleQty = k['leftSettleQty']
    #     maxSettleAmount = k['settlePrice']
    #     curSettleQty = k['curSettleQty']
    #     curSettleAmount = k['curSettleAmount']
    #     leftSettleQty = k['leftSettleQty']

    request_body1 = commonFuc().get_business_data(module, "payload3_1_1_1", pid, settleMonth, hosGoodsId, batchCode,
                                                  distrDetailId, distrId, distrOrderNo, settlePrice, maxSettleQty,
                                                  maxSettleAmount, curSettleQty, curSettleAmount, leftSettleQty,
                                                  leftSettleAmount, hosId,
                                                  provId,
                                                  branchId, balanceDetId, purMode, barCode, viewId)

    request_body2 = commonFuc().get_business_data(module, "payload3_1_1_2", pid2, settleMonth2, hosGoodsId2, batchCode2,
                                                  distrDetailId2, distrId2, distrOrderNo2, settlePrice2, maxSettleQty2,
                                                  maxSettleAmount2, curSettleQty2, curSettleAmount2, leftSettleQty2,
                                                  leftSettleAmount2, hosId,
                                                  provId2,
                                                  branchId2, balanceDetId2, purMode2, barCode2, viewId2)
    # print('request_body1', request_body1,request_body1)
    # print('request_body2', request_body2, request_body2)
    request_body3 = str(request_body1) + ',' + str(request_body2)
    request_body4 = get_process_list(request_body3)
    print('request_body4', request_body4)
    result = commonFuc().http_post(url, request_body4, headers)
    print('result', result)

def set_dept_lead1():  # 设置一级科室负责人
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)

    # print(list_id)
    # for i in list_id:
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "deptProcOrder_update__url")
    # url=url+userid
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    dept1_id = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid1"]
    # 请求体
    request_body = commonFuc().get_business_data(module, "payload61_5", uxid, dept1_id)

    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    cname = commonFuc().analysis_json('cname', data1)
    # print(len(data1))
    if code == 0 and data == 1:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)

def set_dept_lead():  # 设置二级科室负责人
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)

    # print(list_id)
    # for i in list_id:
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "deptProcOrder_update__url")
    # url=url+userid
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    dept2_id = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid2"]
    # 请求体
    request_body = commonFuc().get_business_data(module, "payload61_5", uxid, dept2_id)

    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    cname = commonFuc().analysis_json('cname', data1)
    # print(len(data1))
    if code == 0 and data == 1:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


def getUserOnlineLoginWithMgrRange(dept_id):  # 切换权限
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    module = 'b5_spd3_core_business_flow'
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "platformService_getUserOnlineLoginWithMgrRange_url")
    # url=url+userid
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data('b5_spd3_core_business_flow', "payload23", corpId, dept_id, uxid)
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)


def updateUserLoginDefaultRange(roleid):
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data('b5_spd3_core_business_flow',
                                                                             "platformService_updateUserLoginDefaultRange_url")
    url = url + roleid
    print(url)
    result = commonFuc().http_get(url, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)


def get_listUserMgrRangePage(type=1):  # 查询权限id
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data('b5_spd3_core_business_flow',
                                                                             "platformService_listUserMgrRangePage_url")

    request_body = commonFuc().get_business_data('b5_spd3_core_business_flow', "payload23", uxid)
    result = commonFuc().http_post(url, request_body, headers)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    print('data1', data1)
    list2 = []
    mgrRangeName_list = []
    for i in data1:
        mgrRangeName = i['mgrRangeName']
        mgrRangeName_list.append(mgrRangeName)
    print('mgrRangeName_list', mgrRangeName_list)
    for i in mgrRangeName_list:
        print(i)
        if i == '设备科001':
            list2.append(i)

    for i in mgrRangeName_list:
        if i == '二级检验科002':
            list2.append(i)
        else:
            continue
    for i in mgrRangeName_list:
        if i == '三级检测组003':
            list2.append(i)
        else:
            continue
    for i in mgrRangeName_list:
        if i == '科室004':
            list2.append(i)
        else:
            continue

    print('list2', list2)

    if type == 1:
        for i in data1:
            if i['mgrRangeName'] == list2[0]:
                return commonFuc().analysis_json('id', i)
    elif type == 2:
        for i in data1:
            if i['mgrRangeName'] == list2[1]:
                return commonFuc().analysis_json('id', i)
    elif type == 3:
        for i in data1:
            if i['mgrRangeName'] == list2[2]:
                return commonFuc().analysis_json('id', i)
    elif type == 4:
        for i in data1:
            if i['mgrRangeName'] == list2[3]:
                return commonFuc().analysis_json('id', i)


def get_listUserMgrRangePage1(type=1):  # 查询权限id
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data('b5_spd3_core_business_flow',
                                                                             "platformService_listUserMgrRangePage_url")

    request_body = commonFuc().get_business_data('b5_spd3_core_business_flow', "payload23", uxid)
    result = commonFuc().http_post(url, request_body, headers)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    print('data1', data1)
    list2 = []
    mgrRangeName_list = []
    for i in data1:
        mgrRangeName = i['mgrRangeName']
        mgrRangeName_list.append(mgrRangeName)
    print('mgrRangeName_list', mgrRangeName_list)
    for i in mgrRangeName_list:
        print(i)
        if i == '设备科001':
            list2.append(i)

    for i in mgrRangeName_list:
        if i == '二级检验科002':
            list2.append(i)
        else:
            continue
    for i in mgrRangeName_list:
        if i == '三级检测组003':
            list2.append(i)
        else:
            continue
    for i in mgrRangeName_list:
        if i == '科室004':
            list2.append(i)
        else:
            continue
    for i in mgrRangeName_list:
        if i == '二级科室005':
            list2.append(i)
        else:
            continue

    print('list2', list2)

    if type == 1:
        for i in data1:
            if i['mgrRangeName'] == list2[0]:
                return commonFuc().analysis_json('id', i)
    elif type == 2:
        for i in data1:
            if i['mgrRangeName'] == list2[1]:
                return commonFuc().analysis_json('id', i)
    elif type == 3:
        for i in data1:
            if i['mgrRangeName'] == list2[2]:
                return commonFuc().analysis_json('id', i)
    elif type == 4:
        for i in data1:
            if i['mgrRangeName'] == list2[3]:
                return commonFuc().analysis_json('id', i)
    elif type == 5:
        for i in data1:
            if i['mgrRangeName'] == list2[4]:
                return commonFuc().analysis_json('id', i)


def get_stockAreaId_new(dept_id, deptName, type=1):
    module = "b2_herp3_bs"
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    stockId = 'stockId'
    # 获取库房id=========     开始====
    if type == 1:
        # 中心库房名称
        branch_name = FileUtils().r_info(module, '院区新增')["branch_name"]
        stockId = get_stockId(branch_name + '中心库房')
    # 二级库房名称
    elif type == 2:
        stockId = get_stockId(deptName + '库房', 2)
        print(stockId)
    elif type == 3:
        stockId = get_stockId(deptName + '库房', 3)
        print(stockId)

    # 获取库房id==========结束============

    # ====获取库区id===== 开始==========

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockShelf_page_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload62_4", dept_id, stockId)
    print('request_body查询库区id', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)

    if code == 0 and len(data) >= 1:
        commonFuc().check_text_exist(0, result)

    else:
        commonFuc().check_text_exist('error', result)
    # 增加一段返回库区name
    shelfCode = "shelfCode"
    for i in data1:
        shelfName = commonFuc().analysis_json('shelfName', i)
        print(shelfName)
        if shelfName == '默认库区' or shelfName == '自动化测试':
            import time
            id1 = commonFuc().analysis_json('id', i)
            shelfCode = commonFuc().analysis_json('shelfCode', i)
            areaName = commonFuc().analysis_json('shelfName', i)
    # print('shelfCode',shelfCode)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data1)
    list_b.append(data1)
    list_c.append(data1)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将库区信息写入文件
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '库区信息', titlename, 'message22')
    return shelfCode

def get_stockAreaId_new_fromDb(deptName, type=1):
    module = "b2_herp3_bs"
    stockId = 'stockId'
    # 获取库房id=========     开始====
    if type == 1:
    # 中心库房名称
        branch_name = FileUtils().r_info(module, '院区新增')["branch_name"]
        stockId = get_stockId_fromdb(branch_name + '中心库房')
        deptName = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    # 二级库房名称
    elif type == 2:
        stockId = get_stockId_fromdb(deptName + '库房')
        print(stockId)
    elif type == 3:
        stockId = get_stockId_fromdb(deptName + '库房')
        print(stockId)

    # 获取库房id==========结束============

    # ====获取库区id===== 开始==========

    sql="select shelf_code from mcms_stock_shelf where stock_Id='%s'and address='%s';"%(stockId,deptName)
    print(sql)
    shelfCode=get_id(sql)
    return shelfCode

def get_stockAreaId2_new_fromDb(deptName, type=1):
    module = "b2_herp3_bs"
    stockId = 'stockId'
    # 获取库房id=========     开始====
    if type == 1:
    # 中心库房名称
        branch_name = FileUtils().r_info(module, '院区新增')["branch_name"]
        stockId = get_stockId_fromdb(branch_name + '中心库房')
    # 二级库房名称
    elif type == 2:
        stockId = get_stockId_fromdb(deptName + '库房')
        print(stockId)
    elif type == 3:
        stockId = get_stockId_fromdb(deptName + '库房')
        print(stockId)

    # 获取库房id==========结束============

    # ====获取库区id===== 开始==========
    sql="select stock_Id from mcms_stock_shelf where stock_Id='%s'and address='%s' order by create_time desc  LIMIT 1;"%(stockId,deptName)
    print(sql)
    shelfCode=get_id(sql)
    return shelfCode

def herpService_mcmsDeptGoodsInfo_getByProvIdPage():  # 高值跟台获取产品信息
    module = "b5_spd3_core_business_flow"
    username = FileUtils().r_info8('b2_herp3_bs', '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_mcmsDeptGoodsInfo_getByProvIdPage_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    provId = FileUtils().r_info8("b5_spd3_core_business_flow", "供货关系申请2", 'message')['e_corpId']
    hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message1')['hosGoodsId']
    GoodsId = hosGoodsId.replace(get_hosid(), '')

    request_body = commonFuc().get_business_data(module, "payload25", GoodsId, provId)
    print('request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # 写入文件中
    data = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data)
    list_b.append(data)
    list_c.append(data)

    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将产品信息信息写入文件
    FileUtils().w_info8(info, module, '产品信息', titlename, 'message19')


def height_value_order_dp(orderno):  # 高值跟台配送
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "供货关系申请2", 'message')
    # print(info)
    username = info['e_username']

    password = commonFuc().get_business_data("b2_herp3_bs", "password1")
    # username = '001f90380'
    # password='1qaz!QAZ'
    print('username,password', username, password)
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 1)
    # 登录获取用户id等信息，使用创建的用户登录============结束

    # =========================查询待确认订单======================
    module = "b5_spd3_core_business_flow"
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "hdiFusion_operation_page_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    branch_id = get_branch_id()
    hos_id = branch_id[0:5]
    exeProvId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]

    orderNo1 = orderno

    dateValue1 = timeUtils().get_time_add(-30, 2)
    dateValue2 = timeUtils().get_time_add(30, 2)

    request_body = commonFuc().get_business_data(module, "payload1_1_1", dateValue1, dateValue2, orderNo1, exeProvId,
                                                 hos_id, dateValue1, dateValue2)
    print('查询待确认订单request_body', request_body)
    # 发送请求
    while True:
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
        # 断言
        code = commonFuc().analysis_json('code', result)
        data = commonFuc().analysis_json('data', result)
        total = commonFuc().analysis_json('total', data)
        if total == 1:
            break
        else:
            time.sleep(6)

    data1 = commonFuc().analysis_json('data', data)
    id1 = commonFuc().analysis_json('id', data1[0])
    print('id1', id1)

    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data1)
    list_b.append(data1)
    list_c.append(data1)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将配送订单信息息写入到文件中
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '配送订单信息', titlename, 'message8')
    # 从message8文件中获取信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "配送订单信息", 'message8')
    # print('info', info)
    list_a = info['list_a']
    list_a = ','.join(map(str, list_a))
    import json
    new_request_body = list_a.replace("'", '"')
    new_request_body1 = new_request_body.replace("None", 'null')
    print(new_request_body1)
    list_a2 = json.loads(new_request_body1)
    # print('list_a', list_a)
    id1 = "billMode"
    createUserName = 'createUserName'
    hosId = 'hosId'
    provId = 'provId'
    sourceOrderNo = 'sourceOrderNo';
    hosName = 'hosName';
    branchName = 'branchName';
    recDeptName = 'recDeptName';
    operName = 'operName';
    operDate = 'operDate';
    operDoctor = 'operDoctor';
    patientName = 'patientName';
    status = 'status';
    patientInHosId = 'patientInHosId';
    remark = 'remark';
    distPriority = 'distPriority';
    hosVersion = 'hosVersion'
    createTime = 'createTime';
    recDeptId = 'recDeptId'
    for i in list_a2:
        id1 = i["id"]
        createUserName = i["createUserName"]
        hosId = i['hosId']
        provId = i['provId']
        sourceOrderNo = i['sourceOrderNo']
        hosName = i['hosName']
        branchName = i['branchName']
        recDeptName = i['recDeptName']
        operName = i['operName']
        operDate = i['operDate']
        operDoctor = i['operDoctor']
        patientName = i['patientName']
        patientInHosId = i['patientInHosId']
        remark = i['remark']
        distPriority = i['distPriority']
        hosVersion = i['hosVersion']
        createTime = i['createTime']
        recDeptId = i['recDeptId']
        break

    # =========================查询待确认订单======================
    # ==============================确认订单==================

    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "ensure_url")

    request_body = commonFuc().get_business_data(module, "payload26", id1, uxid)

    # print('request_body',request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0:
        commonFuc().check_text_exist(code, result)
    else:
        commonFuc().check_text_exist('error', result)
    # ==============================确认订单==================
    # ==================a3获取订单详细信息
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "operation_one_url")
    url = url + id1
    print('a3获取订单详细信息', url)
    # request_body = commonFuc().get_business_data(module, "payload4", id1)

    # print('request_body',request_body)
    # 发送请求
    result = commonFuc().http_get(url, headers)
    print('a3获取订单详细信息', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)

    id2 = commonFuc().analysis_json('id', data)
    print(id1, id2)
    data1 = commonFuc().analysis_json('data', result)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data1)
    list_b.append(data1)
    list_c.append(data1)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将配送订单信息息写入到文件中1
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '配送订单详细信息', titlename, 'message9')
    # 将配送订单信息息写入到文件中2===================================
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "operation_detail_url")
    url = url + id1 + '/3'
    result = commonFuc().http_get(url, headers)
    data1 = commonFuc().analysis_json('data', result)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data1)
    list_b.append(data1)
    list_c.append(data1)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将配送订单信息息写入到文件中2
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '配送订单详细信息2', titlename, 'message9')
    # 将配送订单信息息写入到文件中2===============================
    # ==================a3获取订单详细信息中的子表
    # ==================高值跟台订单配送========================
    #
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "submit_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    # 从message9文件中获取信息1
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "配送订单详细信息", 'message9')
    list_a = info['list_a']
    sumAmount = commonFuc().analysis_json('sumAmount', list_a)
    statusText = commonFuc().analysis_json('statusText', list_a)
    sumQty = str(commonFuc().analysis_json('sumQty', list_a))
    operationPkg = commonFuc().analysis_json('operationPkg', list_a)
    provName = commonFuc().analysis_json('provName', list_a)
    status = str(commonFuc().analysis_json('status', list_a))
    version = str(commonFuc().analysis_json('version', list_a))
    # 从message9文件中获取信息1==============
    # 从message9文件中获取信息2============
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "配送订单详细信息2", 'message9')
    print('info从message9文件中获取信息', info)
    # print('info', info)
    list_a = info['list_a']
    id3 = 'id3'
    hosGoodsId = 'hosGoodsId'
    goodsCode = 'goodsCode'
    for i in list_a:
        print('aaaaaaaaaaaaaaaaaaaaaaaaaaaa', i)
        for j in i:
            print('bbbbbbbbbbbbbbbbbbb', j)
            hosGoodsId = j['hosGoodsId']
            id3 = j['id']
            goodsNum = j['goodsNum']
            price = j['price']
            inSettlement = j['inSettlement']
            inSettlementText = j['inSettlementText']
            goodsName = j['goodsName']
            goodsSpec = j['goodsSpec']
            goodsMfrsId = j['goodsMfrsId']
            goodsMfrsName = j['goodsMfrsName']
            unit = j['unit']
            subProvId = j['subProvId']
            subProvName = j['subProvName']
            totalAmount = j['totalAmount']
            spdGoodsCode = j['spdGoodsCode']
            barCodeMng = j['barCodeMng']
            settlement = j['inSettlement']
            goodsCode = j['goodsCode']
            break
        # # #获取日期
    productDate = timeUtils().get_time_hms(5)
    expdtDate = timeUtils().get_time_add(190, 2)
    createUser = uxid
    lastModifiedUser = uxid
    viewId = id3
    createUserName = provName
    priceTotal = price
    request_body = commonFuc().get_business_data(module, "payload27", id1, orderno, sourceOrderNo, hosId, hosName,
                                                 branchName, recDeptName, operName, operDate, operDoctor, patientName,
                                                 status, statusText, version, patientInHosId, remark, createUserName,
                                                 distPriority, hosVersion, createTime, sumQty, sumAmount, operationPkg,
                                                 provId, provName, recDeptId, createUser, lastModifiedUser,
                                                 id3, hosGoodsId, goodsNum, price, inSettlement, inSettlementText,
                                                 goodsName, goodsSpec, goodsCode, goodsMfrsId, goodsMfrsName, unit,
                                                 subProvId, subProvName, totalAmount, spdGoodsCode, barCodeMng,
                                                 sumAmount, id3, hosGoodsId, goodsCode, settlement, productDate,
                                                 expdtDate, viewId)

    print('高值跟台订单配送request_body', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    id1 = commonFuc().analysis_json('distrId', data)
    info = (id1, id1)
    titlename = ('distrBillId1', 'distrBillId2')
    # 将配送订单信息息写入到文件中
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '高值跟台配送单号', titlename, 'message10')

    if code == 0:
        commonFuc().check_text_exist(code, result)
    else:
        commonFuc().check_text_exist('error', result)


def Search_OrderNO():
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data('b2_herp3_bs', "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束

    # print( token,projectCode,uxid,corpId,info)
    module = 'b3_herp3_purchase'
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_operationNotice_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # 从文件中获取院区id
    branchId = get_branch_id()

    # # #获取日期
    date1 = timeUtils().get_time_hms(5)
    date2 = timeUtils().get_time_hms(5)
    # print(date1,date2)

    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload23_1_1", date2, date1, branchId)
    print('request_body', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('手术通知单result', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    return commonFuc().analysis_json('orderNo', data1)


# 高值跟台验收管理
def check_accept_order():
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    username = info['username1']

    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束

    # =========================查询待验收订单======================
    module = "b5_spd3_core_business_flow"
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "check_wait_page_url")
    print('url', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hos_id = branch_id[0:5]

    sourceOrderNo = FileUtils().r_info8(module, '高值跟台配送单号', 'message10')["distrBillId1"]

    request_body = commonFuc().get_business_data(module, "payload", hos_id, branch_id, sourceOrderNo)
    print('request_body', request_body)
    # 发送请求
    while True:
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
        # 断言
        code = commonFuc().analysis_json('code', result)
        data = commonFuc().analysis_json('data', result)
        total = commonFuc().analysis_json('total', data)
        if total == 1:
            break
        else:
            time.sleep(6)

    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data1)
    list_b.append(data1)
    list_c.append(data1)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将验收单信息写入到文件中
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '验收单信息', titlename, 'message13')
    # 从message13文件中获取信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "验收单信息", 'message13')
    # print('info', info)
    list_a = info['list_a']
    print('list_a', list_a)
    sourceType = "sourceType"
    billMode = 'billMode'
    recOrgId = 'recOrgId'
    recOrgName = 'recOrgName'
    sourceOrgId = 'sourceOrgId'
    sourceOrgName = 'sourceOrgName'
    sourceVersion = 'sourceVersion'
    tbStatus = 'tbStatus'
    for i in list_a:
        print('i', i)
        for j in i:
            sourceType = j["sourceType"]
            billMode = j["billMode"]
            recOrgId = j['recOrgId']
            recOrgName = j['recOrgName']
            sourceOrgId = j['sourceOrgId']
            sourceOrgName = j['sourceOrgName']
            sourceVersion = j['sourceVersion']
            tbStatus = j['tbStatus']
            break

    # =========================查询待验收订单======================
    # ==============================查看订单详情==================

    sourceId = sourceOrderNo
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "check_wait_detail_url")
    print('url', url)
    request_body = commonFuc().get_business_data(module, "payload1", sourceId, sourceType, billMode, branch_id)

    # print('request_body',request_body)
    # 发送请求
    while True:
        time.sleep(6)
        result = commonFuc().http_post(url, request_body, headers)
        code = commonFuc().analysis_json('code', result)
        if code == 0:
            break
        else:
            print('验收单数据未同步完成，等待6秒')
    print('result', result)
    # 断言
    data = commonFuc().analysis_json('data', result)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data)
    list_b.append(data)
    list_c.append(data)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将验收单详细信息写入到文件中
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '验收单详情信息', titlename, 'message14')
    # 读取viewId
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "验收单详情信息", 'message14')
    # print('info', info)
    list_a = info['list_a']
    print('list_a', list_a)
    viewId = "viewId"
    settlement = 'settlement'
    recTemperature = 'recTemperature'
    recHumidity = 'recHumidity'
    hosGoodsId = 'hosGoodsId'
    distrQty = 'distrQty'
    distrPkgQty = 'distrPkgQty'
    for i in list_a:
        for j in i:
            viewId = j["viewId"]
            settlement = j["settlement"]
            recTemperature = j['recTemperature']
            recHumidity = j['recHumidity']
            hosGoodsId = j['hosGoodsId']
            distrQty = j['distrQty']
            distrPkgQty = j['distrPkgQty']
        break
    # ==============================查看订单详情==================
    # ========设置验收全部合格
    url2 = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "check_barcode_save_url")
    print('check_barcode_save_url', url2)
    sourceBillId = sourceId
    request_body2 = commonFuc().get_business_data(module, "payload2", sourceBillId, viewId)

    print('设置验收全部合格request_body2', request_body2)
    # 发送请求
    time.sleep(6)

    while True:
        result2 = commonFuc().http_post(url2, request_body2, headers)
        print('result2', result2)
        data = commonFuc().analysis_json('data', result2)
        code = commonFuc().analysis_json('code', result2)
        print(code)
        if code == 0 and len(data) >= 1:
            break
        else:
            print('设置产品合格出现问题')
            time.sleep(6)
            continue

    # ========设置验收全部合格
    # =============提交验收单========================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "check_submit_url")
    deptId = recOrgId
    deptName = recOrgName
    provId = sourceOrgId
    provName = sourceOrgName
    createUser = uxid
    sourceNo = sourceId
    checkQty = distrQty
    checkPkgQty = distrPkgQty
    time.sleep(6)
    # request_body = commonFuc().get_business_data(module, "payload3", billMode, branch_id, deptId, deptName, hos_id,
    #                                              provId, provName, recOrgId, recOrgName, sourceId, sourceVersion,
    #                                              sourceType, tbStatus, createUser, sourceNo, viewId, viewId, settlement,
    #                                              recTemperature, recHumidity)
    request_body = commonFuc().get_business_data(module, "payload3", billMode, branch_id, deptId, deptName, hos_id,
                                                 provId, provName, recOrgId, recOrgName, sourceId, sourceVersion,
                                                 sourceType, tbStatus, createUser, sourceNo, viewId, hosGoodsId, viewId,
                                                 settlement,
                                                 checkQty, distrPkgQty, checkPkgQty, recTemperature, recHumidity)

    print('request_body', '提交验收单', request_body)

    # 发送请求
    while True:
        time.sleep(3)
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
        CHECK_NO = commonFuc().analysis_json('data', result)
        code = commonFuc().analysis_json('code', result)
        if code == 0:
            break
        else:
            result2 = commonFuc().http_post(url2, request_body2, headers)
            print('result2', result2)
            continue
    info = (CHECK_NO, CHECK_NO)
    titlename = ('CHECK_NO1', 'CHECK_NO2')
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '验收单号', titlename, 'message15')


# 根据左右边界提取文本，返回匹配到的文本
def reGetString(String, leftBinary="^", rightBinary="$"):
    import re
    try:
        result = re.search("%s(.*?)%s" % (leftBinary, rightBinary), String)
        return result.group(1)
    except:
        return "没有匹配到内容，请检查左右边界"


def set_stockShelf_Linkman(deptId,stockAreaId):
    print('设置库区联系人')
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    module='b2_herp3_bs'
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockShelf_page_url")

    # # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload62_4", deptId, stockAreaId)
    print('request_body查询库区id', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    # 断言

    # info = FileUtils().r_info8('b5_spd3_core_business_flow', "库区信息", 'message22')
    list_a = result
    print('list_a', list_a)
    id1 = commonFuc().analysis_json('id', list_a)
    shelfCode = commonFuc().analysis_json('shelfCode', list_a)
    createTime = commonFuc().analysis_json('createTime', list_a)
    stockId = commonFuc().analysis_json('stockId', list_a)
    shelfName = commonFuc().analysis_json('shelfName', list_a)
    address = commonFuc().analysis_json('address', list_a)
    recPhone = commonFuc().analysis_json('recPhone', list_a)
    lastModified = commonFuc().analysis_json('lastModified', list_a)
    shelfNo = commonFuc().analysis_json('shelfNo', list_a)
    version = commonFuc().analysis_json('version', list_a)
    createUser = uxid

    module = 'b2_herp3_bs'

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_stockShelf_updateById_url")

    # # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    request_body = commonFuc().get_business_data(module, "payload62_7_1_1", id1, lastModified, version, createTime,
                                                 createUser, createUser, stockId,
                                                 shelfCode, shelfName, address, createUser, recPhone, shelfNo)
    print('request_body', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultbbbbbbbbbbb', result)


def pickScan(PICK_ID, udi_code, type=1):  # 拣货扫码
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # ==============================获取条码信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_hdiBarcode_scan_url")
    url = url + udi_code
    print('获取条码信息url', url)
    result = commonFuc().http_get(url, headers)
    print('获取条码信息', result)
    # 获取必要信息
    data1 = commonFuc().analysis_json('data', result)
    areaCode = commonFuc().analysis_json('areaCode', data1)
    UTid = commonFuc().analysis_json('id', data1)
    createTime = commonFuc().analysis_json('id', data1)
    stockId = commonFuc().analysis_json('stockId', data1)
    areaCode = commonFuc().analysis_json('areaCode', data1)
    areaName = commonFuc().analysis_json('areaName', data1)
    shelfCode = commonFuc().analysis_json('shelfCode', data1)
    codeType = commonFuc().analysis_json('codeType', data1)
    tagType = commonFuc().analysis_json('tagType', data1)
    hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
    mdmGoodsCode = commonFuc().analysis_json('mdmGoodsCode', data1)
    goodsCode = commonFuc().analysis_json('goodsCode', data1)
    goodsDi = commonFuc().analysis_json('goodsDi', data1)
    barName = commonFuc().analysis_json('barName', data1)
    batchCode = commonFuc().analysis_json('batchCode', data1)
    expdtDate = commonFuc().analysis_json('expdtDate', data1)
    productDate = commonFuc().analysis_json('productDate', data1)
    pkgCode = commonFuc().analysis_json('pkgCode', data1)
    pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
    ssccCode = commonFuc().analysis_json('ssccCode', data1)
    tbStatus = commonFuc().analysis_json('tbStatus', data1)
    ext = commonFuc().analysis_json('ext', data1)
    distrDetailId = commonFuc().analysis_json('distrDetailId', ext)
    distrBillId = commonFuc().analysis_json('distrBillId', ext)
    purBillId = commonFuc().analysis_json('purBillId', ext)
    pkgDefQty = commonFuc().analysis_json('pkgDefQty', ext)
    pkgDefId = commonFuc().analysis_json('pkgDefId', ext)
    pkgDefName = commonFuc().analysis_json('pkgDefName', ext)
    purMode = commonFuc().analysis_json('purMode', data1)
    goodsMfrsName = commonFuc().analysis_json('goodsMfrsName', data1)
    goodsSpec = commonFuc().analysis_json('goodsSpec', data1)
    unit = commonFuc().analysis_json('unit', data1)
    goodsName = commonFuc().analysis_json('goodsName', data1)
    pkgDefId = commonFuc().analysis_json('pkgDefId', data1)
    # pkgDefQty=commonFuc().analysis_json('pkgDefQty',data1)
    pkgDefName = commonFuc().analysis_json('pkgDefName', data1)
    printNum = commonFuc().analysis_json('printNum', data1)
    made = commonFuc().analysis_json('made', data1)
    hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
    stockName = commonFuc().analysis_json('stockName', data1)
    # ==============================获取条码信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_BuyPick_pickScan_url")
    print('url', url)

    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    deptName = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid1"]
    stockName = get_branch_name()
    createTime = timeUtils().get_time_hms(1)
    request_body = "request_body"
    # # 请求体
    if type == 1:
        request_body = commonFuc().get_business_data(module, "payload50", areaCode, UTid, createTime, UTid, get_hosid(),
                                                     stockId,
                                                     areaCode, areaName, shelfCode, codeType, tagType, hosGoodsId,
                                                     mdmGoodsCode, goodsCode, goodsDi, barName, batchCode, expdtDate,
                                                     productDate, pkgCode, pkgCodeSee, ssccCode, tbStatus,
                                                     distrDetailId,
                                                     distrBillId, purBillId, pkgDefQty, pkgDefId, pkgDefName, purMode,
                                                     goodsMfrsName, goodsSpec, unit, goodsName, pkgDefId, pkgDefQty,
                                                     pkgDefName, printNum, made,
                                                     hosGoodsCode, PICK_ID, areaName, stockName)
    elif type == 2:
        request_body = commonFuc().get_business_data(module, "payload50_2", areaCode, UTid, createTime, UTid,
                                                     get_hosid(),
                                                     stockId,
                                                     areaCode, areaName, shelfCode, codeType, tagType, hosGoodsId,
                                                     mdmGoodsCode, goodsCode, goodsDi, barName, batchCode, expdtDate,
                                                     productDate, pkgCode, pkgCodeSee, ssccCode, tbStatus,
                                                     distrDetailId,
                                                     distrBillId, purBillId, pkgDefQty, purMode,
                                                     goodsMfrsName, goodsSpec, unit, goodsName,
                                                     printNum, made,
                                                     hosGoodsCode, PICK_ID, areaName, stockName)
    elif type == 3:
        request_body = commonFuc().get_business_data(module, "payload50", areaCode, UTid, createTime, UTid,
                                                     get_hosid(), stockId,
                                                     areaCode, areaName, shelfCode, codeType, tagType, hosGoodsId,
                                                     mdmGoodsCode, goodsCode, goodsDi, barName, batchCode,
                                                     expdtDate,
                                                     productDate, pkgCode, pkgCodeSee, ssccCode, tbStatus,
                                                     distrDetailId,
                                                     distrBillId, purBillId, pkgDefQty, pkgDefId, pkgDefName,
                                                     purMode,
                                                     goodsMfrsName, goodsSpec, unit, goodsName, pkgDefId, pkgDefQty,
                                                     pkgDefName, printNum, made,
                                                     hosGoodsCode, PICK_ID, areaName, stockName)
    print('request_body', '拣货扫码', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    PICK_ID = commonFuc().analysis_json('data', result)


def pickScan2(PICK_ID, udi_code, type=1):  # 二级库出库拣货扫码
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # ==============================获取条码信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_stock_pick_scan_url")
    print('获取条码信息url', url)
    request_body = commonFuc().get_business_data(module, "payload59", udi_code)
    result = commonFuc().http_post(url, request_body, headers)
    # import pdb
    # pdb.set_trace()
    code=commonFuc().analysis_json('code',result)
    if code=='14030053':
        commonFuc().check_text_exist_result_text('error', 'SUCCESS')
    print('获取条码信息result', result)
    # 获取必要信息
    data1 = commonFuc().analysis_json('data', result)
    areaCode = commonFuc().analysis_json('areaCode', data1)
    UTid = commonFuc().analysis_json('id', data1)
    createTime = commonFuc().analysis_json('id', data1)
    stockId = commonFuc().analysis_json('stockId', data1)
    areaCode = commonFuc().analysis_json('areaCode', data1)
    areaName = commonFuc().analysis_json('areaName', data1)
    shelfCode = commonFuc().analysis_json('shelfCode', data1)
    codeType = commonFuc().analysis_json('codeType', data1)
    tagType = commonFuc().analysis_json('tagType', data1)
    hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
    mdmGoodsCode = commonFuc().analysis_json('mdmGoodsCode', data1)
    goodsCode = commonFuc().analysis_json('goodsCode', data1)
    goodsDi = commonFuc().analysis_json('goodsDi', data1)
    barName = commonFuc().analysis_json('barName', data1)
    batchCode = commonFuc().analysis_json('batchCode', data1)
    expdtDate = commonFuc().analysis_json('expdtDate', data1)
    productDate = commonFuc().analysis_json('productDate', data1)
    pkgCode = commonFuc().analysis_json('pkgCode', data1)
    pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
    ssccCode = commonFuc().analysis_json('ssccCode', data1)
    tbStatus = commonFuc().analysis_json('tbStatus', data1)
    ext = commonFuc().analysis_json('ext', data1)
    distrDetailId = commonFuc().analysis_json('distrDetailId', ext)
    distrBillId = commonFuc().analysis_json('distrBillId', ext)
    purBillId = commonFuc().analysis_json('purBillId', ext)
    pkgDefQty = commonFuc().analysis_json('pkgDefQty', ext)
    pkgDefId = commonFuc().analysis_json('pkgDefId', ext)
    pkgDefName = commonFuc().analysis_json('pkgDefName', ext)
    purMode = commonFuc().analysis_json('purMode', data1)
    goodsMfrsName = commonFuc().analysis_json('goodsMfrsName', data1)
    goodsSpec = commonFuc().analysis_json('goodsSpec', data1)
    unit = commonFuc().analysis_json('unit', data1)
    goodsName = commonFuc().analysis_json('goodsName', data1)
    pkgDefId = commonFuc().analysis_json('pkgDefId', data1)
    # pkgDefQty=commonFuc().analysis_json('pkgDefQty',data1)
    pkgDefName = commonFuc().analysis_json('pkgDefName', data1)
    printNum = commonFuc().analysis_json('printNum', data1)
    made = commonFuc().analysis_json('made', data1)
    hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
    stockName = commonFuc().analysis_json('stockName', data1)
    sourceId = commonFuc().analysis_json('sourceId', data1)
    price = commonFuc().analysis_json('price', data1)
    inStockTime = commonFuc().analysis_json('inStockTime', data1)
    purModeText = commonFuc().analysis_json('purModeText', data1)
    version = commonFuc().analysis_json('version', data1)
    unitName = commonFuc().analysis_json('unitName', data1)
    # ==============================获取条码信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_stock_out_use_buyInfo_url")
    url = url + PICK_ID
    result = commonFuc().http_get(url, headers)
    pickerId = commonFuc().analysis_json('pickId', commonFuc().analysis_json('data', result))

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_stock_out_pickScan_url")
    print('url', url)

    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    deptName2 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid5"]
    stockName = deptName2 + "库房"
    createTime = timeUtils().get_time_hms(1)
    request_body = "request_body"
    # # 请求体
    if type == 1:
        request_body = commonFuc().get_business_data(module, "payload50_1_1", areaCode, areaName, UTid, createTime,
                                                     UTid, get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi, barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee, ssccCode,
                                                     tbStatus, pkgDefId, purBillId, pkgDefName, distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName, pkgDefId, pkgDefQty, pkgDefName, made,
                                                     unitName, hosGoodsCode, purModeText, PICK_ID, pickerId,
                                                     stockName)
    elif type == 2:
        request_body = commonFuc().get_business_data(module, "payload50_2_2", areaCode, areaName, UTid, createTime,
                                                     UTid, get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi, barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee, ssccCode,
                                                     tbStatus, purBillId, distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName, made,
                                                     unitName, hosGoodsCode, purModeText, PICK_ID, pickerId,
                                                     stockName)
    elif type == 3:
        request_body = commonFuc().get_business_data(module, "payload50_1_1", areaCode, areaName, UTid, createTime,
                                                     UTid, get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi, barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee, ssccCode,
                                                     tbStatus, pkgDefId, purBillId, pkgDefName, distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName, pkgDefId, pkgDefQty, pkgDefName, made,
                                                     unitName, hosGoodsCode, purModeText, PICK_ID, pickerId,
                                                     stockName)
    print('request_body', '拣货扫码', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', '拣货扫码', result)
    code=commonFuc().analysis_json('code',result)
    if code==0:
        print('拣货扫码','ok')
    elif code==14030001:
        print('单据已被扫码，请刷新页面数据', 'ok')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    print('result', result)
    return areaCode, pickerId


def pickScan4(udi_code):  # 二级库扫码 只扫码不发放
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # ==============================获取条码信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_stock_pick_scan_url")
    print('获取条码信息url', url)

    deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
    deptName = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
    stockId = get_stockId(deptName + '库房', 2)
    deptName2 = deptName + '库房'
    areaCode = get_stockAreaId_new(deptid2, deptName, 2)
    request_body = commonFuc().get_business_data(module, "payload60", udi_code, stockId, deptName2, areaCode)
    print('获取条码信息request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('获取条码信息result', result)
    data1 = commonFuc().analysis_json('data', result)
    return data1


def pickScan3(udi_code, type=1):  # 二级库扫码发放(高值产品不能扫码发放)
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # ==============================获取条码信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_stock_pick_scan_url")
    print('获取条码信息url', url)

    deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
    deptName = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
    stockId = get_stockId(deptName + '库房', 2)
    deptName2 = deptName + '库房'
    areaCode = get_stockAreaId_new(deptid2, deptName, 2)
    request_body = commonFuc().get_business_data(module, "payload60", udi_code, stockId, deptName2, areaCode)
    print('获取条码信息request_body', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('获取条码信息result', result)

    # 获取必要信息
    data1 = commonFuc().analysis_json('data', result)
    areaCode = commonFuc().analysis_json('areaCode', data1)
    UTid = commonFuc().analysis_json('id', data1)
    createTime = commonFuc().analysis_json('id', data1)
    stockId = commonFuc().analysis_json('stockId', data1)
    areaCode = commonFuc().analysis_json('areaCode', data1)
    areaName = commonFuc().analysis_json('areaName', data1)
    shelfCode = commonFuc().analysis_json('shelfCode', data1)
    codeType = commonFuc().analysis_json('codeType', data1)
    tagType = commonFuc().analysis_json('tagType', data1)
    hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
    mdmGoodsCode = commonFuc().analysis_json('mdmGoodsCode', data1)
    goodsCode = commonFuc().analysis_json('goodsCode', data1)
    goodsDi = commonFuc().analysis_json('goodsDi', data1)
    barName = commonFuc().analysis_json('barName', data1)
    batchCode = commonFuc().analysis_json('batchCode', data1)
    expdtDate = commonFuc().analysis_json('expdtDate', data1)
    productDate = commonFuc().analysis_json('productDate', data1)
    pkgCode = commonFuc().analysis_json('pkgCode', data1)
    pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
    ssccCode = commonFuc().analysis_json('ssccCode', data1)
    tbStatus = commonFuc().analysis_json('tbStatus', data1)
    ext = commonFuc().analysis_json('ext', data1)
    distrDetailId = commonFuc().analysis_json('distrDetailId', ext)
    distrBillId = commonFuc().analysis_json('distrBillId', ext)
    purBillId = commonFuc().analysis_json('purBillId', ext)
    pkgDefQty = commonFuc().analysis_json('pkgDefQty', ext)
    pkgDefId = commonFuc().analysis_json('pkgDefId', ext)
    pkgDefName = commonFuc().analysis_json('pkgDefName', ext)
    purMode = commonFuc().analysis_json('purMode', data1)
    goodsMfrsName = commonFuc().analysis_json('goodsMfrsName', data1)
    goodsSpec = commonFuc().analysis_json('goodsSpec', data1)
    unit = commonFuc().analysis_json('unit', data1)
    goodsName = commonFuc().analysis_json('goodsName', data1)
    pkgDefId = commonFuc().analysis_json('pkgDefId', data1)
    # pkgDefQty=commonFuc().analysis_json('pkgDefQty',data1)
    pkgDefName = commonFuc().analysis_json('pkgDefName', data1)
    printNum = commonFuc().analysis_json('printNum', data1)
    made = commonFuc().analysis_json('made', data1)
    hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
    sourceId = commonFuc().analysis_json('sourceId', data1)
    price = commonFuc().analysis_json('price', data1)
    purModeText = commonFuc().analysis_json('purModeText', data1)
    version = commonFuc().analysis_json('version', data1)
    unitName = commonFuc().analysis_json('unitName', data1)
    # ==============================获取条码信息
    # 从message18文件中获取信息
    info = FileUtils().r_info8(module, "条码信息", 'message18')
    # print('info', info)
    list_a = info['list_a']
    extInfo = commonFuc().analysis_json('extInfo', list_a)
    print('extInfo', extInfo)
    # inStockTime = commonFuc().analysis_json('inStockTime', extInfo)
    inStockTime = reGetString(extInfo, 'inStockTime\"\: \"', '\"\, \"distrDetailId')
    print('inStockTime', inStockTime)
    # 从message18文件中获取信息
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "dept_stock_out_submit_url")

    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    deptName2 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
    stockName2 = deptName2 + "库房"
    createTime = timeUtils().get_time_hms(1)
    request_body = "request_body"
    mgrCorpName = get_hosname()
    mgrRangeId = deptid2
    mgrRangeName = deptName2
    extStr1 = get_branch_name()
    extStr3 = get_branch_name()
    snCode = UTid
    userLoginCode = username
    cname = username
    orgCode1 = get_orgCode()
    orgName1 = get_orgName()
    print(orgCode1, orgName1)

    # # 请求体
    if type == 1:
        request_body = commonFuc().get_business_data(module, "payload50_1_2", stockId, stockName2, areaCode, areaName,
                                                     uxid, userLoginCode, cname, get_hosid(), get_branch_id(), deptid1,
                                                     orgCode1, orgName1, get_hosid(), get_hosid(), mgrCorpName,
                                                     get_branch_id(),
                                                     get_branch_name(), mgrRangeId, mgrRangeName, extStr1, extStr3,
                                                     get_hosid(), stockId,
                                                     stockName2, areaCode, areaName, UTid, createTime, snCode,
                                                     get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi, barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee, ssccCode,
                                                     tbStatus, pkgDefId, pkgDefQty, purBillId, pkgDefName, distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName, pkgDefId, pkgDefQty, unitName,
                                                     hosGoodsCode, purModeText)

    elif type == 3:
        request_body = commonFuc().get_business_data(module, "payload50_1_2", stockId, stockName2, areaCode, areaName,
                                                     uxid, userLoginCode, cname, get_hosid(), get_branch_id(), deptid1,
                                                     orgCode1, orgName1, get_hosid(), get_hosid(), mgrCorpName,
                                                     get_branch_id(),
                                                     get_branch_name(), mgrRangeId, mgrRangeName, extStr1, extStr3,
                                                     get_hosid(), stockId,
                                                     stockName2, areaCode, areaName, UTid, createTime, snCode,
                                                     get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi, barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee, ssccCode,
                                                     tbStatus, pkgDefId, pkgDefQty, purBillId, pkgDefName, distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName, pkgDefId, pkgDefQty, unitName,
                                                     hosGoodsCode, purModeText)

    print('request_body', '发放扫码', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    return data1


def get_branch_name():
    return FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_name"]


def get_hosname():
    return "邹城市人民医院(test)"


def get_orgCode():
    str = delData().get_orgCode()
    str = str.replace('(', '')
    str = str.replace(',)', '')
    str = str.replace("'", '')
    str = str.replace("'", '')
    return str


def get_orgName():
    str = delData().get_orgName()
    str = str.replace('(', '')
    str = str.replace(',)', '')
    str = str.replace("'", '')
    str = str.replace("'", '')
    return str


def out_warehouse_review(PICK_ID):  # 出库复核
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束

    # url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_pick_submit_url")
    # print('url', url)
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # 从文件中获取必要信息
    info = FileUtils().r_info8(module, "条码信息", 'message18')
    # print('info', info)
    list_a = info['list_a']
    print('list_a', list_a[0], type(list_a), len(list_a))
    UTid = 'UT'
    areaCode = 'areaCode';
    createTime = 'createTime';
    hosId = 'hosId';
    stockId = 'stockId';
    areaCode = 'areaCode';
    areaName = 'areaName';
    shelfCode = 'shelfCode'
    codeType = 'codeType';
    # tagType = 'tagType';
    hosGoodsId = 'hosGoodsId';
    mdmGoodsCode = 'mdmGoodsCode';
    goodsCode = 'goodsCode';
    # goodsDi = 'goodsDi';
    barName = 'barName';
    batchCode = 'batchCode'
    expdtDate = 'expdtDate';
    productDate = 'productDate'
    pkgCode = 'pkgCode'
    print('aaaaaaaaaaaaaaaaaaaaaaaaa', list_a[0])
    list_b = list_a[0]
    for i in list_b:
        print(i)
        UTid = i['id']
        areaCode = i['areaCode']
        # createTime = i['createTime']
        # hosId = i['hosId']
        stockId = i['stockId'];
        areaCode = i['areaCode'];
        areaName = i['areaName'];
        shelfCode = i['shelfCode']
        codeType = i['codeType'];
        # tagType = i['tagType'];
        hosGoodsId = i['hosGoodsId'];
        # mdmGoodsCode = i['mdmGoodsCode']
        goodsCode = i['goodsCode'];
        # goodsDi = i['goodsDi'];
        barName = i['barName'];
        batchCode = i['batchCode']
        expdtDate = i['expdtDate'];
        productDate = i['productDate']
        # pkgCode = i['pkgCode']
        pkgCodeSee = i['pkgCodeSee']
        ssccCode = i['ssccCode']
        # tbStatus = i['tbStatus']
        onlyKey = i['hosGoodsId']
        # ext = i['extInfo']
        # print('ext', ext)
        # distrDetailId = ext['distrDetailId']
        # distrBillId = ext['distrBillId']
        # purBillId = ext['purBillId']
        # pkgDefQty = ext['pkgDefQty']
        # pkgDefId = ext['pkgDefId']
        # pkgDefName = ext['pkgDefName']
        purMode = i['purMode']
        goodsMfrsName = i['goodsMfrsName']
        goodsSpec = i['goodsSpec']
        unit = i['unit']
        goodsName = i['goodsName']
        pkgDefId = i['pkgDefId']
        pkgDefQty = i['pkgDefQty']
        pkgDefName = i['pkgDefName']
        # printNum = i['printNum']
        made = i['made']
        provId = i['provId']
        provName = i['provName']
        # subProvId = i['subProvId']
        # subProvName = i['subProvName']
        hosGoodsCode = i['hosGoodsCode']
        # subSendFlag = i['subSendFlag']
        areaName = i['areaName']
        # hosId = i['hosId']
        break
    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    deptName = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid1"]
    # # # 请求体
    # request_body = commonFuc().get_business_data(module, "payload19", areaCode, UTid, createTime, UTid, hosId, stockId,
    #                                              areaCode, areaName, shelfCode, codeType, tagType, hosGoodsId,
    #                                              mdmGoodsCode, goodsCode, goodsDi, barName, batchCode, expdtDate,
    #                                              productDate, pkgCode, pkgCodeSee, ssccCode, tbStatus, distrDetailId,
    #                                              distrBillId, purBillId, pkgDefQty, pkgDefId, pkgDefName, purMode,
    #                                              goodsMfrsName, goodsSpec, unit, goodsName, pkgDefId, pkgDefQty,
    #                                              pkgDefName, printNum, made, provId, provName, subProvId, subProvName,
    #                                              hosGoodsCode, subSendFlag, onlyKey, areaName, hosId, get_branch_id(),
    #                                              deptid1, deptName, stockId)
    # print('request_body', 'ccccccc', request_body)
    #
    # # # # # 发送请求
    # result = commonFuc().http_post(url, request_body, headers)
    # print('result', result)
    # PICK_ID = commonFuc().analysis_json('data', result)
    # =====================出库复核列表查询获取pickid===============
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_pick_return_page_url")
    print('url', url)
    request_body = commonFuc().get_business_data(module, "payload20", get_branch_id(), get_hosid(), deptid1)
    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)

    # =====================出库复核列表查询获取pickid===============

    # ========================扫码复核
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_stock_hdiBarcode_scan_url")
    url = url + pkgCodeSee
    print('扫码复核url', url)
    # # # # 发送请求
    result = commonFuc().http_get(url, headers)
    print('扫码复核result', result)
    data = commonFuc().analysis_json('data', result)
    UT_id = commonFuc().analysis_json('id', data)
    createTime = commonFuc().analysis_json('createTime', data)
    snCode = commonFuc().analysis_json('snCode', data)
    tbStatus = commonFuc().analysis_json('tbStatus', data)
    tagType = commonFuc().analysis_json('tagType', data)
    goodsDi = commonFuc().analysis_json('goodsDi', data)
    distrBillId = commonFuc().analysis_json('distrBillId', commonFuc().analysis_json('ext', data))
    purBillId = commonFuc().analysis_json('purBillId', commonFuc().analysis_json('ext', data))
    distrDetailId = commonFuc().analysis_json('distrDetailId', commonFuc().analysis_json('ext', data))
    print(UT_id)
    # ========================扫码复核
    # ========出库复核提交==========
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_stock_review_pass_submit_url")

    print('url', url)
    # sourceId = ' '.join(PICK_ID)
    sourceId = PICK_ID
    # 请求体
    request_body = commonFuc().get_business_data(module, "payload21", UT_id, createTime, snCode, hosId, stockId,
                                                 areaCode, areaName, shelfCode, codeType, tagType, hosGoodsId,
                                                 mdmGoodsCode, goodsCode, goodsDi, barName, batchCode, expdtDate,
                                                 productDate, pkgCode, pkgCodeSee, ssccCode, tbStatus, distrDetailId,
                                                 distrBillId, purBillId, pkgDefQty, pkgDefId, pkgDefName, purMode,
                                                 goodsMfrsName, goodsSpec, unit, goodsName, pkgDefId, pkgDefQty,
                                                 pkgDefName, made, hosGoodsCode, sourceId)
    print('request_body', request_body)
    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('herpService_stock_review_pass_submit_url_result', result)
    # ========出库复核提交


def second_dept_one_key_in(type=2):
    if type == 2:
        updateUserLoginDefaultRange(get_listUserMgrRangePage(2))  # 设置登录账号默认权限是二级库
    elif type == 3:
        updateUserLoginDefaultRange(get_listUserMgrRangePage1(3))  # 设置登录账号默认权限是二级库
    elif type == 5:
        updateUserLoginDefaultRange(get_listUserMgrRangePage1(5))  # 设置登录账号默认权限是二级库
    module = "b5_spd3_core_business_flow"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # 科室入库,列表查询=========
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "dept_stock_in_page_url")
    print('科室入库,列表查询url', url)
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    request_body = commonFuc().get_business_data(module, "payload28", get_branch_id(), get_hosid())
    print('request_body', '科室入库,列表查询ur', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    while True:
        result = commonFuc().http_post(url, request_body, headers)
        total = commonFuc().analysis_json('total', commonFuc().analysis_json('data', result))
        if total>=1:
            break
        elif total==0:
            return
        else:
            continue

    deptid = commonFuc().analysis_json('deptId',
                                       commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    sourceId = commonFuc().analysis_json('sourceId',
                                         commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    sourceType = commonFuc().analysis_json('sourceType',
                                           commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    billMode = commonFuc().analysis_json('billMode',
                                         commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
    deptName = commonFuc().analysis_json('deptName',
                                         commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))

    # 科室入库,列表查询==========================================================
    # 科室入库页面获取库区信息=================================================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "dept_stockUser_queryStockShelfList_url")
    print('科室入库页面获取库区信息,url', url)
    request_body = commonFuc().get_business_data(module, "payload29", deptid, uxid)
    print('request_body', '科室入库页面获取库区信息', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('科室入库页面获取库区信息result', result)
    data = commonFuc().analysis_json('data', result)
    areaCode = commonFuc().analysis_json('areaCode', data)
    areaName = commonFuc().analysis_json('areaName', data)
    # 科室入库页面获取库区信息=================================================

    # 科室入库页面获取单据详细信息=================================================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "dept_stock_in_detail_url")
    print('科室入库页面获取单据详细信息,url', url)
    targetAreaCode = areaCode
    request_body = commonFuc().get_business_data(module, "payload30", deptid, targetAreaCode, get_hosid(), sourceId,
                                                 sourceType, billMode)
    print('request_body', '科室入库页面获取单据详细信息', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    data = commonFuc().analysis_json('data', result)
    viewId = commonFuc().analysis_json('viewId', data)
    shelfCode = commonFuc().analysis_json('shelfCode', data)
    # 科室入库页面获取单据详细信息====================================================
    # 一键入库====================================================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "dept_stock_in_submit_url")
    print('一键入库,url', url)
    targetAreaCode = areaCode
    targetAreaName = areaName
    request_body = commonFuc().get_business_data(module, "payload31", viewId, shelfCode, sourceId,
                                                 sourceType, deptid, deptName, targetAreaCode, targetAreaName)
    print('一键入库', 'request_body', request_body)

    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('一键入库result', result)
    data=commonFuc().analysis_json('data',result)
    code=commonFuc().analysis_json('code',result)
    if code==1010:
        commonFuc().check_text_exist_result_text('error', 'succees')
    elif len(data)>=1:
        commonFuc().check_text_exist_result_text('succees', 'succees')
        return data
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
        return None
    # 一键入库====================================================


def login_platform():
    module = "a3_mdm3_hs"
    from air_case.mdm_login.登录外网系统.登录资源管控平台 import login_system
    # 登录
    username = commonFuc().get_business_data(module, "username2")
    password = commonFuc().get_business_data(module, "password")
    print(username, password)
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    return token, projectCode, uxid, corpId, info


def login_logic_stock():
    module = "b5_spd3_core_business_flow"
    from air_case.mdm_login.登录外网系统.登录云仓 import login_system
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    # 登录
    username = commonFuc().get_business_data(module, "username2")
    password = commonFuc().get_business_data(module, "password")
    print(username, password)
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    return token, projectCode, uxid, corpId, info


def branch_add():
    module = "b2_herp3_bs"
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    # print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)
    # a4_院区新增
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "insert_url")
    print('a4_院区新增', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    name = timeUtils().get_time_hms(5)
    # 请求体
    request_body = commonFuc().get_business_data(module, "payload", name, name)

    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    commonFuc().check_text_exist(0, result)
    id1 = commonFuc().analysis_json('id', commonFuc().analysis_json('data', result))
    name = commonFuc().analysis_json('name', commonFuc().analysis_json('data', result))

    # print(id1,name,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    return id1, name


def get_in_userid():
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    return uxid


def set_dept_lead_new(dept2_id):  # 设置新增的二级科室负责人
    module = 'b2_herp3_bs'
    username = FileUtils().r_info8(module, '用户名信息', 'message3')["username1"]
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)

    # print(list_id)
    # for i in list_id:
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "deptProcOrder_update__url")
    # url=url+userid
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # dept2_id = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid5"]
    # 请求体
    request_body = commonFuc().get_business_data(module, "payload61_5", uxid, dept2_id)

    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    data1 = commonFuc().analysis_json('data', data)
    cname = commonFuc().analysis_json('cname', data1)
    # print(len(data1))
    if code == 0 and data == 1:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


def grants_user_new():
    module = "b2_herp3_bs"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8(module, "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token1, projectCode1, uxid1, corpId1, info1 = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "sys_user_grants_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    userId = uxid1
    mgrBranchId = FileUtils().r_info(module, '院区新增')["branch_id"]
    mgrBranchName = FileUtils().r_info(module, '院区新增')["branch_name"]
    deptid1 = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid1"]
    deptid2 = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid2"]
    deptid3 = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid3"]
    deptid4 = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid4"]
    deptid5 = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid5"]
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload63_12_2_2", userId, mgrBranchId, mgrBranchName,
                                                 deptid1,
                                                 mgrBranchId, mgrBranchName, deptid2, mgrBranchId, mgrBranchName,
                                                 deptid3, mgrBranchId, mgrBranchName, deptid4, mgrBranchId,
                                                 mgrBranchName, deptid5
                                                 )
    print('request_body', request_body)
    # # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == 5:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


def dept_goods_distribute(detpid):  # 科室添加产品信息(产品是从外网同步过来的)
    module = "b2_herp3_bs"
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    # print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()

    #
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_mcmsGoodsInfo_insert")
    print('basic_mcmsGoodsInfo_insert', url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    list2 = []
    i = 1
    while True:
        if i == 1000:
            print('6000秒过去了，产品还没过来，检查同步是否正常')
            break
        try:
            for i in range(1, 6):
                info = FileUtils().r_info8('b5_spd3_core_business_flow', "产品审核信息", 'message%s' % i)
                hosGoodsId = info['hosGoodsId']
                list2.append(hosGoodsId)
        except:
            print('产品没有同步过来，等待6秒')
            time.sleep(6)
            i = i + 1
            continue
        else:
            break

    dept2_id = detpid
    j = 1
    for i in list2:
        # 请求体
        if j == 1:
            request_body = commonFuc().get_business_data(module, "payload58_6_3", dept2_id, i, 20)
        elif j == 2:
            request_body = commonFuc().get_business_data(module, "payload58_6_3", dept2_id, i, 10)
        elif j == 3:
            request_body = commonFuc().get_business_data(module, "payload58_6_3", dept2_id, i, 60)
        else:
            request_body = commonFuc().get_business_data(module, "payload58_6_3", dept2_id, i, 20)
        j = j + 1
        request_body = '[' + str(request_body) + ']'
        new_request_body = request_body.replace("'", '"')
        print(new_request_body)
        import json
        request_body_json = json.loads(new_request_body)
        # # # 发送请求
        result = commonFuc().http_post(url, request_body_json, headers)
        print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
        # 断言
        # checkDict=commonFuc().get_business_data(module,'checkDict10')
        # commonFuc().check_result(checkDict,result)
        code = commonFuc().analysis_json('code', result)
        data = commonFuc().analysis_json('data', result)
        if code == 0 and data == 1:
            commonFuc().check_text_exist(0, result)
        else:
            commonFuc().check_text_exist('error', result)

def get_login_user_uxid():
    module = "b2_herp3_bs"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8(module, "用户名信息", 'message3')
    print(info)
    username1 = info['username1']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token1, projectCode1, uxid1, corpId1, info1 = login_system(username, password).get_token()
    return uxid1

def get_login_user_uxid2():
    module = "b5_spd3_core_business_flow"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8(module, "供货关系申请2", 'message')
    print(info)
    username1 = info['e_username']

    username = username1
    ## print('医院名称',username)
    password = commonFuc().get_business_data(module, "password1")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token1, projectCode1, uxid1, corpId1, info1 = login(username, password,1)
    return uxid1

def comparison_result(actual,expected):
    actual_value1 = get_process_list2(actual)
    expected_value1 = get_process_list2(expected)
    actual_value2 = actual_value1.replace(" ", "")
    expected_value2 = expected_value1.replace(" ", "")
    # print('actual_value2',actual_value2)
    print('expected_value2')
    print(expected_value2)
    print('actual_value2')
    print(actual_value2)
    result = (compare_text_index(actual_value2, expected_value2))
    print('result', result)
    if actual_value2 == expected_value2:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        print('error')
        commonFuc().check_text_exist_result_text('error', 'succees')
def get_prov_id():
    return  FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]

def get_prov_name():
    return  FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]

def get_rec_org_id(type=1):
    if type==1:
        return FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    elif type==2:
        return FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
def get_rec_org_name(type=1):
    if type==1:
        return FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    elif type==2:
        return FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']