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

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,a_n7_手术通知单_查看,id2297,id2297-137,sit,on
内网:a_n7_手术通知单_查看 
"""

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 = "b3_herp3_purchase"
    """
     场景:a_n7_手术通知单_查看
     用例名称：a_n7_手术通知单_查看
     输入：无
     输出："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)
    # 从文件中获取手术通知单id
    info = FileUtils().r_info8(module, "手术通知单信息", 'message8')
    # print('info', info)
    list_a = info['list_a']
    # print('list_a', list_a)
    id1 = 'id1'
    orderNo = 'orderNo'
    for i in list_a:
        id1 = i['id']
        orderNo = i['orderNo']
        break
    # 查看统计数据接口
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "herpService_operationNotice_statistic_url")
    url = url + id1
    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)

    # 发送请求
    result = commonFuc().http_get(url, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    purAmount = commonFuc().analysis_json('purAmount', data)
    if code == 0 and len(data) >= 1 and purAmount >= 0:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
    # 查看详情数据接口
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module,
                                                                    "herpService_operationNotice_getDetailById_url")
    url = url + id1
    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)

    # 发送请求
    result = commonFuc().http_get(url, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    orderNo1 = commonFuc().analysis_json('orderNo', data)
    if code == 0 and len(data) >= 1 and orderNo1 == orderNo:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)

test1()
