# -*- 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_b7流程十四退库业务_消耗退库,id2302,id2302-17,sit,on
核心业务流:a_b7流程十四退库业务_消耗退库
python runner_test.py tag id2302-17 debug mdm3
"""


def second_dept_consume_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:
    #     print('下面处理')
    # elif type == 3:
    #     # udi_code = get_udi2(3)  # 获取条码 低值1 高值2 试剂3
    #     print('下面处理')
    # else:
    #     udi_code = 'udi_code'
    if type == 2:
        udi_code = get_udi2(2)  # 获取条码 低值1 高值2 试剂3
        # import pdb
        # pdb.set_trace()
        info = (udi_code, udi_code)
        titlename = ('udi_code', 'udi_code')
        # 将高值消耗出库条码信息写入文件
        FileUtils().w_info8(info, 'b5_spd3_core_business_flow', '高值消耗条码', titlename, 'message24')
        # 高值消耗
        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)
        # 从message18文件中获取信息
        request_body = commonFuc().get_business_data(module, "payload61", udi_code, stockId, stockName, areaCode,
                                                     areaName)
        result = commonFuc().http_post(url, request_body, headers)
        # 获取必要信息
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        deptName = FileUtils().r_info8('b2_herp3_bs', '所有科室name', '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)
        stockName=commonFuc().analysis_json('stockName', 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)
        # 从message18文件中获取信息
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_out_submit_url")
        # import pdb
        # pdb.set_trace()

        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)

        request_body = commonFuc().get_business_data(module, "payload50_1_3", stockId, stockName2, areaCode,
                                                     areaName,
                                                     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,
                                                     stockName2, areaCode, areaName, 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, unitName,
                                                     hosGoodsCode, purModeText)
        print('request_body', '高值消耗出库', request_body)

        # # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
    elif type == 1:
        print('低值耗材消耗出库')
        udi_code = get_udi2(1)
        data1 = pickScan4(udi_code)
        # 获取必要信息
        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()
        url2 = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                  "herpService_stockpile_list_url")

        request_body2 = commonFuc().get_business_data(module, "payload62", stockId, stockName2, areaCode, areaName,
                                                      get_hosid())
        # # # # 发送请求
        result2 = commonFuc().http_post(url2, request_body2, headers)
        availableQty = commonFuc().analysis_json('availableQty', commonFuc().analysis_json('data',
                                                                                           commonFuc().analysis_json(
                                                                                               'data', result2)))
        transferRatio = commonFuc().analysis_json('transferRatio', commonFuc().analysis_json('data',
                                                                                             commonFuc().analysis_json(
                                                                                                 'data', result2)))
        print('result2', result2)
        request_body = commonFuc().get_business_data(module, "payload50_1_4", stockId, stockName2, areaCode,
                                                     areaName, get_hosid(), deptid2,
                                                     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,
                                                     stockId,
                                                     stockName2, areaCode, areaName, areaCode,
                                                     purMode,
                                                     hosGoodsId, goodsCode, batchCode, expdtDate, goodsSpec, goodsName,
                                                     goodsMfrsName, unit, mdmGoodsCode, availableQty, transferRatio
                                                     )

        print('request_body', request_body)
        # # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        print('result', result)
    elif type == 3:
        print('检验试剂消耗出库')
        udi_code = get_udi2(4)  # 试剂单瓶条码
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        data1 = info['list_a']
        UTid = 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)
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
        goodsCode = commonFuc().analysis_json('goodsCode', 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)
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
        ssccCode = commonFuc().analysis_json('ssccCode', data1)
        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)
        made = commonFuc().analysis_json('made', data1)
        hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
        purModeText = commonFuc().analysis_json('purModeText', 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)
        pkgBarcodeId = commonFuc().analysis_json('id', list_a)
        print('extInfo', extInfo)
        # inStockTime = commonFuc().analysis_json('inStockTime', extInfo)
        inStockTime = reGetString(extInfo, r'inStockTime": "', r'",')
        shelfNo = commonFuc().analysis_json('shelfNo', list_a)
        pkgUdi = reGetString(extInfo, r'pkgDefId": "', r'",')
        bottleId = commonFuc().analysis_json('bottleId', list_a)
        shelfKindName = commonFuc().analysis_json('shelfKindName', list_a)
        provName = commonFuc().analysis_json('provName', list_a)
        provId = commonFuc().analysis_json('provId', list_a)
        inStockDate = commonFuc().analysis_json('inStockDate', list_a)
        # 从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_1_5", stockId, stockName2, areaCode,
                                                     areaName,
                                                     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,
                                                     stockName2, areaCode, areaName, UTid, snCode, ssccCode, pkgCodeSee,
                                                     hosGoodsId, hosGoodsCode, goodsCode,
                                                     goodsName, goodsSpec, goodsMfrsName, unit, purMode, batchCode,
                                                     productDate, expdtDate, stockId, stockName2, areaName, areaCode,
                                                     unitName, shelfCode, shelfNo, pkgUdi, inStockTime, pkgBarcodeId,
                                                     bottleId, shelfKindName, provName, provId, inStockDate, made,
                                                     barName,
                                                     purModeText
                                                     )

        print('request_body', request_body)
        # # # # 发送请求
        result = commonFuc().http_post(url, request_body, headers)
        # import pdb
        # pdb.set_trace()
        print('result', result)


def sCan_grant(type=1):  # 获取条码and扫码发放高值不能发放
    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等信息，使用创建的用户登录============结束
    if type == 1:
        udi_code = get_udi2(1)  # 获取条码 低值1 高值2 试剂3
    elif type == 3:
        udi_code = get_udi2(3)  # 获取条码 低值1 高值2 试剂3
    else:
        udi_code = 'udi_code'
    if type == 1:
        pickScan3(udi_code, 1)  # 低值扫码发放
    elif type == 3:
        pickScan3(udi_code, 3)  # 试剂扫码发放


def second_dept_consume_in_Stock(type=1):
    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:
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_scan_url")
        print('消耗扫条码,url', url)
        # 从message18文件中获取信息
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        data1 = info['list_a']
        stockId = commonFuc().analysis_json('stockId', data1)
        areaCode = commonFuc().analysis_json('areaCode', data1)
        areaName = commonFuc().analysis_json('areaName', data1)
        shelfCode = commonFuc().analysis_json('shelfCode', data1)
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', data1)
        goodsCode = commonFuc().analysis_json('goodsCode', 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)
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', data1)
        ssccCode = commonFuc().analysis_json('ssccCode', data1)
        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)
        made = commonFuc().analysis_json('made', data1)
        hosGoodsCode = commonFuc().analysis_json('hosGoodsCode', data1)
        purModeText = commonFuc().analysis_json('purModeText', 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)
        pkgBarcodeId = commonFuc().analysis_json('id', list_a)
        print('extInfo', extInfo)
        # inStockTime = commonFuc().analysis_json('inStockTime', extInfo)
        inStockTime = reGetString(extInfo, r'inStockTime": "', r'",')
        shelfNo = commonFuc().analysis_json('shelfNo', list_a)
        pkgUdi = reGetString(extInfo, r'pkgDefId": "', r'",')
        bottleId = commonFuc().analysis_json('bottleId', list_a)
        shelfKindName = commonFuc().analysis_json('shelfKindName', list_a)
        provName = commonFuc().analysis_json('provName', list_a)
        provId = commonFuc().analysis_json('provId', list_a)
        inStockDate = commonFuc().analysis_json('inStockDate', list_a)
        stockName = commonFuc().analysis_json('stockName', list_a)

        request_body = commonFuc().get_business_data(module, "payload34", pkgCodeSee, stockId, stockName,
                                                     areaCode, areaName)
        print('消耗扫条码', 'request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('消耗扫条码,result', result)
        viewId2 = commonFuc().analysis_json('id', commonFuc().analysis_json('data', result))
        DRh_id = commonFuc().analysis_json('billId', commonFuc().analysis_json('data', result))
        barcodeId = commonFuc().analysis_json('bottleId', commonFuc().analysis_json('data', result))
        # 扫条码 == == == == == == == == == == == == == == == ==
        # 消耗退回 == == == == == == == == == == == == == == == ==
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_rtn_submit_url")
        print('高值消耗退回,url', url)
        billMode = '20'
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        request_body = commonFuc().get_business_data(module, "payload35", viewId2, hosGoodsId, DRh_id,
                                                     barcodeId, billMode, deptid2, areaCode, areaName)
        print('消耗退回', 'request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('消耗退回,result', result)
        data = commonFuc().analysis_json('data', result)
        code = commonFuc().analysis_json('code', result)
        if data != None and code == 0:
            commonFuc().check_text_exist_result_text('succees', 'succees')
        else:
            commonFuc().check_text_exist_result_text('error', 'succees')
    elif type == 1:
        print('低值耗材消耗退回入库')
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "herpService_dept_availablePage_list_url")
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        list_a = info['list_a']
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', 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)
        request_body = commonFuc().get_business_data(module, "payload63", stockId, stockName,
                                                     areaCode, areaName, get_hosid())
        print('低值消耗产品查询', 'request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('低值消耗产品查询,result', result)

        viewId2 = commonFuc().analysis_json('viewId', commonFuc().analysis_json('data',
                                                                                commonFuc().analysis_json('data',
                                                                                                          result)))
        DRh_id = commonFuc().analysis_json('billId',
                                           commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
        barcodeId = commonFuc().analysis_json('bottleId', commonFuc().analysis_json('data',
                                                                                    commonFuc().analysis_json('data',
                                                                                                              result)))
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', commonFuc().analysis_json('data',
                                                                                       commonFuc().analysis_json('data',
                                                                                                                 result)))
        # 消耗退回 == == == == == == == == == == == == == == == ==
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_rtn_submit_url")
        print('低值消耗消耗退回,url', url)
        billMode = '10'
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        request_body = commonFuc().get_business_data(module, "payload35", viewId2, hosGoodsId, DRh_id,
                                                     barcodeId, billMode, deptid2, areaCode, areaName)
        print('低值消耗消耗退回', 'request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('低值消耗消耗退回,result', result)
        data = commonFuc().analysis_json('data', result)
        code = commonFuc().analysis_json('code', result)
        if data != None and code == 0:
            commonFuc().check_text_exist_result_text('succees', 'succees')
        else:
            commonFuc().check_text_exist_result_text('error', 'succees')
    elif type == 3:
        print('试剂耗材消耗退回入库')
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "herpService_dept_availablePage_list_url")
        info = FileUtils().r_info8(module, "条码信息", 'message18')
        list_a = info['list_a']
        pkgCodeSee = commonFuc().analysis_json('pkgCodeSee', 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)
        request_body = commonFuc().get_business_data(module, "payload64", stockId, stockName,
                                                     areaCode, areaName, get_hosid())
        print('试剂耗材消耗退回入库产品查询', 'request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('试剂耗材消耗退回入库产品查询,result', result)
        # import pdb
        # pdb.set_trace()

        viewId2 = commonFuc().analysis_json('viewId', commonFuc().analysis_json('data',
                                                                                commonFuc().analysis_json('data',
                                                                                                          result)))
        DRh_id = commonFuc().analysis_json('billId',
                                           commonFuc().analysis_json('data', commonFuc().analysis_json('data', result)))
        barcodeId = commonFuc().analysis_json('bottleId', commonFuc().analysis_json('data',
                                                                                    commonFuc().analysis_json('data',
                                                                                                              result)))
        hosGoodsId = commonFuc().analysis_json('hosGoodsId', commonFuc().analysis_json('data',
                                                                                       commonFuc().analysis_json('data',
                                                                                                                 result)))
        # 消耗退回 == == == == == == == == == == == == == == == ==
        url = commonFuc().get_api_add_port_url() + commonFuc().get_business_data(module,
                                                                                 "dept_stock_rtn_submit_url")
        print('试剂耗材消耗退回,url', url)
        billMode = '67'
        deptid2 = FileUtils().r_info8('b2_herp3_bs', '所有科室id', 'message6')["deptid2"]
        request_body = commonFuc().get_business_data(module, "payload35", viewId2, hosGoodsId, DRh_id,
                                                     barcodeId, billMode, deptid2, areaCode, areaName)
        print('试剂耗材消耗退回', 'request_body', request_body)
        result = commonFuc().http_post(url, request_body, headers)
        print('试剂耗材消耗退回,result', result)
        data = commonFuc().analysis_json('data', result)
        code = commonFuc().analysis_json('code', result)
        if data != None and code == 0:
            commonFuc().check_text_exist_result_text('succees', 'succees')
        else:
            commonFuc().check_text_exist_result_text('error', 'succees')

def main():
    try:
        updateUserLoginDefaultRange(get_listUserMgrRangePage1(2))  # 设置登录账号默认权限是二级库
        sCan_grant(1)  # 低值扫码发放
        sCan_grant(3)  # 试剂扫码发放
        second_dept_consume_Out_Stock(2)  # 高值消耗出库
        second_dept_consume_in_Stock(2)  # 高值消耗退货入库
        second_dept_consume_Out_Stock(1)  # 低值消耗出库
        second_dept_consume_in_Stock(1)  # 低值消耗退回入库
        second_dept_consume_Out_Stock(3)  # 试剂消耗出库
        second_dept_consume_in_Stock(3)  # 试剂消耗退回入库
        commonFuc().check_text_exist_result_text('SUCCESS', 'SUCCESS')
        print('================流程十四执行完毕===================')
    except:
        commonFuc().check_text_exist_result_text('error', 'SUCCESS')
# main()