# -*- encoding=utf8 -*-
import json
import traceback

from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from air_case.public1.public1.public1 import *
from common.db.sql.sql_del_branch_info import delData
from common.db.sql.sql_tools import get_create_time, check_mcms_dept_buy_car_sql, get_dept_buy_id, \
    check_mcms_dept_buy_sql, get_mdm_goods_code, get_expdt_date, check_mcms_pur_plan_sql, check_in_check_mcms_purchase, \
    get_expdt_date1, process_date, get_mdm_goods_code1, get_goods_code1, get_goods_name, get_goods_gg, \
    get_goods_mfrs_id, get_supply_id, check_mcms_pur_sql, check_source_id, get_pkg_def_id, get_buyBillId, \
    get_planBillId, get_planOrderNo, get_buyOrderNo, get_purOrderNo, get_purBillId, get_distrBillId, \
    get_distrOrderNo, get_distr_detail_id, get_ext_info, get_login_user_uxid_bydb, get_purBillDate, get_purBillDate2, \
    get_mcms_chek_purBillDate, get_PICK_id, get_PICK_order_no, get_account_date, get_checkBillId, get_checkOrderNo, \
    get_psiInBillId, get_psiInOrderNo, check_batch_id, check_barcode_id
from common.db.sql.sql_tools_out import check_out_check_mcms_purchase

from common.fileUtls import FileUtils
from common.run_cmd_script import execute_command
from common.timeUtils import timeUtils
from airtest.core.api import using

__author__ = "xiaohesheng"

"""
case_tag:api,b6_spd3_core_business_flow_database_check,a_b4流程十一请领业务流_二级库向直送,id2303,id2303-14,sit,on
核心业务流:a_b4流程十一请领业务流_二级库向直送
python runner_test.py tag id2303-14 debug mdm3
"""


def check_mcms_dept_buy_car(type=1):
    hos_goods_id = 'hos_goods_id'
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    elif type == 3:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    branch_id = get_branch_id()
    # 获取create_time的值
    create_time = get_create_time(
        "select create_time from mcms_dept_buy_car where branch_id='%s'and hos_goods_id='%s'order by create_time desc LIMIT 1;" % (
            branch_id, hos_goods_id))
    print('create_time', create_time)
    id = get_id(
        "select id from mcms_dept_buy_car where branch_id='%s'and hos_goods_id='%s' order by create_time desc LIMIT 1;" % (
            branch_id, hos_goods_id))
    print('id', id)
    create_user = get_id(
        "select create_user from mcms_dept_buy_car where branch_id='%s'and hos_goods_id='%s' order by create_time desc LIMIT 1;;" % (
            branch_id, hos_goods_id))
    print('create_time', create_time, 'id', id)
    sql = """select * from mcms_dept_buy_car where branch_id='%s' and hos_goods_id='%s' order by create_time desc LIMIT 1;
             """ % (branch_id, hos_goods_id)
    # 要验证的sql，取自数据库的表中
    actual_value1 = check_mcms_dept_buy_car_sql(sql)
    print(actual_value1)
    deptid2 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
    deptname2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    areaCode = get_stockAreaId_new_fromDb(deptname2, 2)
    areaName = '默认库区'
    # 读取文件中的信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "二级库请领产品信息", 'message21')
    list_a = info['list_a']
    mdm_goods_code = commonFuc().analysis_json('mdmGoodsCode', list_a)
    pur_mode = commonFuc().analysis_json('purMode', list_a)
    goodsCode = commonFuc().analysis_json('goodsCode', list_a)
    pkgDefId = commonFuc().analysis_json('pkgDefId', list_a)
    pkgDefName = commonFuc().analysis_json('pkgDefName', list_a)
    last_modified_user = create_user
    last_modified = create_time
    # print('actual_value1',actual_value1)
    actual_value2 = get_process_list2(actual_value1)
    # print('actual_value2')
    # print( actual_value2)
    # prov_hos_goods_id = '8d6273b7bca84dd8aace12b9422d7fd6'
    expected_value2 = 'expected_value2'
    if type == 1 or type == 3:
        expected_value2 = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                        'check_mcms_dept_buy_car_low_value', id, get_hosid(), branch_id,
                                                        deptid2,
                                                        deptname2, areaCode, areaName, hos_goods_id, mdm_goods_code,
                                                        goodsCode, pur_mode, pkgDefId, pkgDefName
                                                        , create_user, create_time, last_modified, last_modified_user)
    elif type == 2:
        expected_value2 = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                        'check_mcms_dept_buy_car_high_value', id, get_hosid(),
                                                        branch_id,
                                                        deptid2,
                                                        deptname2, areaCode, areaName, hos_goods_id, mdm_goods_code,
                                                        goodsCode, pur_mode,
                                                        create_user, create_time, last_modified, last_modified_user)
    # print('expected_value2', expected_value2)
    # expected_value2=get_process_list2(expected_value2)
    actual_value2 = actual_value2.replace(" ", "")
    expected_value2 = expected_value2.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 mcms_dept_buy_detail(type=16):
    branch_id = get_branch_id()
    # 获取主表主键
    sql = "select id from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    id1 = process_tuple(get_dept_buy_id(sql))
    # 获取order_no
    sql1 = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
        branch_id, type)
    order_no1 = get_dept_buy_id(sql1)
    order_no1 = process_tuple(order_no1)
    # 子表sql
    sql1 = "select * from mcms_dept_buy_detail where pid='%s';" % id1
    # 从数据库中获取实际值
    actual = check_mcms_dept_buy_sql(sql1)
    print('actual', actual)
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]

    # print(hos_goods_id,process_tuple(hos_goods_id))

    # 获取子表id
    detail_id = get_id("select id from mcms_dept_buy_detail where pid='%s';" % id1)
    print('detail_id', detail_id)
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "二级库请领产品信息", 'message21')
    list_a = info['list_a']
    mdm_goods_code = process_tuple(
        get_mdm_goods_code("select mdm_goods_code from mcms_goods_info  where id='%s';" % hos_goods_id))
    goods_code = process_tuple(
        get_mdm_goods_code("select hos_goods_code from mcms_goods_info  where id='%s';" % hos_goods_id))
    pkg_def_id = process_tuple(
        get_id("select pkg_def_id from mcms_pkg where hos_goods_id='%s' LIMIT 1;" % hos_goods_id))
    if pkg_def_id == 'None':
        print(pkg_def_id)
        pkg_def_id = pkg_def_id.replace("'", "")
        print(pkg_def_id)
    pkg_def_name = process_tuple(
        get_id("select pkg_def_name from mcms_pkg where hos_goods_id='%s' LIMIT 1;" % hos_goods_id))
    create_user = get_login_user_uxid()
    create_time = get_create_time("select create_time from  mcms_dept_buy_detail where pid='%s';" % id1)
    last_modified = create_time
    last_modified_user = create_user
    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_detail', detail_id, id1, order_no1, hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, pkg_def_name, create_user,
                                                 create_time, last_modified, last_modified_user)
    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_detail1', detail_id, id1, order_no1, hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, pkg_def_name, create_user,
                                                 create_time, last_modified, last_modified_user)
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_detail2', detail_id, id1, order_no1, hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, pkg_def_name, create_user,
                                                 create_time, last_modified, last_modified_user)

    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 check_mcms_dept_buy(type=16):
    branch_id = get_branch_id()
    sql = """select * from mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;
                 """ % (branch_id, type)
    actual = check_mcms_dept_buy_sql(sql)
    print(actual)
    # 获取主键id
    sql = "select id from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    id1 = get_dept_buy_id(sql)
    # 获取order_no
    sql1 = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
        branch_id, type)
    order_no1 = get_dept_buy_id(sql1)
    print(process_tuple(id1), process_tuple(order_no1))
    id1 = process_tuple(id1)
    order_no1 = process_tuple(order_no1)
    deptid2 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
    deptname2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    target_stock_name = get_branch_name() + "中心库房"
    # target_dept_id=FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']

    # area_code = get_stockAreaId_new(deptid2, deptname2, 2)
    info = FileUtils().r_info8("b5_spd3_core_business_flow", "库区信息", 'message22')
    list_a = info['list_a']
    area_code = get_stockAreaId_new_fromDb(deptname2, 2)
    area_name = '默认库区'
    # 读取文件中的信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "二级库请领产品信息", 'message21')
    list_a = info['list_a']
    target_dept_id = commonFuc().analysis_json('targetDeptId', list_a)
    target_dept_name = commonFuc().analysis_json('targetDeptName', list_a)
    pur_mode = commonFuc().analysis_json('purMode', list_a)
    goodsCode = commonFuc().analysis_json('goodsCode', list_a)
    pkgDefId = commonFuc().analysis_json('pkgDefId', list_a)
    pkgDefName = commonFuc().analysis_json('pkgDefName', list_a)

    bill_expdt_date = get_expdt_date(
        "select bill_expdt_date from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    rec_user = get_login_user_uxid()
    # rec_addr='二级检验科002'
    create_user = rec_user
    create_time = get_create_time(
        "select create_time from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    last_modified = get_create_time(
        "select last_modified from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    last_modified_user = rec_user
    last_auditor = rec_user
    last_audit_time = get_create_time(
        "select last_audit_time from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    rec_addr = deptname2
    dept_id1 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    stock_name = get_branch_name() + "中心库房"
    target_stock_id = get_stockId_fromdb(stock_name)
    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_direct_sending', id1, order_no1, get_hosid(), branch_id,
                                                 deptid2,
                                                 deptname2, area_code, area_name, target_dept_id, target_dept_name,
                                                 target_stock_id, target_stock_name, bill_expdt_date, rec_user,
                                                 rec_addr, create_user, create_time,
                                                 last_modified, last_modified_user)
    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_direct_sending2', id1, order_no1, get_hosid(),
                                                 branch_id, deptid2,
                                                 deptname2, area_code, area_name, target_dept_id, target_dept_name,
                                                 target_stock_id, target_stock_name, bill_expdt_date, rec_user,
                                                 rec_addr, create_user, create_time,
                                                 last_modified, last_modified_user)
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_direct_sending3', id1, order_no1, get_hosid(),
                                                 branch_id, deptid2,
                                                 deptname2, area_code, area_name, target_dept_id, target_dept_name,
                                                 target_stock_id, target_stock_name, bill_expdt_date, rec_user,
                                                 rec_addr, create_user, create_time,
                                                 last_modified, last_modified_user)

    print('expected', expected)
    print('aaaaaaaaaaaaaaaaa')
    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)
    print(compare_text_index(actual_value2, expected_value2))
    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 check_mcms_dept_buy_approval_after(type=16):
    branch_id = get_branch_id()
    sql = """select * from mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;
                 """ % (branch_id, type)
    actual = check_mcms_dept_buy_sql(sql)
    print(actual)
    # 获取主键id
    sql = "select id from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    id1 = get_dept_buy_id(sql)
    # 获取order_no
    sql1 = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
        branch_id, type)
    order_no1 = get_dept_buy_id(sql1)
    print(process_tuple(id1), process_tuple(order_no1))
    id1 = process_tuple(id1)
    order_no1 = process_tuple(order_no1)
    deptid2 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
    deptname2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    # target_dept_id=FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']

    # area_code = get_stockAreaId_new(deptid2, deptname2, 2)
    info = FileUtils().r_info8("b5_spd3_core_business_flow", "库区信息", 'message22')
    list_a = info['list_a']
    area_code =get_stockAreaId_new_fromDb(deptname2, 2)
    area_name = '默认库区'
    # 读取文件中的信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "二级库请领产品信息", 'message21')
    list_a = info['list_a']
    target_dept_id = commonFuc().analysis_json('targetDeptId', list_a)
    target_dept_name = commonFuc().analysis_json('targetDeptName', list_a)
    pur_mode = commonFuc().analysis_json('purMode', list_a)
    goodsCode = commonFuc().analysis_json('goodsCode', list_a)
    pkgDefId = commonFuc().analysis_json('pkgDefId', list_a)
    pkgDefName = commonFuc().analysis_json('pkgDefName', list_a)
    # # 获取边仓id
    # target_stock_id = get_id("select logic_id  FROM yb_direct WHERE branch_id ='%s';" % branch_id)
    stock_name = get_branch_name() + "中心库房"
    target_stock_id = get_stockId_fromdb(stock_name)
    bill_expdt_date = get_expdt_date(
        "select bill_expdt_date from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    rec_user = get_login_user_uxid()
    # rec_addr='二级检验科002'
    create_user = rec_user
    create_time = get_create_time(
        "select create_time from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    last_modified = get_create_time(
        "select last_modified from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    last_modified_user = rec_user
    last_auditor = rec_user
    last_audit_time = get_create_time(
        "select last_audit_time from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type))
    target_stock_name = get_branch_name() + "中心库房"

    rec_addr = deptname2
    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_approval_after4', id1, order_no1, get_hosid(),
                                                 branch_id,
                                                 deptid2,
                                                 deptname2, area_code, area_name, target_dept_id, target_dept_name,
                                                 target_stock_id, target_stock_name, bill_expdt_date, rec_user,
                                                 rec_addr, create_user, create_time,
                                                 last_modified, last_modified_user, last_auditor, last_audit_time)
    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_approval_after5', id1, order_no1, get_hosid(),
                                                 branch_id, deptid2,
                                                 deptname2, area_code, area_name, target_dept_id, target_dept_name,
                                                 target_stock_id, target_stock_name, bill_expdt_date, rec_user,
                                                 rec_addr, create_user, create_time,
                                                 last_modified, last_modified_user, last_auditor, last_audit_time)
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_approval_after6', id1, order_no1, get_hosid(),
                                                 branch_id, deptid2,
                                                 deptname2, area_code, area_name, target_dept_id, target_dept_name,
                                                 target_stock_id, target_stock_name, bill_expdt_date, rec_user,
                                                 rec_addr, create_user, create_time,
                                                 last_modified, last_modified_user, last_auditor, last_audit_time)

    print('expected', expected)
    print('aaaaaaaaaaaaaaaaa')
    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)
    print(compare_text_index(actual_value2, expected_value2))
    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 mcms_dept_buy_detail_approval_after(type=16):
    branch_id = get_branch_id()
    # 获取主表主键
    sql = "select id from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    id1 = process_tuple(get_dept_buy_id(sql))
    # 获取order_no
    sql1 = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
        branch_id, type)
    order_no1 = get_dept_buy_id(sql1)
    order_no1 = process_tuple(order_no1)
    # 子表sql
    sql1 = "select * from mcms_dept_buy_detail where pid='%s';" % id1
    # 从数据库中获取实际值
    actual = check_mcms_dept_buy_sql(sql1)
    print('actual', actual)
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]

    # print(hos_goods_id,process_tuple(hos_goods_id))

    # 获取子表id
    detail_id = get_id("select id from mcms_dept_buy_detail where pid='%s';" % id1)
    print('detail_id', detail_id)
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "二级库请领产品信息", 'message21')
    list_a = info['list_a']
    mdm_goods_code = process_tuple(
        get_mdm_goods_code("select mdm_goods_code from mcms_goods_info  where id='%s';" % hos_goods_id))
    goods_code = process_tuple(
        get_mdm_goods_code("select hos_goods_code from mcms_goods_info  where id='%s';" % hos_goods_id))
    pkg_def_id = process_tuple(
        get_id("select pkg_def_id from mcms_pkg where hos_goods_id='%s' LIMIT 1;" % hos_goods_id))
    if pkg_def_id == 'None':
        print(pkg_def_id)
        pkg_def_id = pkg_def_id.replace("'", "")
        print(pkg_def_id)
    pkg_def_name = process_tuple(
        get_id("select pkg_def_name from mcms_pkg where hos_goods_id='%s' LIMIT 1;" % hos_goods_id))
    create_user = get_login_user_uxid()
    create_time = get_create_time("select create_time from  mcms_dept_buy_detail where pid='%s';" % id1)
    last_modified = get_create_time("select last_modified from  mcms_dept_buy_detail where pid='%s';" % id1)
    last_modified_user = create_user
    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_detail_approval_after', detail_id, id1, order_no1,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, pkg_def_name, create_user,
                                                 create_time, last_modified, last_modified_user)
    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_detail_approval_after1', detail_id, id1, order_no1,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, pkg_def_name, create_user,
                                                 create_time, last_modified, last_modified_user)
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_dept_buy_detail_approval_after2', detail_id, id1, order_no1,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, pkg_def_name, create_user,
                                                 create_time, last_modified, last_modified_user)

    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 check_mcms_mcms_pur_plan(type=16):
    branch_id = get_branch_id()
    # 获取请领单主键id
    sql = "select id from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    print(sql)
    id1 = process_tuple(get_dept_buy_id(sql))
    sql = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
        branch_id, type)
    print(sql)
    buyOrderNo1 = process_tuple(get_dept_buy_id(sql))
    # 根据请领单的id获取采购计划单主表主键
    sql = "select id from mcms_pur_plan where branch_id='%s' and source_id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    id2 = process_tuple(get_dept_buy_id(sql))  # 采购计划主表主键
    sql = "select order_no from mcms_pur_plan where branch_id='%s' and source_id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    PLAN_order_no = process_tuple(get_dept_buy_id(sql))  # 采购计划主表order_no

    # 要验证的数据sql
    sql1 = "select * from mcms_pur_plan where branch_id='%s' and source_id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql1)
    print('actual', actual)
    hos_id = get_hosid()
    dept_id1 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    dept_name1 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    dept_name2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    rec_org_id = process_tuple(
        get_id("select id from sys_org where branch_id='%s' and ename='%s';" % (branch_id, dept_name2)))
    rec_org_name = dept_name2
    info = FileUtils().r_info8("b5_spd3_core_business_flow", "库区信息", 'message22')
    list_a = info['list_a']
    area_code =get_stockAreaId_new_fromDb(dept_name2, 2)
    sql1 = "select area_name from mcms_pur_plan where branch_id='%s' and source_id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    area_name = process_tuple(get_id(sql1))
    source_id = id1
    rec_user = get_login_user_uxid()
    sql1 = "select rec_addr from mcms_pur_plan where branch_id='%s' and source_id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    rec_addr = process_tuple(get_id(sql1))
    sql = "select bill_expdt_date from  mcms_pur_plan where branch_id='%s' and source_id='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, id1)
    print(sql)
    bill_expdt_date = get_expdt_date(sql)
    buyBillId = id1
    planBillId = id2
    buyOrderNo = buyOrderNo1
    create_user = rec_user
    create_time = get_create_time(
        "select create_time from mcms_pur_plan where branch_id='%s' and source_id='%s' order by  create_time desc LIMIT 1;" % (
            branch_id, id1))
    last_modified = create_time
    last_modified_user = create_user
    planOrderNo = PLAN_order_no
    if type == 16:
        # 验证子表数据
        check_mcms_mcms_pur_plan_detail(id2, type, planOrderNo)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_pur_plan', id2, PLAN_order_no, hos_id,
                                                 get_branch_id(), dept_id1, dept_name1, rec_org_id, rec_org_name,
                                                 area_code, area_name, source_id, rec_user,
                                                 rec_addr, bill_expdt_date, buyBillId, planBillId, planOrderNo,
                                                 buyOrderNo,
                                                 create_user, create_time, last_modified, last_modified_user)
    elif type == 20:
        check_mcms_mcms_pur_plan_detail(id2, type, planOrderNo)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_pur_plan2', id2, PLAN_order_no, hos_id,
                                                 get_branch_id(), dept_id1, dept_name1, rec_org_id, rec_org_name,
                                                 area_code, area_name, source_id, rec_user,
                                                 rec_addr, bill_expdt_date, buyBillId, planBillId, planOrderNo,
                                                 buyOrderNo,
                                                 create_user, create_time, last_modified, last_modified_user)
    elif type == 66:
        check_mcms_mcms_pur_plan_detail(id2, type, planOrderNo)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_pur_plan3', id2, PLAN_order_no, hos_id,
                                                 get_branch_id(), dept_id1, dept_name1, rec_org_id, rec_org_name,
                                                 area_code, area_name, source_id, rec_user,
                                                 rec_addr, bill_expdt_date, buyBillId, planBillId, planOrderNo,
                                                 buyOrderNo,
                                                 create_user, create_time, last_modified, last_modified_user)
    else:
        expected = None
    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 check_mcms_mcms_pur_plan_detail(id, type, planOrderNo):
    branch_id = get_branch_id()
    # 根据采购计划主表的id获取采购计划单子表主键
    sql = "select id from mcms_pur_plan_detail where pid='%s' order by  create_time desc LIMIT 1;" % (
        id)
    id2 = process_tuple(get_dept_buy_id(sql))  # 采购计划单子表主键
    # # 将采购计划子表主键写入文件中
    # info = (id2, id2)
    # titlename = ("id2", 'id2')
    # FileUtils().w_info8(info, 'b6_spd3_core_business_flow_database_check', '采购计划单子表主键', titlename, 'message')
    sql = "select order_no from mcms_pur_plan where id='%s' order by  create_time desc LIMIT 1;" % (
        id2)
    PLAN_order_no = process_tuple(get_dept_buy_id(sql))  # 采购计划单子表order_no
    # 要验证的数据sql
    sql1 = "select * from mcms_pur_plan_detail where id='%s' order by  create_time desc LIMIT 1;" % (
        id2)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql1)
    print('actual', actual)
    hos_id = get_hosid()
    dept_id1 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    dept_name1 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    dept_name2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    rec_org_id = process_tuple(
        get_id("select id from sys_org where branch_id='%s' and ename='%s';" % (branch_id, dept_name2)))
    rec_user = get_login_user_uxid()
    create_user = rec_user
    # last_modified = create_time
    last_modified_user = create_user
    pid = id
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
        mdm_goods_code = process_tuple(
            get_id("select mdm_goods_code from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        # print(mdm_goods_code)
        goods_code = process_tuple(
            get_id("select goods_code from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        pkg_def_id = process_tuple(
            get_id("select pkg_def_id from mcms_pkg where hos_goods_id='%s' LIMIT 1;" % hos_goods_id))
        supply_id = process_tuple(
            get_id("select supply_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        sub_prov_id = prov_id
        create_time = get_create_time(
            "select create_time from mcms_pur_plan_detail where id='%s';" % (
                id2))
        last_modified = create_time
        sub_prov_name = prov_name
        source_id = process_tuple(
            get_id("select source_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_pur_plan_detail', id2, pid, planOrderNo, source_id, hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, supply_id, prov_id, prov_name,
                                                 sub_prov_id, sub_prov_name,
                                                 create_user, create_time, last_modified, last_modified_user
                                                 )
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
        mdm_goods_code = process_tuple(
            get_id("select mdm_goods_code from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        # print(mdm_goods_code)
        goods_code = process_tuple(
            get_id("select goods_code from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        pkg_def_id = process_tuple(
            get_id("select pkg_def_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        supply_id = process_tuple(
            get_id("select supply_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        sub_prov_id = prov_id
        create_time = get_create_time(
            "select create_time from mcms_pur_plan_detail where id='%s';" % (
                id2))
        last_modified = create_time
        sub_prov_name = prov_name
        source_id = process_tuple(
            get_id("select source_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_pur_plan_detail2', id2, pid, planOrderNo, source_id,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, supply_id, prov_id, prov_name,
                                                 sub_prov_id, sub_prov_name,
                                                 create_user, create_time, last_modified, last_modified_user
                                                 )

    else:

        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
        mdm_goods_code = process_tuple(
            get_id("select mdm_goods_code from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        # print(mdm_goods_code)
        goods_code = process_tuple(
            get_id("select goods_code from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        pkg_def_id = process_tuple(
            get_id("select pkg_def_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        supply_id = process_tuple(
            get_id("select supply_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        sub_prov_id = prov_id
        create_time = get_create_time(
            "select create_time from mcms_pur_plan_detail where id='%s';" % (
                id2))
        last_modified = create_time
        sub_prov_name = prov_name
        source_id = process_tuple(
            get_id("select source_id from mcms_pur_plan_detail where hos_goods_id='%s' and  id='%s';" % (
                hos_goods_id, id2)))
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_pur_plan_detail3', id2, pid, planOrderNo, source_id,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, pkg_def_id, supply_id, prov_id, prov_name,
                                                 sub_prov_id, sub_prov_name,
                                                 create_user, create_time, last_modified, last_modified_user
                                                 )

    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 check_mcms_purchase(type=16):
    branch_id = get_branch_id()
    # 获取采购订单主键id
    sql = "select id from  mcms_purchase where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    print(sql)
    id1 = process_tuple(get_dept_buy_id(sql))
    sql = "select order_no from  mcms_purchase where branch_id='%s' and bill_mode='%s'and id='%s' order by create_time desc LIMIT 1;" % (
        branch_id, type, id1)
    print(sql)
    order_no = process_tuple(get_dept_buy_id(sql))
    sql = "select id from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    print(sql)
    buyBillId = process_tuple(get_dept_buy_id(sql))

    # 要验证的数据sql
    sql1 = "select * from mcms_purchase where branch_id='%s' and bill_mode='%s' and id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, type, id1)
    print(sql1)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql1)
    print('actual', actual)
    hos_id = get_hosid()

    dept_id1 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    dept_name1 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    dept_name2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    rec_org_id = process_tuple(
        get_id("select id from sys_org where branch_id='%s' and ename='%s';" % (branch_id, dept_name2)))
    rec_org_name = dept_name2
    info = FileUtils().r_info8("b5_spd3_core_business_flow", "库区信息", 'message22')
    list_a = info['list_a']
    area_code =get_stockAreaId_new_fromDb(dept_name2, 2)
    sql1 = "select area_name from mcms_purchase where branch_id='%s' and id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    area_name = process_tuple(get_id(sql1))
    rec_user = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1']
    # rec_user = get_login_user_uxid()
    sql1 = "select rec_addr from mcms_purchase where branch_id='%s' and id='%s' order by  create_time desc LIMIT 1;" % (
        branch_id, id1)
    rec_addr = process_tuple(get_id(sql1))
    sql = "select bill_expdt_date from  mcms_pur_plan where branch_id='%s' and source_id='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, buyBillId)
    print(sql)
    bill_expdt_date = get_expdt_date(sql)

    create_user = get_login_user_uxid()
    create_time = get_create_time(
        "select create_time from mcms_purchase where branch_id='%s' and id='%s' order by  create_time desc LIMIT 1;" % (
            branch_id, id1))
    last_modified = get_create_time(
        "select last_modified from mcms_purchase where branch_id='%s' and id='%s' order by  create_time desc LIMIT 1;" % (
            branch_id, id1))
    last_modified_user = create_user
    last_auditor = rec_user
    last_audit_time = get_create_time(
        "select last_audit_time from mcms_purchase where branch_id='%s' and id='%s' order by  create_time desc LIMIT 1;" % (
            branch_id, id1))

    if type == 16:
        # 验证子表数据
        check_mcms_purchase_detail(id1, type, order_no)
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
        planBillId = process_tuple(
            get_id(
                "select pid from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        planOrderNo = process_tuple(
            get_id(
                "select order_no from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        sql = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        buyOrderNo = process_tuple(get_dept_buy_id(sql))
        purOrderNo = order_no
        purBillId = id1
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        exe_prov_id = prov_id
        exe_prov_name = prov_name
        close_date = get_create_time(
            "select close_date from mcms_purchase where id='%s';" % (
                id1))
        source_id = planBillId
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_purchase', id1, order_no, hos_id,
                                                 get_branch_id(), dept_id1, dept_name1, rec_org_id, rec_org_name,
                                                 area_code, area_name, bill_expdt_date, source_id, rec_user,
                                                 rec_addr, prov_id, prov_name, exe_prov_id, exe_prov_name, buyBillId,
                                                 planBillId, planOrderNo,
                                                 buyOrderNo, purOrderNo, purBillId, close_date, create_user,
                                                 create_time, last_modified, last_auditor, last_audit_time
                                                 )

    elif type == 20:
        # 检查采购订单子表
        check_mcms_purchase_detail(id1, type, order_no)
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
        planBillId = process_tuple(
            get_id(
                "select pid from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        planOrderNo = process_tuple(
            get_id(
                "select order_no from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        sql = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        buyOrderNo = process_tuple(get_dept_buy_id(sql))
        purOrderNo = order_no
        purBillId = id1
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        exe_prov_id = prov_id
        exe_prov_name = prov_name
        close_date = get_create_time(
            "select close_date from mcms_purchase where id='%s';" % (
                id1))
        source_id = planBillId
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_purchase2', id1, order_no, hos_id,
                                                 get_branch_id(), dept_id1, dept_name1, rec_org_id, rec_org_name,
                                                 area_code, area_name, bill_expdt_date, source_id, rec_user,
                                                 rec_addr, prov_id, prov_name, exe_prov_id, exe_prov_name, buyBillId,
                                                 planBillId, planOrderNo,
                                                 buyOrderNo, purOrderNo, purBillId, close_date, create_user,
                                                 create_time, last_modified, last_auditor, last_audit_time
                                                 )
    elif type == 66:
        # 检查采购订单子表数据
        check_mcms_purchase_detail(id1, type, order_no)
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
        planBillId = process_tuple(
            get_id(
                "select pid from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        planOrderNo = process_tuple(
            get_id(
                "select order_no from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        sql = "select order_no from  mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        buyOrderNo = process_tuple(get_dept_buy_id(sql))
        purOrderNo = order_no
        purBillId = id1
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        exe_prov_id = prov_id
        exe_prov_name = prov_name
        close_date = get_create_time(
            "select close_date from mcms_purchase where id='%s';" % (
                id1))
        source_id = planBillId
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_purchase3', id1, order_no, hos_id,
                                                 get_branch_id(), dept_id1, dept_name1, rec_org_id, rec_org_name,
                                                 area_code, area_name, bill_expdt_date, source_id, rec_user,
                                                 rec_addr, prov_id, prov_name, exe_prov_id, exe_prov_name, buyBillId,
                                                 planBillId, planOrderNo,
                                                 buyOrderNo, purOrderNo, purBillId, close_date, create_user,
                                                 create_time, last_modified, last_auditor, last_audit_time
                                                 )
    else:
        expected = None
    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 check_mcms_purchase_detail(id, type, OrderNo):
    branch_id = get_branch_id()
    # 根据采购订单主表的id获取采购订单子表主键
    sql = "select id from mcms_purchase_detail where pid='%s' order by  create_time desc LIMIT 1;" % (
        id)
    detail_main_key = process_tuple(get_dept_buy_id(sql))  # 采购订单单子表主键
    sql = "select order_no from mcms_purchase_detail where pid='%s' order by  create_time desc LIMIT 1;" % (
        id)
    PLAN_order_no = process_tuple(get_dept_buy_id(sql))  # 采购计划单子表order_no
    # 要验证的数据sql
    sql1 = "select * from mcms_purchase_detail where pid='%s' order by  create_time desc LIMIT 1;" % (
        id)
    # 获取实际值
    actual = check_mcms_pur_sql(sql1)
    print('actual', actual)
    hos_id = get_hosid()
    dept_id1 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    dept_name1 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    dept_name2 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    rec_org_id = process_tuple(
        get_id("select id from sys_org where branch_id='%s' and ename='%s';" % (branch_id, dept_name2)))
    rec_user = get_login_user_uxid()
    create_user = rec_user
    # last_modified = create_time
    last_modified_user = create_user
    pid = id
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    source_id = get_id(
        "select source_id from mcms_purchase_detail where pid='%s' order by  create_time desc LIMIT 1;" % id)
    if check_source_id(hos_goods_id, source_id) == True:
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    supply_id = get_supply_id(hos_goods_id)
    pkg_def_id = get_pkg_def_id(hos_goods_id)
    planBillId = process_tuple(
        get_id(
            "select pid from mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                hos_goods_id)))
    sql = "select id from  spd3_herp_test2.mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        get_branch_id(), type)
    print(sql)
    buyBillId = process_tuple(get_dept_buy_id(sql))
    buyDetailId = get_id(
        "select id from mcms_dept_buy_detail where pid='%s';" % buyBillId)

    planDetailId = get_id(
        "select id from spd3_herp_test2.mcms_pur_plan_detail where pid='%s';" % planBillId)
    source_id = planDetailId
    goodsGg = get_goods_gg(hos_goods_id)
    goodsCode = get_goods_code1(hos_goods_id)
    goodsName = get_goods_name(hos_goods_id)
    create_user = get_login_user_uxid()
    create_time = get_create_time("select create_time from mcms_purchase_detail where id='%s';" % detail_main_key)
    last_modified = create_time
    last_modified_user = create_user

    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_purchase_detail', detail_main_key, pid, OrderNo, source_id,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, supply_id, pkg_def_id, planBillId,
                                                 buyDetailId, planDetailId,
                                                 goodsGg, goodsCode, goodsName, create_user, create_time, last_modified,
                                                 last_modified_user
                                                 )

    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_purchase_detail1', detail_main_key, pid, OrderNo, source_id,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, supply_id, pkg_def_id, planBillId,
                                                 buyDetailId, planDetailId,
                                                 goodsGg, goodsCode, goodsName, create_user, create_time, last_modified,
                                                 last_modified_user
                                                 )

    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_purchase_detail2', detail_main_key, pid, OrderNo, source_id,
                                                 hos_goods_id,
                                                 mdm_goods_code, goods_code, supply_id, pkg_def_id, planBillId,
                                                 buyDetailId, planDetailId,
                                                 goodsGg, goodsCode, goodsName, create_user, create_time, last_modified,
                                                 last_modified_user)

    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 check_mcms_purchase_out_and_in(type=1):
    branch_id = get_branch_id()
    create_user = get_login_user_uxid2()
    if type == 1:
        sql = "select * from mcms_purchase where branch_id='%s' and create_user='%s' order by create_time desc LIMIT 3;" % (
            branch_id, create_user)
    else:
        sql = "select * from mcms_purchase_detail where create_user='%s' order by create_time desc LIMIT 3;" % create_user
    result_in = check_in_check_mcms_purchase(sql)
    result_out = check_out_check_mcms_purchase(sql)
    result = (compare_text_index(result_in, result_out))
    print(result)
    print(result_in)
    print(result_out)
    i = 0
    while True:
        if i == 1000:
            print('采购订单同步到外网已经过去16分钟未完成，请检查同步是否出现问题')
            commonFuc().check_text_exist_result_text('error', 'succees')
            break
        result_in = check_in_check_mcms_purchase(sql)
        result_out = check_out_check_mcms_purchase(sql)
        if result_in == result_out:
            print('ok')
            commonFuc().check_text_exist_result_text('succees', 'succees')
            break
        else:
            print('error')
            time.sleep(10)
            i = 1 + 10
            continue


def  check_hdi_distr(type=16):
    from common.db.sql.sql_tools_out import check_mcms_pur_plan_sql, get_id
    branch_id = get_branch_id()
    # 验证配送单主表
    sql = "select * from hdi_distr  where branch_id = '%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    hos_id = get_hosid()
    # 获取采购订单id
    purchase_id = get_id(
        "select id from mcms_purchase where branch_id = '%s'  and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
    # 查询配送单主键
    distr_main_key = get_id(
        "select id from hdi_distr a where branch_id = '%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
    # 查询配送单order_no
    distr_order_no = get_id(
        "select order_no from hdi_distr a where id = '%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            distr_main_key, type))
    # 从采购订单获取source_id
    source_id = get_id(
        "select id from mcms_purchase where branch_id = '%s'  and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
    pur_bill_id = source_id
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    rec_user = info['username1']
    sql = "select id from  spd3_herp_test2.mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        branch_id, type)
    print(sql)
    buyBillId = process_tuple(get_dept_buy_id(sql))
    bill_relation_json = get_id(
        "select bill_relation_json from hdi_distr a where id = '%s' and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            distr_main_key, type))
    print(bill_relation_json)
    purBillDate = reGetString(bill_relation_json, r'purBillDate":"', r'""distrBillId')
    distrBillId = distr_main_key
    distrOrderNo = distr_order_no
    distrUser = get_login_user_uxid2()
    create_user = distrUser
    create_user_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    create_time = get_create_time(
        "select create_time from hdi_distr where branch_id = '%s'  and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
    last_modified_user = distrUser
    if type == 16:
        # 验证子表数据
        check_hdi_distr_detail(distr_main_key, type, purchase_id)
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]

        planBillId = process_tuple(
            get_id(
                "select pid from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))

        planOrderNo = process_tuple(
            get_id(
                "select order_no from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        sql = "select order_no from  spd3_herp_test2.mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        buyOrderNo = process_tuple(get_dept_buy_id(sql))
        sql = "select id from  mcms_purchase where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        id1 = process_tuple(get_dept_buy_id(sql))
        sql = "select order_no from  mcms_purchase where branch_id='%s' and bill_mode='%s'and id='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type, id1)
        print(sql)
        purOrderNo = process_tuple(get_dept_buy_id(sql))
        purBillId = id1
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        exe_prov_id = prov_id
        exe_prov_name = prov_name
        pur_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
        pur_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
        rec_org_id = process_tuple(
            get_id("select id from spd3_herp_test2.sys_org where branch_id='%s' and ename='%s';" % (
                branch_id, FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2'])))
        rec_org_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
        last_modified = get_create_time(
        "select last_modified from hdi_distr where branch_id = '%s'  and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
        confirmUser = distrUser
        ext_info = get_ext_info(branch_id, type)
        confirmTime = reGetString(ext_info, r'"confirmTime":"', r'""confirmUser')
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'hdi_distr', distr_main_key, distr_order_no, hos_id, get_hosname(),
                                                 get_branch_id(), source_id, pur_bill_id, prov_id, prov_name,
                                                 exe_prov_id, exe_prov_name, pur_dept_id, pur_dept_name, rec_org_id,
                                                 rec_org_name, rec_user, buyBillId, planBillId, planOrderNo, buyOrderNo,
                                                 purOrderNo, purBillId, purBillDate, distrBillId, distrOrderNo,
                                                 confirmTime, confirmUser, distrUser, create_user, create_user_name,
                                                 create_time, last_modified,
                                                 last_modified_user
                                                 )

    elif type == 20:
        # 验证子表数据
        check_hdi_distr_detail(distr_main_key, type, purchase_id)
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]

        planBillId = process_tuple(
            get_id(
                "select pid from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))

        planOrderNo = process_tuple(
            get_id(
                "select order_no from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        sql = "select order_no from  spd3_herp_test2.mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        buyOrderNo = process_tuple(get_dept_buy_id(sql))
        sql = "select id from  mcms_purchase where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        id1 = process_tuple(get_dept_buy_id(sql))
        sql = "select order_no from  mcms_purchase where branch_id='%s' and bill_mode='%s'and id='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type, id1)
        print(sql)
        purOrderNo = process_tuple(get_dept_buy_id(sql))
        purBillId = id1
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        exe_prov_id = prov_id
        exe_prov_name = prov_name
        pur_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
        pur_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
        rec_org_id = process_tuple(
            get_id("select id from spd3_herp_test2.sys_org where branch_id='%s' and ename='%s';" % (
                branch_id, FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2'])))
        rec_org_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
        last_modified = get_create_time(
        "select last_modified from hdi_distr where branch_id = '%s'  and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
        confirmUser = distrUser
        ext_info = get_ext_info(branch_id, type)
        confirmTime = reGetString(ext_info, r'"confirmTime":"', r'""confirmUser')
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'hdi_distr1', distr_main_key, distr_order_no, hos_id, get_hosname(),
                                                 get_branch_id(), source_id, pur_bill_id, prov_id, prov_name,
                                                 exe_prov_id, exe_prov_name, pur_dept_id, pur_dept_name, rec_org_id,
                                                 rec_org_name, rec_user, buyBillId, planBillId, planOrderNo, buyOrderNo,
                                                 purOrderNo, purBillId, purBillDate, distrBillId, distrOrderNo,
                                                 confirmTime, confirmUser, distrUser, create_user, create_user_name,
                                                 create_time, last_modified,
                                                 last_modified_user
                                                 )

    elif type == 66:
        # 验证子表数据
        check_hdi_distr_detail(distr_main_key, type, purchase_id)
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]

        planBillId = process_tuple(
            get_id(
                "select pid from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))

        planOrderNo = process_tuple(
            get_id(
                "select order_no from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                    hos_goods_id)))
        sql = "select order_no from  spd3_herp_test2.mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        buyOrderNo = process_tuple(get_dept_buy_id(sql))
        sql = "select id from  mcms_purchase where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
            branch_id, type)
        print(sql)
        id1 = process_tuple(get_dept_buy_id(sql))
        sql = "select order_no from  mcms_purchase where branch_id='%s' and bill_mode='%s'and id='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type, id1)
        print(sql)
        purOrderNo = process_tuple(get_dept_buy_id(sql))
        purBillId = id1
        prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
        prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
        exe_prov_id = prov_id
        exe_prov_name = prov_name
        pur_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
        pur_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
        rec_org_id = process_tuple(
            get_id("select id from spd3_herp_test2.sys_org where branch_id='%s' and ename='%s';" % (
                branch_id, FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2'])))
        rec_org_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
        last_modified = get_create_time(
        "select last_modified from hdi_distr where branch_id = '%s'  and bill_mode='%s' order by create_time desc LIMIT 1;" % (
            branch_id, type))
        confirmUser = distrUser
        ext_info = get_ext_info(branch_id, type)
        confirmTime = reGetString(ext_info, r'"confirmTime":"', r'""confirmUser')
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'hdi_distr2', distr_main_key, distr_order_no, hos_id, get_hosname(),
                                                 get_branch_id(), source_id, pur_bill_id, prov_id, prov_name,
                                                 exe_prov_id, exe_prov_name, pur_dept_id, pur_dept_name, rec_org_id,
                                                 rec_org_name, rec_user, buyBillId, planBillId, planOrderNo, buyOrderNo,
                                                 purOrderNo, purBillId, purBillDate, distrBillId, distrOrderNo,
                                                 confirmTime, confirmUser, distrUser, create_user, create_user_name,
                                                 create_time, last_modified,
                                                 last_modified_user
                                                 )

    else:
        expected = None
    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 check_hdi_distr_detail(distr_main_key, type, purchase_id):
    sql = "select * from hdi_distr_detail where pid = '%s';" % distr_main_key
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    # 获取子表主键
    distr_detail_main_key = get_id(
        "select id from hdi_distr_detail where pid = '%s';" % (
            distr_main_key))
    source_id = purchase_id
    source_detail_id = get_id("select id from mcms_purchase_detail where pid='%s'" % purchase_id)
    pur_detail_id = source_detail_id
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]

    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    goods_name = get_goods_name(hos_goods_id)
    goods_gg = get_goods_gg(hos_goods_id)
    mfrs_id = get_goods_mfrs_id(hos_goods_id)
    expdt_date = get_expdt_date(
        "select expdt_date from hdi_distr_detail where pid = '%s';" % (
            distr_main_key))
    product_date = get_expdt_date(
        "select product_date from hdi_distr_detail where pid = '%s';" % (
            distr_main_key))
    pkg_def_id = process_tuple(
        get_id("select pkg_def_id from mcms_pkg where hos_goods_id='%s' LIMIT 1;" % hos_goods_id))
    supply_id = get_supply_id(hos_goods_id)
    sub_prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    sub_prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    planBillId = process_tuple(
        get_id(
            "select pid from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
                hos_goods_id)))
    sql = "select id from  spd3_herp_test2.mcms_dept_buy where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        get_branch_id(), type)
    print(sql)
    buyBillId = process_tuple(get_dept_buy_id(sql))
    buyDetailId = get_id(
        "select id from mcms_dept_buy_detail where pid='%s';" % buyBillId)
    # planBillId = process_tuple(
    #     get_id(
    #         "select pid from spd3_herp_test2.mcms_pur_plan_detail  where hos_goods_id='%s' order by create_time desc  LIMIT 1;" % (
    #             hos_goods_id)))
    planDetailId = get_id(
        "select id from spd3_herp_test2.mcms_pur_plan_detail where pid='%s';" % planBillId)
    purDetailId = pur_detail_id
    sql = "select id from  mcms_purchase where branch_id='%s' and bill_mode='%s' order by create_time desc  LIMIT 1;" % (
        get_branch_id(), type)
    print(sql)
    id1 = process_tuple(get_dept_buy_id(sql))
    purBillId = id1
    distrDetailId = distr_detail_main_key
    distrBillId = distr_main_key
    erpCode = mdm_goods_code  # 11661563
    create_user = get_login_user_uxid2()
    create_time = get_create_time(
        "select create_time from hdi_distr_detail where id = '%s';" % (
            distr_detail_main_key))
    last_modified = get_create_time(
        "select last_modified from hdi_distr_detail where id = '%s';" % (
            distr_detail_main_key))
    last_modified_user = create_user
    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'hdi_distr_detail', distr_detail_main_key, distr_main_key, source_id,
                                                 source_detail_id, pur_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, goods_name, goods_gg,
                                                 mfrs_id, expdt_date, product_date
                                                 , pkg_def_id, supply_id, sub_prov_id, sub_prov_name, planBillId,
                                                 buyDetailId, planDetailId, purDetailId, purBillId, distrDetailId,
                                                 distrBillId, goods_gg, goods_code, goods_name, erpCode, create_user,
                                                 create_time, last_modified, last_modified_user)
    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'hdi_distr_detail2', distr_detail_main_key, distr_main_key, source_id,
                                                 source_detail_id, pur_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, goods_name, goods_gg,
                                                 mfrs_id, expdt_date, product_date
                                                 , pkg_def_id, supply_id, sub_prov_id, sub_prov_name, planBillId,
                                                 buyDetailId, planDetailId, purDetailId, purBillId, distrDetailId,
                                                 distrBillId, goods_gg, goods_code, goods_name, erpCode, create_user,
                                                 create_time, last_modified, last_modified_user)
    elif type == 66:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'hdi_distr_detail3', distr_detail_main_key, distr_main_key, source_id,
                                                 source_detail_id, pur_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, goods_name, goods_gg,
                                                 mfrs_id, expdt_date, product_date
                                                 , pkg_def_id, supply_id, sub_prov_id, sub_prov_name, planBillId,
                                                 buyDetailId, planDetailId, purDetailId, purBillId, distrDetailId,
                                                 distrBillId, goods_gg, goods_code, goods_name, erpCode, create_user,
                                                 create_time, last_modified, last_modified_user)
    else:
        expected = None

    # 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 check_mcms_check(type=1):
    if type == 1:
        bill_mode = 16
    elif type == 2:
        bill_mode = 20
    else:
        bill_mode = 66
    print('检查验收单数据库写值')
    check_no = FileUtils().r_info8('b5_spd3_core_business_flow', '验收单号', 'message15')['CHECK_NO1']
    sql = "select * from mcms_check where id = '%s';" % check_no
    order_no = get_id("select order_no from mcms_check where id = '%s';" % check_no)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    if type == 1:
        source_id = FileUtils().r_info8('b5_spd3_core_business_flow', '低值配送单号', 'message10')['distrBillId1']
    elif type == 2:
        source_id = FileUtils().r_info8('b5_spd3_core_business_flow', '高值配送单号', 'message10')['distrBillId1']
    else:
        source_id = FileUtils().r_info8('b5_spd3_core_business_flow', '试剂配送单号', 'message10')['distrBillId1']
    source_no = source_id
    prov_id = get_prov_id()
    prov_name = get_prov_name()
    rec_org_id = get_rec_org_id(2)
    rec_org_name = get_rec_org_name(2)
    dept_id = rec_org_id
    dept_name = rec_org_name
    branch_id = get_branch_id()
    buyBillId = get_buyBillId(branch_id, bill_mode)
    buyOrderNo = get_buyOrderNo(branch_id, bill_mode)
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    planBillId = get_planBillId(hos_goods_id)
    planOrderNo = get_planOrderNo(hos_goods_id)
    purOrderNo = get_purOrderNo(branch_id, bill_mode)
    purBillId = get_purBillId(branch_id, bill_mode)
    bill_relation_json = get_mcms_chek_purBillDate(branch_id, bill_mode)
    purBillDate = reGetString(bill_relation_json, r'purBillDate":"', r'""distrBillId')
    distrBillId = get_distrBillId(branch_id, bill_mode)
    distrOrderNo = get_distrOrderNo(branch_id, bill_mode)
    checkBillId = check_no
    checkOrderNo = order_no
    create_user = get_login_user_uxid()
    sql = "select create_time from mcms_check where id='%s';" % check_no
    create_time = get_create_time(sql)
    sql = "select last_modified from mcms_check where id='%s';" % check_no
    last_modified = get_create_time(sql)
    last_modified_user = create_user
    if type == 1:
        check_mcms_check_batch(type, check_no, order_no, hos_goods_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'mcms_check', check_no,
                                                 order_no, get_hosid(), get_branch_id(), source_id, source_no, prov_id,
                                                 prov_name, rec_org_id, rec_org_name, dept_id, dept_name, buyBillId,
                                                 planBillId, planOrderNo, buyOrderNo, purOrderNo, purBillId,
                                                 purBillDate,
                                                 distrBillId, distrOrderNo, checkBillId, checkOrderNo, create_user,
                                                 create_time, last_modified,
                                                 last_modified_user)
    elif type == 2:
        check_mcms_check_batch(type, check_no, order_no, hos_goods_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'mcms_check1', check_no,
                                                 order_no, get_hosid(), get_branch_id(), source_id, source_no, prov_id,
                                                 prov_name, rec_org_id, rec_org_name, dept_id, dept_name, buyBillId,
                                                 planBillId, planOrderNo, buyOrderNo, purOrderNo, purBillId,
                                                 purBillDate,
                                                 distrBillId, distrOrderNo, checkBillId, checkOrderNo, create_user,
                                                 create_time, last_modified,
                                                 last_modified_user)
    else:
        check_mcms_check_batch(type, check_no, order_no, hos_goods_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'mcms_check2', check_no,
                                                 order_no, get_hosid(), get_branch_id(), source_id, source_no, prov_id,
                                                 prov_name, rec_org_id, rec_org_name, dept_id, dept_name, buyBillId,
                                                 planBillId, planOrderNo, buyOrderNo, purOrderNo, purBillId,
                                                 purBillDate,
                                                 distrBillId, distrOrderNo, checkBillId, checkOrderNo, create_user,
                                                 create_time, last_modified,
                                                 last_modified_user)
    # 对比预期值和实际值是否一致
    # 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 check_mcms_check_batch(type, check_no, order_no, hos_goods_id):
    print('数据库检查验收单子表')
    if type == 1:
        bill_mode = 16
    elif type == 2:
        bill_mode = 20
    else:
        bill_mode = 66
    sql = "select * from mcms_check_batch where pid='%s'" % check_no
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    id = get_id("select id from mcms_check_batch where pid='%s'" % check_no)
    pid = check_no
    branch_id = get_branch_id()
    distr_detail_id = get_distr_detail_id(branch_id, bill_mode)
    source_detail_id = distr_detail_id
    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    sql = "select id from hdi_barcode  where code_type='%s' and branch_id='%s' order by create_time desc LIMIT 1;" % (
        bill_mode, branch_id)
    barcode_id = get_id(sql)
    create_user = get_login_user_uxid()
    create_time = get_create_time("select create_time from mcms_check_batch where pid='%s'" % check_no)
    last_modified = get_create_time("select last_modified from mcms_check_batch where pid='%s'" % check_no)
    last_modified_user = create_user
    if type == 1:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'mcms_check_batch', id,
                                                 pid, order_no, source_detail_id, distr_detail_id, hos_goods_id,
                                                 mdm_goods_code,
                                                 goods_code, barcode_id, create_user, create_time, last_modified,
                                                 last_modified_user
                                                 )
    elif type == 2:

        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'mcms_check_batch1', id,
                                                 pid, order_no, source_detail_id, distr_detail_id, hos_goods_id,
                                                 mdm_goods_code,
                                                 goods_code, barcode_id, create_user, create_time, last_modified,
                                                 last_modified_user
                                                 )
    else:

        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'mcms_check_batch2', id,
                                                 pid, order_no, source_detail_id, distr_detail_id, hos_goods_id,
                                                 mdm_goods_code,
                                                 goods_code, barcode_id, create_user, create_time, last_modified,
                                                 last_modified_user
                                                 )
    # 对比预期值和实际值是否一致
    # 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 check_mcms_psi(type=1):
    print('检查中心库入库单和出库单')
    if type == 1:
        bill_mode = 16
    elif type == 2:
        bill_mode = 20
    else:
        bill_mode = 66
    branch_id = get_branch_id()
    sql = "select * from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='RK_YS' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    sql = "select id from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='RK_YS' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    id = get_id(sql)
    sql = "select order_no from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='RK_YS' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    order_no = get_id(sql)
    target_corp_id = get_hosid()
    target_branch_id = get_branch_id()
    target_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    target_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    stock_name = get_branch_name() + "中心库房"
    target_stock_id = get_stockId_fromdb(stock_name)
    target_area_code = get_stockAreaId_new_fromDb(target_dept_name, 1)
    source_id = FileUtils().r_info8('b5_spd3_core_business_flow', '验收单号', 'message15')['CHECK_NO1']
    source_no = get_distrBillId(branch_id, bill_mode)
    source_repl_id = source_no
    source_corp_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    source_dept_id = source_corp_id
    source_dept_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    source_stock_id = source_corp_id
    accounter = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    account_date = get_create_time("select account_date from  mcms_psi where id='%s';" % id)

    buyBillId = get_buyBillId(branch_id, bill_mode)
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    planBillId = get_planBillId(hos_goods_id)
    planOrderNo = get_planOrderNo(hos_goods_id)
    buyOrderNo = get_buyOrderNo(branch_id, bill_mode)
    purOrderNo = get_purOrderNo(branch_id, bill_mode)
    purBillId = get_purBillId(branch_id, bill_mode)
    bill_relation_json = get_purBillDate2(branch_id, bill_mode)
    purBillDate = reGetString(bill_relation_json, r'purBillDate":"', r'""distrBillId')
    distrBillId = get_distrBillId(branch_id, bill_mode)
    distrOrderNo = get_distrOrderNo(branch_id, bill_mode)
    checkBillId = source_id
    sql = "select order_no from mcms_check where id='%s';" % checkBillId
    checkOrderNo = get_id(sql)
    psiInBillId = id
    psiInOrderNo = order_no
    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_psi where id='%s';" % id)
    last_modified = get_create_time("select last_modified from  mcms_psi where id='%s';" % id)
    last_modified_user = create_user
    if type == 1:
        # 检查子表
        check_mcms_psi_batch_in(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_psi1', id,
                                                 order_no, target_corp_id, target_branch_id, target_dept_id,
                                                 target_dept_name, target_stock_id
                                                 , target_area_code, source_id, source_no, source_repl_id,
                                                 source_corp_id, source_dept_id, source_dept_name
                                                 , source_stock_id, accounter, account_date, buyBillId, planBillId,
                                                 planOrderNo, buyOrderNo, purOrderNo, purBillId
                                                 , purBillDate, distrBillId, distrOrderNo, checkBillId, checkOrderNo,
                                                 psiInBillId, psiInOrderNo, create_user
                                                 , create_time, last_modified, last_modified_user)
    elif type == 2:
        check_mcms_psi_batch_in(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_psi2', id,
                                                 order_no, target_corp_id, target_branch_id, target_dept_id,
                                                 target_dept_name, target_stock_id
                                                 , target_area_code, source_id, source_no, source_repl_id,
                                                 source_corp_id, source_dept_id, source_dept_name
                                                 , source_stock_id, accounter, account_date, buyBillId, planBillId,
                                                 planOrderNo, buyOrderNo, purOrderNo, purBillId
                                                 , purBillDate, distrBillId, distrOrderNo, checkBillId, checkOrderNo,
                                                 psiInBillId, psiInOrderNo, create_user
                                                 , create_time, last_modified, last_modified_user)
    else:
        check_mcms_psi_batch_in(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_psi3', id,
                                                 order_no, target_corp_id, target_branch_id, target_dept_id,
                                                 target_dept_name, target_stock_id
                                                 , target_area_code, source_id, source_no, source_repl_id,
                                                 source_corp_id, source_dept_id, source_dept_name
                                                 , source_stock_id, accounter, account_date, buyBillId, planBillId,
                                                 planOrderNo, buyOrderNo, purOrderNo, purBillId
                                                 , purBillDate, distrBillId, distrOrderNo, checkBillId, checkOrderNo,
                                                 psiInBillId, psiInOrderNo, create_user
                                                 , create_time, last_modified, last_modified_user)
    # 对比预期值和实际值是否一致
    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')
    # 检查中心库出库单====================================================================
    sql = "select * from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='CK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    sql = "select id from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='CK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    id_out = get_id(sql)
    sql = "select order_no from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='CK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    order_no_out = get_id(sql)
    target_corp_id = get_hosid()
    target_branch_id = get_branch_id()
    target_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
    target_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    stock_name = target_dept_name + "库房"
    target_stock_id = get_stockId_fromdb(stock_name)
    target_area_code = get_stockAreaId_new_fromDb(target_dept_name, 2)
    source_id_out = id
    source_no_out = order_no
    source_repl_id = source_no
    source_corp_id = get_hosid()
    source_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    source_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    source_stock_id = get_stockId_fromdb(get_branch_name() + '中心库房')
    accounter = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    account_date = get_create_time("select account_date from  mcms_psi where id='%s';" % id_out)

    buyBillId = get_buyBillId(branch_id, bill_mode)
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    planBillId = get_planBillId(hos_goods_id)
    planOrderNo = get_planOrderNo(hos_goods_id)
    buyOrderNo = get_buyOrderNo(branch_id, bill_mode)
    purOrderNo = get_purOrderNo(branch_id, bill_mode)
    purBillId = get_purBillId(branch_id, bill_mode)
    bill_relation_json = get_purBillDate2(branch_id, bill_mode)
    purBillDate = reGetString(bill_relation_json, r'purBillDate":"', r'""distrBillId')
    distrBillId = get_distrBillId(branch_id, bill_mode)
    distrOrderNo = get_distrOrderNo(branch_id, bill_mode)
    checkBillId = source_id
    sql = "select order_no from mcms_check where id='%s';" % checkBillId
    checkOrderNo = get_id(sql)
    psiInBillId = id
    psiInOrderNo = order_no
    psiOutBillId = id_out
    psiOutOrderNo = order_no_out
    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_psi where id='%s';" % id_out)
    last_modified = get_create_time("select last_modified from  mcms_psi where id='%s';" % id_out)
    last_modified_user = create_user
    source_branch_id = get_branch_id()
    source_area_code = get_stockAreaId_new_fromDb(source_dept_name)
    if type == 1:
        check_mcms_psi_batch_out(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_psi_out1',
                                                 id_out,
                                                 order_no_out, target_corp_id, target_branch_id, target_dept_id,
                                                 target_dept_name, target_stock_id
                                                 , target_area_code, source_id_out, source_no_out, source_repl_id,
                                                 source_corp_id, source_branch_id, source_dept_id, source_dept_name
                                                 , source_stock_id, source_area_code, buyBillId, planBillId,
                                                 planOrderNo, buyOrderNo, purOrderNo, purBillId
                                                 , purBillDate, distrBillId, distrOrderNo, checkBillId, checkOrderNo,
                                                 psiInBillId, psiInOrderNo, psiOutBillId, psiOutOrderNo, create_user
                                                 , create_time, last_modified, last_modified_user)
    elif type == 2:
        check_mcms_psi_batch_out(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_psi_out2',
                                                 id_out,
                                                 order_no_out, target_corp_id, target_branch_id, target_dept_id,
                                                 target_dept_name, target_stock_id
                                                 , target_area_code, source_id_out, source_no_out, source_repl_id,
                                                 source_corp_id, source_branch_id, source_dept_id, source_dept_name
                                                 , source_stock_id, source_area_code, buyBillId, planBillId,
                                                 planOrderNo, buyOrderNo, purOrderNo, purBillId
                                                 , purBillDate, distrBillId, distrOrderNo, checkBillId, checkOrderNo,
                                                 psiInBillId, psiInOrderNo, psiOutBillId, psiOutOrderNo, create_user
                                                 , create_time, last_modified, last_modified_user)
    else:
        check_mcms_psi_batch_out(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_psi_out3',
                                                 id_out,
                                                 order_no_out, target_corp_id, target_branch_id, target_dept_id,
                                                 target_dept_name, target_stock_id
                                                 , target_area_code, source_id_out, source_no_out, source_repl_id,
                                                 source_corp_id, source_branch_id, source_dept_id, source_dept_name
                                                 , source_stock_id, source_area_code, buyBillId, planBillId,
                                                 planOrderNo, buyOrderNo, purOrderNo, purBillId
                                                 , purBillDate, distrBillId, distrOrderNo, checkBillId, checkOrderNo,
                                                 psiInBillId, psiInOrderNo, psiOutBillId, psiOutOrderNo, create_user
                                                 , create_time, last_modified, last_modified_user)
    # 对比预期值和实际值是否一致
    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 check_mcms_psi_dept_in(type=16):
    bill_mode = type
    branch_id = get_branch_id()
    sql = " select * from  mcms_psi_dept where target_branch_id='%s' and bill_mode='%s' and stock_kind='RK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    actual = check_mcms_dept_buy_sql(sql)
    print(actual)
    # 获取主键
    id = get_id(
        " select id from  mcms_psi_dept where target_branch_id='%s' and bill_mode='%s' and stock_kind='RK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
            branch_id, bill_mode))
    # 获取source_id
    sql = "select id from  mcms_psi  where target_branch_id='%s' and bill_mode='%s' and stock_kind='CK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    source_id = get_id(sql)
    source_no = get_id("select order_no from  mcms_psi where id='%s';" % source_id)
    # 获取order_no
    sql = " select order_no from  mcms_psi_dept where target_branch_id='%s' and bill_mode='%s' and stock_kind='RK_QL' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, bill_mode)
    order_no = get_id(sql)
    target_corp_id = get_hosid()
    target_branch_id = get_branch_id()
    target_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid2']
    target_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    target_stock_id = get_stockId_fromdb(target_dept_name + '库房')
    target_area_code = get_stockAreaId_new_fromDb(target_dept_name, 2)
    PICK_id = get_PICK_id(branch_id, bill_mode)

    source_corp_id = get_hosid()
    source_branch_id = get_branch_id()
    source_dept_id = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    source_dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    source_stock_id = get_stockId_fromdb(get_branch_name() + '中心库房')
    source_area_code = get_stockAreaId_new_fromDb(source_dept_name, 1)
    buyBillId = get_buyBillId(branch_id, bill_mode)
    pickOrderNo = get_PICK_order_no(branch_id, bill_mode)
    buyOrderNo = get_buyOrderNo(branch_id, bill_mode)
    pickBillId = get_PICK_id(branch_id, bill_mode)
    psiDeptOutBillId = source_id
    psiDeptOutOrderNo = source_no
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    elif type == 66:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    else:
        hos_goods_id = None
    planBillId = get_planBillId(hos_goods_id)
    purOrderNo = get_purOrderNo(branch_id, bill_mode)
    purBillId = get_purBillId(branch_id, bill_mode)
    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_psi_dept where id='%s';" % id)
    last_modified = get_create_time("select last_modified from  mcms_psi_dept where id='%s';" % id)
    last_modified_user = create_user
    accounter = create_user
    sql = "select account_date from  mcms_psi_dept where id='%s';" % id
    account_date = get_account_date(sql)
    psiDeptInBillId = id
    psiDeptInOrderNo = order_no
    source_repl_id = get_distrBillId(branch_id, bill_mode)
    bill_relation_json = get_id(
        "select bill_relation_json from mcms_psi_dept a where id = '%s';" % (
            id))
    print(bill_relation_json)
    purBillDate = reGetString(bill_relation_json, r'purBillDate":"', r'""distrBillId')
    distrBillId = get_distrBillId(branch_id, bill_mode)
    distrOrderNo = get_distrOrderNo(branch_id, bill_mode)
    checkBillId = get_checkBillId(branch_id, bill_mode)
    checkOrderNo = get_checkOrderNo(branch_id, bill_mode)
    psiInBillId = get_psiInBillId(branch_id, bill_mode)
    psiInOrderNo = get_psiInOrderNo(branch_id, bill_mode)
    planOrderNo = get_planOrderNo(hos_goods_id)
    if type == 16:
        # 子表检查
        check_mcms_psi_dept_batch_in(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_dept_in_4', id, order_no, target_corp_id, target_branch_id,
                                                 target_dept_id, target_dept_name, target_stock_id
                                                 , target_area_code, source_id, source_no, source_repl_id,
                                                 source_corp_id, source_branch_id,
                                                 source_dept_id, source_dept_name, source_stock_id, source_area_code,
                                                 accounter, account_date, buyBillId, planBillId, planOrderNo,
                                                 buyOrderNo, purOrderNo, purBillId, purBillDate, distrBillId,
                                                 distrOrderNo, checkBillId, checkOrderNo, psiInBillId, psiInOrderNo,
                                                 psiDeptOutBillId, psiDeptOutOrderNo, psiDeptInBillId, psiDeptInOrderNo,
                                                 create_user, create_time, last_modified, last_modified_user)


    elif type == 20:
        # 子表检查
        check_mcms_psi_dept_batch_in(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_dept_in_5', id, order_no, target_corp_id, target_branch_id,
                                                 target_dept_id, target_dept_name, target_stock_id
                                                 , target_area_code, source_id, source_no, source_repl_id,
                                                 source_corp_id, source_branch_id,
                                                 source_dept_id, source_dept_name, source_stock_id, source_area_code,
                                                 accounter, account_date, buyBillId, planBillId, planOrderNo,
                                                 buyOrderNo, purOrderNo, purBillId, purBillDate, distrBillId,
                                                 distrOrderNo, checkBillId, checkOrderNo, psiInBillId, psiInOrderNo,
                                                 psiDeptOutBillId, psiDeptOutOrderNo, psiDeptInBillId, psiDeptInOrderNo,
                                                 create_user, create_time, last_modified, last_modified_user)


    else:
        # 子表检查
        check_mcms_psi_dept_batch_in(id, type, order_no, source_id)
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_dept_in_6', id, order_no, target_corp_id, target_branch_id,
                                                 target_dept_id, target_dept_name, target_stock_id
                                                 , target_area_code, source_id, source_no, source_repl_id,
                                                 source_corp_id, source_branch_id,
                                                 source_dept_id, source_dept_name, source_stock_id, source_area_code,
                                                 accounter, account_date, buyBillId, planBillId, planOrderNo,
                                                 buyOrderNo, purOrderNo, purBillId, purBillDate, distrBillId,
                                                 distrOrderNo, checkBillId, checkOrderNo, psiInBillId, psiInOrderNo,
                                                 psiDeptOutBillId, psiDeptOutOrderNo, psiDeptInBillId, psiDeptInOrderNo,
                                                 create_user, create_time, last_modified, last_modified_user)

    print('expected', expected)
    print('aaaaaaaaaaaaaaaaa')
    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)
    print(compare_text_index(actual_value2, expected_value2))
    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 check_mcms_psi_dept_batch_in(DR_ID, type, order_no, source_id1):
    branch_id = get_branch_id()
    sql = " select * from  mcms_psi_dept_batch where pid='%s';" % (
        DR_ID)
    actual = check_mcms_dept_buy_sql(sql)
    print('actual', actual)
    batch_main_key = get_id("select id from mcms_psi_dept_batch where pid='%s';" % DR_ID)
    pid = DR_ID
    # order_no = get_id("select order_no from mcms_psi_dept_batch where pid='%s';" % DR_ID)
    source_detail_id = source_id1 + '0001'
    pick_detail_id = None
    if type == 16:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 20:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    pkg_def_id = get_pkg_def_id(hos_goods_id)
    picker_name = FileUtils().r_info8("b2_herp3_bs", "用户名信息", 'message3')['username1']
    picker = get_login_user_uxid_bydb(picker_name)
    source_batch_id = get_id("select source_batch_id from mcms_psi_dept_batch where pid='%s';" % DR_ID)
    target_batch_id = source_batch_id
    if check_batch_id(source_batch_id) == True:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    barcode_id = get_id("select barcode_id from mcms_psi_dept_batch where pid='%s';" % DR_ID)
    if check_barcode_id(barcode_id) == True:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    shelf_code = get_stockAreaId_new_fromDb(dept_name, 2)
    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_psi_dept_batch where pid='%s';" % DR_ID)
    last_modified = get_create_time("select last_modified from  mcms_psi_dept_batch where pid='%s';" % DR_ID)
    last_modified_user = create_user
    if type == 16:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_dept_batch_in4', batch_main_key, pid, order_no,
                                                 source_detail_id
                                                 , pick_detail_id, hos_goods_id, mdm_goods_code, goods_code,
                                                 source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified

                                                 )
    elif type == 20:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_dept_batch_in5', batch_main_key, pid, order_no,
                                                 source_detail_id
                                                 , pick_detail_id, hos_goods_id, mdm_goods_code, goods_code,
                                                 source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified

                                                 )
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_dept_batch_in6', batch_main_key, pid, order_no,
                                                 source_detail_id
                                                 , pick_detail_id, hos_goods_id, mdm_goods_code, goods_code,
                                                 source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified

                                                 )

    print('expected', expected)
    print('aaaaaaaaaaaaaaaaa')
    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)
    print(compare_text_index(actual_value2, expected_value2))
    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 check_mcms_psi_batch_in(DR_ID, type, order_no, source_id1):
    if type == 1:
        bill_mode = 16
    elif type == 2:
        bill_mode = 20
    else:
        bill_mode = 66
    branch_id = get_branch_id()
    sql = " select * from  mcms_psi_batch where pid='%s';" % (
        DR_ID)
    actual = check_mcms_dept_buy_sql(sql)
    print('actual', actual)
    batch_main_key = get_id("select id from mcms_psi_batch where pid='%s';" % DR_ID)
    pid = DR_ID
    # order_no = get_id("select order_no from mcms_psi_dept_batch where pid='%s';" % DR_ID)
    source_detail_id = source_id1 + '0001'
    pick_detail_id = None
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    pkg_def_id = get_pkg_def_id(hos_goods_id)
    picker_name = FileUtils().r_info8("b2_herp3_bs", "用户名信息", 'message3')['username1']
    picker = get_login_user_uxid_bydb(picker_name)
    source_batch_id = get_id("select source_batch_id from mcms_psi_batch where pid='%s';" % DR_ID)
    distrBillId = get_distrBillId(branch_id, bill_mode)
    target_batch_id = get_id(
        "select id from mcms_hos_batch where hos_goods_id='%s' order by create_time desc LIMIT 1;" % hos_goods_id)
    if check_batch_id(source_batch_id) == True:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    barcode_id = get_id("select barcode_id from mcms_psi_batch where pid='%s';" % DR_ID)
    if check_barcode_id(barcode_id) == True:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    shelf_code = get_stockAreaId_new_fromDb(get_branch_name(), 1)
    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_psi_batch where pid='%s';" % DR_ID)
    last_modified = get_create_time("select last_modified from  mcms_psi_batch where pid='%s';" % DR_ID)
    last_modified_user = create_user
    if type == 1:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_batch_in1', batch_main_key, pid, order_no, source_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified, last_modified_user

                                                 )
    elif type == 2:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_batch_in2', batch_main_key, pid, order_no, source_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified, last_modified_user

                                                 )
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_batch_in3', batch_main_key, pid, order_no, source_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified, last_modified_user

                                                 )

    print('expected', expected)
    print('aaaaaaaaaaaaaaaaa')
    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)
    print(compare_text_index(actual_value2, expected_value2))
    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 check_mcms_psi_batch_out(DR_ID, type, order_no, source_id1):
    if type == 1:
        bill_mode = 16
    elif type == 2:
        bill_mode = 20
    else:
        bill_mode = 66
    branch_id = get_branch_id()
    sql = " select * from  mcms_psi_batch where pid='%s';" % (
        DR_ID)
    actual = check_mcms_dept_buy_sql(sql)
    print('actual', actual)
    batch_main_key = get_id("select id from mcms_psi_batch where pid='%s';" % DR_ID)
    pid = DR_ID
    # order_no = get_id("select order_no from mcms_psi_dept_batch where pid='%s';" % DR_ID)
    source_detail_id = source_id1 + '0001'
    pick_detail_id = None
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    else:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    pkg_def_id = get_pkg_def_id(hos_goods_id)
    picker_name = FileUtils().r_info8("b2_herp3_bs", "用户名信息", 'message3')['username1']
    picker = get_login_user_uxid_bydb(picker_name)
    source_batch_id = get_id("select source_batch_id from mcms_psi_batch where pid='%s';" % DR_ID)
    distrBillId = get_distrBillId(branch_id, bill_mode)
    target_batch_id = get_id(
        "select id from mcms_hos_batch where hos_goods_id='%s' order by create_time desc LIMIT 1;" % hos_goods_id)
    if check_batch_id(source_batch_id) == True:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    barcode_id = get_id("select barcode_id from mcms_psi_batch where pid='%s';" % DR_ID)
    if check_barcode_id(barcode_id) == True:
        print('ok')
        commonFuc().check_text_exist_result_text('succees', 'succees')
    else:
        commonFuc().check_text_exist_result_text('error', 'succees')
    dept_name = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid2']
    shelf_code = get_stockAreaId_new_fromDb(get_branch_name(), 1)
    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_psi_batch where pid='%s';" % DR_ID)
    last_modified = get_create_time("select last_modified from  mcms_psi_batch where pid='%s';" % DR_ID)
    last_modified_user = create_user
    if type == 1:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_batch_in1', batch_main_key, pid, order_no, source_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified, last_modified_user

                                                 )
    elif type == 2:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_batch_in2', batch_main_key, pid, order_no, source_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified, last_modified_user

                                                 )
    else:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check',
                                                 'mcms_psi_batch_in3', batch_main_key, pid, order_no, source_detail_id
                                                 , hos_goods_id, mdm_goods_code, goods_code, source_batch_id,
                                                 target_batch_id, barcode_id, shelf_code, create_user, create_time,
                                                 last_modified, last_modified_user

                                                 )

    print('expected', expected)
    print('aaaaaaaaaaaaaaaaa')
    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)
    print(compare_text_index(actual_value2, expected_value2))
    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 check_mcms_hos_batch(type=1):  # 检查批次表信息
    print('中心库入库后检查批次表信息')
    if type == 1:
        bill_mode = 16
        pur_mode = 10
    elif type == 2:
        bill_mode = 20
        pur_mode = 20
    else:
        pur_mode = 60
        bill_mode = 66
    branch_id = get_branch_id()
    sql = "select * from  mcms_hos_batch  where branch_id='%s' and pur_mode='%s' order by  CREATE_TIME desc LIMIT 1;" % (
        branch_id, pur_mode)
    # 获取实际值
    actual = check_mcms_pur_plan_sql(sql)
    print('actual', actual)
    sql = "select id from  mcms_hos_batch  where branch_id='%s' and pur_mode='%s' order by   CREATE_TIME desc LIMIT 1;" % (
        branch_id, pur_mode)
    id = get_id(sql)
    hos_id = get_hosid()
    branch_id = get_branch_id()

    stock_name = get_branch_name() + "中心库房"
    stock_id = get_stockId_fromdb(stock_name)
    src_batch_id = get_id("select src_batch_id from mcms_hos_batch where id='%s';" % id)
    src_batch_id = id
    hos_goods_id='hos_goods_id'
    if type == 1:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    elif type == 2:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    elif type == 3:
        hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]
    mdm_goods_code = get_mdm_goods_code1(hos_goods_id)
    goods_code = get_goods_code1(hos_goods_id)
    goods_name = get_goods_name(hos_goods_id)
    goods_gg = get_goods_gg(hos_goods_id)
    mfrs_id = get_goods_mfrs_id(hos_goods_id)


    purBillId = get_purBillId(branch_id, bill_mode)
    bill_relation_json = get_purBillDate2(branch_id, bill_mode)
    # purBillDate = reGetString(bill_relation_json, r'purBillDate":"', r'""distrBillId')
    # distrBillId = get_distrBillId(branch_id, bill_mode)
    # distrOrderNo = get_distrOrderNo(branch_id, bill_mode)
    # checkBillId = source_id
    # sql = "select order_no from mcms_check where id='%s';" % checkBillId
    # checkOrderNo = get_id(sql)
    # psiInBillId = id

    create_user = get_login_user_uxid_bydb(FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')['username1'])
    create_time = get_create_time("select create_time from  mcms_hos_batch where id='%s';" % id)
    last_modified = get_create_time("select last_modified from  mcms_hos_batch where id='%s';" % id)
    last_modified_user = create_user
    supply_id = get_supply_id(hos_goods_id)
    prov_id = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    prov_name = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    sub_prov_id = prov_id
    sub_prov_name = prov_name
    expdt_date = get_create_time("select expdt_date from  mcms_hos_batch where id='%s';" % id)
    product_date = get_create_time("select product_date from  mcms_hos_batch where id='%s';" % id)
    distr_id = get_distrBillId(branch_id, bill_mode)
    distr_detail_id = get_distr_detail_id(branch_id, bill_mode)
    in_time = get_create_time("select in_time from  mcms_hos_batch where id='%s';" % id)
    goodsGg = goods_gg
    goodsCode = goods_code
    goodsName = goods_name
    erpCode = mdm_goods_code
    if type == 1:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_hos_batch1',
                                                 id,
                                                 hos_id, branch_id, stock_id, src_batch_id, hos_goods_id,
                                                 mdm_goods_code, goods_code, goods_name, goods_gg
                                                 , mfrs_id, supply_id, prov_id, prov_name, sub_prov_id,
                                                 sub_prov_name, expdt_date, product_date
                                                 , distr_id, distr_detail_id, purBillId, in_time, goodsGg, goodsCode,
                                                 goodsName, erpCode, create_user, create_time
                                                 , last_modified, last_modified_user
                                                 )
    elif type == 2:
        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_hos_batch2',
                                                 id,
                                                 hos_id, branch_id, stock_id, src_batch_id, hos_goods_id,
                                                 mdm_goods_code, goods_code, goods_name, goods_gg
                                                 , mfrs_id, supply_id, prov_id, prov_name, sub_prov_id,
                                                 sub_prov_name, expdt_date, product_date
                                                 , distr_id, distr_detail_id, purBillId, in_time, goodsGg, goodsCode,
                                                 goodsName, erpCode, create_user, create_time
                                                 , last_modified, last_modified_user)
    else:
        # fcatId=get_id("select id from mcms_goods_kind where kind_name='财务试剂';")

        expected = commonFuc().get_business_data('b6_spd3_core_business_flow_database_check', 'check_mcms_hos_batch3',
                                                 id,
                                                 hos_id, branch_id, stock_id, src_batch_id, hos_goods_id,
                                                 mdm_goods_code, goods_code, goods_name, goods_gg
                                                 , mfrs_id, supply_id, prov_id, prov_name, sub_prov_id,
                                                 sub_prov_name, expdt_date, product_date
                                                 , distr_id, distr_detail_id, purBillId, in_time, goodsGg, goodsCode,
                                                 goodsName, erpCode,create_user, create_time
                                                 , last_modified, last_modified_user)
    # 对比预期值和实际值是否一致
    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 main():
    pro_path = commonFuc().get_pro_path2()
    print('pro_path', pro_path)
    sys.path.append(pro_path + r'/air_case/b5_spd3_core_business_flow/a_b4流程十一请领业务流_二级库向直送.air')
    using(pro_path + r'//air_case/b5_spd3_core_business_flow/a_b4流程十一请领业务流_二级库向直送.air')

    from a_b4流程十一请领业务流_二级库向直送 import goods_move2,second_dept_Request,BuyCarSubmit,purchase_module_process,order_dp,check_accept_order


    for i in range(1):
        updateUserLoginDefaultRange(get_listUserMgrRangePage(2)) #设置登录账号默认权限是二级库
        goods_move2()  # 设置产品出库渠道为直送
        # # 低值
        second_dept_Request(FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message2')['hosGoodsId'], 1)
        check_mcms_dept_buy_car(1)#检查请领车数据库表数据 （低值）
        # # 高值
        second_dept_Request(FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message1')['hosGoodsId'], 2)
        check_mcms_dept_buy_car(2)#检查请领车数据库表数据（高值）
        # # 试剂
        second_dept_Request(FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message3')['hosGoodsId'], 3)
        check_mcms_dept_buy_car(3)#检查请领车数据库表数据（试剂）
        BuyCarSubmit()  # 请领车提交

        list_data = ['16', '20', '66']
        for i in list_data:
            check_mcms_dept_buy(int(i))#检查请领单主表
            mcms_dept_buy_detail(int(i))#检查请领单子表
        for i in range(6):  # 三个单据共审批6次
            approval_center()
        list_data = ['16', '20', '66']
        for i in list_data:
            check_mcms_dept_buy_approval_after(int(i))#检查审批后的请领单
            mcms_dept_buy_detail_approval_after(int(i))#检查审批后的请领单子表

        time.sleep(20)
        # 检查自动生成的采购计划数据
        list_data = ['16', '20', '66']
        for i in list_data:
            check_mcms_mcms_pur_plan(int(i))#检查采购计划数据（包括主表和子表）
        #         # 采购模块处理
        purchase_module_process()

        # 三个单据共审批三次
        approval_center(FileUtils().r_info8('b5_spd3_core_business_flow', '采购计划单号试剂', 'message12'))
        approval_center(FileUtils().r_info8('b5_spd3_core_business_flow', '采购计划单号', 'message7'))
        approval_center(FileUtils().r_info8('b5_spd3_core_business_flow', '采购计划单号高值', 'message11'))
        time.sleep(20)
        list_data = ['16', '20', '66']
        for i in list_data:
            check_mcms_purchase(int(i))#检查采购订单数据（包括主表和子表）

        # 检查同步到外网的采购订单数据跟内网的是否一致
        check_mcms_purchase_out_and_in(1) #1主表
        print('检查同步到外网的采购订单数据跟内网的是否一致')
        check_mcms_purchase_out_and_in(2) #2子表
        # 外网配送前再检查一下是否有单据未审批
        approval_center_all()
        order_dp(1)  # 1低值 配送单发货
        time.sleep(6)
        order_dp(2)  # 2高值 配送单发货
        time.sleep(6)
        order_dp(3)  # 3试剂 配送单发货
        time.sleep(6)
        time.sleep(20)

        list_data = ['16', '20', '66']
        for i in list_data:
            time.sleep(6)
            check_hdi_distr(int(i))#检查配送单（外网）

        time.sleep(20)
        # 到这里就是验收和中心库自动入库以及中心库出库
        check_accept_order(1)  # 低值 验收和自动入库和出库
        time.sleep(6)
        check_mcms_check(1)  # 调用函数检查验收单数据库写值
        check_mcms_psi(1)  # 调用函数检查中心库入库单和出库单数据库写值
        check_accept_order(2)  # 高值 验收和自动入库和出库
        time.sleep(6)

        # #这里验收后会自动生成出入库单，批次信息，需要同步验证入库单和批次信息
        check_mcms_check(2)  # 调用函数检查验收单数据库写值
        check_mcms_psi(2)  # 调用函数检查中心库入库单数据库写值
        check_accept_order(3)  # 试剂 验收和自动入库和出库
        time.sleep(6)
        check_mcms_check(3)  # 调用函数检查验收单数据库写值
        check_mcms_psi(3)  # 调用函数检查中心库入库单数据库写值
        time.sleep(6)
        # # 上面暂时注释========================================
        # 检查批次信息
        check_mcms_hos_batch(1)
        check_mcms_hos_batch(2)
        check_mcms_hos_batch(3)
        second_dept_one_key_in()
        second_dept_one_key_in()
        second_dept_one_key_in()
        time.sleep(6)
        # 检查二级库入库单
        check_mcms_psi_dept_in(16)
        check_mcms_psi_dept_in(20)
        check_mcms_psi_dept_in(66)
    commonFuc().check_text_exist_result_text('succees', 'succees')
try:
    main()
except  Exception as e:
    # 打印错误信息
    print(f"发生错误: {e}")
    commonFuc().check_text_exist_result_text('error', 'succees')
