# -*- encoding=utf8 -*-
import random
import sys

from airtest.core.helper import using

from common.db.sql.sql_del_branch_info import delData
from common.db.sql.sql_del_kind_goodsinfo import delKindGoodsinfo
from common.db.sql.sql_del_notices_info import delByNoticeName
from common.fileUtls import FileUtils
from common.timeUtils import timeUtils
import threading

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,生成采购数据,id20250527,id20250412-20250527,sit,on
内网:生成采购数据
"""

from common.common_func import commonFuc
from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
import requests
import json

module = "b2_herp3_bs"

# 内网登录
username = commonFuc().get_business_data(module, "username411")
## print('医院名称',username)
password = commonFuc().get_business_data(module, "password411")
# print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
# 获取token和projectCode
token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
# print( token,projectCode,uxid,corpId,info)
headers = commonFuc().get_business_data(module, "json_headers_pur", token)


def c_purplan():


    # 暂存
    url = 'http://spdtest.cmic.com.cn:8080/api/herpService/purPlan/insert'
    # print(url)
    request_body = {
        "purPlanDetail": [
            {
                "hosGoodsId": "h034700000012",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700000110",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020449",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700000010",
                "pkgDefId": "C20231229000012013",
                "pkgDefName": "大包（边仓）",
                "pkgDefQty": 100,
                "planPkgQty": 0,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700000010",
                "pkgDefId": "C20231229000032013",
                "pkgDefName": "中包（边仓）",
                "pkgDefQty": 20,
                "planPkgQty": 0,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700000010",
                "pkgDefId": "c691c04edd054768a774fd97ff6fba02",
                "pkgDefName": "盒",
                "pkgDefQty": 10,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020450",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020454",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020453",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020452",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020451",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            },
            {
                "hosGoodsId": "h034700020455",
                "pkgDefQty": 1,
                "planPkgQty": 1,
                "codingType": 0
            }
        ],
        "hosId": "h0347",
        "branchId": "h0347-2013",
        "mgrCorpName": "测试医院",
        "deptName": "",
        "deptId": "391d5e06d0ba4cb39a3a7ee2e7934ae7",
        "recOrgId": "391d5e06d0ba4cb39a3a7ee2e7934ae7",
        "recOrgName": "",
        "areaCode": "area0379",
        "areaName": "千泉院区中心库库区1",
        "recUser": "UID-048770",
        "recPhone": "18271691751",
        "recAddr": "千泉中心库房库区1-001",
        "remark": "",
        "sourceType": "",
        "createType": "SG",
        "checkLcTaskQty": True
    }
    """
    场景: 采购
    """

    # 发送请求
    result = requests.post(url, json=request_body, headers=headers)
    # 获取接口响应时间
    result = json.loads(result.content)
    # 获取暂存信息
    pid = result["data"]
    # 提交
    url = 'http://spdtest.cmic.com.cn:8080/api/herpService/purPlan/submitPurPlan'
    # print(url)
    request_body = {
        "id": pid,
        "planDetailList": [
            {
                "closeStatus": 0,
                "id": "c8c2e0102f62499f8b7d1695ec747fb7",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 10,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p00002a25",
                "subProvName": "国药器械光谷三路分公司",
                "hosGoodsId": "h034700000010",
                "purMode": 10,
                "version": 0,
                "pkgDefId": "c691c04edd054768a774fd97ff6fba02",
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "fbb430bc9a7643b8810e7807683faec3",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p00002a0c",
                "provName": "国药器械光谷分公司",
                "subProvId": "p00002a0c",
                "subProvName": "国药器械光谷分公司",
                "hosGoodsId": "h034700000012",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "5a07d4396d464a108080e629b2937657",
                "inSettlement": 3,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p00a3sc",
                "provName": "北京中杉金桥生物技术有限公司",
                "subProvId": "p00a3sc",
                "subProvName": "北京中杉金桥生物技术有限公司",
                "hosGoodsId": "h034700000110",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "0014115fdfb94268a5d8d5e6ac9969a8",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020449",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "c474d86ddbcb4edc92deeff572c16daa",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020450",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "8e14b6345a02464a97b77a168ae9ba43",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020451",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "33ea7f4fa38f4943909c911af9b27671",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020452",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "c279764c70d84edaa2baac5191ba9a05",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020453",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "f292359df1744a49ac6b2152d6a20206",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020454",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            },
            {
                "closeStatus": 0,
                "id": "f9800bdf1da443dfa145f70e467d6a2d",
                "inSettlement": 1,
                "planPkgQty": 1,
                "pkgDefQty": 1,
                "provId": "p10d95",
                "provName": "浙江高仰医疗科技有限公司",
                "subProvId": "p10d95",
                "subProvName": "浙江高仰医疗科技有限公司",
                "hosGoodsId": "h034700020455",
                "purMode": 20,
                "version": 0,
                "pkgDefId": None,
                "purTaskId": None,
                "sourceId": None,
                "codingType": 0,
                "checkAreaCode": None,
                "checkAreaName": None
            }
        ],
        "tempFlag": 0,
        "version": 0,
        "remark": "",
        "checkLcTaskQty": True
    }

    # 发送请求
    result = requests.post(url, json=request_body, headers=headers)
    # 获取接口响应时间
    result = json.loads(result.content)

    print(result)


n = 0
while n < 1000:
    # 创建多线程
    threads = []
    for _ in range(3):
        t = threading.Thread(target=c_purplan)
        threads.append(t)
        t.start()

    # 等待所有线程完成
    for t in threads:
        t.join()

    n = n + 1
