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

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,a7_3订单配送提交_2_0医院,id2291,id2291-36,sit,on
主数据平台:a7_3订单配送提交_2_0医院    因此脚本数据来源于2.0内网采购-审核，后续需要写2.0采购脚本将此脚本连接起来
"""

from common.common_func import commonFuc
from airtest.core.api import using
import sys
module = "a6_mdm3_dp"
def select1():
    pro_path = commonFuc().get_pro_path()
    sys.path.append(pro_path + r'\\air_case\\a6_mdm3_dp\\a1企业登录.air')
    using(pro_path + r'\\air_case\\a6_mdm3_dp\\a1企业登录.air')
    from a1企业登录 import e_login
    token, projectCode, uxid, corpId, e_name = e_login()
    # # 获取医院corpId
    sys.path.append(pro_path + r'\\air_case\\a6_mdm3_dp\\a7_2获取订单详细信息中的子表id_2_0医院.air')
    using(pro_path + r'\\air_case\\a6_mdm3_dp\\a7_2获取订单详细信息中的子表id_2_0医院.air')
    from a7_2获取订单详细信息中的子表id_2_0医院 import select1
    id1,id2 = select1()
    """
     场景:a7_3订单配送提交_2_0医院
     用例名称：a7_3订单配送提交_2_0医院
     输入：无
     输出："rtn_msg": 0
    """
    module = "a6_mdm3_dp"
    #a1订单配送列表数据查询_全部
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "submit_url")
      # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    sourceVersion=0
    # request_body = commonFuc().get_business_data(module, "payload9_3",id1,id1,rand_num,rand_num,id2,id2)
    request_body = commonFuc().get_business_data(module, "payload9_3",id1,id1,sourceVersion,id2,id2)

    print('request_body',request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    #断言
    code=commonFuc().analysis_json('code',result)
    data=commonFuc().analysis_json('data',result)
    total=commonFuc().analysis_json('total',data)
    if code==0:
        commonFuc().check_text_exist(code,result)
    else:
        # commonFuc().check_text_exist('error', result)
        sourceVersion=commonFuc().analysis_json('sourceVersion',request_body)

        sourceVersion=int(sourceVersion)+1
        request_body = commonFuc().get_business_data(module, "payload9_3", id1, id1, sourceVersion,id2, id2)
        print(request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print(result)
        commonFuc().analysis_json('code',result)
select1()

