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

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,a_i7_临采任务_临采任务_执行,id2297,id2297-87,sit,on
内网:a_i7_临采任务_临采任务_执行 
"""

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_i7_临采任务_临采任务_执行
     用例名称：a_i7_临采任务_临采任务_执行
     输入：无
     输出："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_temporaryPurchase_execute_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)
    # 从文件中获取院区id
    branchId = commonFuc().get_business_data(module, 'branchId')
    # # #获取日期
    # date1=timeUtils().get_time_hms(2)
    # date2=timeUtils().get_time_add(-1)
    # print(date1,date2)
    # a_i2_临采任务_新增临采任务_新增产品页面列表查询_条件查询_精确查询_产品名称
    # 从文件中获取产品名称
    # info = FileUtils().r_info8(module, "产品明细信息", 'message4')
    # print('info', info)
    # list_a = info['list_a']
    # print('list_a', list_a)
    # hosGoodsId = 'hosGoodsId'
    # hosGoodsCode = 'hosGoodsCode'
    # for i in list_a:
    #     hosGoodsId = i['hosGoodsId']
    #     hosGoodsCode =i['hosGoodsCode']
    #     break
    #读取临采任务id
    info = FileUtils().r_info8(module, "临采任务id", 'message5')
    list2 = info['list_a']
    my_string = ' '.join(list2)
    print('bbbb',my_string,type(my_string))
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload21_6",my_string)
    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 ==None:
        commonFuc().check_text_exist(0, result)

    else:
        commonFuc().check_text_exist('error', result)

test1()
