# -*- 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_c7_期初录入_低值_已生成单据_查看详情,id2301,id2301-27,sit,on
内网:a_c7_期初录入_低值_已生成单据_查看详情
"""

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_c7_期初录入_低值_已生成单据_查看详情
     用例名称：a_c7_期初录入_低值_已生成单据_查看详情
     输入：无
     输出："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)
    #
    pro_path = commonFuc().get_pro_path()
    sys.path.append(pro_path + r'\\air_case\\b4_herp3_InitStock\\a_c2_期初录入_列表_条件查询_精确查询_状态.air')
    using(pro_path + r'\\air_case\\b4_herp3_InitStock\\a_c2_期初录入_列表_条件查询_精确查询_状态.air')
    from a_c2_期初录入_列表_条件查询_精确查询_状态 import test1

    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "herpService_mcmsInitStock_getById_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)
    # 从文件读取期初单号_已生成状态期初单号
    info = FileUtils().r_info8(module, "已生成状态期初单号", 'message7')
    list_a = info['list_a']
    list_a = ','.join(map(str, list_a))
    print('list_a', list_a)
    import json
    new_request_body = list_a.replace("'", '"')
    new_request_body1 = new_request_body.replace("None", 'null')
    print(new_request_body1)
    list_a2 = json.loads(new_request_body1)
    id1 = 'id'
    for i in list_a2:
        id1 = i['id']
        break
    url = url + id1
    print(url)
    # 发送请求
    result = commonFuc().http_get(url, 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)


test1()

