# -*- encoding=utf8 -*-
import json

from common.common_func import commonFuc
from common.timeUtils import timeUtils
from common.fileUtls import FileUtils
from common.common_func import commonFuc, using
from air_case.mdm_login.登录外网系统.登录外网系统 import login_system
import sys

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,a8产品信息审核批量_驳回,id2251,id2251-8,sit,on
主数据平台:a8产品信息审核批量_驳回
"""
module = "a5_mdm3_pdm"
def test1():
    module = "a5_mdm3_pdm"
    pro_path=commonFuc().get_pro_path()
    sys.path.append(pro_path+r'\\air_case\\a4_mdm3_cm\\a2供货关系申请_客户类型_医院_登录_企业登录.air')
    using(pro_path+r'\\air_case\\a4_mdm3_cm\\a2供货关系申请_客户类型_医院_登录_企业登录.air')
    from a2供货关系申请_客户类型_医院_登录_企业登录 import e_login
    token,projectCode,uxid,corpId,username=e_login()
    #获取医院corpId
    sys.path.append(pro_path + r'\\air_case\\a4_mdm3_cm\\a1供货关系申请_客户类型_医院_登录_医院登录获取医院id.air')
    using(pro_path + r'\\air_case\\a4_mdm3_cm\\a1供货关系申请_客户类型_医院_登录_医院登录获取医院id.air')
    from a1供货关系申请_客户类型_医院_登录_医院登录获取医院id import h_login
    h_token,h_projectCode,h_uxid,h_corpId,h_name=h_login()

    # 新增产品信息,保证查询有数据
    sys.path.append(pro_path + r'\\air_case\\a5_mdm3_pdm\\a1产品新增导入.air')
    using(pro_path + r'\\air_case\\a5_mdm3_pdm\\a1产品新增导入.air')
    from a1产品新增导入 import add_goods
    add_goods()

    sys.path.append(pro_path + r'\\air_case\\a5_mdm3_pdm\\a3产品信息审核_查询.air')
    using(pro_path + r'\\air_case\\a5_mdm3_pdm\\a3产品信息审核_查询.air')
    from a3产品信息审核_查询 import select1
    # select1()
    """
     场景:a8产品信息审核批量_驳回
     用例名称：a8产品信息审核批量_驳回
     输入：CRid
     输出："rtn_msg": "ok"
    """
    # 登录
    username = h_name
    password = commonFuc().get_business_data(module, "password")
    print(username, password)
    # 获取token和projectCode
    token, projectCode, uxid, corpId,info = login_system(username, password).get_token()
    # 审批产品驳回
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "batchRejectAudit_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    info = FileUtils().r_info6(module, "产品审核信息",'message2')
    print(info)
    MSPid = info['MSPid']
    hosId = info['hosId']
    hosGoodsId = info['hosGoodsId']
    provGoodsid = info['provGoodsid']
    goodsAuditBillId= info['goodsAuditBillId']
    targetId= info['targetId']

    request_body = commonFuc().get_business_data(module, "payload3_2",MSPid,hosId,hosGoodsId,provGoodsid,goodsAuditBillId,targetId)
    request_body="["+str(request_body)+"]"
    # string = "这是一段包含'单引号'的文本"
    new_request_body = request_body.replace("'", '"')

    request_body_json=json.loads(new_request_body)
    print('a8产品信息审核批量_驳回', request_body_json)
    # 发送请求
    result = commonFuc().http_post(url, request_body_json, headers)
    print("a8产品信息审核批量_驳回返回结果", result)
    checkDict=commonFuc().get_business_data(module,'checkDict3')
    commonFuc().check_result(checkDict,result)
test1()
