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

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,产品信息申报,id2251,id2251-2,sit,on,2023091201
主数据平台:产品信息申报
"""
module = "mdm3_pim"
from common.common_func import commonFuc, using
from air_case.mdm_login.登录外网系统.登录外网系统 import login_system
pro_path=commonFuc().get_pro_path()
sys.path.append(pro_path+r'\\air_case\\mdm3_pim\\a1分页查询供应商产品数据.air')
using(pro_path+r'\\air_case\\mdm3_pim\\a1分页查询供应商产品数据.air')
from a1分页查询供应商产品数据 import *

"""
 场景:产品信息申报
 用例名称：产品信息申报
 输入：CRid
 输出："rtn_msg": "ok"
"""
# 登录
username = global_var_cname
password = commonFuc().get_business_data(module, "password")
print(username, password)
# 获取token和projectCode
token, projectCode, uxid, corpId,info = login_system(username, password).get_token()
# 产品信息申报接口
module = "mdm3_pim"
# 产品申报
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "submitGoodsRegist_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
                                        commonFuc().get_business_data(module, "json_contentType"), token,
                                        projectCode)
p_name = commonFuc().get_business_data(module, "name1")  # 获取前缀name
p_name = p_name + commonFuc().randomString(5)  # 随机数生成拼接产品名称
request_body = commonFuc().get_business_data(module, "payload6", p_name, p_name, p_name, p_name, p_name, p_name, p_name,
                                             p_name, p_name, p_name, p_name, p_name, p_name, p_name)
# print('新增产品请求体', request_body)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
# print("新增产品返回结果", result)
goodsRegistVO = commonFuc().analysis_json('goodsRegistVO', result)
goodsName = commonFuc().analysis_json('goodsName', goodsRegistVO)
commonFuc().check_text_exist(goodsName, result)  # 检查返回结果中是否存在新增的产品名称
global_var_p_name=p_name