1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
--[[ 
 编码: 
 名称: GetLocationStatusByRow 
 作者: 
 入口函数:GetLocationStatusByRow 
 功能说明: 
 变更历史: 
 --]] 
 
 
json = require("json")
mobox = require("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
wms_base = require( "wms_base" )
 
function GetLocationStatusByRow(strLuaDEID) 
    local nRet, inputData = m3.GetSysDataJson(strLuaDEID)
    if nRet ~= 0 then
        lua.Stop(strLuaDEID, "无法获取数据包!") 
        return
    end
 
    local wh_code = inputData.wh_code
    local area_code = inputData.area_code
    local row = inputData.n_row
 
    if wh_code == "" or area_code == "" then
        lua.Stop(strLuaDEID, "仓库号和库区号不能为空!") 
        return
    end
    if (area_code == 'ZG2') then
        -- 联表查询 Location 和 Container
        local strTable = "TN_Location a LEFT JOIN TN_Container b ON a.S_CODE = b.S_POSITION"
        local strAttrs = 
            "a.S_CODE, a.N_ROW, a.N_COL, a.N_LAYER, a.C_ENABLE, a.N_CURRENT_NUM, b.N_EMPTY_FULL, b.N_TYPE"                    
        local strCondition = "a.S_WH_CODE = '" .. wh_code .. "' AND a.S_AREA_CODE = '" .. area_code .. "' AND a.N_ROW = '"..row.."'"
        local nRet, strRetInfo = mobox.queryMultiTable(strLuaDEID, strAttrs, strTable, 100000, strCondition, "a.S_CODE")
        if nRet ~= 0 then
            lua.Stop(strLuaDEID, "查询货位和容器状态失败!")
            return
        end
 
        local queryResult = json.decode(strRetInfo)
        local result_list = {}
        
        for i = 1, #queryResult do
            local row = queryResult[i]
 
            local s_code       = row[1]
            local n_row        = tonumber(row[2])
            local n_col        = tonumber(row[3])
            local n_layer      = tonumber(row[4])
            local c_enable     = row[5]
            local n_current    = tonumber(row[6]) or 0
            local empty_full   = tonumber(row[7])
            local cntr_type    = tonumber(row[8])
 
            local loc_info = {
                code = s_code,
                pos = { n_row, n_col, n_layer },
                status = (c_enable == "Y") and 1 or 0,
                load_status = 0,
                cntr_type = ""
            }
 
            if n_current > 0 then
                -- load_status: 2 表示有货或满,1 表示空
                if empty_full == 1 or empty_full == 2 then
                    loc_info.load_status = 2
                else
                    loc_info.load_status = 1
                end
 
                if cntr_type == 1 then
                    loc_info.cntr_type = "pallet"
                elseif cntr_type == 2 then
                    loc_info.cntr_type = "normal"
                elseif cntr_type == 3 then
                    loc_info.cntr_type = "cell_box"
                elseif cntr_type == 4 then
                    loc_info.cntr_type = "picking_box"
                end
            end
 
            table.insert(result_list, loc_info)
        end
 
        mobox.returnValue(strLuaDEID, 1, lua.table2str(result_list))
    else
        local strRetInfo
        local strHeader = ""
        local strurl = "http://192.168.1.208:8001/api/GetGoodsinfoByContainer"
        nRet, strRetInfo = mobox.sendHttpRequest(strurl, strHeader, lua.table2str(inputData))
 
        if (nRet ~= 0) then
            lua.Stop(strLuaDEID, "接口调用失败! 原因:")
            return
        else
            local retAttrs = json.decode(strRetInfo)
            local errCode = retAttrs.code
            local errMsg = retAttrs["data"]
            if (errCode ~= 200) then
                lua.Stop(strLuaDEID, "接口处理失败! 原因:" .. errMsg) 
                return
            else
                mobox.returnValue(strLuaDEID, 1, lua.table2str(errMsg))
            end
        end
    end
end