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

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,a7产品信息审核查询,id2251,id2251-7-1,sit,on,2023091201
主数据平台:a7产品信息审核查询
"""
from common.common_func import commonFuc, using
from air_case.mdm_login.登录外网系统.登录外网系统 import login_system
module = "a5_mdm3_pdm"
def select1():
    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()
    """
     场景:a7产品信息审核查询
     用例名称：a7产品信息审核查询
     输入：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, "getAuditGoodsListByPage_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)

    request_body = commonFuc().get_business_data(module, "payload2",h_corpId)

    # print('产品信息审核查询请求体', request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print("产品信息审核查询返回结果", result)
    data = commonFuc().analysis_json('data', result)
    total=commonFuc().analysis_json('total', data)
    data1=commonFuc().analysis_json('data', data)
    if total>=1:
        id1 = commonFuc().analysis_json('id', data1[0])
        auditOrgId=commonFuc().analysis_json('hosId', data1[0])
        hosGoodsId=commonFuc().analysis_json('hosGoodsid', data1[0])
        provGoodsid=commonFuc().analysis_json('provGoodsid', data1[0])
        goodsAuditBillId=commonFuc().analysis_json('billId', data1[0])
        targetId=commonFuc().analysis_json('id', data1[0])
        print(id1, auditOrgId, hosGoodsId,provGoodsid,goodsAuditBillId,targetId)
        info = (id1, auditOrgId,hosGoodsId,provGoodsid,goodsAuditBillId,targetId)
        titlename = ("MSPid", 'hosId','hosGoodsId','provGoodsid','goodsAuditBillId','targetId')
        # 将产品审核信息写入到文件中
        FileUtils().w_info6(info, module, '产品审核信息', titlename,'message2')
    else:
        commonFuc().check_text_exist(0, result)
select1()