# -*- encoding=utf8 -*-
import traceback

from air_case.public1.public1.public1 import get_hosid, get_branch_id, login, get_stockAreaId_new_fromDb, call_login, \
    updateUserLoginDefaultRange, get_listUserMgrRangePage
from common.fileUtls import FileUtils
from common.run_cmd_script import execute_command

__author__ = "xiaohesheng"

"""
case_tag:api,spd_core,a_a5流程五_中心库入库结算_正结算,id2302,id2302-5,sit,on
主数据平台:a_a5流程五_中心库入库结算_正结算 
python runner_test.py tag id2302-5 debug mdm3
"""

from common.common_func import commonFuc
from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from airtest.core.api import using
import sys
import time

module = "b5_spd3_core_business_flow"


# def login():
#     module = "b2_herp3_bs"
#     # 登录获取用户id等信息，使用创建的用户登录===========开始
#     info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
#     print(info)
#     username1 = info['username1']
#
#     username = username1
#     ## print('医院名称',username)
#     password = commonFuc().get_business_data(module, "password")
#     # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
#     # 获取token和projectCode
#     token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
#     return token, projectCode, uxid, corpId, info
#     # 登录获取用户id等信息，使用创建的用户登录============结束


# 采购计划_低值
def low_vaule_purchase_plan(token='token',uxid='uxid'):
    module = "b3_herp3_purchase"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    # info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    # username1 = info['username1']
    #
    # username = username1
    # ## print('医院名称',username)
    # password = commonFuc().get_business_data(module, "password")
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    # token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # 获取暂存的单号=======================================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_insert_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    hosGoodsId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    pkgDefId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品包装信息', 'message6')["unitPackageid1"]
    # 获取院区id
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    hospital_name = commonFuc().get_business_data(module, 'hospital_name')
    areaCode = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["shelfCode"]
    # deptname1 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    # areaCode =get_stockAreaId_new_fromDb(deptname1, 1)
    areaName = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["areaName"]
    recUser = uxid

    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload1_1_1", hosGoodsId, pkgDefId, hosId, branch_id,
                                                 hospital_name, deptid1, deptid1, areaCode, areaName, recUser)
    print('低值采购计划request_body', request_body)
    # new_request_body = request_body.replace("'", '"')
    # new_request_body = new_request_body.replace("None", 'null')
    # # print(new_request_body)
    # import json
    # request_body_json = json.loads(new_request_body)
    # print('request_body_json', request_body_json)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    pid = commonFuc().analysis_json('data', result)  # 采购计划号
    # 获取暂存的单号==========================================================

    # 获取采购计划详情中的id
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_listVo_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload11", pid)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    data = commonFuc().analysis_json('data', result)
    id1 = commonFuc().analysis_json('id', data[0])
    orderNo = commonFuc().analysis_json('orderNo', data[0])
    print('orderNo',orderNo)
    titlename=('orderNo1','orderNo2')
    info=(orderNo,orderNo)
    FileUtils().w_info8(info,'b5_spd3_core_business_flow', '采购计划单号', titlename, 'message7')
    # =====================================

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_submitPurPlan_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    provId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    provName = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    subProvId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    subProvName = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload12_1_1", pid, id1, provId, provName, subProvId,
                                                 subProvName, hosGoodsId, pkgDefId)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultbbbbbbbbbbbbbbbbbbbb', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == None:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)

def approval_center(token='token'):
    module = "b2_herp3_bs"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    # info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    # username1 = info['username1']
    #
    # username = username1
    # ## print('医院名称',username)
    # password = commonFuc().get_business_data(module, "password")
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    # token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "apprCenter_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_6")
    print(request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    # checkDict=commonFuc().get_business_data(module,'checkDict10')
    # commonFuc().check_result(checkDict,result)
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', result)
    data1 = commonFuc().analysis_json('data', data)

    commonFuc().check_text_exist(0, result)
    taskId = commonFuc().analysis_json('taskId', data1[0])


    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "approvalBatch_url")

    # 请求体
    request_body = commonFuc().get_business_data(module, "payload50_7", taskId)
    print(request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    # 断言
    # checkDict=commonFuc().get_business_data(module,'checkDict10')
    # commonFuc().check_result(checkDict,result)
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', result)
    if code >= 0:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)

def get_GoodsPkgDef(hosGoodsId,token='token'):
    # 获取院区产品id==================开始
    module = "b2_herp3_bs"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    # info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    # username1 = info['username1']
    #
    # username = username1
    # ## print('医院名称',username)
    # password = commonFuc().get_business_data(module, "password")
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    # token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录===========结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "mcmsBranchGoodsInfo_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # 获取院区id
    branch_id = FileUtils().r_info(module, '院区新增')["branch_id"]
    hos_id = branch_id[0:5]
    print(hos_id)
    # hosGoodsId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
    GoodsId = hosGoodsId.replace(hos_id, '')
    print(GoodsId)
    deptid1 = FileUtils().r_info8(module, '所有科室id', 'message6')["deptid1"]
    # #请求体
    request_body = commonFuc().get_business_data(module, "payload39_1_1", branch_id, hos_id, GoodsId, deptid1)
    print(request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    total = commonFuc().analysis_json('total', commonFuc().analysis_json('data', result))

    data = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    branchGoodsId = commonFuc().analysis_json('branchGoodsId', data)
    hosGoodsId = commonFuc().analysis_json('hosGoodsId', data)

    # 获取院区产品id ===========结束

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "branchGoodsPkgDef_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    # 获取院区id
    branch_id = FileUtils().r_info(module, '院区新增')["branch_id"]

    # #请求体
    request_body = commonFuc().get_business_data(module, "payload42_2", hos_id, branch_id, branchGoodsId)
    print('request_body', request_body)
    # # # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # 断言
    # checkDict=commonFuc().get_business_data(module,'checkDict10')
    # commonFuc().check_result(checkDict,result)
    unitPackageid = commonFuc().analysis_json('id', commonFuc().analysis_json('data', result))
    print('unitPackageid', unitPackageid)
    info = (unitPackageid, unitPackageid)
    titlename = ('unitPackageid1', 'unitPackageid2')
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '产品包装信息', titlename, 'message6')
#高值采购计划
def hight_vaule_purchase_plan(token='token',uxid='uxid'):
    module = "b3_herp3_purchase"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    # info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    # username1 = info['username1']
    #
    # username = username1
    # ## print('医院名称',username)
    # password = commonFuc().get_business_data(module, "password")
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    # token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # 获取暂存的单号=======================================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_insert_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    hosGoodsId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message1')["hosGoodsId"]
    pkgDefId = None
    # 获取院区id
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    hospital_name = commonFuc().get_business_data(module, 'hospital_name')
    areaCode = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["shelfCode"]
    # deptname1 = FileUtils().r_info8("b2_herp3_bs", "所有科室name", 'message6')['deptid1']
    # areaCode = get_stockAreaId_new_fromDb(deptname1, 1)
    areaName = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["areaName"]
    recUser = uxid

    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload1_1_2", hosGoodsId, hosId, branch_id,
                                                 hospital_name, deptid1, deptid1, areaCode, areaName, recUser)
    print('request_body', request_body)
    # new_request_body = request_body.replace("'", '"')
    # new_request_body = new_request_body.replace("None", 'null')
    # # print(new_request_body)
    # import json
    # request_body_json = json.loads(new_request_body)
    # print('request_body_json', request_body_json)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    pid = commonFuc().analysis_json('data', result)  # 采购计划号
    # 获取暂存的单号==========================================================

    # 获取采购计划详情中的id
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_listVo_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload11", pid)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    data = commonFuc().analysis_json('data', result)
    id1 = commonFuc().analysis_json('id', data[0])
    orderNo = commonFuc().analysis_json('orderNo', data[0])
    print('orderNo',orderNo)
    titlename=('orderNo1','orderNo2')
    info=(orderNo,orderNo)
    FileUtils().w_info8(info,'b5_spd3_core_business_flow', '采购计划单号高值', titlename, 'message11')
    # =====================================

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_submitPurPlan_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    provId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    provName = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    subProvId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    subProvName = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload12_1_2", pid, id1, provId, provName, subProvId,
                                                 subProvName, hosGoodsId)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultbbbbbbbbbbbbbbbbbbbb', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == None:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
#试剂采购计划
def reagent_purchase_plan(token='token',uxid='uxid'):
    module = "b3_herp3_purchase"
    # 登录获取用户id等信息，使用创建的用户登录===========开始
    # info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    # username1 = info['username1']
    #
    # username = username1
    # ## print('医院名称',username)
    # password = commonFuc().get_business_data(module, "password")
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    # token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # 获取暂存的单号=======================================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_insert_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    hosGoodsId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message3')["hosGoodsId"]

    get_GoodsPkgDef(hosGoodsId,token)  # 获取单元包id
    pkgDefId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品包装信息', 'message6')["unitPackageid1"]

    # 获取院区id
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    hospital_name = commonFuc().get_business_data(module, 'hospital_name')
    areaCode = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["shelfCode"]
    areaName = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["areaName"]
    recUser = uxid

    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload1_1_3", hosGoodsId,pkgDefId, hosId, branch_id,
                                                 hospital_name, deptid1, deptid1, areaCode, areaName, recUser)
    print('request_body', request_body)
    # new_request_body = request_body.replace("'", '"')
    # new_request_body = new_request_body.replace("None", 'null')
    # # print(new_request_body)
    # import json
    # request_body_json = json.loads(new_request_body)
    # print('request_body_json', request_body_json)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    pid = commonFuc().analysis_json('data', result)  # 采购计划号
    # 获取暂存的单号==========================================================

    # 获取采购计划详情中的id
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_listVo_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload11", pid)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    data = commonFuc().analysis_json('data', result)
    id1 = commonFuc().analysis_json('id', data[0])
    orderNo = commonFuc().analysis_json('orderNo', data[0])
    print('orderNo', orderNo)
    titlename = ('orderNo1', 'orderNo2')
    info = (orderNo, orderNo)
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '采购计划单号试剂', titlename, 'message12')
    # =====================================

    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "herpService_purPlan_submitPurPlan_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    provId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    provName = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    subProvId = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_corpId"]
    subProvName = FileUtils().r_info8('b5_spd3_core_business_flow', '供货关系申请2', 'message')["e_username"]
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload12_1_3", pid, id1, provId, provName, subProvId,
                                                 subProvName, hosGoodsId,pkgDefId)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultbbbbbbbbbbbbbbbbbbbb', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == None:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)
def goods_move3(token='token'):  # 设置请领出库渠道为中心库
    # # # 登录获取用户id等信息，使用创建的用户登录===========开始
    # info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # username = info['username1']
    # password = commonFuc().get_business_data("b2_herp3_bs", "password")
    # print('username,password', username, password)
    # # # 获取token和projectCode
    # token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    module = "b2_herp3_bs"
    # 设置请领出库渠道为中心库
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "updateSettleType_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    for i in range(1, 4):
        info = FileUtils().r_info8('b5_spd3_core_business_flow', "产品审核信息", 'message%s' % i)
        hosGoodsId = info['hosGoodsId']
        GoodsId = hosGoodsId.replace(get_hosid(), '')
        branchGoodsId = SERACH_goods_id(GoodsId)
        # #请求体
        request_body = commonFuc().get_business_data(module, "payload47_3", branchGoodsId, hosGoodsId, get_branch_id())
        print(request_body)
        # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('goods_move,result', result)
def edit_goods_property():
    # 2024年11月19日，检测试剂产品增加了是否单瓶管理功能，默认为否，需要修改脚本
    # 在科室产品分配中查询检测试剂
    #修改试剂的属性值,单瓶管理为"是"
    module = "b2_herp3_bs"
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)

    info = FileUtils().r_info8('b5_spd3_core_business_flow', "产品审核信息", 'message3')
    hosGoodsId = info['hosGoodsId']
    GoodsId = hosGoodsId.replace(get_hosid(), "")
    currentDeptId = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
    targetDeptId= FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "basic_mcmsDeptGoodsInfo_page_url")

    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))

    # #请求体
    request_body = commonFuc().get_business_data(module, "payload58_13_2",GoodsId, currentDeptId, get_hosid())
    result = commonFuc().http_post(url, request_body, headers)
    print('科室产品列表查询', result)
    data1 = commonFuc().analysis_json('data', commonFuc().analysis_json('data', result))
    for i in data1:
        shelfCode = commonFuc().analysis_json('shelfCode', i)
        id1 = commonFuc().analysis_json('id', i)
        pkgDefId = commonFuc().analysis_json('pkgDefId', i)
        purMode = commonFuc().analysis_json('purMode', i)
        tbStatus = commonFuc().analysis_json('tbStatus', i)
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "herpService_basic_mcmsDeptGoodsInfo_url")
        url = url + id1
        result = commonFuc().http_get(url, headers)
        print('获取产品详情信息', result)
        data2 = commonFuc().analysis_json('data', result)
        packetQty = commonFuc().analysis_json('packetQty', data2)
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "basic_mcmsDeptGoodsInfo_updateById")
        if purMode == 60:  # 低值和试剂
            request_body = commonFuc().get_business_data(module, "payload58_10_3", id1, pkgDefId, targetDeptId,
                                                         shelfCode, packetQty,
                                                         tbStatus)

        print('编辑试剂产品属性request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('编辑试剂产品属性result', result)
def SERACH_goods_id(GoodsId):
    # 在请领出库渠道直送中搜索产品
    module = 'b5_spd3_core_business_flow'
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    username = info['username1']
    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    print('username,password', username, password)
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login(username, password, 2)
    # 登录获取用户id等信息，使用创建的用户登录============结束\
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                             "herpService_mcmsBranchGoodsInfo_page_url")
    dept1 = FileUtils().r_info8("b2_herp3_bs", "所有科室id", 'message6')['deptid1']
    # hosGoodsId = FileUtils().r_info8("b5_spd3_core_business_flow", "产品审核信息", 'message2')['hosGoodsId']
    # GoodsId = hosGoodsId.replace(get_hosid(), '')
    request_body = commonFuc().get_business_data(module, "payload53_3", GoodsId, get_hosid(), get_branch_id(), dept1)
    result = commonFuc().http_post(url, request_body, headers)
    branchGoodsId = commonFuc().analysis_json('id', commonFuc().analysis_json('data', commonFuc().analysis_json('data',
                                                                                                                result)))
    return branchGoodsId
def main():
    token, projectCode1, uxid1, corpId1, info1 = call_login(2)
    updateUserLoginDefaultRange(get_listUserMgrRangePage(1))  # 设置登录账号默认权限是1级库
    try:
        goods_move3(token)#
        edit_goods_property()
        # 获取低值的hosGoodsId
        hosGoodsId = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"]
        get_GoodsPkgDef(hosGoodsId,token)  # 获取单元包id
    except:
        print('流程五获取hosGoodsId出现错误,请检查脚本或者数据')
    try:
        low_vaule_purchase_plan(token,uxid1)
    except Exception as e:
        print('低值采购计划提交出现错误,请检查脚本或者数据')
        print("发生异常：", str(e))
        traceback.print_exc()
    #审批
    try:
        approval_center(token)
    except Exception as e:
        print('审批采购计划出现错误,请检查脚本或者数据')
        print("发生异常：", str(e))
    try:
        hight_vaule_purchase_plan(token,uxid1)
    except Exception as e:
        print('高值采购计划出现错误,请检查脚本或者数据')
        print("发生异常：", str(e))
    try:
        approval_center(token)
    except Exception as e:
        print('审批采购计划出现错误,请检查脚本或者数据')
        print("发生异常：", str(e))
    try:
        reagent_purchase_plan(token,uxid1)
    except Exception as e:
        print('试剂采购计划出现错误,请检查脚本或者数据')
        print("发生异常：", str(e))
    try:
        approval_center(token)
    except Exception as e:
        print('审批采购计划出现错误,请检查脚本或者数据')
        print("发生异常：", str(e))
    commonFuc().check_text_exist_result_text('succees','succees')

main()