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

from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from air_case.public1.public1.public1 import *
from common.db.sql.sql_del_branch_info import delData

from common.fileUtls import FileUtils
from common.run_cmd_script import execute_command
from common.timeUtils import timeUtils
from airtest.core.api import using

__author__ = "xiaohesheng"

"""
case_tag:api,spd_core,a_b9流程十六退库业务_二级库向一级库退库,id2302,id2302-19,sit,on
核心业务流:a_b9流程十六退库业务_二级库向一级库退库
python runner_test.py tag id2302-19 debug mdm3
"""

# 入库上架
def putaway():
    module = "b5_spd3_core_business_flow"
    updateUserLoginDefaultRange(get_listUserMgrRangePage1(1))  # 设置登录账号默认权限是一级库
    # # 登录获取用户id等信息，使用创建的用户登录===========开始
    info = FileUtils().r_info8('b2_herp3_bs', "用户名信息", 'message3')
    # print(info)
    username = info['username1']

    password = commonFuc().get_business_data("b2_herp3_bs", "password")
    # username = '001f90380'
    # password='1qaz!QAZ'
    print('username,password', username, password)
    # # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # 登录获取用户id等信息，使用创建的用户登录============结束
    # =====================上架入库列表查询==========================
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "stock_in_page_url")
    print(url)
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    request_body = commonFuc().get_business_data(module, "payload6", branch_id, hosId)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    data = commonFuc().analysis_json('data', result)
    total = commonFuc().analysis_json('total', data)
    if total >= 1:
        # 将上架入库列表数据写入文件
        data = commonFuc().analysis_json('data', result)
        data1 = commonFuc().analysis_json('data', data)
        list_a = []
        list_b = []
        list_c = []
        list_a.append(data1)
        list_b.append(data1)
        list_c.append(data1)
        # print('list_a', len(list_a), list_a)
        info = (list_a, list_b, list_c)
        titlename = ('list_a', 'list_b', 'list_c')
        # 将验收单详细信息写入到文件中
        FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '上架入库列表数据', titlename, 'message16')
    # =====================上架入库列表查询==========================
    # =============查看验收单详情========================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "stock_detail_url")
    print('查看验收单详情',url)
    deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
    areaCode = FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["shelfCode"]
    branch_id = FileUtils().r_info('b2_herp3_bs', '院区新增')["branch_id"]
    hosId = branch_id[0:5]
    # 从message16文件中获取信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "上架入库列表数据", 'message16')
    list_a = info['list_a']
    print('list_a', list_a)
    sourceId = 'sourceId'
    sourceType='sourceType'
    for i in list_a:
        for j in i:
            sourceId = j['sourceId']
            sourceType = j["sourceType"]
            break

    request_body = commonFuc().get_business_data(module, "payload4_1", deptid1, areaCode, hosId, sourceId, sourceType)

    print('request_body', 'd', request_body)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    targetDeptId =commonFuc().analysis_json('targetDeptId',commonFuc().analysis_json('data',result))
    # 将验收单详情写入文件
    data = commonFuc().analysis_json('data', result)
    list_a = []
    list_b = []
    list_c = []
    list_a.append(data)
    list_b.append(data)
    list_c.append(data)
    # print('list_a', len(list_a), list_a)
    info = (list_a, list_b, list_c)
    titlename = ('list_a', 'list_b', 'list_c')
    # 将验收单详细信息写入到文件中
    FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '验收单库存详情信息', titlename, 'message17')
    time.sleep(6)
    # =============    # =============查看验收单详情================================================
    # ================================入库上架===================
    url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module, "stock_detail_submit_url")
    print(url)
    viewId = 'viewId'
    shelfCode = 'shelfCode'
    sourceId = 'sourceId'
    sourceVersion = '1'
    targetDeptId = deptid1
    targetDeptName = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid1"]
    targetAreaCode =  FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["shelfCode"]
    targetAreaName =  FileUtils().r_info8('b2_herp3_bs', 'shelfinfo', 'message7')["areaName"]
    # 从message17文件中获取信息
    info = FileUtils().r_info8('b5_spd3_core_business_flow', "验收单库存详情信息", 'message17')
    # print('info', info)
    list_a = info['list_a']
    print('list_a', list_a)
    for i in list_a:
        print('i', i)
        for j in i:
            viewId = j["viewId"]
            shelfCode = j['shelfCode']
            sourceId = j['pid']
            break
    # # 从message16文件中获取信息
    # info = FileUtils().r_info8('b5_spd3_core_business_flow', "上架入库列表数据", 'message16')
    # list_a = info['list_a']
    # print('list_a', list_a)
    # for i in list_a:
    #     for j in i:
    #         sourceId = j['sourceId']
    #         targetAreaName = j['areaName']
    #         targetAreaCode = j['areaCode']
    #         break
    request_body = commonFuc().get_business_data(module, "payload5", viewId, shelfCode, sourceId, sourceType,
                                                 sourceVersion, targetDeptId,
                                                 targetDeptName, targetAreaCode, targetAreaName)
    print('request_body', request_body)
    time.sleep(3)
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    # ================================入库上架================================



def second_dept_return_Out_Stock(type):  # 二级库退库出库
    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"))

    if type == 2:
        udi_code = get_udi2(2,token)  # 获取条码 低值1 高值2 试剂3

        # 高值退库出库
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "herpService_stock_pick_scan_url")
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        # print('info', info)
        list_a = info['list_a']
        stockId = commonFuc().analysis_json('stockId', list_a)
        stockName = commonFuc().analysis_json('stockName', list_a)
        areaCode = commonFuc().analysis_json('areaCode', list_a)
        areaName = commonFuc().analysis_json('areaName', list_a)
        deptId2= FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        targetDeptId= FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
        deptName = get_branch_name()
        targetStockId =get_stockId(deptName+'中心库房',1)

        request_body = commonFuc().get_business_data(module, "payload65", udi_code, stockId, deptId2,areaCode, areaName,
                                                     targetStockId,targetDeptId)
        print('request_body',request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('退库出库扫码result',result)
        # 获取必要信息
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]

        data1 = commonFuc().analysis_json('data', result)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        UTid = commonFuc().analysis_json('id', data1)
        createTime = commonFuc().analysis_json('id', data1)
        stockId = commonFuc().analysis_json('stockId', data1)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        areaName = commonFuc().analysis_json('areaName', data1)
        shelfCode = commonFuc().analysis_json('shelfCode', data1)
        codeType = commonFuc().analysis_json('codeType', data1)
        tagType = commonFuc().analysis_json('tagType', data1)
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
        mdmGoodsCode = commonFuc().analysis_json('mdmGoodsCode', data1)
        goodsCode = commonFuc().analysis_json('goodsCode', data1)
        goodsDi = commonFuc().analysis_json('goodsDi', data1)
        barName = commonFuc().analysis_json('barName', data1)
        batchCode = commonFuc().analysis_json('batchCode', data1)
        expdtDate = commonFuc().analysis_json('expdtDate', data1)
        productDate = commonFuc().analysis_json('productDate', data1)
        pkgCode = commonFuc().analysis_json('pkgCode', data1)
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
        ssccCode = commonFuc().analysis_json('ssccCode', data1)
        tbStatus = commonFuc().analysis_json('tbStatus', data1)
        ext = commonFuc().analysis_json('ext', data1)
        distrDetailId = commonFuc().analysis_json('distrDetailId', ext)
        distrBillId = commonFuc().analysis_json('distrBillId', ext)
        purBillId = commonFuc().analysis_json('purBillId', ext)
        pkgDefQty = commonFuc().analysis_json('pkgDefQty', ext)
        pkgDefId = commonFuc().analysis_json('pkgDefId', ext)
        pkgDefName = commonFuc().analysis_json('pkgDefName', ext)
        purMode = commonFuc().analysis_json('purMode', data1)
        goodsMfrsName = commonFuc().analysis_json('goodsMfrsName', data1)
        goodsSpec = commonFuc().analysis_json('goodsSpec', data1)
        unit = commonFuc().analysis_json('unit', data1)
        goodsName = commonFuc().analysis_json('goodsName', data1)
        pkgDefId = commonFuc().analysis_json('pkgDefId', data1)
        # pkgDefQty=commonFuc().analysis_json('pkgDefQty',data1)
        pkgDefName = commonFuc().analysis_json('pkgDefName', data1)
        printNum = commonFuc().analysis_json('printNum', data1)
        made = commonFuc().analysis_json('made', data1)
        hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
        sourceId = commonFuc().analysis_json('sourceId', data1)
        price = commonFuc().analysis_json('price', data1)
        purModeText = commonFuc().analysis_json('purModeText', data1)
        version = commonFuc().analysis_json('version', data1)
        unitName = commonFuc().analysis_json('unitName', data1)
        # ==============================获取条码信息
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        # print('info', info)
        list_a = info['list_a']
        extInfo = commonFuc().analysis_json('extInfo', list_a)
        print('extInfo', extInfo)
        # inStockTime = commonFuc().analysis_json('inStockTime', extInfo)
        inStockTime = reGetString(extInfo, r'inStockTime": "', r'", "')
        print('inStockTime', inStockTime)
        # import pdb
        # pdb.set_trace()
        # 从message18文件中获取信息
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_out_submit_url")


        deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
        deptName2 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
        stockName2 = deptName2 + "库房"
        createTime = timeUtils().get_time_hms(1)
        request_body = "request_body"
        mgrCorpName = get_hosname()
        mgrRangeId = deptid2
        mgrRangeName = deptName2
        extStr1 = get_branch_name()
        extStr3 = get_branch_name()
        snCode = UTid
        userLoginCode = username
        cname = username
        orgCode1 = get_orgCode()
        orgName1 = get_orgName()
        # print(orgCode1, orgName1)
        # import pdb
        # pdb.set_trace()

        request_body = commonFuc().get_business_data(module, "payload50_2_3", stockId, deptId2, areaCode,
                                                     areaName,targetStockId,targetDeptId,
                                                     uxid, userLoginCode, cname, get_hosid(), get_branch_id(),
                                                     deptid1,
                                                     orgCode1, orgName1, get_hosid(), get_hosid(), mgrCorpName,
                                                     get_branch_id(),
                                                     get_branch_name(), mgrRangeId, mgrRangeName, extStr1, extStr3,
                                                     get_hosid(), stockId,deptId2,
                                                     areaCode, areaName, targetStockId, targetDeptId, UTid,createTime,snCode,
                                                     get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi,
                                                     barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee,
                                                     ssccCode,
                                                     tbStatus, purBillId,
                                                     distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName,made, unitName,
                                                     hosGoodsCode, purModeText)
        print('request_body', '高值退库出库', request_body)
        # import pdb
        # pdb.set_trace()
        # # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
    elif type == 1:
        print('低值耗材或者试剂退库出库')
        udi_code = get_udi2(1,token)  # 获取条码 低值1 高值2 试剂3
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "herpService_stock_pick_scan_url")
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        # print('info', info)
        list_a = info['list_a']
        stockId = commonFuc().analysis_json('stockId', list_a)
        stockName = commonFuc().analysis_json('stockName', list_a)
        areaCode = commonFuc().analysis_json('areaCode', list_a)
        areaName = commonFuc().analysis_json('areaName', list_a)
        deptId2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        targetDeptId = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
        deptName =  get_branch_name()
        targetStockId = get_stockId(deptName + '中心库房', 1)

        request_body = commonFuc().get_business_data(module, "payload65", udi_code, stockId, deptId2, areaCode,
                                                     areaName,
                                                     targetStockId, targetDeptId)
        print('request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('退库出库扫码result', result)

        # 获取必要信息
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        data1 = commonFuc().analysis_json('data', result)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        UTid = commonFuc().analysis_json('id', data1)
        createTime = commonFuc().analysis_json('id', data1)
        stockId = commonFuc().analysis_json('stockId', data1)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        areaName = commonFuc().analysis_json('areaName', data1)
        shelfCode = commonFuc().analysis_json('shelfCode', data1)
        codeType = commonFuc().analysis_json('codeType', data1)
        tagType = commonFuc().analysis_json('tagType', data1)
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
        mdmGoodsCode = commonFuc().analysis_json('mdmGoodsCode', data1)
        goodsCode = commonFuc().analysis_json('goodsCode', data1)
        goodsDi = commonFuc().analysis_json('goodsDi', data1)
        barName = commonFuc().analysis_json('barName', data1)
        batchCode = commonFuc().analysis_json('batchCode', data1)
        expdtDate = commonFuc().analysis_json('expdtDate', data1)
        productDate = commonFuc().analysis_json('productDate', data1)
        pkgCode = commonFuc().analysis_json('pkgCode', data1)
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
        ssccCode = commonFuc().analysis_json('ssccCode', data1)
        tbStatus = commonFuc().analysis_json('tbStatus', data1)
        ext = commonFuc().analysis_json('ext', data1)
        distrDetailId = commonFuc().analysis_json('distrDetailId', ext)
        distrBillId = commonFuc().analysis_json('distrBillId', ext)
        purBillId = commonFuc().analysis_json('purBillId', ext)
        pkgDefQty = commonFuc().analysis_json('pkgDefQty', ext)
        pkgDefId = commonFuc().analysis_json('pkgDefId', ext)
        pkgDefName = commonFuc().analysis_json('pkgDefName', ext)
        purMode = commonFuc().analysis_json('purMode', data1)
        goodsMfrsName = commonFuc().analysis_json('goodsMfrsName', data1)
        goodsSpec = commonFuc().analysis_json('goodsSpec', data1)
        unit = commonFuc().analysis_json('unit', data1)
        goodsName = commonFuc().analysis_json('goodsName', data1)
        pkgDefId = commonFuc().analysis_json('pkgDefId', data1)
        # pkgDefQty=commonFuc().analysis_json('pkgDefQty',data1)
        pkgDefName = commonFuc().analysis_json('pkgDefName', data1)
        printNum = commonFuc().analysis_json('printNum', data1)
        made = commonFuc().analysis_json('made', data1)
        hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
        sourceId = commonFuc().analysis_json('sourceId', data1)
        price = commonFuc().analysis_json('price', data1)
        purModeText = commonFuc().analysis_json('purModeText', data1)
        version = commonFuc().analysis_json('version', data1)
        unitName = commonFuc().analysis_json('unitName', data1)
        # ==============================获取条码信息
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        # print('info', info)
        list_a = info['list_a']
        extInfo = commonFuc().analysis_json('extInfo', list_a)
        print('extInfo', extInfo)
        # inStockTime = commonFuc().analysis_json('inStockTime', extInfo)
        inStockTime = reGetString(extInfo, 'inStockTime\"\: \"', '\"\, \"distrDetailId')
        print('inStockTime', inStockTime)
        # 从message18文件中获取信息
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_out_submit_url")

        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
        deptName2 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
        stockName2 = deptName2 + "库房"
        createTime = timeUtils().get_time_hms(1)
        request_body = "request_body"
        mgrCorpName = get_hosname()
        mgrRangeId = deptid2
        mgrRangeName = deptName2
        extStr1 = get_branch_name()
        extStr3 = get_branch_name()
        snCode = UTid
        userLoginCode = username
        cname = username
        orgCode1 = get_orgCode()
        orgName1 = get_orgName()

        request_body = commonFuc().get_business_data(module, "payload50_2_4", stockId, deptId2, areaCode,
                                                     areaName,targetStockId,targetDeptId,
                                                     uxid, userLoginCode, cname, get_hosid(), get_branch_id(),
                                                     deptid1,
                                                     orgCode1, orgName1, get_hosid(), get_hosid(), mgrCorpName,
                                                     get_branch_id(),
                                                     get_branch_name(), mgrRangeId, mgrRangeName, extStr1, extStr3,
                                                     get_hosid(), stockId,deptId2,
                                                     areaCode, areaName, targetStockId, targetDeptId, UTid,createTime,snCode,
                                                     get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi,
                                                     barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee,
                                                     ssccCode,
                                                     tbStatus, pkgDefId,purBillId,
                                                     distrBillId,
                                                     inStockTime, distrDetailId,purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName,pkgDefId,pkgDefName,made, unitName,
                                                     hosGoodsCode, purModeText)

        print('request_body', request_body)
        # # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('低值产品退库出库，result', result)
    elif type == 3:
        print('试剂产品退库出库')
        udi_code = get_udi2(3,token)  # 获取条码 低值1 高值2 试剂3
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "herpService_stock_pick_scan_url")
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        # print('info', info)
        list_a = info['list_a']
        stockId = commonFuc().analysis_json('stockId', list_a)
        stockName = commonFuc().analysis_json('stockName', list_a)
        areaCode = commonFuc().analysis_json('areaCode', list_a)
        areaName = commonFuc().analysis_json('areaName', list_a)
        deptId2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        targetDeptId = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
        deptName =  get_branch_name()
        targetStockId = get_stockId(deptName + '中心库房', 1)

        request_body = commonFuc().get_business_data(module, "payload65", udi_code, stockId, deptId2, areaCode,
                                                     areaName,
                                                     targetStockId, targetDeptId)
        print('request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('退库出库扫码result', result)

        # 获取必要信息
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        data1 = commonFuc().analysis_json('data', result)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        UTid = commonFuc().analysis_json('id', data1)
        createTime = commonFuc().analysis_json('id', data1)
        stockId = commonFuc().analysis_json('stockId', data1)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        areaName = commonFuc().analysis_json('areaName', data1)
        shelfCode = commonFuc().analysis_json('shelfCode', data1)
        codeType = commonFuc().analysis_json('codeType', data1)
        tagType = commonFuc().analysis_json('tagType', data1)
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
        mdmGoodsCode = commonFuc().analysis_json('mdmGoodsCode', data1)
        goodsCode = commonFuc().analysis_json('goodsCode', data1)
        goodsDi = commonFuc().analysis_json('goodsDi', data1)
        barName = commonFuc().analysis_json('barName', data1)
        batchCode = commonFuc().analysis_json('batchCode', data1)
        expdtDate = commonFuc().analysis_json('expdtDate', data1)
        productDate = commonFuc().analysis_json('productDate', data1)
        pkgCode = commonFuc().analysis_json('pkgCode', data1)
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
        ssccCode = commonFuc().analysis_json('ssccCode', data1)
        tbStatus = commonFuc().analysis_json('tbStatus', data1)
        ext = commonFuc().analysis_json('ext', data1)
        distrDetailId = commonFuc().analysis_json('distrDetailId', ext)
        distrBillId = commonFuc().analysis_json('distrBillId', ext)
        purBillId = commonFuc().analysis_json('purBillId', ext)
        pkgDefQty = commonFuc().analysis_json('pkgDefQty', ext)
        pkgDefId = commonFuc().analysis_json('pkgDefId', ext)
        pkgDefName = commonFuc().analysis_json('pkgDefName', ext)
        purMode = commonFuc().analysis_json('purMode', data1)
        goodsMfrsName = commonFuc().analysis_json('goodsMfrsName', data1)
        goodsSpec = commonFuc().analysis_json('goodsSpec', data1)
        unit = commonFuc().analysis_json('unit', data1)
        goodsName = commonFuc().analysis_json('goodsName', data1)
        pkgDefId = commonFuc().analysis_json('pkgDefId', data1)
        # pkgDefQty=commonFuc().analysis_json('pkgDefQty',data1)
        pkgDefName = commonFuc().analysis_json('pkgDefName', data1)
        printNum = commonFuc().analysis_json('printNum', data1)
        made = commonFuc().analysis_json('made', data1)
        hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
        sourceId = commonFuc().analysis_json('sourceId', data1)
        price = commonFuc().analysis_json('price', data1)
        purModeText = commonFuc().analysis_json('purModeText', data1)
        version = commonFuc().analysis_json('version', data1)
        unitName = commonFuc().analysis_json('unitName', data1)
        # ==============================获取条码信息
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        # print('info', info)
        list_a = info['list_a']
        extInfo = commonFuc().analysis_json('extInfo', list_a)
        print('extInfo', extInfo)
        # inStockTime = commonFuc().analysis_json('inStockTime', extInfo)
        inStockTime = reGetString(extInfo, 'inStockTime\"\: \"', '\"\, \"distrDetailId')
        print('inStockTime', inStockTime)
        # 从message18文件中获取信息
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_out_submit_url")

        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        deptid1 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid1"]
        deptName2 = FileUtils().r_info8('b2_herp3_bs', '所有科室name', 'message6')["deptid2"]
        stockName2 = deptName2 + "库房"
        createTime = timeUtils().get_time_hms(1)
        request_body = "request_body"
        mgrCorpName = get_hosname()
        mgrRangeId = deptid2
        mgrRangeName = deptName2
        extStr1 = get_branch_name()
        extStr3 = get_branch_name()
        snCode = UTid
        userLoginCode = username
        cname = username
        orgCode1 = get_orgCode()
        orgName1 = get_orgName()

        request_body = commonFuc().get_business_data(module, "payload50_2_4", stockId, deptId2, areaCode,
                                                     areaName, targetStockId, targetDeptId,
                                                     uxid, userLoginCode, cname, get_hosid(), get_branch_id(),
                                                     deptid1,
                                                     orgCode1, orgName1, get_hosid(), get_hosid(), mgrCorpName,
                                                     get_branch_id(),
                                                     get_branch_name(), mgrRangeId, mgrRangeName, extStr1, extStr3,
                                                     get_hosid(), stockId, deptId2,
                                                     areaCode, areaName, targetStockId, targetDeptId, UTid, createTime,
                                                     snCode,
                                                     get_hosid(), stockId, areaCode, areaName, shelfCode,
                                                     codeType, hosGoodsId, mdmGoodsCode, goodsCode, goodsDi,
                                                     barName,
                                                     batchCode, expdtDate, productDate, pkgCode, pkgCodeSee,
                                                     ssccCode,
                                                     tbStatus, pkgDefId, purBillId,
                                                     distrBillId,
                                                     inStockTime, distrDetailId, purMode, price, goodsMfrsName,
                                                     goodsSpec, unit, goodsName, pkgDefId, pkgDefName, made, unitName,
                                                     hosGoodsCode, purModeText)

        print('request_body', request_body)
        # # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('试剂产品退库出库，result', result)

def main():
    try:
        updateUserLoginDefaultRange(get_listUserMgrRangePage1(2))#设置登录账号默认权限是二级库
        second_dept_return_Out_Stock(2)#高值耗材退货出库
        approval_center()#审批
        putaway()#中心库上架
        updateUserLoginDefaultRange(get_listUserMgrRangePage1(2))#设置登录账号默认权限是二级库
        second_dept_return_Out_Stock(1)#低值耗材退货出库
        approval_center()  # 审批
        putaway()  # 中心库上架
        updateUserLoginDefaultRange(get_listUserMgrRangePage1(2))#设置登录账号默认权限是二级库
        second_dept_return_Out_Stock(3)#试剂耗材退货出库
        approval_center()#审批
        putaway()#中心库上架
        # ===============上面调通了================================
        commonFuc().check_text_exist_result_text('succees', 'succees')
        print('================流程十六执行完毕===================')

    except:
        commonFuc().check_text_exist_result_text('error', '1')
# main()