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

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,a2结算管理-发票暂存,id2292,id2292-4,sit,on
主数据平台:a2结算管理-发票暂存
"""

from common.common_func import commonFuc
from airtest.core.api import using
import sys
module = "a6_mdm3_si"
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()
    # # 获取发票信息
    sys.path.append(pro_path + r'\\air_case\\a6_mdm3_si\\a2结算管理_发票录入查询.air')
    using(pro_path + r'\\air_case\\a6_mdm3_si\\a2结算管理_发票录入查询.air')
    from a2结算管理_发票录入查询 import select1
    data1 = select1()
    """
     场景:a2结算管理-发票暂存
     用例名称：a2结算管理-发票暂存
     输入：无
     输出："rtn_msg": 0
    """
    # module = "a6_mdm3_si"
    #a1订单配送列表数据查询_全部
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "saveCacheBatch_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)



    detailList=commonFuc().analysis_json('detailList',data1)
    detailList=detailList[0]
    settleMonth = detailList['settleMonth']
    hosGoodsId = detailList['hosGoodsId']
    batchCode = detailList['batchCode']
    distrDetailId=detailList['distrDetailId']
    distrId=detailList['distrId']
    distrOrderNo=detailList['distrOrderNo']
    settlePrice=detailList['settlePrice']
    maxSettleQty=detailList['maxSettleQty']
    maxSettleAmount=detailList['maxSettleAmount']
    curSettleQty=detailList['curSettleQty']
    curSettleAmount=detailList['curSettleAmount']
    leftSettleQty=detailList['leftSettleQty']
    leftSettleAmount=detailList['leftSettleAmount']
    hosId=detailList['hosId']
    provId=detailList['provId']
    branchId=detailList['branchId']
    balanceDetId=detailList['balanceDetId']
    purMode=detailList['purMode']
    barCode=detailList['barCode']
    request_body = commonFuc().get_business_data(module, "payload3_1",settleMonth,hosGoodsId,batchCode,distrDetailId,distrId,distrOrderNo,hosId,provId,branchId,balanceDetId,barCode)
    print('request_body',request_body)
    request_body='['+str(request_body)+']'
    print('request_body',request_body)
    new_request_body = request_body.replace("'", '"')
    new_request_body1 = new_request_body.replace("None", 'null')
    print('new_request_body',new_request_body1)
    import json
    request_body_json = json.loads(new_request_body1,encoding='utf-8')
    print('request_body_json',request_body_json)
    # 发送请求
    result = commonFuc().http_post(url, request_body_json, headers)
    print('result', result)
    #断言
    code=commonFuc().analysis_json('code',result)
    data=commonFuc().analysis_json('data',result)
    total=commonFuc().analysis_json('total',data)
    data1=commonFuc().analysis_json('data',data)
    if code==0:
        commonFuc().check_text_exist(code,result)
    else:
        commonFuc().check_text_exist('error', result)
select1()

