wsz
2025-06-10 4be5e6f4ae34bcb7cb47f05816421459bbfaedf1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
--[[
    版本:Version 2.1
    名称: 
    作者:HAN
    日期:2025-3-29
    
    WMS-Basis-Model-Version: V15.5
 
    共用程序包
    名称:   wms_wcs
    应用:   涉及和设备层进行交互,比如库区中堆垛机的状态,延伸到库区哪个个巷道可用
 
    函数:
        -- Get_DVC_State 获取设备状态
        -- Get_Area_Stacker_Dev_State 获取库区里堆垛机状态
 
    更改记录:
 
--]]
 
wms_base = require ("wms_base")
 
local wms_wcs = {_version = "0.2.1"}
 
-- Get_DVC_State 获取设备状态
-- reqDvc设备号 Z01,Z02,..., 
-- scanning_loc -- 读码位
local function wms_wcs.Get_DVC_State( strLuaDEID, reqDvc, scanning_loc )
    local nRet, strRetInfo
 
    local now = os.date("%Y%m%d%H%M%S")  
    local randomNum = math.random(1, 99999)  
    local requestPk = "PK"..now..randomNum
    local wcs_url
    nRet, wcs_url = wms_base.Get_sConst2( strLuaDEID, "WCS服务地址")
    if ( nRet ~= 0 ) then
        return 1, "系统无法获取常量'WCS服务地址'"
    end
 
    local strurl =  wcs_url..'/wcs-admin/api/dvc-state'
 
    if ( scanning_loc == nil ) then scanning_loc = '' end
 
    local body = {
                    requestPk = requestPk,
                    reqDvc = reqDvc,
                    readingBit = scanning_loc
                }
    lua.Debug( strLuaDEID, debug.getinfo(1), "调WCS接口-->", strurl )                     
    lua.Debug( strLuaDEID, debug.getinfo(1), "body", body )
 
 
    nRet, strRetInfo = mobox.sendHttpRequest( strurl, "", table2str(body) )
    if ( nRet ~= 0 or strRetInfo == '' ) then 
        return 2, "调用WCS /wcs-admin/api/receive 接口失败! "..strRetInfo 
    end  
 
    local ret_info = json.decode(strRetInfo)
    return 0, ret_info.data
end
 
--[[
    获取某个库区内设备的状态(在JX项目中特指库区内的堆垛机状态)
    输入参数:
        area_code   -- 库区编码
 
    返回参数:
        nRet = 0 成功 非零 失败
        stacker_dev = [{"dev_no"::xxx",lane:1,enable:0/1,cntr_num:0}]
        -- cntr_num 巷道入库接驳位容器数量
        -- lane 巷道号
        -- dev_no 堆垛机号
--]]
function wms_wcs.Get_Area_Stacker_Dev_State( strLuaDEID, area_code, scanning_loc )
    local nRet, strRetInfo
    if ( station == nil ) then station = '' end
 
    -- 获取 area_code 库区堆垛机设备工作状态,确定哪些巷道可以使用
    nRet, strRetInfo = wms_base.Get_sConst2( strLuaDEID, "Area-"..area_code.."-StackerCrane" )
    if ( nRet ~= 0 ) then
        return 1, "系统无法获取常量'Area-"..area_code.."-StackerCrane'"
    end
    if ( strRetInfo == '') then
        return 1, "常量'库区"..area_code.."-堆垛机设备' 不能为空! "
    end
    --[{"dev_no"::xxx",aisle:1,enable:false/true}]
    local stacker_dev = json.decode( strRetInfo )
    local n, m
    local dev_codes = ''
    for n = 1, #stacker_dev do
        dev_codes = dev_codes..stacker_dev[n].dev_no..","
    end
    if ( dev_codes == '') then
        return 1, "库区'"..area_code.."'没有定义设备!"
    end
    dev_codes = lua.trim_laster_char( dev_codes )
 
    -- 调用WCS接口获取设备状态
    -- [{"DVC_NO":"TC21","IS_USE":0/1,"CON_NUM":1},...]    
    nRet, dev_state =  wms_wcs.Get_DVC_State( strLuaDEID, dev_codes, scanning_loc )
    if ( nRet ~= 0 ) then return nRet, dev_state end
    local find
    for n = 1, #stacker_dev do
        find = false
        for m = 1, #dev_state do
            if ( stacker_dev[n].dev_no == dev_state[m].DVC_NO ) then
                find = true
                stacker_dev[n].enable = lua.Get_NumAttrValue( dev_state[m].IS_USE )
                stacker_dev[n].cntr_num = lua.Get_NumAttrValue( dev_state[m].CON_NUM )
                break
            end
        end
        if ( find == false ) then
            return 1, "WCS返回的设备状态中没有编码='"..stacker_dev[n].dev_no.."'的设备状态!"
        end
    end
    return 0, stacker_dev
end
 
-- 获取库区库可用的堆垛机巷道号 -- 1, 2, 4
function wms_wcs.Get_Area_Available_Aisle( strLuaDEID, area_code )
    local nRet, stacker_dev
 
    nRet, stacker_dev = wms_wcs.Get_Area_Stacker_Dev_State( strLuaDEID, area_code )
    if ( nRet ~= 0 ) then return nRet, stacker_dev end
 
    local n
    local aisle = ''
    for n = 1, #stacker_dev do
        if ( stacker_dev[n].enable == 1 ) then
            aisle = aisle..stacker_dev[n].aisle..","
        end
    end
    aisle = lua.trim_laster_char( aisle )
    return 0, lane
end