# -*- 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_a9_期初录入_高值_扫条码,id2301,id2301-9,sit,on
内网:a_a9_期初录入_高值_扫条码
"""

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_a9_期初录入_高值_扫条码
     用例名称：a_a9_期初录入_高值_扫条码
     输入：无
     输出："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_decode_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)

    #从message1文件中获取表头部分信息
    info = FileUtils().r_info8(module, "期初单号信息", 'message1')
    # print('info', info)
    list_a = info['list_a']
    # print('list_a', list_a)
    stockId='stockId'
    for i in list_a:
        stockId=i['stockId']
        break
    #从文件中获取条码
    decode1=commonFuc().get_business_data(module,'decode1')
    # # 请求体
    hospitalId = commonFuc().get_business_data(module, "hospitalId")
    print(stockId,hospitalId,decode1)
    request_body = commonFuc().get_business_data(module, "payload_6",stockId, hospitalId,decode1)
    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 len(data) >= 1 :
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
    # 期初高值产品信息写入文件

    list_a = []
    list_b = []
    list_c = []

    list_a.append(data)
    list_b.append(data)
    list_c.append(data)
    # print('list_a', len(list_a), list_a)

    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将期初产品信息写入到文件中
    FileUtils().w_info8(info, module, '期初高值产品信息', titlename, 'message4')

test1()
