# -*- 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,r_e2用户管理_角色管理_角色列表展示,id20250820,id20250412-id20250514,sit,on
内网:手工入库
"""

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

module = "b2_herp3_bs"


def l_pur():
    # 内网登录
    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)

    # 获取产品信息
    url = 'http://spdtest.cmic.com.cn:8080/api/herpService/mcmsManualStock/getGoodsList'
    # print(url)
    request_body = {
        "queryObject": {
            "branchId": "h0347-2013",
            "deptId": "391d5e06d0ba4cb39a3a7ee2e7934ae7",
            "stockId": "b278f988a25c4678a1448fb08c3b4a41",
            "provId": "p10d95",
            "subProvId": "p10d95",
            "purMode": "60",
            "purModeName": "检验试剂",
            "stockLevel": "",
            "checkAreaCode": "area0381",
            "goodsSpec": "YYTZM"
        },
        "pageNum": 1,
        "pageSize": 1200
    }
    """
    场景: 手工入库
    """

    # 发送请求
    result = requests.post(url, json=request_body, headers=headers)
    # 获取接口响应时间
    result = json.loads(result.content)
    # 获取产品信息
    for i in result["data"]["data"]:
        u_random = random.randint(1000, 100000000000000)
        i["batchVOS"] = [
            {
                "batchCode": u_random,
                "productDate": "2025-05-01",
                "expdtDate": "2025-10-31",
                "stockQty": 1,
                "viewId": "4a75660d-5580-4b7a-fb3a-0f2b",
                "pkgDefId": None,
                "pkgDefName": None,
                "pkgDefQty": 1
            }
        ]
        i["initStockBatchVOS"] = [
            {
                "batchCode": u_random,
                "productDate": "2025-05-01",
                "expdtDate": "2025-10-31",
                "stockQty": 1,
                "viewId": "4a75660d-5580-4b7a-fb3a-0f2b",
                "pkgDefId": None,
                "pkgDefName": None,
                "pkgDefQty": 1
            }
        ]

        # 手工入库
        url = 'http://spdtest.cmic.com.cn:8080/api/herpService/mcmsManualStock/submit'
        # print(url)

        request_body = {
            "areaCode": "area0381",
            "checkAreaCode": "area0381",
            "deptId": "391d5e06d0ba4cb39a3a7ee2e7934ae7",
            "provId": "p10d95",
            "purMode": "60",
            "remark": "",
            "sourceType": 3,
            "stockId": "b278f988a25c4678a1448fb08c3b4a41",
            "subProvId": "p10d95",
            "attachmentList": [],
            "ignoreValidExpDate": True
        }
        request_body["detailVOS"] = [i]
        # print(request_body)
        # 发送请求
        result = requests.post(url, json=request_body, headers=headers)
        # 获取接口响应时间
        result = json.loads(result.content)
        print(result)



# 创建线程
thread1 = threading.Thread(target=l_pur(), args=("Thread-1", 1))

# 启动线程
thread1.start()

# 等待线程结束
thread1.join()
