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

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,a_c5_采购计划审核_列表查询_条件查询_模糊查询_根据采购计划号,id2297,id2297-25,sit,on
内网:a_c5_采购计划审核_列表查询_条件查询_模糊查询_根据采购计划号 
"""

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_c5_采购计划审核_列表查询_条件查询_模糊查询_根据采购计划号
     用例名称：a_c5_采购计划审核_列表查询_条件查询_模糊查询_根据采购计划号
     输入：无
     输出："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_purPlan_listVoPage_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)
    # # #获取日期
    # date1=timeUtils().get_time_hms(2)
    # date2=timeUtils().get_time_add(-1)
    # print(date1,date2)
    info = FileUtils().r_info8(module, "采购计划信息", 'message')
    print(info)
    orderNo = info['orderNo']
    print(type(orderNo))
    list_a = []
    orderNo1 = orderNo[0:8]  # 获取模糊查询前面的字符串
    orderNo2 = orderNo[8:len(orderNo) - 1]  # 获取模糊查询后面的字符串
    orderNo3 = orderNo[8:12]  # 获取模糊查询中间的字符串
    # print(orderNo3,'aaaaaaaabbbbbbbbbbbcccccccccccccccc')
    list_a.append(orderNo1)
    list_a.append(orderNo2)
    list_a.append(orderNo3)
    print('list_a', list_a)
    # # 请求体
    for i in list_a:
        request_body = commonFuc().get_business_data(module, "payload18_1", i)
        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)
        total = commonFuc().analysis_json('total', data)
        if code == 0 and total >= 1:
            commonFuc().check_text_exist(0, result)

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


test1()
