# -*- 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_l1_带量采购目录_明细行_停止,id2297,id2297-111,sit,on
内网:a_l1_带量采购目录_明细行_停止 
"""

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_l1_带量采购目录_明细行_停止
     用例名称：a_l1_带量采购目录_明细行_停止
     输入：id
     输出："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, "带量采购目录信息", 'message7')
    list2 = info['list_a']
    id1 = ' '.join(list2)
    print('bbbb', id1, type(id1))
    # ======================================获取明细id=======================================
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module,
                                                               "herpService_vbp_detailListVo_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)

    #get方式没有请求体
    # 发送请求
    result = commonFuc().http_get(url, headers)
    print('result', result)
    data = commonFuc().analysis_json('data', result)
    id2=commonFuc().analysis_json('id', data[0])
    #======================================获取明细id=======================================
    # 从文件中获取院区id
    # branchId = commonFuc().get_business_data(module, 'branchId')
    # # # #获取日期
    # date1 = timeUtils().get_time_hms(4)
    # date2 = timeUtils().get_time_hms(3)
    # print(date1,date2)
    # a_l1_带量采购目录_明细行_停止
    # 从文件中获取产品名称
    # info = FileUtils().r_info8(module, "产品明细信息", 'message6')
    # print('info', info)
    # list_b = info['list_b']
    # print('list_b', list_b)
    # hosGoodsCode = 'hosGoodsCode'
    # goodsName = 'goodsName'
    # goodsGeneralName = 'goodsGeneralName'
    # goodsSpec = 'goodsSpec'
    # goodsMfrsName = 'goodsMfrsName'
    # hosGoodsId = 'hosGoodsId'
    # goodsMfrsId = 'goodsMfrsId'
    # for i in list_b:
    #     hosGoodsCode = i['hosGoodsCode']
    #     goodsName = i['goodsName']
    #     goodsGeneralName = i['goodsGeneralName']
    #     goodsSpec = i['goodsSpec']
    #     goodsMfrsName = i['goodsMfrsName']
    #     hosGoodsId = i['hosGoodsId']
    #     goodsMfrsId = i['goodsMfrsId']
    #     break
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module,
                                                                    "herpService_vbp_detailClose_url")
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload22_8",id2)
    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 == True:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


test1()
