# -*- encoding=utf8 -*-
__author__ = "liguangyu"

"""
case_tag:cmdc_api,cmdc需求单取消功能验证,2289,2289-14,sit,bs
涉及到接口:多采商城需求单取消接口
"""

from common.common_func import commonFuc
from air_case.cmdc_login.多采商城登录.多采商城登录 import CmdcMaiiLogin
from common.db.db import mySql
import requests
import json

module = "cmdc_demand_mall"

# 第一步登录多采商城获取token
# 获取登录所需账号密码
username = commonFuc().get_business_data(module, "username")
password = commonFuc().get_business_data(module, "password")
# 获取登录后Cmdc_access_token
cmdc_access_token = CmdcMaiiLogin(username, password).get_token()
headers = commonFuc().get_business_data(module, "json_headers1", cmdc_access_token)

# 数据库操作
mysql_handle = mySql()
# 获取conf.ini文件中配置的数据库信息
host, port, user, pwd = mysql_handle.getConf(db="cmdc_db")

# 第二步进行需求单取消操作
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url23")
request_body = commonFuc().get_business_data(module, "payload23")
# print(request_body)
"""
 场景: 需求单取消功能验证
 用例名称：需求单取消功能验证
 输出：{"orderStatus":201}
"""

# 发送请求
result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.content)
print(result)
if result["success"]:
    # 查询需求单状态
    sql = "SELECT t.orderStatus FROM `cmdc-order`.tc_demand t WHERE t.demandId = 40213"
    result = {"orderStatus": mysql_handle.selectSql(host, port, user, pwd, "cmdc-order", sql)[0][0]}
    # print(result)
    # 获取预期结果
    check_dict = commonFuc().get_business_data(module, "checkDict23")
    # print(check_dict)
    # 断言实际结果中是否包含预期结果的内容
    commonFuc().check_result(check_dict, result)
else:
    # 获取预期结果
    check_dict = commonFuc().get_business_data(module, "checkDict23_1")
    # print(check_dict)
    # 断言实际结果中是否包含预期结果的内容
    commonFuc().check_result(check_dict, result)

# 进行需求单状态调整为待审核操作
sql = "UPDATE `cmdc-order`.tc_demand t SET t.orderStatus = 102, t.auditStatus = 0 WHERE t.demandId = 40213"
mysql_handle.executeUpdate(host, port, user, pwd, "cmdc-order", sql)