# -*- encoding=utf8 -*-
from common.db.sql.sql_get_info import sql_get_info
from common.fileUtls import FileUtils
from common.timeUtils import timeUtils

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,a_b0_期初录入_高值_暂存,id2301,id2301-10,sit,on
内网:a_b0_期初录入_高值_暂存
"""

from common.common_func import commonFuc
from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from airtest.core.api import using
import sys


def test1():
    module = "b4_herp3_InitStock"
    """
     场景:a_b0_期初录入_高值_暂存
     用例名称：a_b0_期初录入_高值_暂存
     输入：无
     输出："rtn_msg": {"code": 0, "msg": null,    "data": true}
    """
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    # print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)
    #
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module,
                                                                    "herpService_mcmsInitStock_insertTemp_url")
    print(url)

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # 调用a_a4_期初录入_低值_录入_获取单据信息
    pro_path = commonFuc().get_pro_path()
    sys.path.append(pro_path + r'\\air_case\\b4_herp3_InitStock\\a_a4_期初录入_低值_录入_获取单据信息.air')
    using(pro_path + r'\\air_case\\b4_herp3_InitStock\\a_a4_期初录入_低值_录入_获取单据信息.air')
    from a_a4_期初录入_低值_录入_获取单据信息 import test1
    # 从文件读取期初单号_低值
    info = FileUtils().r_info8(module, "期初单号高值", 'message')
    list2 = info['list_a']
    QCID = ' '.join(list2)
    print('bbbb', QCID, type(QCID))
    test1(QCID)
    # 从message1文件中获取表头部分信息
    info = FileUtils().r_info8(module, "期初单号信息", 'message1')
    # print('info', info)
    list_a = info['list_a']
    # print('list_a', list_a)
    id = 'id'
    orderNo = 'orderNo'
    for i in list_a:
        id = i['id']
        orderNo = i['orderNo']
        break

    # 从message4'文件中获取详情信息

    info = FileUtils().r_info8(module, "期初高值产品信息", 'message4')
    # print('info', info)
    list_a = info['list_a']
    # print('list_a啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊', list_a)
    hosGoodsId = 'hosGoodsId'
    hosGoodsCode = 'hosGoodsCode'
    provId = 'provId'
    subProvId = 'subProvId'
    inSettlement = 'inSettlement'
    supplyId = 'supplyId'
    batchCode = 'batchCode'
    stockQty = '1'
    provName = 'provName'
    subProvName = 'subProvName'
    pkgCodeSee = 'pkgCodeSee'
    mfrCode = 'mfrCode'
    for i in list_a:
        hosGoodsId = i['hosGoodsId']
        hosGoodsCode = i['hosGoodsCode']
        provId = i['provId']
        subProvId = i['subProvId']
        inSettlement = i['inSettlement']
        supplyId = i['supplyId']
        batchCode = 'batchCode'
        stockQty = "1"
        provName = i['provName']
        subProvName = i['subProvName']
        mfrCode = i['mfrCode']
        pkgCodeSee = i['pkgCodeSee']
        break
    # # #获取日期
    productDate = timeUtils().get_time_hms(3)
    expdtDate = timeUtils().get_time_hms(4,365)
    initStockId = QCID
    # # 请求体
    hospitalId = commonFuc().get_business_data(module, "hospitalId")
    branchId = commonFuc().get_business_data(module, "branchId")
    request_body = commonFuc().get_business_data(module, "payload_7", hosGoodsCode, inSettlement, hosGoodsId, provId,
                                                 subProvId, provName, subProvName, supplyId, mfrCode, pkgCodeSee,
                                                 batchCode, expdtDate, productDate, stockQty, initStockId, orderNo)
    print('request_body', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == 1:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


test1()
